Error while using rgb2gray

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);

 채택된 답변

Image Analyst
Image Analyst 2013년 7월 14일

1 개 추천

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 14일

2 개 추천

Maybe your image is not RGB, check
size(X)

댓글 수: 7

Febin Benjamin
Febin Benjamin 2013년 7월 14일
편집: Febin Benjamin 2013년 7월 14일
size is= 480 640
nw what should i do?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 14일
In windows Matlab command, just to check if your image is nxmx3
i did that.... and it showed me this....
ans=
480 640
now what should i do?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 14일
편집: Azzi Abdelmalek 2013년 7월 14일
Nothing, your image is already grayscale
Febin Benjamin
Febin Benjamin 2013년 7월 14일
편집: Febin Benjamin 2013년 7월 14일
And what if it shows
ans =
3058 3382 3
m sorry if m irritating u..... m a rookie actually.... :)
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 14일
Have you the same error message with this case?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 14일
편집: Azzi Abdelmalek 2013년 7월 14일
[X,map] = imread(tifFilename)
Check if map is nx3 array
then write
gmap = rgb2gray(map);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Blue에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by