DSPRelated.com
Forums

anybody knows how to compute variance of a block of pixel in DCT domain?

Started by walala January 19, 2004
Dear all,

I want to ask the following question:

suppose we have 8x8 image pixels, and if we take variance in the image pixel
domain, that's quite easy; however, can I compute variance by way of 8x8 DCT
domain directly?

Anybody throw some lights to me?

Thanks a lot,

-Walala


"walala" <mizhael@yahoo.com> wrote in message news:<bugthg$23o$1@mozo.cc.purdue.edu>...
> Dear all, > > I want to ask the following question: > > suppose we have 8x8 image pixels, and if we take variance in the image pixel > domain, that's quite easy; however, can I compute variance by way of 8x8 DCT > domain directly? > > Anybody throw some lights to me? > > Thanks a lot, > > -Walala
Hello Walala, The way I would approach this problem is I would look at writing the expression for the variance of your signal in terms of the variances and covariances of your basis functions. Plus I can see a neat application of Parseval's may help a lot. Think about how Parseval's (actually the special case known as Bessel's) theorem relates to the 2nd moments about the origin in both the time and frequency domains. The DCT is easliy related to the DFT, so this isn't a far reach. Plus the second moment about the mean (what you want??) is easy to find if you have the 1st moment and the 2nd moment about the origin. I haven't time to work it out, but I think it would be a kind of neat result. Clay
"walala" <mizhael@yahoo.com> wrote in message
news:bugthg$23o$1@mozo.cc.purdue.edu...
> Dear all, > > I want to ask the following question: > > suppose we have 8x8 image pixels, and if we take variance in the image
pixel
> domain, that's quite easy; however, can I compute variance by way of 8x8
DCT
> domain directly? > > Anybody throw some lights to me? >
Walala, Parseval's Theorem should help with that. Is there preservation of variance? Fred
Hello Fred and Walala,

I sat down and worked out some details, and as I thought the answer
would be neat. Basically if you wish to find the variance of a
sequence (finite length with N elements) and if you have the coefs (N
terms) for a complete orthonormal expansion of said sequence and the
said basis set contains the DC (constant) vector, then the variance is
simply (1/N)times the sum of the squares of the magnitudes for all of
the expansion coefs except for the DC term. The proof of this is not
terribly dfficult. And the proof of this is very similar to the proof
of Bessel's theorem - i.e., the special case of Parseval's theorem.
Since your transform has both an analysis (finds the coefs) and a
synthesis (reconstutes) equations, then just take the defn of variance
and plug in the the synthesis eqn. THen cancel out the DC term. You
will now have a triple sum, so just swap the order of the summation
and the resulting inner product is a Kronecker delta function, and
then you end up with this simple and amazing result.

Clay

p.s. An example. If you have a sequence and it's DFT, where the DFT
uses basis vector's whose normalization is N, then the variance is
simply (1/(N^2)) * times the sum of the squared magnitudes of all of
the coefs except the DC coef.




"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message news:<uOednYoO76V_oJHdRVn-tw@centurytel.net>...
> "walala" <mizhael@yahoo.com> wrote in message > news:bugthg$23o$1@mozo.cc.purdue.edu... > > Dear all, > > > > I want to ask the following question: > > > > suppose we have 8x8 image pixels, and if we take variance in the image > pixel > > domain, that's quite easy; however, can I compute variance by way of 8x8 > DCT > > domain directly? > > > > Anybody throw some lights to me? > > > > Walala, > > Parseval's Theorem should help with that. Is there preservation of > variance? > > Fred
physics@bellsouth.net (Clay S. Turner) wrote in message news:<1ae4d220.0401210623.3309a24d@posting.google.com>...
> Hello Fred and Walala, > > I sat down and worked out some details, and as I thought the answer > would be neat. Basically if you wish to find the variance of a > sequence (finite length with N elements) and if you have the coefs (N > terms) for a complete orthonormal expansion of said sequence and the > said basis set contains the DC (constant) vector, then the variance is > simply (1/N)times the sum of the squares of the magnitudes for all of > the expansion coefs except for the DC term. The proof of this is not > terribly dfficult. And the proof of this is very similar to the proof > of Bessel's theorem - i.e., the special case of Parseval's theorem. > Since your transform has both an analysis (finds the coefs) and a > synthesis (reconstutes) equations, then just take the defn of variance > and plug in the the synthesis eqn. THen cancel out the DC term. You > will now have a triple sum, so just swap the order of the summation > and the resulting inner product is a Kronecker delta function, and > then you end up with this simple and amazing result. > > Clay > > p.s. An example. If you have a sequence and it's DFT, where the DFT > uses basis vector's whose normalization is N, then the variance is > simply (1/(N^2)) * times the sum of the squared magnitudes of all of > the coefs except the DC coef. > > >
Dear Clay, Thank you very much for the detailed answer. I thought I understand at that time. But now after a third looking I should honestly say I still don't understand how to apply this to DCT case. First I try to use matlab to test it. A simple 4x4 case A: 239 15 36 70 235 90 52 51 105 208 51 4 229 3 155 191 Then vectorize it to 16x1 vector: 239 15 36 70 235 90 52 51 105 208 51 4 229 3 155 191 The variance is 7607.45. Then take 4x4 DCT, in matlab just dct(A): 1.0e+002 * 4.04000000000000 1.58000000000000 1.47000000000000 1.58000000000000 0.41710561333885 -0.24091192119367 -0.77469898360071 -0.66328951021585 0.64000000000000 -1.40000000000000 0.44000000000000 1.03000000000000 -0.82220612216233 0.80334391528583 -0.32854449441137 -0.63446593733440 Excluding the DC term, and sum all square of above matrix up: Got 138818. 138818/7607.45=18.24763882772808, is not any factor such as 2, 4, 16, etc. ------------------------ Second, I cannot prove your statement theoratically for NXN DCT... I guess the problem is that I am talking about 2D transform and you are talking about 1D case... Any thoughts? Thanks a lot, -Walala
Hello Walala,
Comments below:

"> Dear Clay,
> > Thank you very much for the detailed answer. I thought I understand at > that time. But now after a third looking I should honestly say I still > don't understand how to apply this to DCT case.
Not a problem, I'll point out the errors
> > First I try to use matlab to test it. A simple 4x4 case A: > > 239 15 36 70 > 235 90 52 51 > 105 208 51 4 > 229 3 155 191
Good example
> > Then vectorize it to 16x1 vector: > > 239 15 36 70 235 90 52 51 105 208 51 4 > 229 3 155 191
So far so good.
> > The variance is 7607.45.
The value you have is the sample variance and I'm using the population variance. It is 7134.9844 for this data set. The difference between the two is the division by N (pop.) or by N-1 (sample). Just choose the correct one at the end of the calculation. It won't matter which one you use as long as you are consistant.
> > Then take 4x4 DCT, in matlab just dct(A): > > 1.0e+002 * > > 4.04000000000000 1.58000000000000 1.47000000000000 > 1.58000000000000 > 0.41710561333885 -0.24091192119367 -0.77469898360071 > -0.66328951021585 > 0.64000000000000 -1.40000000000000 0.44000000000000 > 1.03000000000000 > -0.82220612216233 0.80334391528583 -0.32854449441137 > -0.63446593733440 >
Here you have only done a 1 dimensional DCT on the data. You will need to find the 2 dimensional transform. For your example dataset, it will be approx. (rounded to the nearest integer) 434 164 129 59 -63 85 38 -6 35 -75 132 110 -49 18 -97 -79 where the DC term is 434. Just sum the squares of the integers excluding the DC term we find 114441 and divide by N=16, we get 7152.56. If instead of rounding to the nearest integer we use the full precision, we get the correct value for the variance. The sum of the squares is then 114111.75. For your case of using the sample variance, just divide by 15 in this case. 114111.75/15 = 7607.45.
> Excluding the DC term, and sum all square of above matrix up: > > Got 138818. > > 138818/7607.45=18.24763882772808, is not any factor such as 2, 4, 16, > etc. > > ------------------------ > Second, I cannot prove your statement theoratically for NXN DCT... I > guess the problem is that I am talking about 2D transform and you are > talking about 1D case...
The 2-D case is okay in that it is separable. So only a 1-D proof is needed.
> > Any thoughts? > > Thanks a lot, > > -Walala
I think you should be able to make it work now. Clay
An explanatory note to wallala: 

The population variance is used when the data include the entire 
population, as here. Then the variance is THE variance. When the data 
represent a sample of a larger population, the sample variance gives a 
better estimate of the variance of the entire population. It's a matter 
of counting degrees of freedom, but I forget the details.

Jerry
-- 
Engineering is the art of making what you want from things you can get.
&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
"Clay S. Turner" <CSTurner@WSE.Biz> wrote in message
news:5omRb.1541$qR3.571@bignews3.bellsouth.net...
> Hello Walala, > Comments below: > > "> Dear Clay, > > > > Thank you very much for the detailed answer. I thought I understand at > > that time. But now after a third looking I should honestly say I still > > don't understand how to apply this to DCT case. > > Not a problem, I'll point out the errors > > > > > First I try to use matlab to test it. A simple 4x4 case A: > > > > 239 15 36 70 > > 235 90 52 51 > > 105 208 51 4 > > 229 3 155 191 > > Good example > > > > > Then vectorize it to 16x1 vector: > > > > 239 15 36 70 235 90 52 51 105 208 51 4 > > 229 3 155 191 > > So far so good. > > > > > The variance is 7607.45. > > > The value you have is the sample variance and I'm using the population > variance. It is 7134.9844 for this data set. The difference between the
two
> is the division by N (pop.) or by N-1 (sample). > Just choose the correct one at the end of the calculation. It won't matter > which one you use as long as you are consistant. > > > > > Then take 4x4 DCT, in matlab just dct(A): > > > > 1.0e+002 * > > > > 4.04000000000000 1.58000000000000 1.47000000000000 > > 1.58000000000000 > > 0.41710561333885 -0.24091192119367 -0.77469898360071 > > -0.66328951021585 > > 0.64000000000000 -1.40000000000000 0.44000000000000 > > 1.03000000000000 > > -0.82220612216233 0.80334391528583 -0.32854449441137 > > -0.63446593733440 > > > > Here you have only done a 1 dimensional DCT on the data. You will need to > find the 2 dimensional transform. For your example dataset, it will be > approx. (rounded to the nearest integer) > > 434 164 129 59 > -63 85 38 -6 > 35 -75 132 110 > -49 18 -97 -79 > > where the DC term is 434. > > Just sum the squares of the integers excluding the DC term we find 114441 > and divide by N=16, we get 7152.56. If instead of rounding to the nearest > integer we use the full precision, we get the correct value for the > variance. The sum of the squares is then 114111.75. For your case of
using
> the sample variance, just divide by 15 in this case. 114111.75/15 = > 7607.45. > > > > Excluding the DC term, and sum all square of above matrix up: > > > > Got 138818. > > > > 138818/7607.45=18.24763882772808, is not any factor such as 2, 4, 16, > > etc. > > > > ------------------------ > > Second, I cannot prove your statement theoratically for NXN DCT... I > > guess the problem is that I am talking about 2D transform and you are > > talking about 1D case... > > The 2-D case is okay in that it is separable. So only a 1-D proof is
needed.
> > > > > > Any thoughts? > > > > Thanks a lot, > > > > -Walala > > > I think you should be able to make it work now. > > Clay > >
Dear Clay, Thank you so much! Now I understand! Have a great day! Michael.
"Jerry Avins" <jya@ieee.org> wrote in message
news:5cc6b040.0401270953.6841fa58@posting.google.com...
> An explanatory note to wallala: > > The population variance is used when the data include the entire > population, as here. Then the variance is THE variance. When the data > represent a sample of a larger population, the sample variance gives a > better estimate of the variance of the entire population. It's a matter > of counting degrees of freedom, but I forget the details. > > Jerry > -- > Engineering is the art of making what you want from things you can get.
Dear Jerry, That's interesting! Anything that I did not know before is interesting... Thank you so much! Have a great day! Walala