visualization of the generated image.
pzz2011 opened this issue · 3 comments
pzz2011 commented
I used the modified code below to generate the ouput image of the model, but got images filled by noise. I checked the code a lot of time but didn't find any problem. So can u help me?
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)
def colorize(y, ycbcr):
img = np.zeros((y.shape[0], y.shape[1], 3))
img[:,:,0] = y
img[:,:,1] = ycbcr[:,:,1]
img[:,:,2] = ycbcr[:,:,2]
img = Image.fromarray(img, "YCbCr").convert("RGB")
return img
for image_name in image_list:
print("Processing ", image_name)
im_gt_y = sio.loadmat(image_name)['im_gt_y']
im_b_y = sio.loadmat(image_name)['im_b_y']
im_l_y = sio.loadmat(image_name)['im_l_y']
im_b_ycbcr = sio.loadmat(image_name)['im_b_ycbcr']
im_b_ycbcr = im_b_ycbcr*255.
im_b_ycbcr[im_b_ycbcr<0] = 0
im_b_ycbcr[im_b_ycbcr>255.] = 255.
im_gt_y = im_gt_y.astype(float)
im_b_y = im_b_y.astype(float)
im_l_y = im_l_y.astype(float)
psnr_bicubic = PSNR(im_gt_y, im_b_y,shave_border=opt.scale)
avg_psnr_bicubic += psnr_bicubic
im_input = im_l_y/255.
im_input = Variable(torch.from_numpy(im_input).float()).view(1, -1, im_input.shape[0], im_input.shape[1])
if cuda:
model = model.cuda()
im_input = im_input.cuda()
else:
model = model.cpu()
start_time = time.time()
HR_2x, HR_4x = model(im_input)
elapsed_time = time.time() - start_time
avg_elapsed_time += elapsed_time
HR_4x = HR_4x.cpu()
im_h_y = HR_4x.data[0].numpy().astype(np.float32)
im_h_y = im_h_y*255.
im_h_y[im_h_y<0] = 0
im_h_y[im_h_y>255.] = 255.
im_h_y = im_h_y[0,:,:]
psnr_predicted = PSNR(im_gt_y, im_h_y,shave_border=opt.scale)
avg_psnr_predicted += psnr_predicted
im_h = colorize(im_h_y, im_b_ycbcr)
im_h.save("store path") ==========> save the np array as array
twtygqyy commented
The type of output should be np.uint8
pzz2011 commented
thanks.