As per this post the cross-correlation between 2 images is obtained as it follows:
def cross_correlate_2d(x, h):
h = ifftshift(ifftshift(h, axes=0), axes=1)
return ifft2(fft2(x) * np.conj(fft2(h))).real
x = np.array(Image.open("covid.png").convert("L")) / 255.
h1 = x.copy()
out1 = cross_correlate_2d(x, h1)
This works fine in case the images have same dimensions, otherwise (when sizes differ) the multiplication
fft2(x) * np.conj(fft2(h))
will not work since the rule for matrices multiplication is not respected (nrCols 1st matrix = nrRows 2nd matrix)
Let's say the template image is smaller in dimensions.
Could i fill it with 0's up until the target image rows and cols values are obtained and after that fft2D it and then continue the process?