【发布时间】:2019-05-02 15:09:34
【问题描述】:
我有多个小的 *.mat 文件,每个文件包含 4 个输入图像(template{1:4} 和第二个通道 template2{1:4})和 4 个输出图像(region_of_interests{1:4}),一个二值化(“掩码”)图像来训练深度神经网络。
我基本上按照 Mathworks 和 it suggests to use a function(在本例中为 @matreader)上的示例来读取自定义文件格式。
然而……
- 似乎不可能使用任何加载函数从一个 *.mat 文件加载多个图像,因为它只允许一个输出,并且 imageDatastore 似乎不允许从工作区加载数据。如何做到这一点?
- 同样,从工作区变量加载
pixelLabelDatastore似乎是不可能的。作为一种解决方法,我最终将 *.mat 文件的内容保存到图像中(使用imwrite,保存到save_dir),然后从那里重新加载(在这种情况下,该函数甚至不允许加载 *.mat 文件。)。 (如何)在不将文件重新保存为图像的情况下实现这一点?
这是我失败的尝试:
%main script
image_dir = pwd; %location of *.mat files
save_dir = [pwd '/a/']; %location of saved output masks
imds = imageDatastore(image_dir,'FileExtensions','.mat','ReadFcn',@matreader); %load template (input) images
pxds = pixelLabelDatastore(save_dir,{'nothing','something'},[0 255]);%load region_of_interests (output) image
%etc, etc, go on to train network
%matreader function, save as separate file
function data=matreader(filename)
in=1; %give up the 3 other images stored in template{1:4}
load(filename); %loads template and template2, containing 4x input images each
data=cat(3,template{in},template2{in}); %concatinate 2 template input images in 3rd dimension
end
%generate example data for this question, will save into a file 'example.mat' in workspace
for ind=1:4
template{ind}=rand([200,400]);
template2{ind}=rand([200,400]);
region_of_interests{ind}=rand([200,400])>.5;
end
save('example','template','template2','output')
【问题讨论】:
-
请至少发表评论,以便作者可以改进问题...
-
至于问题1。语法是
data=load(file.mat),其中data将是一个结构体,其字段引用文件file.mat中的所有变量。例如,data.template将是文件中的变量template。
标签: matlab deep-learning