Combining plot, line, text2string with getframe

1 次查看(过去 30 天)
Hi,
I have an image stack, in which I would like to plot data points, label the data points and draw a trajectory as a line. To do so I loop through the images of the stack, use imshow to show an image, use plot to create the data points, use line to draw some lines, use inserttext to add the labels and then try to get the whole image with getframe. Before adding the inserttext command, it was working fine, but now I only get a white image containing the inserted text. The code does not create an error. I think I need to store the information from inserttext differently, but I don't know how. Below is the code:
v = VideoWriter('C:\Users\mrst\Desktop\Auswertungen mit Skript\test1 218\Stack\218 bearbeitet tracks.tif','Uncompressed AVI');
open(v);
for n=1:numberOfImages %loops through images in stack
clear text
clear temp
clear pos
close all
f1=figure;
set(f1, 'Visible', 'off');
imshow(stack(:,:,n),[0 255]) %stack is the image stack
axis on
hold on;
c = 1;
for m=1:length(X(:,1,2)) %determines which data points and lines should be plotted
if find(X(m,:,2)==n) > 0
temp(c)=m; %#ok<SAGROW>
c = c+1;
end
end
plot(nonzeros(X(temp,n,1)),nonzeros(Y(temp,n,1)), 'r+', 'MarkerSize', 3, 'LineWidth', 0.1); %plots data points
for o=1:length(temp) %creates variables for content and position of label
text{o}=sprintf('%4.0f',temp(o)); %#ok<SAGROW>
pos(o,:)=[imported_array(bubble_tracks(temp(o),n,1),8) + 10, imported_array(bubble_tracks(temp(o),n,1),9) + 10]; %#ok<SAGROW> stores position for text
end
for m=1:length(temp) %plots chosen lines
line(nonzeros(X(temp(m),:,1)),nonzeros(Y(temp(m),:,1)),'color',bubble_tracks(temp(m),1:3,3))
end
dummy=insertText(stack(:,:,n),pos,text,'FontSize',18); %inserts text --> I think the problem lies here or in the next line
imshow(dummy)
frame(n)=getframe(gcf); %#ok<SAGROW>
hold off
close(gcf)
end
writeVideo(v,frame);
close(v);
  1 个评论
Malte Römer-Stumm
Malte Römer-Stumm 2022-4-13
Ok so to my understanding the problem is using imshow twice. By using inserttext on the stack first and then using imshow only once, the problem could be solved.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by