[SciPy-User] Sign or weights reversal in ndimage.convolve?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] Sign or weights reversal in ndimage.convolve?

Juan Nunez-Iglesias
Hi,

Can someone clear up exactly what ndimage.convolve does with the weights input? Here's an example session:

In [1]: sig = np.array([0, 0, 1, 1, 0, 0])
In [2]: w = np.array([-1, 1])
In [3]: from scipy import ndimage as nd
In [4]: nd.convolve(sig, w)
Out[4]: array([ 0, -1,  0,  1,  0,  0])

I would have expected the output to be [0, 1, 0, -1, 0, 0]. ie:

out[1] = sig[1]w[0] + sig[2]w[1] = 0 * -1 + 1 * 1 = 1.

Where am I going wrong?

Thanks!

Juan.



_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Sign or weights reversal in ndimage.convolve?

Juan Nunez-Iglesias
Erm, never mind, a quick trip to Wikipedia shows that I was confusing convolution with cross-correlation. Sorry for the noise! =)

http://en.wikipedia.org/wiki/Convolution




On Wed, Feb 11, 2015 at 10:36 PM, Juan Nunez-Iglesias <[hidden email]> wrote:

Hi,

Can someone clear up exactly what ndimage.convolve does with the weights input? Here's an example session:

In [1]: sig = np.array([0, 0, 1, 1, 0, 0])
In [2]: w = np.array([-1, 1])
In [3]: from scipy import ndimage as nd
In [4]: nd.convolve(sig, w)
Out[4]: array([ 0, -1,  0,  1,  0,  0])

I would have expected the output to be [0, 1, 0, -1, 0, 0]. ie:

out[1] = sig[1]w[0] + sig[2]w[1] = 0 * -1 + 1 * 1 = 1.

Where am I going wrong?

Thanks!

Juan.




_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user