def convert2YUV(input, stream, idx): streamtmp = input[stream][idx] streamtmp = rgb2YUV(streamtmp) input[stream][idx] = streamtmp return (input)
def encode_decode_lightfield(data, LF_LR, LF_HR, inputs, outputs, ColorSpace, decoder_path='cv'): # light field size H = LF_LR.shape[2] W = LF_LR.shape[3] H_HR = LF_HR.shape[2] W_HR = LF_HR.shape[3] dc = cdf.data_config # patch step sizes bs_y = dc['SY'] bs_x = dc['SX'] bs_y_HR = dc['SY_HR'] bs_x_HR = dc['SX_HR'] # patch height/width ps_y = dc['H'] ps_x = dc['W'] ps_y_HR = dc['H_HR'] ps_x_HR = dc['W_HR'] ps_v = dc['D'] # patches per row/column by = np.int16((H - ps_y) / bs_y) + 1 bx = np.int16((W - ps_x) / bs_x) + 1 # one complete row per batch cv_interp = np.zeros([H_HR, W_HR, 3], np.float32) cv_raw = np.zeros([H_HR, W_HR, 3], np.float32) mask_sum = np.zeros([H_HR, W_HR], dtype=np.float32) print('starting LF encoding/decoding [', end='', flush=True) start = timer() results_received = 0 for py in range(by): print('.', end='', flush=True) stacks_h = np.zeros([bx, ps_v, ps_y, ps_x, 3], np.float32) stacks_v = np.zeros([bx, ps_v, ps_y, ps_x, 3], np.float32) cv_in = np.zeros([bx, ps_y_HR, ps_x_HR, 3], np.float32) for px in range(bx): # get single patch patch = cdf.get_patch(LF_LR, py, px) stacks_v[px, :, :, :, :] = patch['stack_v'] stacks_h[px, :, :, :, :] = patch['stack_h'] cv_in[px, :, :, :] = patch['cv'] if ColorSpace == 'YUV': stacks_v[px, :, :, :, :] = rgb2YUV(stacks_v[px, :, :, :, :]) stacks_h[px, :, :, :, :] = rgb2YUV(stacks_h[px, :, :, :, :]) cv_in[px, :, :, :] = rgb2YUV(cv_in[px, :, :, :]) elif ColorSpace == 'YCBCR': stacks_v[px, :, :, :, :] = rgb2YCbCr(stacks_v[px, :, :, :, :]) stacks_h[px, :, :, :, :] = rgb2YCbCr(stacks_h[px, :, :, :, :]) cv_in[px, :, :, :] = rgb2YCbCr(cv_in[px, :, :, :]) elif ColorSpace == 'LAB': stacks_v[px, :, :, :, :] = rgb2lab(stacks_v[px, :, :, :, :]) stacks_h[px, :, :, :, :] = rgb2lab(stacks_h[px, :, :, :, :]) cv_in[px, :, :, :] = rgb2lab(cv_in[px, :, :, :]) # push complete batch to encoder/decoder pipeline batch = dict() batch['stacks_h'] = stacks_h batch['stacks_v'] = stacks_v batch['cv'] = cv_in batch['py'] = py batch['decoder_path'] = decoder_path inputs.put(batch) # if not outputs.empty(): result = outputs.get() add_result_to_cv(data, result, cv_interp, cv_raw, mask_sum, bs_x_HR, bs_y_HR, bx, dc) results_received += 1 outputs.task_done() # catch remaining results while results_received < by: result = outputs.get() add_result_to_cv(data, result, cv_interp, cv_raw, mask_sum, bs_x_HR, bs_y_HR, bx, dc) results_received += 1 outputs.task_done() # elapsed time since start of dmap computation end = timer() total_time = end - start print('] done, total time %g seconds.' % total_time) # evaluate result mse = 0.0 # compute stats and return result print('total time ', end - start) # print('MSE : ', mse) # code.interact( local=locals() ) return (cv_interp, total_time, mse, mask_sum, cv_raw)
import numpy as np import matplotlib.pyplot as plt import numpy as np from libs.convert_colorspace import rgb2YUV, rgb2YCbCr from scipy.misc import imread from skimage.color import rgb2lab, lab2rgb a = np.zeros((2, 512, 512, 3)) imgx = imread( '/home/z/PycharmProjects/SR/full_data_512/platonic/input_Cam044.png') / 255 imgy = imread( '/home/z/PycharmProjects/SR/full_data_512/platonic/input_Cam045.png') / 255 a[0, :, :, :] = imgx a[1, :, :, :] = imgy a2 = rgb2lab(a) img1x = rgb2lab(imgx) img1y = rgb2lab(imgy) err1 = np.sum(np.abs(img1x - a2[0, :, :, :])) err2 = np.sum(np.abs(img1y - a2[1, :, :, :])) img2 = rgb2YUV(imgx) err = np.sum(np.abs(img1x - img2)) k = 0
data_file = data_eval_folder + lf_name[0] + "/" + lf_name[1] + "/" + lf_name[2] + "/" + \ lf_name[3] + ".hdf5" hdf_file = h5py.File(data_file, 'r') # hard-coded size, just for testing LF_LR = hdf_file['LF_LR'] LF_HR = hdf_file['LF'] cv_gt = lf_tools.cv(LF_HR) cv_LR = lf_tools.cv(LF_LR) data = [] color_space = hp.config['ColorSpace'] if color_space == 'YUV': cv_gt_orig = rgb2YUV(cv_gt) cv_LR_orig = rgb2YUV(cv_LR) decoder_path = 'Y' result_cv = encode_decode_lightfield( data, LF_LR, LF_HR, inputs, outputs, color_space, decoder_path=decoder_path, ) cv_out1 = result_cv[0] mask = result_cv[3]