Rgb2gray error

조회 수: 5 (최근 30일)
Benjamin Lemoine
Benjamin Lemoine 2020년 4월 1일
댓글: Benjamin Lemoine 2020년 4월 2일
Good evening everyone,
I'm trying to read all images in a folder and convert them in gray scale with rgb2gray with this code (my images are not gray scale , there are RGB)
Filelist= dir('Clipboard*.png');
nfiles = length(Filelist);
for i=1:size(Filelist,1)
t=imread(Filelist(i).name);
I(:,:,i)=rgb2gray(t);
end
And after calculate the ssd between all the images :
N=((size(I(:,:,1),1)*size(I(:,:,1),2)).^2);
SSD=zeros(size(Filelist,1),size(Filelist,1));
for i=1:1:nfiles
for j=1:1:nfiles
SSD(i,j)=sum(sum(((I(:,:,i)-I(:,:,j)).^2)/(261501241)));
end
end
imagesc(SSD);
but i have this error:
Error using rgb2gray>parse_inputs (line 80)
MAP must be a m x 3 array.
Error in rgb2gray (line 52)
isRGB = parse_inputs(X);
Error in test21 (line 32)
I(:,:,i)=rgb2gray(t);

채택된 답변

Image Analyst
Image Analyst 2020년 4월 1일
Convert to gray scale:
Filelist= dir('Clipboard*.png');
numberOfFiles = length(Filelist);
for k = 1 : numberOfFiles % Don't use i (the imaginary variable).
thisImage = imread(Filelist(k).name);
[rows, columns, numberOfColorChannels] = size(thisImage);
if k == 1
% Instantiate I with the size of the first image.
I = zeros(rows, columns, numberOfFiles, class(thisImage));
end
if numberOfColorChannels > 1
% It's color. Need to convert to gray scale before putting it into the 3D image as the k'th slice.
I(:,:, k) = rgb2gray(thisImage);
else
% Already grayscale. No need to convert. Just put in directly as the k'th slice.
I(:,:, k) = thisImage;
end
end
  댓글 수: 1
Benjamin Lemoine
Benjamin Lemoine 2020년 4월 2일
Thank you vey much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by