Perform Local Mean with circular neighboorhod
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2017-7-4
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.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!