필터 지우기
필터 지우기

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