Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a video from a 3d matrix in matlab

Tags:

matrix

matlab

I have a whole bunch of 2D matrices in matlab (they're suppose to make up a 3D matrix where the 3rd dimension is time), and I'm trying to make a video from the image data.

I know that I can use surf() to make a surface plot using one of the 2D matrices, but I'm not sure which command to invoke to take all my 2D matrices and convert them into a video of the surface plot.

Can anyone help?

like image 480
Mechy Avatar asked May 14 '13 01:05

Mechy


People also ask

How do I convert a matrix to an image in Matlab?

I = mat2gray( A , [amin amax] ) converts the matrix A to a grayscale image I that contains values in the range 0 (black) to 1 (white). amin and amax are the values in A that correspond to 0 and 1 in I . Values less than amin are clipped to 0, and values greater than amax are clipped to 1.

How do you vectorize a matrix in Matlab?

Conversion of a Matrix into a Row Vector. This conversion can be done using reshape() function along with the Transpose operation. This reshape() function is used to reshape the specified matrix using the given size vector.


1 Answers

The built-in function immovie(X,map) is one option for what you want. This function expects a m-by-n-by-1-by-k 4D matrix, where the 4th dimension is the frames of the movie. Since you're starting with a 3D matrix, use permute first:

Orig; % 3D matrix
X = permute(Orig,[1 2 4 3]); % 4D matrix
movie = immovie(X,map); % map is the colormap you want to use

implay(movie);
like image 125
tmpearce Avatar answered Oct 20 '22 08:10

tmpearce