MATLAB: Frame Difference

frame differenceim2frameMATLAB

In the frame difference method,on converting an image to frame,i have got an error in the following statement:
M(i-1)=im2frame(unit8(fg),gray);
fg is gray image.
the error is :
Indexed movie data values must be legal color map indices:
1.0<=value<=length(colormap) for double-precision movie data,and
0<=value<=length(colormap)-1 for unit8 movie data.
plzz tell me how can i fix this error?

Best Answer

The default size of the colormap for gray() is smaller than 256 elements. You need to use
M(i-1)=im2frame(uint8(fg),gray(256));