From: fred broccard on
Hi all,
I'm trying to make a movie from images created with imagesc. These images corresponds to matrices which can have 18 different values and I created a custom colormap to represent these different 18 values.
Now, this matrix, called featuremap, is in a for loop, for let say 100 iterations, so I'll get 100 images. I tried to use im2frame to convert the image into frames but get this error message:
??? Error using ==> im2frame
double-precision indexed CData values
must be legal colormap indices: 1.0 <= value <= length(colormap)

I also tried getframe but didn't have much success.
I'd like to be sure that the frames correspond to the images using my colormap.
Here's the for loop I'm using:

cm=[0,0,0;...
0,1,1;0,.875,1;0,.75,1;0,.625,1;0,.5,1;0,.25,1;0,.125,1;0,0,1;...
1,1,0;1,.875,0;1,.75,0;1,.625,0;1,.5,0;1,.25,0;1,.125,0;1,0,0];

M=[];
for j=1:100
M(j)=im2frame(imagesc(featuremap),cm);
end
figure;
movie(M,1,2);

Is there a problem with the scaling of the colormap indexes ?
Any help appreciated !
Thanks.

fred
From: Walter Roberson on
fred broccard wrote:
> I tried to use im2frame to convert
> the image into frames but get this error message: ??? Error using ==>
> im2frame
> double-precision indexed CData values
> must be legal colormap indices: 1.0 <= value <= length(colormap)

> M=[];
> for j=1:100
> M(j)=im2frame(imagesc(featuremap),cm);
> end

imagesc() is a call to display the given image using color map scaling.
imagesc() returns the handle of the image object that was created. You then
attempt to pass that image object handle to im2frame(), but im2frame is
expecting a matrix of data rather than a handle.

If you want to convert a matrix of data to an indexed image, you can do it
without displaying anything, by using

CMap = colormap;
CMapEntries = size(CMap,1);

ImMin = min(ImageName(:));
ImMax = max(ImageName(:));

ThisFrame = im2frame(floor((ImageName - ImMin) ./ (ImMax - ImMin) *
CmapEntries), CMap);

Provided, that is, that the image is not constant intensity (in which case the
maximum would be the same as the minimum.)
From: fred broccard on
> imagesc() is a call to display the given image using color map scaling.
> imagesc() returns the handle of the image object that was created. You then
> attempt to pass that image object handle to im2frame(), but im2frame is
> expecting a matrix of data rather than a handle.
>
> If you want to convert a matrix of data to an indexed image, you can do it
> without displaying anything, by using
>
> CMap = colormap;
> CMapEntries = size(CMap,1);
>
> ImMin = min(ImageName(:));
> ImMax = max(ImageName(:));
>
> ThisFrame = im2frame(floor((ImageName - ImMin) ./ (ImMax - ImMin) *
> CmapEntries), CMap);
>
> Provided, that is, that the image is not constant intensity (in which case the
> maximum would be the same as the minimum.)

It doesn't work, probably because some of the frames are of constant intensity.
I tried with image instead of imagesc, which should return an indexed image (right ?) but get the same error message.
Basically, I'd like to get a frame from an image consisting of a matrix (say 5x5) of, let's say 20 values, in which each value has been assigned to a different color by using a custom colormap of 20 colors. And this for several matrices, let's say 100, stored in a 3D array of 5x5x100.
The image is how I'd like to be if I plot it and should be indexed. But still can't get the frame..

M=[];
for it=1:100
im=image(matrix,it);
colormap(custom); % works fine
M(it)=im2frame(im, custom);
end
movie(M,1,2);