我想检查当前目录中的所有jpg图片是否为灰度图像或包含彩色像素... 我尝试了:
figdirectory = pwd;
fullpath = sprintf('%s/*.jpg', figdirectory);
d = dir(fullpath);
% Loop
pages = [];
for i = 1:length(d)
f = d(i).name;
fname_input = sprintf('%s/%s', figdirectory, f);
A = imread(fname_input);
B = rgb2gray(A);
if(A-B == 0)
hascolor = 0;
else
hascolor = 1;
end
pages = [pages; hascolor];
end
但是这让我在A和B的矩阵维度上出现了错误。为什么A有第三个维度呢?谢谢!
A = imread(fname_input); [r c e] = size(A); if(e > 1) hascolor = 1; else hascolor = 0; end
,但它不起作用:灰度图像也被识别为彩色图像 :( - tim