Making movie out of images

6 views (last 30 days)
Ahmad Alsabbagh
Ahmad Alsabbagh on 17 Apr 2016
Answered: Peter O on 17 Apr 2016
I am trying to make a movie out of a group of images. The images are basically 2D matrices and I get this error
double-precision indexed CData values must be legal colormap indices: 1.0 <= value <= length(colormap)
What can I do to solve this issue. My code is very simple as shown below
clear
clc
I1=[1 0 0 0 0 0 ; 0 0 0 0 0 0 ];
I2=[0 1 0 0 0 0 ; 0 0 0 0 0 0 ];
I3=[0 0 1 0 0 0 ; 0 0 0 0 0 0 ];
I4=[0 0 0 1 0 0 ; 0 0 0 0 0 0 ];
I5=[0 0 0 0 1 0 ; 0 0 0 0 0 0 ];
I6=[0 0 0 0 0 1 ; 0 0 0 0 0 0 ];
F(1) = im2frame(I1);
F(2) = im2frame(I2);
F(3) = im2frame(I3);
F(4) = im2frame(I4);
F(5) = im2frame(I5);
F(6) = im2frame(I6);
implay(F,1);

Accepted Answer

Peter O
Peter O on 17 Apr 2016
It would appear you're giving it a matrix of values to make frames, but MATLAB is looking for indices for each pixel to relate to the colormap vector. The colormap vector is what MATLAB uses to apply the color shading in plots. You can generate one in the jet scheme, for example, by typing jet(N), where N is the number of levels you want. You'll get an N by 3 matrix which is each level's RGB values, normalized so that black is 0 and full saturation of that color component is 1.
If you create a surface plot of a matrix X, usually it assigns the maximum value of X to the maximum colormap index, the minimum X value to colormap index (level) 1, and a linear scale in between for all other X values, truncating to the nearest integer. A value in X of 12.11 would not necessarily map to an index of 12, unless the maximum value was 100, the minimum was 1, and there were 100 levels in between. If there were only 50 levels, it would map to colormap index 6.
Your code should be supplying this (in this example) value of 6, or 12, or whatever level in the map you want it to take. If your colormap vector is 256 elements long, you'll have 256 values, 1 to 256. Here you're asking for value 0, which doesn't exist. Try adding 1 to each of your values, and also deliberately specifying how many levels you want.
mymap = jet(11); %creates 11-level map of colors
I1=[1 0 0 0 0 0 ; 0 0 0 0 0 0 ] + 1; %will fill levels 1 and 2 of the 11-level map.
%and so on
F1 = im2frame(I1, mymap)
Then MATLAB should be able to parse them to frames.
I hope this helps!

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!