Finding Local mean value of pixels of window
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens

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 commentaire
Nehal fawzy
le 7 Avr 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
Réponse acceptée
Jan
le 19 Mar 2019
Modifié(e) : Jan
le 19 Mar 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
