How to convert the video into frames and get binary images of those frames and save them individually
16 次查看(过去 30 天)
显示 更早的评论
I have a video of microscopy trial. I need to get each of the frames from the video and convert them into binary images and save each one of them in a folder. I have written code for it but there is a problem here. I cannot get frames and its corresponding binary images saved in image format in a folder.
0 个评论
回答(1 个)
Kiran Felix Robert
2020-7-22
Hi AB,
It is my understanding that you need to convert each frame of your video into binary image and write it to a file in readable image format.
The video reader object can be used to read files with video data which can be found in the VideoReader documentation.
Each frame can be converted to binary using the imbinarize function (Assuming that the frame is in 2D Grayscale, rgb2gray can be used if this Is not the case).
If A.mp4 is the video file, and suppose you want to save the frames as A_frame_<frame number>.png, as shown below,
v = Videoreader("a.mp4");
i = 0
while hasFrame(v)
frame = readFrame(v);
gray_frame = rgb2gray(frame);
binary_frame = imbinarize(gray_frame)
file = sprintf("a_frame_%d.png",i);
imwrite(binary_frame,file);
i = i + 1;
end
Thank You,
Kiran
0 个评论
另请参阅
类别
在 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!