Error using rgb2gray parse input

1 view (last 30 days)
Ulfah
Ulfah on 9 Jul 2014
Edited: Image Analyst on 28 Aug 2014
Hello,
I want to change an image into binary image, and I have the following code:
for i = 1: OBJ.NumberOfFrames
NUM = sprintf('%03d',i);
IMG_ORIGINAL = read(OBJ,i);
IMG_GRAY = rgb2gray(IMG_ORIGINAL);
IMG_BINARY = edge(IMG_GRAY,'canny',90/255);
IMG_EDGE1 = IMG_ORIGINAL;
IMG_EDGE2 = IMG_ORIGINAL;
imwrite(IMG_ORIGINAL, strcat(SAVEFOLDER1,'\ORIGINAL_',NUM,'.bmp'));
imwrite(IMG_GRAY, strcat(SAVEFOLDER2,'\GRAY_',NUM,'.bmp'));
imwrite(IMG_BINARY, strcat(SAVEFOLDER3,'\BINARY_',NUM,'.bmp'));
[y1,x1] = find(IMG_BINARY == 1);
for j = 1:length(x1)
IMG_EDGE1(y1(j),x1(j),1) = 255; % R
IMG_EDGE1(y1(j),x1(j),2) = 0; % G
IMG_EDGE1(y1(j),x1(j),3) = 0; % B
end
Then the following error appeared:
Error using rgb2gray>parse_inputs (line 80)
MAP must be a m x 3 array.
Error in rgb2gray (line 35) X = parse_inputs(X);
Can anybody help me with this, please? Thank you in advance

Answers (1)

Image Analyst
Image Analyst on 9 Jul 2014
What does this say
[rows, columns, numberOfColorChannels] = size(IMG_ORIGINAL);
Then try this:
if numberOfColorChannels > 1
% Only try to convert if it's a color image.
IMG_GRAY = rgb2gray(IMG_ORIGINAL);
else
% Already gray
IMG_GRAY = IMG_ORIGINAL;
end
  19 Comments
Ulfah
Ulfah on 28 Aug 2014
Dear Image Analyst,
Finally i was able to analyze the data. I just need to change IMG_GRAY = rgb2gray(IMG_ORIGINAL) into IMG_GRAY = IMG_ORIGINAL
Thank you for all the discussion.
Do you mind if I ask you 1 more thing? Could you tell me how to open workspace?
Thank you.
Ulfah rimayanti
Image Analyst
Image Analyst on 28 Aug 2014
Edited: Image Analyst on 28 Aug 2014
There is a function called workspace that will open and display the workspace panel if you're running the MATLAB IDE and not a compiled program.
workspace
If you want to see the Current folder panel with the files listed, issue the filebrowser command
filebrowser
If your original question is answered, can you please mark my answer as "Accepted" - thanks.

Sign in to comment.

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!