Why does not line appear over plot
9 views (last 30 days)
Show older comments
I am trying to draw a skeleton over an RGB image. pos2D is a cell which holds the x,y coordinates of the body.
for w= 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
c.im = imshow(color,[]);
%set(c.im,'CData',color);
skeleton = pos2D{1,w};
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
line(X1,Y1, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+', 'Color', 'r');
end
end
Outside the loop it works perfecty, i.e. if i change the w index by hand and do step by step, the line appears. However, when I do these nested loops it does not work. It only appears in the last frame before closing the loop. I tried hold on and off several times. What am I missing?
Thanks!
0 Comments
Answers (2)
OCDER
on 16 Oct 2017
Using imshow will replace the current axes and everything drawn on that axes, including the lines. To fix, use imshow once and then change CData of that image handle. This way, your lines are not deleted.
for w = 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
skeleton = pos2D{1,w};
if w == 1
c.im = imshow(color, []);
else
c.im.CData = color;
end
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
line(X1,Y1, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+', 'Color', 'r');
end
end
3 Comments
Walter Roberson
on 17 Oct 2017
for w = 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
skeleton = pos2D{1,w};
if w == 1
c.im = imshow(color, []);
c.lh = line(nan, nan, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+' 'Color', 'r');
else
c.im.CData = color;
end
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
set(c.lh, 'XData', X1, 'YData', Y1);
drawnow()
end
end
OCDER
on 17 Oct 2017
Hi Andrés, Walter answered your next question. What you want to do is the first loop w = 1, do imshow and draw your 19 lines. In all other loop w > 1, adjust the data in imshow and line.
for w = 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
skeleton = pos2D{1,w};
if w == 1 %First time, make image and 19 lines
c.im = imshow(color, []);
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
c.lh(m) = line(X1, Y1, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+', 'Color', 'r');
end
else %All other times, adjust image and 19 lines position
c.im.CData = color;
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
set(c.lh(m), 'XData', X1, 'YData', Y1);
drawnow()
end
end
end
See Also
Categories
Find more on Loops and Conditional Statements 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!