Hello,
I have a problem with putting processed images into a movie. I use im2frame to set these images as frames, but I get the following error:
??? Error using ==> im2frame double-precision indexed CData values must be legal colormap indices: 1.0 <= value <= length(colormap)
I've already set the colormap to gray(255), but the error still exists. So probably I'm misinterpreting the error.
Could someone point me out what I'm doing wrong? That would be really great.
Roland
clcclear allclose all%Read target folder directory
myFolder = uigetdir('D:\rchoefkens\Bloemen PEP');if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return; endfilePattern = fullfile(myFolder, 'uvs120424-*.bmp');imageFiles = dir(filePattern);%Load and crop backgroundimage
baseFileName = imageFiles(end,:).name;fullFileName = fullfile(myFolder, baseFileName);BGin = imread(fullFileName);BG = imcrop(BGin,[230 300 250 227]);BGX = rgb2gray(BG);%Load and process sample images
for k = 1:length(imageFiles)-1 baseFileName1 = imageFiles(k).name; nF = {k}; numFrames= cell2mat(nF); fullFileName1 = fullfile(myFolder, baseFileName1); imageArray = imread(fullFileName1); %Remove noise and background
Im = imcrop(imageArray,[230 300 250 227]); I = rgb2gray(Im); Diff = imabsdiff(I,BGX); Diff1 = filter2(fspecial('average',8),Diff)/255; Diff2 = medfilt2(Diff1,[3 3]); Imench = imadjust(Diff2); BW = im2bw(Imench,0.12); BW2 = bwareaopen(BW, 300); mask = cast(BW2, class(Imench)); img_masked = Imench .* repmat(mask, [1 1 1]); %Put data in array
array3D{k} = cat(3, img_masked); endfor L = 1:numFrames imVis = mat2gray(array3D{L}); map = gray(255); M(L) = im2frame(imVis,map); endimplay(M);
Best Answer