How to draw a line/vector between start and end point of a movement between two images

1 view (last 30 days)
hi all! my task is to detect differences between two images. I have two images taken with a tripod and there is only a car moving and I want to draw a vector between the front bumpers and use it as a velocity vector. I hope that it is clear enough. what i did so far is:
clear all, close all, clc
first=imread('first.jpg');
second=imread('second.jpg');
gray1=rgb2gray(first);
gray2=rgb2gray(second);
fs=abs(gray1-gray2);
sf=abs(gray2-gray1);
sf(sf<100)=[0];
sf_open = bwareaopen(sf,75); %deletes the pixels smaller than 75
fs(fs<100)=[0];
fs_open = double(bwareaopen(fs,75)); %deletes the pixels smaller than 75
l=abs(fs_open+sf_open);
imtool(l);
se1 = strel('square',5);
l_dilate = imdilate(l,se1);
imtool(l_dilate) %combines close values to have a better view
and my outcome is this:
I am satisfied with the image as it contains only 1 and 0 in the matrix. Now I dont know how can I do the vector and maybe even calculate the speed of the car from this two images (I have the time information from the exif info of the pictures).
Any ideas to draw the velocity vector?
thanks

Answers (1)

Image Analyst
Image Analyst on 11 Oct 2015
Keep them as two separate images. Then call bwareafilt() or bwareaopen() to get rid of small noise specks, if any. Then call bwconncomp() and regionprops() to get the bounding boxes. From the bounding boxes, determine the right most edge.
  3 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!