load是导入文件,一般从mat文件中,读取的是结构体
imread是图像处理工具箱的库函数,处理图像比较方便,读取的是矩阵
1、之前将数组或者矩阵保存为一个mat格式的文件,在进行load命令读取时:
s1=load(\'qiyipuzong.mat\');
得到的s1是struct类型的数据,而我想要的是一个矩阵或者数组。
经过搜索查询,参考下面这个链接的内容
http://baike.baidu.com/link?url=k4G5EtvGr_zj_MgN2jnjxLFTM9m8hC1nYwUbCAXB3_cVwKBcpcSKMu1PuRhVlgutxhDAW9K3ehAh4M1ahRM4cq
,将命令:
s1=load(\'qiyipuzong.mat\');
改写为:
s1=cell2mat(struct2cell(load(\'qiyipuzong.mat\')));
得到的s1即为矩阵。
2、将普通图像读入变为结构体处理,编写函数load_images实现:
function imgs = load_images(img_name, images_folder)
%% load images
if nargin < 2
images_folder = \'../images/\';
end
target_images_folder = strcat(images_folder, \'target/\');
gsource_images_folder = strcat(images_folder, \'gray_source/\');
csource_images_folder = strcat(images_folder, \'color_source/\');
target_image_name = strcat(target_images_folder, img_name);
gsource_image_name = strcat(gsource_images_folder, img_name);
csource_image_name = strcat(csource_images_folder, img_name);
target_image = im2double(imread(target_image_name));
gsource_image = im2double(imread(gsource_image_name));
csource_image = im2double(imread(csource_image_name));
imgs.target_image = target_image;
imgs.gsource_image = gsource_image;
imgs.csource_image = csource_image;
end