Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

image processing: gauss filter question

Status
Not open for further replies.

Balázs Torma

Newbie level 3
Joined
Feb 28, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
41
Hi there,

I am now getting familiar with the gauss filter in image processing, playing around with it a little. I noticed that the filter in matlab is quite sensitive on the mean value of the picture pixels, which I would not expect. In particular I notice that variance on filtered image is depending on the mean value of the original image. I would expect that the filtered variance only depends on the original variance and not on the offset (= mean).

Here a matlab script to see the problem:

function testGaussianFilterOffset()

H = fspecial('gaussian', 15, 2);

for offset=0:5:40
A = offset + randn(1000, 1000) * 3;
B = imfilter(A, H);

[ mean(A:))) var(A:))) mean(B:))) var(B:)))]
end


output:

ans =

-0.0013 9.0065 -0.0014 0.1773


ans =

5.0043 9.0055 4.9887 0.1999


ans =

9.9995 8.9847 9.9682 0.2668


ans =

15.0045 9.0293 14.9575 0.3763


ans =

20.0017 9.0093 19.9393 0.5345

ans =

25.0010 9.0313 24.9232 0.7299


ans =

30.0035 8.9988 29.9100 0.9766


ans =

35.0042 8.9951 34.8950 1.2593


ans =

40.0027 9.0041 39.8779 1.5867

mean originalvariance originalmean filteredvariance filtered
-0.00139.0065-0.00140.1773
5.00439.00554.98870.1999
9.99958.98479.96820.2668
15.00459.029314.95750.3763
20.00179.009319.93930.5345
25.00109.031324.92320.7299
30.00358.998829.91000.9766
35.00428.995134.89501.2593
40.00279.004139.87791.5867


Here you see an increasing value in the last column (resultig variance), although the original variance is fixed. I expect the filtered variance to be constant as well.

Is this a property of the Gaussian filter I do not understand? Can someone explain this dependency to me pls? Or is this some kind of a numerical matlab problem?

Thanks,
Balazs
 
Last edited:

Remember that whenever,we apply a filter with an image(Convolution),say we use any filter,intuitively the image and the filter are convoluted together to give a matrix(image) that describes the highlighted pixels(which maybe a edge,blob or corner depending upon which filter is being used) with a larger value compared to the surrounding pixels.Even though the mean of the mask(filter) that we use is zero,still the mean of the resulting image wouldn't be the same as the original image,so the change in mean is expected.Now the variance of the convoluted image won't just depend upon the variance of the mask alone as even if we are adding the image with the mask(0 mean,variance:σfilter) and the image(mean :µimg ,variance:σimg.The resulting variance would be,

(√[σimg)2+(σfilter)2+Co-Variance(image,filter)].This is the case for addition of mask with the image,the change in variance when convolution(effectively multiplication) is bound to happen and the resulting variance won't be linear either because of the co-variance term.So the result are correct only.
 

Thanks for the reply!

"still the mean of the resulting image wouldn't be the same as the original image"
Please check the table above more carefully, I collected the numbers into a html table for better visibility. The mean of the resulting image matches the mean of the original, see columns in the table above. This is expected, as the filter should reduce the variance and should not have any effect on the mean (e.g. should not make the picture darker or brighter, just smoother)

"This is the case for addition of mask with the image,the change in variance when convolution(effectively multiplication) is bound to happen and the resulting variance won't be linear either because of the co-variance term"
I am not sure how the co-variance comes into picture as the filter matrix is constant, there is no randomness in it. The variance in the Gaussian kernel controls the degree of filtering, that "variance" is not a parameter of any random distribution.

Anyway, I repeated the same test in a java implementation and did not see a relation between mean of the original and the variance in the resulting image, as expected. So I guess the above table kinda shows a matlab issue.
 

Yeah,the difference between the resulting and original image's mean should be zero.The co-variance term is not to be worried about,but the variance of the Gaussian kernel is determined from the normal distribution assuming zero mean and variance(σfilter).Here the value of sigma physically determines the range of frequencies to be allowed by the image.The resulting variance would be,
(√[(σimg)2+(σfilter)2]

You used the imfilter command in Matlab to convolute the mask with the image.It generally pads values at the end of the image and then truncates it to the size of the image(no. of rows and columns) Try without padding any values at the boundary and you should get a different output.
 
Last edited:

The resulting variance would be,
(√[(σimg)2+(σfilter)2]

Where do you get this relation from, any reference? I think it rather looks like
σresult = σimg / σfilter * Constant,
as the filter reduces the variance instead of increasing it.

Thanks for the idea of the padding, I did not find a way to circumvent that in matlab. But it is rather unlikely to cause the problem as the size of the image is quite big relative to the error caused by padding so I doubt that it counts much in calculating the resulting variance.
 

Sorry that post was valid if for the addition of two distribution,but whereas here it is the multiplication of two signals,so the above mentioned formula in the previous post is not valid.
Also fspecial (assuming 3X3 filter/mask) function creates a filter that is quite different when we create the same 3X3 mask using the Gaussian Kernel formula...That might also be a reason for the error.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top