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

6 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

yanqi liu
yanqi liu el 5 de Feb. de 2021
clear all; clc; close all;
rects = [];
for i = [2 6 12]
img = imread(sprintf('./G%d.JPG', i));
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
  1 comentario
Carlos Imbaquingo
Carlos Imbaquingo el 7 de Feb. de 2021
Yes, Thank you very much Yanqi Liu!
That is exactly what I needed.
Kind regards,
Carlos.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by