Imagesc movie with multiple axes/matrices
Mostra commenti meno recenti
I would like to do the same as this person:
Although, I want multiple axes/matrices in the same movie. I wrote the following code to achieve this:
for i = 1:l
% Switch to first axes
axes(syy_ax)
imagesc(syy(:,:,i))
colorbar
% Switch to second axes
axes(wd_ax)
imagesc(wd(:,:,i))
colorbar
all_mov(i) = getframe;
end
where syy_ax and wd_ax are axis handles, and syy and wd are 3D matrices. I realize how slow this is, but don't know an alternative. I tried specifying the axis in the plot function, but I don't think imagesc supports this. Could anyone suggest another way, please?
1 Commento
Jurgen
il 4 Gen 2013
Have you considered concatenating the matrices into 1 matrix if possible?
Also the post you refer to is trying to display something over time, while your use of getframe implies you want to make a movie object?
Risposte (3)
Image Analyst
il 4 Gen 2013
Modificato: Image Analyst
il 4 Gen 2013
0 voti
Well how slow is it? I would think it would be too fast, if anything, and you'd want to put in pauses so the person viewing it will see more than a blip as the movie goes whizzing by. Just how many frames per second is it doing? Or is it so slow we're talking seconds per frame?
Also I'm puzzled by you using imagesc() rather than imshow()? So, you're okay with that bizarre, arbitrary, default colormap that imagesc() applies? Just by the luck of the draw, that happens to be the best colormap for your images? I'm surprised - you're lucky. For me, almost always I don't want the default colormap that imagesc chooses.
Also, please see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_a_movie_from_my_MATLAB_figures.3F You can use export_fig() to save your figure, with both axes on it, out to files that can then be made into frames of your movie.
Evan Kias
il 4 Gen 2013
8 Commenti
Image Analyst
il 5 Gen 2013
This is somewhat faster:
for k = 1:l
if k == 1
h1 = imshow(syy(:,:,k), [], 'Parent', syy_ax);
else
set(h1, 'CData', syy(:,:,k));
end
colorbar('Peer', syy_ax);
if k == 1
h2 = imshow(wd(:,:,k), [], 'Parent', wd_ax);
else
set(h2, 'CData', wd(:,:,k));
end
colorbar('Peer', wd_ax);
drawnow;
% all_mov(k) = getframe;
end
Jurgen
il 5 Gen 2013
A small improvement to above is run loop from k = 2:l and take out if statements. Also maybe initialize all_mov first (if you actually need it for anything).
Image Analyst
il 5 Gen 2013
Yep, agreed. Actually, the main reason it's faster is I took out the all_mov line - that was the line that was taking up the vast majority of time. It doesn't even take that long anyway - some people wait hours and hours to create a movie frame by frame. They just let it run overnight or whatever, but once you have the movie created, then that's what counts and it plays in real time. So they watch the movie AFTER it's been created, not WHILE it's being created, so the time doesn't really matter that much.
Evan Kias
il 5 Gen 2013
Image Analyst
il 5 Gen 2013
It could be that subsampling for the display got rid of some single pixel lines like in your axes. Try making the window bigger. Regarding partial display, perhaps put in a drawnow or pause(0.1) to give the image time to be shown before it gets saved.
Jurgen
il 6 Gen 2013
You should be aware of what getframe actually saves. f = getframe gets the current axis, so may exclude labels and other axes. Also does not save properties, just what it looks like. http://www.mathworks.nl/support/solutions/en/data/1-1BSP6/?solution=1-1BSP6
Evan Kias
il 10 Gen 2013
Jurgen
il 11 Gen 2013
You can do it in MATLAB with avifile or videowriter, getframe should be faster than export_fig if you intialize a struct array.
That aside, freeware options that come to mind are imagemagick & ffmpeg (both commandline interfaces I believe).
If you insist on saving images, saveas() might be faster than exportfig.
Lastly, either when dumping images or grabbing frames, you may suppress the visible output to speed things up.
Jurgen
il 5 Gen 2013
I dont use colorbars often, so this was my initial idea without them:
syy = reshape(syy,[size(syy,1) size(syy,2) 1 size(syy,3)]);
wd = reshape(wd,[size(wd,1) size(wd,2) 1 size(wd,3)]);
DATA = [syy wd]; clear syy wd %data is now formatted (n-m-1-p) and concatenated
MOV = immovie(DATA,jet(256)); %or some other map (< 256).
close;
Note you may need to convert DATA to indexed format (i.e. integers). A quick fix for this would be real2rgb (from the FEX) then rgb2ind.
fps = 5; %framerate
N = 1; %iterations
movie(MOV,N,fps) %Plays movie MOV, N times at fps frames per second.
Categorie
Scopri di più su Animation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!