这个问题在这里已有答案:
在演示2中,我正在深入学习食物检测。为此,使用.mat文件。我想使用代码进行道路标志检测,但我不知道如何创建我的.mat文件。我有25个图像用于输入,我想做一个.mat文件。我在互联网上搜索,我发现了以下代码。
%Generate mat file
srcFile = dir('..\ROAD-SIGN\*.jpg')
result = cell(1,length(srcFile))
for i = 1 : length(srcFile)
filename = strcat('...\ROAD-SIGN\',srcFile(i).name)
I = imread(filename);
%figure, imshow(I);
I = imresize(I,[273 273]);
result{i} = I;
%figure, imshow(result{i});
end
save images1.mat, result;
length(srcFile)
load('images1.mat')
for j = 1:length(srcFile)
figure, imshow(result{j});
end
%Read mat file
for j =1 :length(srcFile)
filename = strcat('...\ROAD-SIGN\',srcFile(j).name);
I = imread(filename);
a='I';
input = load('images1.mat',a);
figure, imshow(input.(a));
end
whos -file images1.mat
但它不起作用,因为在主程序中使用的是图层属性。在我的.mat文件的代码中,我没有layer属性。
任何人都可以帮我解决问题吗?enter image description here
要从工作区创建包含某些变量的mat文件,您应该能够使用:
save('matfilename','result');
问题是您是否需要为此特定示例创建mat文件?您已经在'结果'中显示了图像,是否真的需要保存它们然后再次加载它们?
另外,(提示!)查看ImageDatastore以便于阅读输入文件。