MATLAB Answers

Help developing an image frame sequence generator

1 view (last 30 days)
Vanessa on 26 Apr 2017
Edited: Will Nitsch on 1 May 2017
Hi all,
I am doing a project where I have to create frames of images, to show a track path of an object and detect it. The end goal of my code is to create a line that shows the track path of the object as it moves and a box to detect the object at it's final position on the image (original image and desired output image that I would like is shown as an example).
In order to do this, I need help with generating the frames with different object positions. I have already created an object from an array (using the zeros function) with a set intensity value and have overlayed it on to the original background image (using imadd(image, object)). I have different frames with the object at different positions. Any idea, how I can show a streak/line to show the track path of the object?
I would really appreciate any help with this.
Kind regards,
Original frame:
Desired image output:

Accepted Answer

Will Nitsch
Will Nitsch on 1 May 2017
Edited: Will Nitsch on 1 May 2017
Since you have all of the object positions (I assume you know the sequential order of each position as well), you can use Bresenham's line drawing algorithm. Here is a file-exchange submission. This is a well implemented algorithm but the author forgot to terminate a couple of lines with ';', so be sure to add those unless you want tons of stuff printed to the command window.
To do this, first get your position coordinates as the (x,y) pixel indices. Then, for each iteration of the sequence (from 1 -> 2, from 2 -> 3, from 3 -> 4, etc.), just call the Breshenam algorithm to generate the list of x and y coordinates associated with the line between each set of two points. For instance, your workflow would go something like this:
Make a red line between points, given two locations '(x1,y1)' and '(x2,y2)':
>> [x y]=bresenham(x1,y1,x2,y2);
>> for i = 1:length(x)
>> Iin(y(i),x(i),1) = 255;
>> Iin(y(i),x(i),2) = 0;
>> Iin(y(i),x(i),3) = 0;
>> end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!