开发者

The concept behind scipy.signal.medfilt2d in python

I am trying to understand how scipy.signal.medfilt2d works. After I looked at the scipy documentation, its format is:

scipy.signal.medfilt2d(input, kernel_size=3)

So like if I have a开发者_JS百科 matrix like

1 2 3 7 2 4
3 4 2 2 6 7
1 7 3 1 2 6
3 2 3 4 3 1
2 6 7 8 2 5
3 4 2 2 1 8

Since the kernel size is set to 3 in default. If I apply medfilt2d to this matrix, will the matrix become the one like below? ( what I did is take every element inside the 3 x 3 box, add them all up and divide by 9 ( average) )

2.8   2.8   2.8   4.1   4.1  4.1
2.8   2.8   2.8   4.1   4.1  4.1
2.8   2.8   2.8   4.1   4.1  4.1
3.5   3.5   3.5   3.7   3.7  3.7
3.5   3.5   3.5   3.7   3.7  3.7
3.5   3.5   3.5   3.7   3.7  3.7

So please share your knowledge and insight with me? Tell me if I am wrong so I can learn from this mistake. Thanks a lot


As explained in the Scipy documentation, medfilt2 is a median filter. Quoting from the documentation,

The sample median is the middle array value in a sorted list of neighborhood values

So for your example, the submatrix at position 1,1

1 2 3
3 4 2
1 7 3

would be sorted into

1 1 2 2 3 3 3 4 7

The middle element is 3 so that would be the output of the filter. There's more detail on Wikipedia.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜