[SciPy-Dev] conv2 and normxcorr2

awebster at falsecolour.com awebster at falsecolour.com
Tue Dec 31 07:43:28 EST 2013


I noticed a couple of popular matlab functions - conv2 and normxcorr2 
were not present in the scipy.signal packages.  I would like to submit 
them for addition.  Can anyone point me on instructions on how to write 
such a thing?  Below are examples.


# 2D convolution using the convolution's FFT property
def conv2(a,b):
    ma,na = a.shape
    mb,nb = b.shape
    return 
fft.ifft2(fft.fft2(a,[2*ma-1,2*na-1])*fft.fft2(b,[2*mb-1,2*nb-1]))

# compute a normalized 2D cross correlation using convolutions
# this will give the same output as matlab, albeit in row-major order
def normxcorr2(b,a):
    c = conv2(a,flipud(fliplr(b)))
    a = conv2(a**2, ones(b.shape))
    b = sum(b.flatten()**2)
    c = c/sqrt(a*b)
    return c

--
Aaron Webster
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20131231/609f9b33/attachment.html>


More information about the SciPy-Dev mailing list