Python Forum

Full Version: Find a shift between 2 pictures
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I have for a project to find a shift between 2 pictures:

[Image: zwvy.tiff]

[Image: smaa.tiff]

I checked with imageJ that the shift is few pixels but I have to be sure with Spyder, this is what I tried:

from scipy.signal import correlate2d
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks


img1=Image.open("combination28_8_5.tiff")
img2=Image.open("combination28_8_15.tiff")

arr1=np.array(img1,dtype=float)
arr2=np.array(img2,dtype=float)

profile1=arr1[:,15]
profile2=arr2[:,15]


# Find the position of the first peak
peak1_position = np.argmax(profile1)

# Create a new array with the first peak removed
data2 = np.delete(profile1  , peak1_position)

# Find the position of the second peak
peak2_position = np.argmax(profile2)

# Calculate the distance between the two peaks in pixels
distance_between_peaks = peak2_position - peak1_position

print("Distance between peaks in pixels: ", distance_between_peaks)
I tried to have the correlation of these 2 images to deduce the shift of the 2 pictures in general ( in x and y ), this is why I tried to plot the profile of the two pictures and measure the difference between the 2 plot (because they are almost the same). My supervisor doesn't like this way to do it, can you give me a program to find the shift (in pixels) of the second image compared to the first one ?

Thank you