How to quantify the object shift between projection images using Matlab?

Hi, I am tasked with quantifying the shift between these 2D simulated images, by implementing an algorithm (e.g. cross-correlation or centre of mass) using matlab. I have attached the data and script for the images. Any help would be appreciated.

Answers (1)

I don't see any images attached, but try imregister or imregcorr
Or try normalized cross correlation. See attached demo.

4 Comments

I included the Matlab script with the image data. And the excel data files.
I will try imregister and imregcorr. Is it likely that they return a constant instead of an image to quantity a shift in the y direction?
Hi again @Image Analyst , I'm new to matlab and cannot figure out how to use the suggested imregister or imregcorr for this application. I have edited the question to include images of the shift a dot was placed at the centre of the graph (75 , 75). I need a value in pixels or cm to verify that the image moved. Please help
Now that I can see your images, why don't you just threshold and find the centroid of the blob? Do this for each image and see how the centroid shifted. Something like
mask1 = grayImage1 > someThresholdValue;
% Take largest blob only.
mask1 = bwareafilt(mask1, 1);
props1 = regionprop(mask1, 'Centroid');
xy1 = props1.Centroid
% Now for image 2
mask2 = grayImage2 > someThresholdValue;
% Take largest blob only.
mask2 = bwareafilt(mask2, 1);
props2 = regionprop(mask2, 'Centroid');
xy2 = props2.Centroid
% Now compute delta x and y
deltax = xy1(1) - xy2(1)
deltay = xy1(2) - xy2(2)
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
Thank you so much for your help, this looks like what I need. I have a problem converting my data to grayscale. The image plot I have is a matlab.primitive.image with cannot be converted. Is there another way to plot this 2D image with x and y: 0-290 and z containing intensity values. I found this mesgrid code but I cannot do any analysis on the image afterward. @Image Analyst
Thank you for all your help
C = readmatrix('G2_source@5cm.xlsx');
D = readmatrix('Shifted_5cm_Source@5cmSDD.xlsx');
xC = C(:,1);
yC = C(:,2);
zC = C(:,3);
xD = D(:,1);
yD = D(:,2);
zD = D(:,3);
n = 290.39;
[Xc, Yc] = meshgrid(linspace(min(-150),max(150),n), linspace(min(-150),max(150),n));
Zc = griddata(xC,yC,zC,Xc,Yc);
[Xd, Yd] = meshgrid(linspace(min(-150),max(150),n), linspace(min(-150),max(150),n));
Zd = griddata(xD,yD,zD,Xd,Yd);
figure (1) % Plot the original image C
GlobalPosZX_C = imagesc(Zc);
title('O R I G I N A L I M A G E: Unshifted')
centre_1 = drawline('Position',[145.175 145.175;145.175 145.175],'StripeColor','r');
figure (2) % Plot the shifted image 5cm
GlobalPosZX_D = imagesc(Zd);
title('S H I F T E D : 5cm Shift')
centre_4 = drawline('Position',[145.175 145.175;145.175 145.175],'StripeColor','r');

Sign in to comment.

Asked:

on 10 Aug 2023

Edited:

on 14 Aug 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!