How to make a Video from 3D array

조회 수: 38 (최근 30일)
Hamed Bolandi
Hamed Bolandi 2021년 7월 22일
댓글: Hamed Bolandi 2021년 7월 23일
I have 3D matrix with dimension of 600x600x28 which the last index is number of frames and want to convert it to video file. I tried as a below but raised with error:
Unrecognized function or variable 'cmap'.
My code:
Orig = rand(600,600,28);
X = permute(Orig,[1 2 4 3]); % 4D matrix
movie = immovie(X,cmap);
implay(movie);

답변 (1개)

millercommamatt
millercommamatt 2021년 7월 22일
You never defined the variable cmap which is supposed to be a color map.
Try This:
Orig = rand(600,600,28);
camp=parula;
X = permute(Orig,[1 2 4 3]); % 4D matrix
movie = immovie(X,cmap);
implay(movie);
  댓글 수: 3
millercommamatt
millercommamatt 2021년 7월 23일
I get the same error and I don't know why. The documentation for immovie says that double is an allowable input data type.
But, I have a fix: Do the conversion of the input array to uint8 yourself.
Orig = randi(256,600,600,28)-1; % 0-255
cmap=parula;
X = permute(Orig,[1 2 4 3]); % 4D matrix
movie = immovie(uint8(X),cmap);
implay(movie);
Hamed Bolandi
Hamed Bolandi 2021년 7월 23일
The reason I was getting this error is because the function call immovie(X,map) requires X to be an indexed image. It means that the values of X must greater than 1. Therefore, changing the code like below solved the issue:
Orig = randi([1 255],600,600,1,28);
cmap=parula;
movie = immovie(Orig,cmap);
implay(movie);

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

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by