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!