Finding Local mean value of pixels of window
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Emerson Nithiyaraj
am 19 Mär. 2019
Kommentiert: Nehal fawzy
am 7 Apr. 2019

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 Kommentar
Nehal fawzy
am 7 Apr. 2019
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
Akzeptierte Antwort
Jan
am 19 Mär. 2019
Bearbeitet: Jan
am 19 Mär. 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
