I am new to cross-correlation. I am working on images which having many multiple repeating pattern. I want to find shift in the image. I have initial image and then I shifted that image a bit in x and y direction.
For example you can take any repeating pattern image like :- https://depositphotos.com/vector-images/repeat-structure.html.
When I am using register_translation
for finding shift in image, it's giving me the shift but its wrong. The reason behind is that there are multiple repeating structure in input image.
I want something which can give me multiple peaks after correlation so manually I can correct some code and can find shift in two images correctly. Is there any way to correct the code so that I can get not one but multiple peaks after doing cross-correlation of two images?
code what i did
image = cv2.imread('/content/download.jpg',0)
shift = (0,0)
offset_image = fourier_shift(np.fft.fftn(image), shift)
offset_image = np.fft.ifftn(offset_image)
print("Known offset (y, x): {}".format(shift))
shift, error, diffphase = register_translation(image, offset_image)
fig = plt.figure(figsize=(8, 3))
ax1 = plt.subplot(1, 3, 1)
ax2 = plt.subplot(1, 3, 2, sharex=ax1, sharey=ax1)
ax3 = plt.subplot(1, 3, 3)
ax1.imshow(image, cmap='gray')
ax1.set_axis_off()
ax1.set_title('Reference image')
ax2.imshow(offset_image.real, cmap='gray')
ax2.set_axis_off()
ax2.set_title('Offset image')
image_product = np.fft.fft2(image) * np.fft.fft2(offset_image).conj()
cc_image = np.fft.fftshift(np.fft.ifft2(image_product))
x=cc_image[0].real
x.sort()
print(x)
ax3.imshow(cc_image.real)
ax3.set_axis_off()
ax3.set_title("Cross-correlation")
plt.show()
Here in code if we look at croos-correlation image we can see there are lot of peak if there are repeating pattern in the image. But register_translation
gives a shift on base of single peak. But there are many other peaks also so how i can get all of them.