Error using rgb2gray parse input

14 ビュー (過去 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 Center および File ExchangeCreating, 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