problem with creating video from black and white images
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi folks,
I am trying to create a video using Black and White images using the following code:
writerObj = VideoWriter(threshVideoName);
writerObj.FrameRate = 10;
open(writerObj);
for j = 1:numThresholds
image = imread([threshFolder threshFiles(j).name]);
frame = im2frame(uint8(image), gray);
writeVideo(writerObj, frame);
end
however, the output is entirely black! I've tried gray(256) and gray(0) but get the same issue. I believe I am not using the correct colour map, although I'm uncertain if this is the problem! If anyone can help me fix this issue, it would be most appreciated!
댓글 수: 0
채택된 답변
DGM
2022년 3월 7일
편집: DGM
2022년 3월 7일
What is
class(image)
and
[min(image) max(image)]
?
Because if the images are logical (or unit-scale floating point) then casting them as uint8() will mean that the image is all essentially black.
Image are treated with respect to some expected data range that defines what white and black are. For logical and floating point classes, that's [0 1]. For uint8, that's [0 255]. If you just cast using uint8(), the white regions of the image are still 1, which is (in the context of uint8 scale, as close to black as you can get without being black.
Use im2uint8() instead of uint8() if you want to both cast and rescale an image to uint8 regardless of its original class.
추가 답변 (2개)
yanqi liu
2022년 3월 8일
writerObj = VideoWriter(threshVideoName);
writerObj.FrameRate = 10;
open(writerObj);
for j = 1:numThresholds
image = imread([threshFolder threshFiles(j).name]);
frame = im2frame(im2uint8(mat2gray(image)), gray);
writeVideo(writerObj, frame);
end
댓글 수: 1
Image Analyst
2022년 3월 8일
Remember to call
close(writerObj);
after the loop. And don't call your variable image because image is the name of a very important built-in variable.
Image Analyst
2022년 3월 8일
Attached is a demo that takes a video and minds some things in the frames (like mean intensity), and (optionally) writes the video frames out to disk. The second part of the demo shows you how to read in frames from individual disk files and create a move from them. Also attached are how to make a movie out of a surface you create from data (two versions : color and grayscale).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!