下载matlab版完整代码
close all;
clear all;
%% 读取真实图像
im = imread('Set5utterfly_GT.bmp');
%im = imread('Set14zebra.bmp');
%% 设定参数
up_scale = 3;
model = 'modelx3.mat';
% up_scale = 2;
% model = 'modelx2.mat';
% up_scale = 4;
% model = 'modelx4.mat';
%% 仅在照度方面工作
if size(im,3)>1
im = rgb2ycbcr(im);
im = im(:, :, 1);
end
im_gnd = modcrop(im, up_scale);
im_gnd = double(im_gnd)/255;%single 这里换成double Matlab 7.0就可以运行了
%% 双三次插值
im_l = imresize(im_gnd, 1/up_scale, 'bicubic'); %缩小
im_b = imresize(im_l, up_scale, 'bicubic');%再放大
%% SRCNN
im_h = SRCNN(model, im_b);
%% 删除边框
im_h = shave(uint8(im_h * 255), [up_scale, up_scale]);
im_gnd = shave(uint8(im_gnd * 255), [up_scale, up_scale]);
im_b = shave(uint8(im_b * 255), [up_scale, up_scale]);
%% 计算 PSNR
psnr_bic = compute_psnr(im_gnd,im_b);
psnr_srcnn = compute_psnr(im_gnd,im_h);
%% 显示结果
fprintf('双三次插值的峰值信噪比: %f dB
', psnr_bic);
fprintf('SRCNN 重建的峰值信噪比: %f dB
', psnr_srcnn);
figure, imshow(im_b); title('双三次插值');
figure, imshow(im_h); title('SRCNN 重建');
imwrite(im_b, ['双三次插值' '.bmp']);
imwrite(im_h, ['SRCNN 重建' '.bmp']);
官方地址