Azzera filtri
Azzera filtri

Creating a movie from binary plots

4 visualizzazioni (ultimi 30 giorni)
Feihao Sun
Feihao Sun il 17 Lug 2020
Commentato: Walter Roberson il 14 Ago 2020
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 Commento
Walter Roberson
Walter Roberson il 17 Lug 2020
Modificato: Walter Roberson il 14 Ago 2020
imagesc() is not suitable for extracting frames. If you have binary frames just write double() of the logical array to the video.

Accedi per commentare.

Risposte (1)

Kiran Felix Robert
Kiran Felix Robert il 14 Ago 2020
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 Commento
Walter Roberson
Walter Roberson il 14 Ago 2020
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.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by