[SciPy-User] Using scipy.signal.fftconvolve() and scipy.signal.convolve()
josef.pktd at gmail.com
josef.pktd at gmail.com
Tue Jan 18 21:58:52 EST 2011
On Tue, Jan 18, 2011 at 9:57 PM, <josef.pktd at gmail.com> wrote:
> On Tue, Jan 18, 2011 at 9:21 PM, Chris Rodgers
> <chris.rodgers at berkeley.edu> wrote:
>> 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 ...
> 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.
>
> integer is start, decimal is end, if I did it correctly:
>
>>>> 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])
>>>> 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. ])
>>>> 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
>
>>>> 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. ])
>>>> 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. ])
>
>>>> 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. ])
>>>> 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
>
>>
>> Thanks!!
>> Chris
>>
>>
>>
>> On Tue, Jan 18, 2011 at 1:19 PM, David Baddeley
>> <david_baddeley at yahoo.com.au> wrote:
>>> 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 <abli at freemail.hu>
>>> To: scipy-user <scipy-user at 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
>>> abli at freemail.hu
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>
More information about the SciPy-User
mailing list