Perform Local Mean with circular neighboorhod

1 view (last 30 days)
Andres Fonts
Andres Fonts on 4 Jul 2017
Commented: Adam on 4 Jul 2017
Hi! I would like to perform a local mean to an image. I am using conv2 function. I know that to compute the local mean of each pixel i may do, for example, something like this:
C = conv2(A, ones(3)/9, 'same')
Where A is the image. This should perform a local mean of a pixel and its 9 surrounding pixels ina 3x3 box.
So, what if I would like to do this local mean calculation but with the surrounding pixels placed in a circle of a certain radius?
I have tried doing the following:
r = 15;
x = -r:r;
y = -r:r;
[X,Y] = meshgrid(x,y);
circ = power(X,2) + power(Y,2) < power(r,2);
kernelMean = double(circ)/(r*2)^2;
So r is the radius and kernelMean would replace ones(3)/9 in the previous example.
Is that correct? I have tried but I am not getting the expected results... May am I doing something wrong?
Thanks!
  1 Comment
Adam
Adam on 4 Jul 2017
kernelMean = double(circ)/nnz( circ );
looks like it would be what is needed. You don't have a perfect circle, of course, with pixels so you should get the count of the number of non-zero pixels in your mask rather than trying to use analytical circle geometry.
I haven't tried applying this to an image, but it does at least provide a kernel whose elements sum to 1.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!