Effacer les filtres
Effacer les filtres

Perform Local Mean with circular neighboorhod

1 vue (au cours des 30 derniers jours)
Andres Fonts
Andres Fonts le 4 Juil 2017
Commenté : Adam le 4 Juil 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 commentaire
Adam
Adam le 4 Juil 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.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by