attempt to execute rgb2gray but showing error
1 view (last 30 days)
Show older comments
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 Comment
Steven Lord
on 15 Apr 2019
That's not the full text of the error message. Show us all the text displayed in red.
Answers (1)
Image Analyst
on 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 Comments
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!