Aligning two images of the same scene is called image registration. If you have access to the Image Processing Toolbox, you can find there a number of functions to help you.
Take a look at these demos (image registration section) for examples.
Aligning two images of the same scene is called image registration. If you have access to the Image Processing Toolbox, you can find there a number of functions to help you.
Take a look at these demos (image registration section) for examples.
Cross-correlation (Wikipedia calls it Phase correlation) won't work if the images are rotated. However, there's a related method based on log-polar coordinates that will work regardless of rotation, scale, shear, and translation.
This method would be best if you have to match any arbitrary images. Matching known shapes or dark lines is better done with other methods.
If those black lines are always in the images, and they're near perfectly straight (not being distorted into curves), a better method would be to use the Hough transform or Radon transform (kind of different ways to think about doing the same thing) to find just the two black lines, and then compare their positions.
You'd invert the images first, so the lines are bright white (large values), and then do the Hough transform. The output for each image will be two bright white points, from which you can do peak detection. The coordinate of each peak tells you the angle and offset of the line.
I haven't done this in MATLAB, but I see a number of examples and documentation:
hough
, houghlines
, and houghpeaks
functions