フィルターのクリア

Perform Local Mean with circular neighboorhod

1 回表示 (過去 30 日間)
Andres Fonts
Andres Fonts 2017 年 7 月 4 日
コメント済み: Adam 2017 年 7 月 4 日
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
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!

Translated by