How does this code work?
Show older comments
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 Comments
Walter Roberson
on 29 Feb 2020
We have no reason to believe that it works. "Works" requires that it performs the function it was designed to do, but as there is no documentation, we only have two choicesb
- to say that it does not work; or
- to say that whatever it does defines what it is intended to do, like spilling a bunch of paint on a canvas and then saying that whatever results is what the painting was intended to be.
naman varyomalani
on 29 Feb 2020
Walter Roberson
on 29 Feb 2020
What does it exactly do, is whatever, exactly, it does. It does it by making the exact sequence of calls that it makes.
You are asking us to read code without context or documentation or comments, and figure out the purpose of the code. In the absence of context and so on, the purpose of the code is just to be code, just like the purpose of this famous painting is just to be whatever it is.
naman varyomalani
on 29 Feb 2020
Walter Roberson
on 29 Feb 2020
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.
Answers (0)
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!