Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

SciPy convolve2d vs Matlab conv2 'same' mode

View gist:4303970
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
In [198]: f = [[2,3,4],[1,6,7]]
 
In [199]: g = [[9,1,0],[2,5,8],[1,3,3]]
 
In [200]: convolve2d(f,g)
Out[200]:
array([[ 18, 29, 39, 4, 0],
[ 13, 71, 108, 51, 32],
[ 4, 26, 71, 104, 68],
[ 1, 9, 28, 39, 21]])
 
In [201]: convolve2d(f,g,'same')
Out[201]:
array([[ 71, 108, 51],
[ 26, 71, 104]])
 
In [202]: convolve2d(g,f,'same')
Out[202]:
array([[ 29, 39, 4],
[ 71, 108, 51],
[ 26, 71, 104]])
 
Compare with the example in http://books.google.com/books?id=fTvQkLBLyK8C&lpg=PA43&ots=0HC1LsH0cE&dq=conv2%20same%20example&pg=PA43#v=onepage&q=conv2%20same%20example&f=false
 
71 108 51
26 71 104
 
and
 
71 108 51
26 71 104
9 28 39
 
http://www.mathworks.com/help/matlab/ref/conv2.html "If there are an odd number of rows or columns, the "center" leaves one more at the beginning than the end."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.