Python Forum
Find a shift between 2 pictures
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find a shift between 2 pictures
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo put a green boarder and text around multiple pictures jackosullivan 5 1,487 Jul-05-2022, 10:39 AM
Last Post: snippsat
  Random pictures from a file aliwien 2 4,345 Apr-23-2021, 06:00 PM
Last Post: snippsat
  Unable to bit shift and logical OR bytes and ints? MysticLord 7 7,043 Sep-01-2020, 03:31 PM
Last Post: deanhystad
  List index out of range error when attempting to make a basic shift code djwilson0495 4 3,007 Aug-16-2020, 08:56 PM
Last Post: deanhystad
  Writing a basic shift code djwilson0495 2 2,277 Aug-16-2020, 01:52 PM
Last Post: djwilson0495
  Help with taking pictures on raspberry pi octavia 1 1,703 Feb-07-2020, 04:54 PM
Last Post: Larz60+
  client-server pictures mcgrim 4 2,990 Oct-25-2019, 09:53 PM
Last Post: micseydel
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 3,038 Jul-17-2019, 11:55 AM
Last Post: VirtualDreamer
  Open Pictures with Python MaxouRuEnIpTF34 1 3,054 Apr-22-2018, 07:48 PM
Last Post: Gribouillis
  Paramter lists when shift+tab doesn't work sobrio1 0 3,170 Oct-15-2017, 03:41 PM
Last Post: sobrio1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020