attempt to execute rgb2gray but showing error
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Here's my code
clc; %rgb2gray
a=imread('2.jpg');
c=rgb2gray(a);
f=double(c);
[row, col, dim]=size(f);
b=255;
g=b-c;
subplot(2,2,1);
imshow(a);
title('original image');
subplot(2,2,2);
imshow(c);
title('rgb2gray');
subplot(2,2,3);
colormap(gray);
imshow(g);
title('negative image');
The error message is :
Error in rg (line 3)
c=rgb2gray(a);
1 Kommentar
Steven Lord
am 15 Apr. 2019
That's not the full text of the error message. Show us all the text displayed in red.
Antworten (1)
Image Analyst
am 15 Apr. 2019
Replace this:
a=imread('2.jpg');
c=rgb2gray(a);
f=double(c);
[row, col, dim]=size(f);
with this:
a = imread('2.jpg');
[row, col, numberOfColorChannels] = size(a)
if numberOfColorChannels == 3
% Convert only if color
grayImage = rgb2gray(a);
else
grayImage = a;
end
f=double(grayImage);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!