讀懂matlab版的SRCNN


% =========================================================================
% Test code for Super-Resolution Convolutional Neural Networks (SRCNN)
%
% Reference
% Chao Dong, Chen Change Loy, Kaiming He, Xiaoou Tang. Learning a Deep Convolutional Network for Image Super-Resolution,
% in Proceedings of European Conference on Computer Vision (ECCV), 2014
%
% Chao Dong, Chen Change Loy, Kaiming He, Xiaoou Tang. Image Super-Resolution Using Deep Convolutional Networks,
% arXiv:1501.00092
%
% Chao Dong
% IE Department, The Chinese University of Hong Kong
% For any question, send email to ndc.forward@gmail.com
% =========================================================================

close all;
clear all;

%% read ground truth image讀入圖片
im = imread('Set5/butterfly_GT.bmp');
%im = imread('Set14\zebra.bmp');

%% set parameters設置SRCNN的每一層的參數,已經訓練好了的
%up_scale = 3;
%model = 'model/9-5-5(ImageNet)/x3.mat';
%up_scale = 3;
%model = 'model/9-3-5(ImageNet)/x3.mat';
%up_scale = 3;
%model = 'model/9-1-5(91 images)/x3.mat';
%up_scale = 2;
%model = 'model/9-5-5(ImageNet)/x2.mat';
up_scale = 4;
model = 'model/9-5-5(ImageNet)/x4.mat';

%% work on illuminance only把圖片轉化為YCbCr的,進行對某一層的處理
if size(im,3)>1%計算第三層的大小
im = rgb2ycbcr(im);
im = im(:, :, 1)

;這個地方把im轉換為第三維的為一,其他的都全部的有什么用??

end剪裁

將圖片裁剪為能夠調整的大小(與放大率匹配)。裁剪舍掉余數行和列

im_gnd = modcrop(im, up_scale);
im_gnd = single(im_gnd)/255;

%% bicubic interpolation
im_l = imresize(im_gnd, 1/up_scale, 'bicubic');
im_b = imresize(im_l, up_scale, 'bicubic');

%% SRCNN
im_h = SRCNN(model, im_b);

%% remove border去除邊緣
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]);

%% compute PSNR
psnr_bic = compute_psnr(im_gnd,im_b);
psnr_srcnn = compute_psnr(im_gnd,im_h);

%% show results
fprintf('PSNR for Bicubic Interpolation: %f dB\n', psnr_bic);
fprintf('PSNR for SRCNN Reconstruction: %f dB\n', psnr_srcnn);

figure, imshow(im_b); title('Bicubic Interpolation');
figure, imshow(im_h); title('SRCNN Reconstruction');

%imwrite(im_b, ['Bicubic Interpolation' '.bmp']);
%imwrite(im_h, ['SRCNN Reconstruction' '.bmp']);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM