attempt to execute rgb2gray but showing error

1 visualizzazione (ultimi 30 giorni)
Shweta Mahajan
Shweta Mahajan il 15 Apr 2019
Risposto: Image Analyst il 15 Apr 2019
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 Commento
Steven Lord
Steven Lord il 15 Apr 2019
That's not the full text of the error message. Show us all the text displayed in red.

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 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);

Categorie

Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by