Creating a movie from binary plots
4 次查看(过去 30 天)
显示 更早的评论
Hi! So i am trying to create a movie from a loop of binary matrix.
Basically i have a big loop that generates a different binary matrix everytime.
i can use imagesc() to extract frames from every loop cycle but i wonder if I can create a movie combining all the frames from each cycle of the loops?
Many thanks!
1 个评论
Walter Roberson
2020-7-17
编辑:Walter Roberson
2020-8-14
imagesc() is not suitable for extracting frames. If you have binary frames just write double() of the logical array to the video.
回答(1 个)
Kiran Felix Robert
2020-8-14
Hi Feihao,
It is my understanding that you have a series of binary matrices and you want to write those to a video file.
This can be done by mapping the logical matrix to an equivalent grayscale image and writing the grayscale image, frame by frame to a video file.
For more information, refer to the videoWriter documentation. This answer contains an example to create a video from a series of images.
The following is an example to create a video from binary matrices, (I have generated 3 random binary matrices just before writing it to file, you can use indexing to access the pre-calculated matrix)
map = colormap(gray(256)); % Define the colour map for Grayscale image
v = VideoWriter('myVideo.avi','Indexed AVI'); % Video Writer Object
v.Colormap = map; % Assign the colourmap
open(v) % Open the Video Writer Object
for u = 1:3 % Writing three images to video
X = 255*randi([0 1],256,256); % I am creating a binary random matrix and
% mapping the 0 -> 0 and 1 -> 255 to make it
% as an 8-bit gray scale image
for z = 1:300 % Time for each frame
writeVideo(v,X) % Video writer
end
end
close(v) % Close the videoWriter
Hope this Helps
Kiran Felix Robert
1 个评论
Walter Roberson
2020-8-14
You would have to onvert X to uint8 for that to work.
... But you can just use
X = randi([0 1],256,256)
without converting to 0 and 255 and without converting to uint8. writeVideo knows to treat single() and double() in the range of 0 to 1 as relative intensities and will construct the appropriate uint8 internally.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!