Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
im2frame

Subject: im2frame

From: Roland

Date: 3 Jun, 2013 14:54:16

Message: 1 of 2

Hello, I'm quite new to Matlab and I ran into a problem with the im2frame function.

I want to make a video of the processed images, but I get the following error message:

Error using ==> im2frame double-precision indexed CData values
must be legal colormap indices: 1.0 <= value <= length(colormap)

I can display the images just fine, but I can't convert them to frames. Could someone please point me to the right direction.

Thanks in advance,

Roland

clc
clear all
close 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;
end

filePattern = 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);
end

%create frames
for L = 1:numFrames
    
    imVis = mat2gray(array3D{L});
    %imshow(imVis);
    %pause(0.25);
    map = gray(256);
    M(L) = im2frame(imVis,map);
end

implay(M);

Subject: im2frame

From: Steven_Lord

Date: 3 Jun, 2013 18:10:00

Message: 2 of 2



"Roland " <r.hoefkens@gmail.com> wrote in message
news:koiamo$p45$1@newscl01ah.mathworks.com...
> Hello, I'm quite new to Matlab and I ran into a problem with the im2frame
> function.
>
> I want to make a video of the processed images, but I get the following
> error message:
> Error using ==> im2frame double-precision indexed CData values
> must be legal colormap indices: 1.0 <= value <= length(colormap)
>
> I can display the images just fine, but I can't convert them to frames.
> Could someone please point me to the right direction.

*snip*

> %create frames
> for L = 1:numFrames
> imVis = mat2gray(array3D{L});
> %imshow(imVis);
> %pause(0.25);
> map = gray(256);
> M(L) = im2frame(imVis,map);
> end

You're mixing image types.

http://www.mathworks.com/help/matlab/creating_plots/image-types.html

MAT2GRAY says it creates intensity images.

http://www.mathworks.com/help/images/ref/mat2gray.html?searchHighlight=intensity

IM2FRAME says it operates on indexed images.

http://www.mathworks.com/help/matlab/ref/im2frame.html?searchHighlight=indexed

It looks like CMUNIQUE may be the function you want to use to convert your
intensity image (returned by MAT2GRAY) into an indexed image (that IM2FRAME
can handle.)

http://www.mathworks.com/help/matlab/image-modifications.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us