Effacer les filtres
Effacer les filtres

Can I capture frame more efficiently?

14 vues (au cours des 30 derniers jours)
Yuxin Tong
Yuxin Tong le 29 Avr 2022
Commenté : Yuxin Tong le 1 Mai 2022
Hi all
I wonder if it is possible to capture frame more efficiently using getframe. I already have done the following:
1) I pre-defined a struct() variable to store the frames before running a for-loop.
2) I have limited the number of frames to capture by (kind of a wired way) I calculated i*length of the dimension I am changing each plot and limited it from around 1500 plots to 150 plot
I wonder if there are other things I can do to make my code more efficient? The thing I am doing is I am plotting three subplots that are updating each time the for-loop runs. (One thing I found is with or without the getframe() command the time difference were around 30seconds. Is getframe() actually this slow or am I doing it wrong?)
Also I wonder if there is a difference with using getframe(gcf) and getframe(figure handle). They seem to have a small time difference (around 5sec) when I run them. I tried google both but couldn'r really process the information, and I kind of get the feeling that there should not be a difference as long as I am only ploting one figure in the loop. Below are how I coded things. There are a bunch of variables in the code defined before it so just to get a sense of what am I doing ;p
t=150;
fEdge(t)=struct('cdata',[],'colormap',[]);
fig=figure('Position',[0.1 0.1 900 300]);
for i=1:t
ind=i*round(size(edgeBOLD,3)/t,0,'decimals');
if ind>size(edgeBOLD,3)
break
end
clf
subplot(1,3,1)
pcolor(edgeRes2D(:,:,ind));
colorbar('southoutside')
caxis('manual')
caxis([0 max(edgeRes2D,[],'all')])
title(sprintf('Original, t= %d',time(ind)))
subplot(1,3,2)
pcolor(edgeBOLD(:,:,ind));
colorbar('southoutside')
caxis('manual')
caxis([0 max(edgeBOLD,[],'all')])
title(sprintf('convn with 1-1-N gaussian, t= %g',time(ind)))
subplot(1,3,3)
pcolor(edgeSMOOTH(:,:,ind));
colorbar('southoutside')
caxis('manual')
caxis([0 max(edgeSMOOTH,[],'all')])
title(sprintf('Smoothdata gaussian, t= %d',time(ind)))
fEdge(i) = getframe(fig);
end
Elapsed time is 60.790442 seconds.
Elapsed time is 33.247113 seconds.
The two time are time of the whole program run with or with out the line
fEdge(i)=getframe(fig);
(but im pretty sure this for-loop is the slowest part of my code so..)
Also not really important but is there a way that I can set the range for colormap for each subplot before I plot them? I don't think I should be setting them inside the loop but the figure and axes handle things are pretty confusing and nothing I have tried worked.

Réponses (1)

Image Analyst
Image Analyst le 29 Avr 2022
Maybe try getimage(). To pseudocolor the image use ind2rgb().
  1 commentaire
Yuxin Tong
Yuxin Tong le 1 Mai 2022
Sadly I dont have the tool box needed for get image, but thank you still for the advice.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by