How does this code work?

2 次查看(过去 30 天)
naman varyomalani
naman varyomalani 2020-2-29
clear; close all;
%% settings
folder = 'test img';
scale = 4;
%% generate data
filepaths = dir(fullfile(folder,'*.bmp'));
for i = 1 : length(filepaths)
im_gt = imread(fullfile(folder,filepaths(i).name));
im_gt = modcrop(im_gt, scale);
im_gt = double(im_gt);
im_gt_ycbcr = rgb2ycbcr(im_gt / 255.0);
im_gt_y = im_gt_ycbcr(:,:,1) * 255.0;
im_l_ycbcr = imresize(im_gt_ycbcr, 1/scale, 'bicubic');
im_b_ycbcr = imresize(im_l_ycbcr, scale, 'bicubic');
im_l_y = im_l_ycbcr(:,:,1) * 255.0;
im_l = ycbcr2rgb(im_l_ycbcr) * 255.0;
im_b_y = im_b_ycbcr(:,:,1) * 255.0;
im_b = ycbcr2rgb(im_b_ycbcr) * 255.0;
filename = sprintf('test_img-output/%s.mat',filepaths(i).name);
save(filename, 'im_gt_y', 'im_b_y', 'im_gt', 'im_b', 'im_l_ycbcr', 'im_l_y', 'im_l');
end
  5 个评论
naman varyomalani
naman varyomalani 2020-2-29
the main code is to enhance the image to improve the resolution. the github link of the project is https://github.com/twtygqyy/pytorch-LapSRN. here when i run the demo it takes my image as the ground truth, detoriates it and then performs the action and improves the resolution whereas what i want it to do is take my input as the input and perform the required action. so i wasnt able to understand the purpose of this code, hence the question.
clear; close all;
%% settings
folder = 'test img';
scale = 4;
%% generate data
filepaths = dir(fullfile(folder,'*.bmp'));
for i = 1 : length(filepaths)
im_gt = imread(fullfile(folder,filepaths(i).name));
im_gt = modcrop(im_gt, scale);
im_gt = double(im_gt);
im_gt_ycbcr = rgb2ycbcr(im_gt / 255.0); %convert the gt to red blue form
%imshow(im_gt_ycbcr)
im_gt_y = im_gt_ycbcr(:,:,1) * 255.0; %white image
%imshow(im_gt_y)
im_l_ycbcr = imresize(im_gt_ycbcr, 1/scale, 'bicubic');%decrease the quality of the image and reduce the scale
%imshow(im_l_ycbcr)
im_b_ycbcr = imresize(im_l_ycbcr, scale, 'bicubic'); %further decrease the size of the image but increase the scale
%imshow(im_b_ycbcr)
im_l_y = im_l_ycbcr(:,:,1) * 255.0; %white image
%imshow(im_l_y);
im_l = ycbcr2rgb(im_l_ycbcr) * 255.0; %get the rgb image from the above white image
%imshow(im_l);
im_b_y = im_b_ycbcr(:,:,1) * 255.0; %again white image
%imshow(im_b_y);
im_b = ycbcr2rgb(im_b_ycbcr) * 255.0; %get the rgb from the above white image
%imshow(im_b);
filename = sprintf('test_img-output/%s.mat',filepaths(i).name);
imshow(im_gt_y)
save(filename, 'im_gt_y', 'im_b_y', 'im_gt', 'im_b', 'im_l_ycbcr', 'im_l_y', 'im_l');
end
Walter Roberson
Walter Roberson 2020-2-29
im_l_y = im_l_ycbcr(:,:,1) * 255.0; %white image
Not really white image, but rather luminance image. Close enough to grayscale for your purposes.
%imshow(im_l_y);
im_l = ycbcr2rgb(im_l_ycbcr) * 255.0; %get the rgb image from the above white image
No, we identified the single pane white image as being the luminance image stored into im_l_y, but this line is working with im_l_cbcr which is 3 pane. This is a bug in the implementation.
Which is why documentation and comments are really important. The first version did whatever it actually did, and that defined what it was intended to do.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by