How to replace specific area of image with zeros in video loop

1 view (last 30 days)
So I have created a video that tracks 2 different coloured tags, 1 yellow 1 red, tracking the border/distance/centroids.
I am reporting the centroid coordinates in real time in the bottom left corner of the video. However, in my current method the figures are repeating over each other while I need them to replace.
Here you can see my output image where you can see my issue with the text being blurred due to repeated numbers being posted on top of each other:
My thought process to fix this issue is to create a zero matrix that also creates itself everytime the figures updates, so each iteration of figures being displayed will have a black background behind it, so you can see the figures live.
So I am just wondering what the code would be to create a matrix of zeros in the bottom left of the corner so you can see the figures as they update.
Below is my current code for the output seen above, RGB is the snapshot image, redYellowOverlay is the border code, ri/rj/yi/yj mean are centroid coordinates, dim/str/annnotation code is the code for the textbox.
Again, my goal is to also put a matrix of zeros in the loop so it repeats everytime the figure repeats. Any help would be greatly appreciated!
hold on;
plot(rjMean,riMean, 'g-x', 'LineWidth',5)
plot(yjMean,yiMean, 'g-x', 'LineWidth',5)
dim = [0.15 0.3 0.3 0];
str = {['Red Tag Centroid i coordinates = ',num2str(riMean)],['Red Tag Centroid j coordinates = ',num2str(rjMean)],['Yellow Tag Centroid i coordinates = ',num2str(yiMean)],['Yellow Tag Centroid j coordinates = ',num2str(yjMean)],['City Block Distance = ',num2str(dCityBlock)],['Chessboard Distance = ',num2str(dChessboard)],['Euclidean Distance = ',num2str(dEuclidean)]};

Accepted Answer

cr on 5 Dec 2022
Edited: cr on 5 Dec 2022
Instead of recreating the annotation in the loop, create just one annotation before the loop, assign a handle to it and inside the loop change the text of the annotation. This will also avoid the problem of overpopulating the figure with objects that are no longer needed. With too many objects the graphics get slow and may crash the session.
annohandle = annotation(....);
while ...
str = blah blah..
annohandle.String = str;
Ted on 8 Dec 2022
Yeah this worked perfectly.
Tried messing around with the first way I was doing but was much easier in your recommended implementation.
Thanks for this!

Sign in to comment.

More Answers (0)


Find more on Environment and Settings in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!