Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quenstions of testing phase #5

Open
Zheng222 opened this issue Apr 15, 2018 · 13 comments
Open

Quenstions of testing phase #5

Zheng222 opened this issue Apr 15, 2018 · 13 comments

Comments

@Zheng222
Copy link

Zheng222 commented Apr 15, 2018

Hello, I carefully read your test code and find that you use opencv to read image.

SESR/test.py

Lines 63 to 65 in e43f85b

for pimg in pimages:
img=cv2.imread(path+'/'+pimg)
psnr,ssim=predict(img,save,convert,eva,pimg)

Actually, the img is in BGR mode. So the following operations are wrong.

SESR/test.py

Lines 86 to 89 in e43f85b

h,w,_=img_read.shape
im_gt_y=convert_rgb_to_y(img_read)
gt_yuv=convert_rgb_to_ycbcr(img_read)
im_gt_y=im_gt_y.astype("float32")

In addition, the customized convert_rgb_to_y() and convert_rgb_to_ycbcr() functions are different from these in Matlab. I find skimage.color.rgb2ycbcr() is same as that in Matlab.

SESR/test.py

Lines 154 to 162 in e43f85b

def PSNR(pred, gt, shave_border=0):
height, width = pred.shape[:2]
pred = pred[shave_border:height - shave_border, shave_border:width - shave_border]
gt = gt[shave_border:height - shave_border, shave_border:width - shave_border]
imdff = pred - gt
rmse = math.sqrt(np.mean(imdff ** 2))
if rmse == 0:
return 100
return 20 * math.log10(255.0 / rmse)

The inputs of this PSNR function (pred, gt) are float type, but the traditional inputs in Matlab are uint8 type, and I find that using your PSNR function can compute higher psnr index. I obtain the rgb images by using the test code and then test these in Matlab R2017a and get the results as follows.

              PSNR          SSIM
tested
Set5         31.99         0.891

original
Set5         32.11         0.895

@opteroncx

@opteroncx
Copy link
Owner

opteroncx commented Apr 16, 2018

The PSNR and SSIM was computed only on Y channel as I mention in the paper, and the code just copied the bicubic upsampled Cb and Cr channels for visualize the colored image.
PSNR function was borrowed from LapSRN
I also tested the skimage.measure.compare_psnr()
from python package skimage and got the same result.
@Zheng222

@opteroncx
Copy link
Owner

opteroncx commented Apr 16, 2018

Thank you for finding the BGR and RGB issue.
this could be fixed the code for reading with
img = np.array(Image.open(path+'/'+pimg))
so the img will be in RGB channel. And the save function should also change to PIL
And the test result (Set5):
32.11-->32.05

@Zheng222
Copy link
Author

The general practice of computing psnr metric is converting the images (predicted and ground-truth) to uint8 type firstly, and then sending them to compute_psnr function in Matlab. In python, the skimage.messure.compute_psnr() function can be used. I find that your customized psnr function is different from that of Matlab, please reedit it. @opteroncx

@opteroncx
Copy link
Owner

OK, thank you!

@Zheng222
Copy link
Author

Zheng222 commented Apr 16, 2018

SESR/test.py

Line 95 in 4bbdfde

img_y=getY(img_read)

Hello, I can't find the getY function in your code. @opteroncx

@Zheng222
Copy link
Author

Your convert_rgb_to_ycbcr() function is different from that in Matlab, please reedit it. I recommend to use skimage.color.rgb2ycbcr(). @opteroncx

@opteroncx
Copy link
Owner

This function was referred from
https://github.com/jiny2001/dcscn-super-resolution/blob/master/helper/utilty.py
The convert method could be found in
https://en.wikipedia.org/wiki/YCbCr

@Zheng222
Copy link
Author

Due to the other state-of-the-art methods use rgb2ycbcr() function in Matlab, the convert_rgb_to_ycbcr() function appeared in your code could be changed to skimage.rgb2ycbcr() that is same as rgb2ycbcr() in Matlab for fair comparison. @opteroncx

@Zheng222
Copy link
Author

SESR/test.py

Lines 180 to 185 in 14860b5

xform = np.array(
[[65.481 / 256.0, 128.553 / 256.0, 24.966 / 256.0], [- 37.945 / 256.0, - 74.494 / 256.0, 112.439 / 256.0],
[112.439 / 256.0, - 94.154 / 256.0, - 18.285 / 256.0]])
ycbcr_image = image.dot(xform.T)
ycbcr_image[:, :, 0] += (16.0 * max_value / 256.0)
ycbcr_image[:, :, [1, 2]] += (128.0 * max_value / 256.0)

SESR/test.py

Lines 165 to 166 in 14860b5

xform = np.array([[65.481 / 256.0, 128.553 / 256.0, 24.966 / 256.0]])
y_image = image.dot(xform.T) + (16.0 * max_value / 256.0)

These are different from https://en.wikipedia.org/wiki/YCbCr, [65.481 / 256.0, 128.553 / 256.0, 24.966 / 256.0] can be modified to [65.738 / 256.0, 129.057 / 256.0, 25.064 / 256.0]. @opteroncx

@opteroncx
Copy link
Owner

opteroncx commented Apr 17, 2018

https://github.com/scikit-image/scikit-image/blob/b0aed02ce906dcf9232ba428f829c8a3d4a74a2b/skimage/color/colorconv.py#L404-L408

Same for Y channel in the source code of skimage
Could you show the code of matlab?
@Zheng222

@Zheng222
Copy link
Author

Zheng222 commented Apr 17, 2018

The skimage.color.rgb2ycbcr() is [65.481 / 255.0, 128.553 / 255.0, 24.966 / 255.0]. The denominator is not 256. You can directly use the skimage.color.rgb2ycbcr() function. @opteroncx
The following is matlab rgb2ycbcr,

origT = [ ...
    65.481 128.553 24.966;...
    -37.797 -74.203 112; ...
    112 -93.786 -18.214];
origOffset = [16; 128; 128];

% The formula ycbcr = origT * rgb + origOffset, converts a RGB image in the
% range [0 1] to a YCbCr image where Y is in the range [16 235], and Cb and
% Cr are in that range [16 240]. For each class type, we must calculate
% scaling factors for origT and origOffset so that the input image is
% scaled between 0 and 1, and so that the output image is in the range of
% the respective class type.

scaleFactor.float.T = 1/255;      % scale output so in range [0 1].
scaleFactor.float.offset = 1/255; % scale output so in range [0 1].
scaleFactor.uint8.T = 1/255;      % scale input so in range [0 1].
scaleFactor.uint8.offset = 1;     % output is already in range [0 255].
scaleFactor.uint16.T = 257/65535; % scale input so it is in range [0 1]
% and scale output so it is in range
% [0 65535] (255*257 = 65535).
scaleFactor.uint16.offset = 257;   % scale output so it is in range [0 65535].

@opteroncx
Copy link
Owner

emmm....
I will fix it, thank you.

@opteroncx
Copy link
Owner

Maybe I have to inform https://github.com/jiny2001 about this issue, since I borrowed this function from https://github.com/jiny2001/dcscn-super-resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants