记录论文中展示图片数据的方法。
基本思路:将图片读取出来,连接成矩阵或者张量,再展示就可以了。
im 是总文件夹,然后有多个子文件夹,图片类型也是不受限制的。
示例:5个不同类别的 fish,每个类别展示6张,效果图如下
数据来源:https://www.kaggle.com/crowww/a-large-scale-fish-dataset
%% Fish data 样本展示
clear;clc
%%%%
% 确定包含多个子文件夹的总文件夹
maindir = '..\im\'; % 路径
saveImg = [];
p = 768;q = 1024; % 每张图片放缩成 p*q 大小
col = 6+2; % 一行展示六张图片
rw = 100; % 中间的白边宽度为100
whit = zeros(rw,(q+rw)*(col-2),3)+255; % 行与行之间的白边
whit2 = zeros(p,rw,3)+255; % 每行相邻图片之间的白边
% 再确定有哪些子文件夹,并过滤掉干扰的文件
subdir = dir( maindir ); % 确定子文件夹
for i = 3:length(subdir)
% if( isequal( subdir( i ).name, '.' ) || isequal( subdir( i ).name, '..' ) || ~subdir( i ).isdir ) % 如果不是目录跳过
% continue;
% end
% 找出子文件中的目标文件
subdirpath = fullfile( maindir, subdir( i ).name); % 不限制图片文件的类型
images = dir( subdirpath );
% 对目标文件进行读取
tempImg = [];
for j = 3:col
imagepath = fullfile( maindir, subdir( i ).name, images( j).name); % 图片所在路径及图片名
Img = imread(imagepath);
tempImg = [tempImg imresize(Img,[p,q]) whit2];
end
saveImg = [saveImg;whit;tempImg];
end
imshow(saveImg)