Error using rgb2gray parse input

조회 수: 3 (최근 30일)
Ulfah
Ulfah 2014년 7월 9일
편집: Image Analyst 2014년 8월 28일
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