How to create a video from grayscale and rgb images?

조회 수: 7 (최근 30일)
MatlabUser
MatlabUser 2023년 1월 2일
댓글: MatlabUser 2023년 1월 3일
I have e.g., 20 grayscale frames and 20 RGB color images.
I would like to make a video that has in each frame one grayscale image in the left and one RGB color image in the right.
I am using this code but I get all the frames are black :
vid = VideoWriter(['./video.avi']);
vid.Quality = 100;
vid.FrameRate = 10;
open(vid);
for i = 1: 20
imout = [ cat(3,grayImg(:, :,i),grayImg(:, :, i),grayImg(:, :, i)) zeros( size(grayImg,1), 10, 3) (RGBImg(:, :, :,i)) ];
writeVideo( vid, imout);
end
close(vid);
any help will be appreciated :)

채택된 답변

Image Analyst
Image Analyst 2023년 1월 2일
편집: Image Analyst 2023년 1월 2일
  댓글 수: 3
Image Analyst
Image Analyst 2023년 1월 2일
편집: Image Analyst 2023년 1월 2일
grayImg is not defined. You need to define it. And when you do this:
for i = 1: 20
imout = [ cat(3,grayImg(:, :,i),grayImg(:, :, i),grayImg(:, :, i)) zeros( size(grayImg,1), 10, 3) (RGBImg(:, :, :,i)) ];
you're assuming grayImg will be a hyperspectral image with 20 color channels, which it's not.
MatlabUser
MatlabUser 2023년 1월 3일
actually grayImg is defined to be a 3D array Y,X,number of freames...
so when I use for i=1:20, I am iterating on the frames one by one.
it works fine after rescale the grayscale images to range 0,255 :)
thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by