我正在尝试计算图像分类功能的结果,但我一直收到无法找到某个文件的错误
f=dir('C:\Users\bla\Documents\MATLAB\Test');
countco = 0;
countfo = 0;
counthi = 0;
countic = 0;
files={f.name};
for k=3:86
fullFileName = fullfile(files{k});
im = imread(fullFileName);
sub = image_classificationhsv(im);
if (result==Coast)
countcoa = countcoa + 1;
end
if (result==Forest)
countcoa = countfo + 1;
end
if (result==Highway)
countcoa = countcoa + 1;
end
if (result==City)
countcoa = countcoa + 1;
end
end
函数image_classification hsv code
function [class] = image_classificationhsv(image1)
f=dir('C:\Users\bla\Documents\MATLAB\Train');
files={f.name};
for k=1:numel(files)
fullFileName = fullfile(files{k});
cellArrayOfImages{k}=imread(fullFileName);
end
我一直收到错误:
Error using ==> imread at 372
File "coast_arnat59.jpg" does not exist.
Error in ==> image_classificationhsv at 7
cellArrayOfImages{k}=imread(fullFileName);
答案 0 :(得分:0)
读取文件时需要添加路径。最简单的方法是将字符串与[]
连接起来。
p = 'C:\Users\bla\Documents\MATLAB\Test\'
f = dir([p,'*.jpg']); % jpg files in directory
然后:
fname = [p, files{k}]; % path + file name
yourcellarray{k} = imread(fname);