How does Mean Filter work?
Afficher commentaires plus anciens
I created a small code to see how does Mean Filter work.
How does it get values?? What is the equation?
A = [ 1 2 3; 4 5 6; 7 8 9]
h = ones(3,3)
imfilter(A,h)
12 21 16
27 45 33
24 39 28
I get this as output, I don't understand how exactly 12,21,16,27 is calculated using imfilter command with 3 by 3 filter.
2 commentaires
Beena Bethel
le 3 Juil 2018
Its taking the sum of the neighboring pixels in the example shown here and not the average. I did not understand how whether it takes sum or average of its neighboring pixels....
Walter Roberson
le 3 Juil 2018
This is taking the sum, according to the weighting stored in h. Except for the edge cases you can use
imfilter(A, h/numel(h))
to get the average.
Getting the edge cases right is a little tougher:
imfilter(A, h) ./ imfilter(ones(size(A)), h)
The denominator is effectively counting the number of pixels that are in the neighborhood -- the number of pixels whose value contributed to the sum.
Réponses (1)
Walter Roberson
le 26 Mai 2016
>> conv2(A,fliplr(flipud(h)))
ans =
1 3 6 5 3
5 12 21 16 9
12 27 45 33 18
11 24 39 28 15
7 15 24 17 9
>> conv2(A,fliplr(flipud(h)), 'same')
ans =
12 21 16
27 45 33
24 39 28
>> imfilter(A,h)
ans =
12 21 16
27 45 33
24 39 28
Catégories
En savoir plus sur Image Filtering dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!