0

I keep getting errors when trying to make an animation from a 4D matrix.

Here is the code:

>> %movie...fail
    c = zeros([size(u_filt1), 339]); %input number of frames
    for ii=1:size(c,3)
        c(:,:,ii)=eval(['u_filt', num2str(ii)]);
    end 

x=permute(c,[1 2 4 3]); %4D matrix
immovie(x,jet);

Error using im2uint8 (line 83)
Invalid indexed image: an index was less than 1.

Error in immovie>parse_inputs (line 89)
    X = im2uint8(X,'indexed');

Error in immovie (line 39)
[X,map] = parse_inputs(varargin{:});
  • Your data is RGB, but you're specifying a colormap. Does `immovie(x);` work? Or try `immovie(rgb2ind(x,jet),jet);`. – horchler Mar 16 '16 at 20:48
  • @horchler: Running the code c is [n m 1 339], might be grey scale but no rgb. – Daniel Mar 16 '16 at 22:59

1 Answers1

4

Indexed images of datatype unsigned integer start at 0. Indexed images of datatype double start at 1. Because of this, your code putting the unsigned integers u_filtX into a double array c made the data invalid. Allocate c using the right class

c = zeros([size(u_filt1), 339],class(u_filt));
Daniel
  • 36,610
  • 3
  • 36
  • 69