Rgb2gray error
조회 수: 5 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!