DIV2K数据集官网上很好找到,但是网上流传的Set5 14 BSD100,Urban100 Manga109都是私人进行处理过的版本,各个处理方式都不同,为了统一方式写了这篇文章。
官方的DIV2K x2、x3、x4的LR图片使用下面matlab代码生成(已经经过测试最后输出为0,就是差异为0)文末给出下载地址。
DIV2K_hr = '0002.png';
savepath = 'tmp.png';
DIV2K_lr = '0002_x2.png';
scale = 2;
hr_img = imread(DIV2K_hr);
%hr_img = im2double(hr_img);
lr_img = imread(DIV2K_lr);
crop_img = modcrop(hr_img ,scale);
crop_lr_img = imresize(crop_img ,1/scale,'bicubic');
imwrite(crop_lr_img,savepath);
crop_lr_img = imread(savepath)
disp(max(crop_lr_img(:)-lr_img(:)))
但是x8的LR图片使用下面代码生成
DIV2K_hr = '0002.png';
savepath = 'tmp.png';
DIV2K_lr = '0002_x2.png';
scale = 2;
hr_img = imread(DIV2K_hr);
hr_img = im2double(hr_img);
lr_img = imread(DIV2K_lr);
crop_img = modcrop(hr_img ,scale);
crop_lr_img = imresize(crop_img ,1/scale,'bicubic');
imwrite(crop_lr_img,savepath);
crop_lr_img = imread(savepath)
disp(max(crop_lr_img(:)-lr_img(:)))
但是经过测试发现网上流传的很多Set5 14 BSD100,Urban100 Manga109并不是经过上面matlab生成的。也就是说你网络训练输入是matlab的LR,但是测试的时候输入的并不是matlab生成的LR。
为了统一,生成了一套和训练集相匹配格式的测试集。matlab代码使用如下(代码参考SRCNN):
最后生成目录:
%创建modcrop.m文件放入代码
function imgs = modcrop(imgs, modulo)
if size(imgs,3)==1
sz = size(imgs);
sz = sz - mod(sz, modulo);
imgs = imgs(1:sz(1), 1:sz(2));
else
tmpsz = size(imgs);
sz = tmpsz(1:2);
sz = sz - mod(sz, modulo);
imgs = imgs(1:sz(1), 1:sz(2),:);
end
end
%主文件main.m
%适用Set5,Set14,Urban100,Manga109,更改对应路径就行了
input_folder = '/MATLAB Drive/train/data/Urban100/HR';
save_mod_folder = '/MATLAB Drive/train/data/Urban100/image_SRF_';
filepaths = dir(fullfile(input_folder,'*.*'));
for i=2:4
lr_path = [save_mod_folder,num2str(i),'/LR'];
hr_path = [save_mod_folder,num2str(i),'/HR'];
check(lr_path)
check(hr_path)
for j = 1 : length(filepaths)
[paths, img_name, ext] = fileparts(filepaths(j).name);
if ext == '.png'
img_hr = imread(fullfile(input_folder, [img_name, ext]));
%img_hr = im2double(img_hr);
crop_hr = modcrop(img_hr,i);
imwrite(crop_hr,fullfile(hr_path, [img_name, ext]));
img_lr = imresize(crop_hr,1/i,'bicubic');
imwrite(img_lr,fullfile(lr_path, [img_name, ext]));
end
end
end
for i=8:8
lr_path = [save_mod_folder,num2str(i),'/LR'];
hr_path = [save_mod_folder,num2str(i),'/HR'];
check(lr_path)
check(hr_path)
for j = 1 : length(filepaths)
[paths, img_name, ext] = fileparts(filepaths(j).name);
if ext == '.png'
img_hr = imread(fullfile(input_folder, [img_name, ext]));
img_hr = im2double(img_hr);
crop_hr = modcrop(img_hr,i);
imwrite(crop_hr,fullfile(hr_path, [img_name, ext]));
img_lr = imresize(crop_hr,1/i,'bicubic');
imwrite(img_lr,fullfile(lr_path, [img_name, ext]));
end
end
end
function check(path)
if exist(path, 'dir')
disp(['It will cover ', path]);
else
mkdir(path);
end
end
% BSD100 Function:
save_folder = '/MATLAB Drive/train/data/BSD100/image_SRF_';
for i=2:4
input_folder = '/MATLAB Drive/train/data/BSD100/image_SRF_3/HR';
hr_path = [save_folder,num2str(i),'/HR'];
lr_path = [save_folder,num2str(i),'/LR'];
filepaths = dir(fullfile(input_folder,'*.*'));
check(lr_path);
check(hr_path);
for j = 1 : length(filepaths)
[paths, img_name, ext] = fileparts(filepaths(j).name);
if ext == '.png'
img_hr = imread(fullfile(input_folder, [img_name, ext]));
%img_hr = im2double(img_hr);
crop_hr = modcrop(img_hr,i);
imwrite(crop_hr,fullfile(hr_path, [img_name, ext]));
img_lr = imresize(crop_hr,1/i,'bicubic');
imwrite(img_lr,fullfile(lr_path, [img_name, ext]));
end
end
end
for i=8:8
input_folder = '/MATLAB Drive/train/data/BSD100/image_SRF_3/HR';
hr_path = [save_folder,num2str(i),'/HR'];
lr_path = [save_folder,num2str(i),'/LR'];
filepaths = dir(fullfile(input_folder,'*.*'));
check(lr_path);
check(hr_path);
for j = 1 : length(filepaths)
[paths, img_name, ext] = fileparts(filepaths(j).name);
if ext == '.png'
img_hr = imread(fullfile(input_folder, [img_name, ext]));
img_hr = im2double(img_hr);
crop_hr = modcrop(img_hr,i);
imwrite(crop_hr,fullfile(hr_path, [img_name, ext]));
img_lr = imresize(crop_hr,1/i,'bicubic');
imwrite(img_lr,fullfile(lr_path, [img_name, ext]));
end
end
end
function check(path)
if exist(path, 'dir')
disp(['It will cover ', path]);
else
mkdir(path);
end
end
链接:https://pan.baidu.com/s/1qeftNHrWSjLxfhJCjfqNyw?pwd=9ag4
https://drive.google.com/file/d/1Wk_OXbfFkNuWxIz23Ji56Ju4knH4DeFm/view?usp=drive_link
阿里云盘不支持压缩文件分享,而且一次最多分享200个文件,吐了,国产软件各有利弊吧