필터 지우기
필터 지우기

Creating a movie from binary plots

조회 수: 4 (최근 30일)
Feihao Sun
Feihao Sun 2020년 7월 17일
댓글: Walter Roberson 2020년 8월 14일
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
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
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
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 CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by