How does Mean Filter work?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Beena Bethel
2018-7-3
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
2018-7-3
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.
回答(1 个)
Walter Roberson
2016-5-26
>> 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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!