[SciPy-user] convolve2d.. or Numeric to numarray conversion

Todd Miller jmiller at stsci.edu
Fri Feb 14 12:27:10 EST 2003


Kasper Souren wrote:

>>I just worked through some of this for one of our developers so
>>numarray's Convolve.convolve2d now has an "fft" mode.  The short answer
>>is,  use the convolution theorem and Numeric's FFT module:
>>
>>    Fdata = FFT.real_fft2d(data)
>>    Fkernel = FFT.real_fft2d(kernel)
>>    multiply(Fdata, Fkernel, Fdata)
>>    convolved = inverse_real_fft2d( Fdata)
>>
>>The edges can be a little tricky,  but other than that, it's mostly
>>already implemented (in Numeric) in the form of 2d Fourier transforms.
>> If the kernel you want to use is bigger than about 15x15,  the FFT is
>>also an increasingly faster way of convolving than the brute force
>>approach in numarray-0.4.
>>    
>>
>
>The multiply part gives me some troubles: ValueError: frames are not alligned.
>
>It seems to me that multiply(a, b) just means a * b. And thus a and b need to 
>have the same dimensions. And I don't know how to deal with this problem.
>I guess filling up Fkernel with 0's doesn't make sense
>
>bye,
>Kasper
>
>
>_______________________________________________
>SciPy-user mailing list
>SciPy-user at scipy.net
>http://www.scipy.net/mailman/listinfo/scipy-user
>  
>
I forgot to mention:  when doing FFT-based convolution, the kernel and 
data must be identically shaped.  I do this by sticking the kernel into 
the center of a data-shaped array of zeros.

Todd





More information about the SciPy-User mailing list