Error using rgb2gray parse input

19 次查看(过去 30 天)
Ulfah
Ulfah 2014-7-9
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

回答(1 个)

Image Analyst
Image Analyst 2014-7-9
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 个评论
Ulfah
Ulfah 2014-8-28
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 2014-8-28
编辑:Image Analyst 2014-8-28
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by