How does Mean Filter work?
조회 수: 10 (최근 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!