# Measure the displacement of an object between two figures or more.

3 views (last 30 days)
Dear all,
I am completely new in image processing and I do not know how to start. I have a set of pictures where only one object has different positions, the rest of the things in the pictures are static. I want to keep the object position of the first picture as a reference and measure how much that object has moved in the other pictures.
I think there must already be a straightforward example, but I could not find it.
Regards.
##### 2 CommentsShowHide 1 older comment
Carlos Imbaquingo on 4 Feb 2021
Sure!

yanqi liu on 5 Feb 2021
clear all; clc; close all;
rects = [];
for i = [2 6 12]
img = imresize(img, 600/size(img,1), 'bilinear');
J = rgb2lab(img);
a = mat2gray(J(:,:,1));
b = im2bw(a, 0.7);
b = imclose(b, strel('disk', 20));
b = imfill(b, 'holes');
b = imclearborder(b);
b = bwareafilt(b,1);
[r, c] = find(b);
rect = [min(c) min(r) max(c)-min(c) max(r)-min(r)];
rects = [rects; rect];
figure(1); cla;
imshow(img, []);
hold on; rectangle('Position', rect, 'EdgeColor', 'm', 'LineWidth', 2);
plot(rects(:,1)+rects(:,3)/2, rects(:,2)+rects(:,4)/2, 'w--', 'LineWidth', 4);
pause(1e-3);
dis = norm([rects(end,1)+rects(end,3)/2 rects(end,2)+rects(end,4)/2]-[rects(1,1)+rects(1,3)/2 rects(1,2)+rects(1,4)/2]);
title(sprintf('moved %.2f', dis));
end
Carlos Imbaquingo on 7 Feb 2021
Yes, Thank you very much Yanqi Liu!
That is exactly what I needed.
Kind regards,
Carlos.