how 2x2 median filter works
10 次查看(过去 30 天)
显示 更早的评论
hi I tried this
- a = [ 1 2 3 ; 4 5 6; 7 8 9]
- b = medfilt2(a);
Output is [0,2,0;2,5,3;0,5,0]
How were values of b calculated from a ?
I can't figure out the logic.
Thanks.
0 个评论
回答(2 个)
KSSV
2017-8-29
When ever you use a function in MATLAB.....it should be a common practice to read the documentation part of it. Read the documentation: https://in.mathworks.com/help/images/ref/medfilt2.html. The doc mentions the reference for the function. You may refer that for further idea.
Lim, Jae S., Two-Dimensional Signal and Image Processing, Englewood Cliffs, NJ, Prentice Hall, 1990, pp. 469-476.
3 个评论
Image Analyst
2017-9-2
Because when the window is centered such that most of the window is "off the image", the off image pixels are considered 0. Since most of the pixels are 0, 0 is the median.
Image Analyst
2017-9-30
When the image is this:
a =
1 2 3
4 5 6
7 8 9
and you're using a 2x2 window, and the 2x2 window is in the upper left, it will see
0 0
0 1
The zeros are where the window is off the array. So the median of three zeros and a 1 is zero, so that's why you got a zero in the upper left element of your output.
2 个评论
Image Analyst
2017-9-30
Are you using a 2x2, like your subject line says, or a 3x3 like your code does?
a = [ 1 2 3 ; 4 5 6; 7 8 9]
am3x3 = medfilt2(a)
am2x2 = medfilt2(a, [2, 2])
a =
1 2 3
4 5 6
7 8 9
am3x3 =
0 2 0
2 5 3
0 5 0
am2x2 =
3 4 1.5
6 7 3
3.5 4 0
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!