超分辨数据集:Set5 Set14 BSD100 Urban100 Manga109

2023-12-21 09:29:57

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):

运行代码前的数据目录格式:
  • ?Set5
    • HR
      • 这里存放高清图片
  • Set14
    • HR
      • 这里存放高清图片
  • ?Urban100
    • HR
      • 这里存放高清图片
  • Managa109
    • HR
      • 这里存放高清图片
  • BSD100
    • image_SRF_3
      • HR
        • 这里存放高清图片(由于x2 x4都是从x3的HR裁剪而来的,懒得更改源数据集格式)

最后生成目录:

  • 公共代码
%创建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
  • Set5,Set14,Urban100,Manga109 对应x2、x3、x4、x8代码
%主文件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

  • 由于BSD使用x3的HR作为x2和x4、x8的裁剪之前的图片所以更改main.m中的代码
% 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个文件,吐了,国产软件各有利弊吧

文章来源:https://blog.csdn.net/weixin_43191153/article/details/135116049
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。