How can I get matlab to compare two pictures and tell me the displacment of a object in the picture?

1 view (last 30 days)
I am very new to MATLAB and I'm having trouble trying to analyze multiple pictures from a camera I have hooked up. What I want to do is take a picture and then make it black and white. I want to then trace the boundaries of a object in the picture. Now I want to save this picture so when the camera takes another picture of the object I can use imregtform to find how far the object has moved. So far I can get a snapshot and trace the boundaries of a object, but I don't know how or where to save it so I can compare it to future images. I also want to erase older images that are no longer needed. At most I would want the last 10 images.

Answers (1)

Image Analyst
Image Analyst on 29 Jul 2015
You can use imfreehand() to trace the object, but I guess you know that. Then you can get the mask and label it and call regionprops to get the centroid of it, then store it. You can use circshift to shift everything to the left and then assign the 10th element with the current centroid
last10xCentroids = zeros(1, 10);
last10yCentroids = zeros(1, 10);
for f = 1 : 1000
% For each frame, you put the code
% code to get snapshot, call imfreehand, and get mask.
% Now that you have the mask, get a labeled, connected components image.
labeledImage = bwlabel(mask);
% Now find centroid coordinates.
measurements = regionprops(labeledImage, 'Centroid');
% Shift old values to the left in the array.
last10xCentroids = circshift(last10xCentroids, -1);
last10yCentroids = circshift(last10yCentroids, -1);
% Stick new values in the last element.
last10xCentroids(end) = measurements.Centroid(1);
last10yCentroids(end) = measurements.Centroid(2);
end

Community Treasure Hunt

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

Start Hunting!