1 Mode
Below the output of three modes:
Filter size must be odd number, eg: 3x3, 5x5. here we consider the situation which the size of image is not less than the size of filter.
let image: m x m and filter: n x n
mode | size of ouptut | extend matrix size |
---|---|---|
full | m + n - 1 | m + 2(n - 1) |
same | m | m + n - 1 |
valid | m - n + 1 | m |
if: A is 6x6, m = 6 V is 3x3, n = 3
1.1 full
mode | size of ouptut | extend matrix size |
---|---|---|
full | 6+3-1 = 8 | 6+2*(3-1) = 10 |
1.2 same
mode | size of ouptut | extend matrix size |
---|---|---|
same | 6 | 6+3-1 = 8 |
1.3 valid
mode | size of ouptut | extend matrix size |
---|---|---|
valid | 6-3+1 = 4 | 6 |
2 Codes
Only using numpy implement the conv2d, and compare the ouput with scipy.signal.convolve2d.
3 References
http://www.songho.ca/dsp/convolution/convolution2d_example.html?source=post_page
https://blog.csdn.net/leviopku/article/details/80327478
https://docs.scipy.org/doc/numpy/reference/generated/numpy.convolve.html
https://blog.csdn.net/majinlei121/article/details/50256049