Error while using rgb2gray

1 Ansicht (letzte 30 Tage)
Febin Benjamin
Febin Benjamin am 14 Jul. 2013
I m trying to accept series of color images and apply edge function on them. this is my code....
if true
for k = 1:10
tifFilename = strcat( num2str(k), '.tif');
[X,map] = imread(tifFilename);
gmap = rgb2gray(map);
BW = edge(gmap,'sobel');
figure, imshow(BW);
end
end
it shows the following error
??? Error using ==> rgb2gray>parse_inputs at 82 MAP must be a m x 3 array.
Error in ==> rgb2gray at 35 X = parse_inputs(varargin{:});
Error in ==> sequenceimageprocessing at 6 gmap = rgb2gray(map);

Akzeptierte Antwort

Image Analyst
Image Analyst am 14 Jul. 2013
Color images don't have a colormap. Try this
fontSize = 20;
for k = 1:10
tifFilename = sprintf('%d.tif', k);
if ~exist(tifFilename, 'file')
fprintf('%s not found.\n', tifFilename);
continue;
end
rgbImage = imread(tifFilename);
grayImage = rgb2gray(rgbImage );
BW = edge(grayImage ,'sobel');
subplot(2,2,1);
imshow(rgbImage);
title('Color Image', 'FontSize', fontSize);
subplot(2,2,2);
imshow(grayImage );
title('Grayscale Image', 'FontSize', fontSize);
subplot(2,2,3);
imshow(BW);
title('Binary Edge Image', 'FontSize', fontSize);
end

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 14 Jul. 2013
Maybe your image is not RGB, check
size(X)
  7 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 14 Jul. 2013
Have you the same error message with this case?
Azzi Abdelmalek
Azzi Abdelmalek am 14 Jul. 2013
Bearbeitet: Azzi Abdelmalek am 14 Jul. 2013
[X,map] = imread(tifFilename)
Check if map is nx3 array
then write
gmap = rgb2gray(map);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images 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!

Translated by