Finding Local mean value of pixels of window
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to solve the equation (1,2) in the attached picture which (2) tells the local mean value of the window. But i don't have any idea about how to evaluate this equation using matlab code. I could only guess w indicates window size. If i fix w=5 in this equation (2), then m and n starts from negative values. What does g(m,n) means? Can anyone please help me to solve this concept? I have tried some coding and please helpme to solve this.
w=5;
for i = 1:size(a,1) %a is my input image
for j = 1:size(a,2)
for m = i-(w/2):i+(w/2)
for n = j-(w/2):j+(w/2)
Output(i,j)= (1/(w*w))*Output(m,n);
end
end
end
end
댓글 수: 1
Nehal fawzy
2019년 4월 7일
can u help me i work in u point when i enter u code with image (a)
there is error
Output(i,j)= (1/(w*w))*Output(m,n);
how i can rewrite it
채택된 답변
Jan
2019년 3월 19일
편집: Jan
2019년 3월 19일
A simple approach:
w = 5;
w2 = floor(w / 2);
sA = size(a);
SumA = zeros(sA);
DivA = zeros(sA);
for i = 1:sA(1) %a is my input image
for j = 1:sA(2)
for m = max(1, i-w2):min(i+w2, sA(1)) % Consider boundaries
for n = max(1, j-w2):min(j+w2, sA(2))
SumA(i,j) = SumA(i, j) + a(m,n);
DivA(i,j) = DivA(i, j) + 1;
end
end
end
end
Output = SumA ./ DivA;
Now the Output is the average over 5x5 elements except for the edges, which use less elements for averaging.
This can be done much faster with conv2:
Output = conv2(ones(5,1)/5, ones(1,5)/5, a, 'same');
This differs at the boundaries.
댓글 수: 2
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!