def correlate(x, y):
from numpy import fft
sx = numpy.array(x.shape)
sy = numpy.array(y.shape)
if (sx >= sy).sum():
slices = [slice(None, sx[i] - sy[i] + 1) for i in range(len(sx))]
X = fft.fftn(x)
Y = fft.fftn(zerofill(y, sx))
else:
sf = sx + sy - 1
slices = [slice(None, sf[i]) for i in range(len(sf))]
X = fft.fftn(x, sf)
Y = fft.fftn(zerofill(y, sf), sf)
return fft.ifftn(X.conjugate() * Y)[slices].real
评论列表
文章目录