Create a video with imagesc (VideoWriter)
Show older comments
Hello,
I've got a program that looks pretty much like that, and I would like to create a video resulting of all the plots created during the k iteration:
for k=1:10000
.%calculations
.%calculations
W=reshape(w,y,x); %Where W is a Matrix
lsd=imagesc(W);
drawnow
end
Any clue? Thank you
Accepted Answer
More Answers (2)
Walter Roberson
on 30 Mar 2019
imagesc(W) displays the given data, W, after changing the color scaling to be from min(W(:)) to max(W(:)) so that the minimum value in W gets mapped to the first color in the color map and the maximum value in W gets mapped to the last color in the color map.
imagesc(W) does not itself put up any color map: whatever color map was in place would be used.
The rescaling that imagesc does from min to max is the same as what you would get if you used
Wscaled = mat2gray(W);
mat2gray() is a pretty obscure name for this functionality, but as of R2017b you can instead use
Wscaled = rescale(W);
Either way, Wscaled would be values in the range 0 to 1.
You can then im2uint8() to get values in the range 0 to 255, and you can then ind2rgb() passing in a color map in order to get out an RGB image that represents the data. After that you can write the RGB as a video frame by using the functionality of videowriter()
5 Comments
io mb
on 30 Mar 2019
Walter Roberson
on 30 Mar 2019
im2uint8() is part of the Image Processing Toolbox. That is included in the Student Suite, which you probably have.
In any case, for this purpose, you could probably use
ind2rgb( uint8(Wscaled * (256*(1-eps))), YourColormapGoesHere )
io mb
on 30 Mar 2019
Walter Roberson
on 30 Mar 2019
By the way I should probably have had a floor() call inside the uint8() call
uint8( floor(Wscaled * (256*(1-eps))) )
Walter Roberson
on 30 Mar 2019
We do not have your full code, and you did not show any error message, so it is difficult for us to guess what "Doesn't work well" means.
io mb
on 30 Mar 2019
0 votes
1 Comment
lubna Albarghouty
on 1 Mar 2022
that's because you're writing the entire 'F' at each iteration.
i.e. should write the following line outside (rather than inside) the 'for' loop :
writeVideo(video,F)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!