Rgb2gray error

16 ビュー (過去 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 Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by