Discussion:
[SciPy-User] Using scipy.signal.fftconvolve() and scipy.signal.convolve()
Ábel Dániel
2011-01-18 19:58:28 UTC
Permalink
[apologies if this might get duplicated, it appears my first
submission didn't show up on the mailling list]

Hi!

I would like to ask some help with the use of scipy.signal.convolve
and scipy.signal.fftconvolve. (On a greyscale 2d image.)

Based on the documentation of fftconvolve (which is simply 'See
convolve.'), I am assuming that they should give (mostly) the same
result. (I.e. the result won't be exactly identical since they are
using different methods, but they shouldn't be too different.)

However, I am getting drastically different results: using convolve
results in basically random noise, while fftconvolve gives a very
sharp peak.

I uploaded a short program with the input and the results I am getting
to http://hal.elte.hu/~abeld/scipy_signal_issue/

Am I doing something wrong? Should there be such a difference in the
output of these functions? What is causing the difference?

(I am using Ubuntu Lucid, version of python-scipy package is
0.7.0-2ubuntu0.1)

Thanks in advance,
Daniel Abel
***@freemail.hu
David Baddeley
2011-01-18 21:19:24 UTC
Permalink
What you're getting form fftconvolve looks about right - with ordinary convolve
I suspect your problem might be that you're using 8 bit ints and it's
overflowing & thus giving you the random noise pattern. Ffts cast their inputs
to double first. I'd suggest casting your image to float - ie:
a = a.astype('f')
before doing the standard convolutions.

cheers,
David


----- Original Message ----
From: Ábel Dániel <***@freemail.hu>
To: scipy-user <scipy-***@scipy.org>
Sent: Wed, 19 January, 2011 8:58:28 AM
Subject: [SciPy-User] Using scipy.signal.fftconvolve() and
scipy.signal.convolve()

[apologies if this might get duplicated, it appears my first
submission didn't show up on the mailling list]

Hi!

I would like to ask some help with the use of scipy.signal.convolve
and scipy.signal.fftconvolve. (On a greyscale 2d image.)

Based on the documentation of fftconvolve (which is simply 'See
convolve.'), I am assuming that they should give (mostly) the same
result. (I.e. the result won't be exactly identical since they are
using different methods, but they shouldn't be too different.)

However, I am getting drastically different results: using convolve
results in basically random noise, while fftconvolve gives a very
sharp peak.

I uploaded a short program with the input and the results I am getting
to http://hal.elte.hu/~abeld/scipy_signal_issue/

Am I doing something wrong? Should there be such a difference in the
output of these functions? What is causing the difference?

(I am using Ubuntu Lucid, version of python-scipy package is
0.7.0-2ubuntu0.1)

Thanks in advance,
Daniel Abel
***@freemail.hu
Chris Rodgers
2011-01-19 02:21:37 UTC
Permalink
While the output from the convolution statements looks qualitatively
correct to me, I always have difficulty interpreting them because I
don't know the "lags" associated with each value. By lag I mean the
amount by which one signal was delayed before calculating the dot
product of the two signals. In Matlab for example, the conv function
returns both the values and a separate array called "lags" of the same
size, which is very helpful.

The scipy documentation is not very clear on this point. Does anyone
know a good resource documenting the lags in each of the 3 modes of
operation ('same', 'valid', 'full')? I tried convolving dummy
sequences ([0,1,0,0] etc) but I couldn't figure it out.

Thanks!!
Chris



On Tue, Jan 18, 2011 at 1:19 PM, David Baddeley
Post by David Baddeley
What you're getting form fftconvolve looks about right - with ordinary convolve
I suspect your problem might be that you're using 8 bit ints and it's
overflowing & thus giving you the random noise pattern. Ffts cast their inputs
a = a.astype('f')
before doing the standard convolutions.
cheers,
David
----- Original Message ----
Sent: Wed, 19 January, 2011 8:58:28 AM
Subject: [SciPy-User] Using scipy.signal.fftconvolve() and
scipy.signal.convolve()
[apologies if this might get duplicated, it appears my first
submission didn't show up on the mailling list]
Hi!
I would like to ask some help with the use of scipy.signal.convolve
and scipy.signal.fftconvolve. (On a greyscale 2d image.)
Based on the documentation of fftconvolve (which is simply 'See
convolve.'), I am assuming that they should give (mostly) the same
result. (I.e. the result won't be exactly identical since they are
using different methods, but they shouldn't be too different.)
However, I am getting drastically different results: using convolve
results in basically random noise, while fftconvolve gives a very
sharp peak.
I uploaded a short program with the input and the results I am getting
to http://hal.elte.hu/~abeld/scipy_signal_issue/
Am I doing something wrong? Should there be such a difference in the
output of these functions? What is causing the difference?
(I am using Ubuntu Lucid, version of python-scipy package is
0.7.0-2ubuntu0.1)
Thanks in advance,
Daniel Abel
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
j***@gmail.com
2011-01-19 02:57:53 UTC
Permalink
On Tue, Jan 18, 2011 at 9:21 PM, Chris Rodgers
Post by Chris Rodgers
While the output from the convolution statements looks qualitatively
correct to me, I always have difficulty interpreting them because I
don't know the "lags" associated with each value. By lag I mean the
amount by which one signal was delayed before calculating the dot
product of the two signals. In Matlab for example, the conv function
returns both the values and a separate array called "lags" of the same
size, which is very helpful.
The scipy documentation is not very clear on this point. Does anyone
know a good resource documenting the lags in each of the 3 modes of
operation ('same', 'valid', 'full')? I tried convolving dummy
sequences ([0,1,0,0] etc) but I couldn't figure it out.
valid and full have a clear definition
for valid, signal convolve cuts on both sides symmetrically, I think.
I wrote some helper functions, so I don't have to think. And I found
the comparison
with ndimage useful, because it has an option for this.
Post by Chris Rodgers
Post by David Baddeley
from scipy.signal import convolve
convolve(np.arange(1,10), [0.1, 0, 1], mode='valid')
array([ 1.3, 2.4, 3.5, 4.6, 5.7, 6.8, 7.9])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 1], mode='full')
array([ 0.1, 0.2, 1.3, 2.4, 3.5, 4.6, 5.7, 6.8, 7.9, 8. , 9. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 1], mode='same')
array([ 0.2, 1.3, 2.4, 3.5, 4.6, 5.7, 6.8, 7.9, 8. ])

not so clear with even length window
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0, 1], mode='full')
array([ 0.1, 0.2, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8, 6.9, 7. , 8. ,
9. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0, 1], mode='same')
array([ 0.2, 0.3, 1.4, 2.5, 3.6, 4.7, 5.8, 6.9, 7. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0,0, 1], mode='full')
array([ 0.1, 0.2, 0.3, 0.4, 1.5, 2.6, 3.7, 4.8, 5.9, 6. , 7. ,
8. , 9. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0,0, 1], mode='same')
array([ 0.3, 0.4, 1.5, 2.6, 3.7, 4.8, 5.9, 6. , 7. ])

I think I usually avoided same

Josef
Post by Chris Rodgers
Thanks!!
Chris
On Tue, Jan 18, 2011 at 1:19 PM, David Baddeley
Post by David Baddeley
What you're getting form fftconvolve looks about right - with ordinary convolve
I suspect your problem might be that you're using 8 bit ints and it's
overflowing & thus giving you the random noise pattern. Ffts cast their inputs
a = a.astype('f')
before doing the standard convolutions.
cheers,
David
----- Original Message ----
Sent: Wed, 19 January, 2011 8:58:28 AM
Subject: [SciPy-User] Using scipy.signal.fftconvolve() and
scipy.signal.convolve()
[apologies if this might get duplicated, it appears my first
submission didn't show up on the mailling list]
Hi!
I would like to ask some help with the use of scipy.signal.convolve
and scipy.signal.fftconvolve. (On a greyscale 2d image.)
Based on the documentation of fftconvolve (which is simply 'See
convolve.'), I am assuming that they should give (mostly) the same
result. (I.e. the result won't be exactly identical since they are
using different methods, but they shouldn't be too different.)
However, I am getting drastically different results: using convolve
results in basically random noise, while fftconvolve gives a very
sharp peak.
I uploaded a short program with the input and the results I am getting
to http://hal.elte.hu/~abeld/scipy_signal_issue/
Am I doing something wrong? Should there be such a difference in the
output of these functions? What is causing the difference?
(I am using Ubuntu Lucid, version of python-scipy package is
0.7.0-2ubuntu0.1)
Thanks in advance,
Daniel Abel
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
j***@gmail.com
2011-01-19 02:58:52 UTC
Permalink
Post by j***@gmail.com
On Tue, Jan 18, 2011 at 9:21 PM, Chris Rodgers
Post by Chris Rodgers
While the output from the convolution statements looks qualitatively
correct to me, I always have difficulty interpreting them because I
don't know the "lags" associated with each value. By lag I mean the
amount by which one signal was delayed before calculating the dot
product of the two signals. In Matlab for example, the conv function
returns both the values and a separate array called "lags" of the same
size, which is very helpful.
The scipy documentation is not very clear on this point. Does anyone
know a good resource documenting the lags in each of the 3 modes of
operation ('same', 'valid', 'full')? I tried convolving dummy
sequences ([0,1,0,0] etc) but I couldn't figure it out.
valid and full have a clear definition
for valid, signal convolve cuts on both sides symmetrically, I think.
typo
for "same", signal convolve ...
Post by j***@gmail.com
I wrote some helper functions, so I don't have to think. And I found
the comparison
with ndimage useful, because it has an option for this.
Post by Chris Rodgers
Post by David Baddeley
from scipy.signal import convolve
convolve(np.arange(1,10), [0.1, 0, 1], mode='valid')
array([ 1.3,  2.4,  3.5,  4.6,  5.7,  6.8,  7.9])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 1], mode='full')
array([ 0.1,  0.2,  1.3,  2.4,  3.5,  4.6,  5.7,  6.8,  7.9,  8. ,  9. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 1], mode='same')
array([ 0.2,  1.3,  2.4,  3.5,  4.6,  5.7,  6.8,  7.9,  8. ])
not so clear with even length window
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0, 1], mode='full')
array([ 0.1,  0.2,  0.3,  1.4,  2.5,  3.6,  4.7,  5.8,  6.9,  7. ,  8. ,
       9. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0, 1], mode='same')
array([ 0.2,  0.3,  1.4,  2.5,  3.6,  4.7,  5.8,  6.9,  7. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0,0, 1], mode='full')
array([ 0.1,  0.2,  0.3,  0.4,  1.5,  2.6,  3.7,  4.8,  5.9,  6. ,  7. ,
       8. ,  9. ])
Post by Chris Rodgers
Post by David Baddeley
convolve(np.arange(1,10), [0.1, 0, 0,0, 1], mode='same')
array([ 0.3,  0.4,  1.5,  2.6,  3.7,  4.8,  5.9,  6. ,  7. ])
I think I usually avoided same
Josef
Post by Chris Rodgers
Thanks!!
Chris
On Tue, Jan 18, 2011 at 1:19 PM, David Baddeley
Post by David Baddeley
What you're getting form fftconvolve looks about right - with ordinary convolve
I suspect your problem might be that you're using 8 bit ints and it's
overflowing & thus giving you the random noise pattern. Ffts cast their inputs
a = a.astype('f')
before doing the standard convolutions.
cheers,
David
----- Original Message ----
Sent: Wed, 19 January, 2011 8:58:28 AM
Subject: [SciPy-User] Using scipy.signal.fftconvolve() and
scipy.signal.convolve()
[apologies if this might get duplicated, it appears my first
submission didn't show up on the mailling list]
Hi!
I would like to ask some help with the use of scipy.signal.convolve
and scipy.signal.fftconvolve. (On a greyscale 2d image.)
Based on the documentation of fftconvolve (which is simply 'See
convolve.'), I am assuming that they should give (mostly) the same
result. (I.e. the result won't be exactly identical since they are
using different methods, but they shouldn't be too different.)
However, I am getting drastically different results: using convolve
results in basically random noise, while fftconvolve gives a very
sharp peak.
I uploaded a short program with the input and the results I am getting
to http://hal.elte.hu/~abeld/scipy_signal_issue/
Am I doing something wrong? Should there be such a difference in the
output of these functions? What is causing the difference?
(I am using Ubuntu Lucid, version of python-scipy package is
0.7.0-2ubuntu0.1)
Thanks in advance,
Daniel Abel
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
Abel Daniel
2011-01-19 08:19:10 UTC
Permalink
Post by David Baddeley
What you're getting form fftconvolve looks about right - with ordinary convolve
I suspect your problem might be that you're using 8 bit ints and it's
overflowing & thus giving you the random noise pattern. Ffts cast their inputs
a = a.astype('f')
before doing the standard convolutions.
Thanks!
Indeed that was the problem, casting as you suggested results in convolve giving
the same results as fftconvolve

Daniel Abel
***@freemail.hu

Loading...