def create_hdf5_container(path_i1, path_o, lf_name): px = 48 py = 48 nviews = 9 sx = 16 sy = 16 file = h5py.File(path_o + '/' + lf_name + '.hdf5', 'w') # read diffuse color LF = file_io.read_lightfield(path_i1) LF = LF.astype(np.float32) # / 255.0 cv_gt = lf_tools.cv(LF) lf_tools.save_image(path_o + '/' + lf_name, cv_gt) # maybe we need those, probably not. param_dict = file_io.read_parameters(path_i1) dset_blocks = [] # block count: write out one individual light field cx = np.int32((LF.shape[3] - px) / sx) + 1 cy = np.int32((LF.shape[2] - py) / sy) + 1 for i, j in itertools.product(np.arange(0, nviews), np.arange(0, nviews)): dset_blocks.append( file.create_dataset('views%d%d' % (i, j), (cy, cx, 3, px, py), chunks=(1, 1, 3, px, py), maxshape=(None, None, 3, px, py))) # lists indexed in 2D dset_blocks = [ dset_blocks[x:x + nviews] for x in range(0, len(dset_blocks), nviews) ] sys.stdout.write(lf_name + ': ') for bx in np.arange(0, cx): sys.stdout.write('.') sys.stdout.flush() for by in np.arange(0, cy): x = bx * sx y = by * sx # extract data for i, j in itertools.product(np.arange(0, nviews), np.arange(0, nviews)): dset_blocks[i][j][bx, by, :, :, :] = np.transpose( np.array(LF[i, j, x:x + px, y:y + py, :]), (-1, 0, 1)).reshape(3, px, py) sys.stdout.write(' Done.\n')
def convert_to_hdf5(data_folder, tgt=None): if tgt is None: tgt = os.path.join(data_folder, "scene.h5") scene = dict() scene["LF"] = file_io.read_lightfield(data_folder) params = file_io.read_parameters(data_folder) if params["category"] != "test": scene["disp_highres"] = file_io.read_disparity(data_folder, highres=True) scene["disp_lowres"] = file_io.read_disparity(data_folder, highres=False) scene["depth_highres"] = file_io.read_depth(data_folder, highres=True) scene["depth_lowres"] = file_io.read_depth(data_folder, highres=False) file_io.write_hdf5(scene, tgt)
def visualize_scene(data_folder): params = file_io.read_parameters(data_folder) if params["category"] == "test": print("Test scenes with hidden ground truth are not visualized.") return light_field = file_io.read_lightfield(data_folder) disp_map_highres = file_io.read_disparity(data_folder, highres=True) disp_map_lowres = file_io.read_disparity(data_folder, highres=False) depth_map_lowres = file_io.read_depth(data_folder, highres=False) rows, cols = 1, 4 cb_shrink = 0.7 fig = plt.figure(figsize=(20, 4)) plt.suptitle("%s:%s (%s)" % (params["category"].title(), params["scene"].title(), "x".join(str(i) for i in list(np.shape(light_field))))) plt.subplot(rows, cols, 1) plt.title("Center View") plt.imshow(light_field[4, 4, :, :, :]) plt.subplot(rows, cols, 2) plt.title("Depth Map (%dx%d)" % np.shape(depth_map_lowres)) cc = plt.imshow(depth_map_lowres, cmap=cm.viridis, interpolation="none") plt.colorbar(cc, shrink=cb_shrink) plt.subplot(rows, cols, 3) plt.title("Disparity Map (%dx%d)" % np.shape(disp_map_lowres)) cc = plt.imshow(disp_map_lowres, cmap=cm.viridis, interpolation="none") plt.colorbar(cc, shrink=cb_shrink) plt.subplot(rows, cols, 4) plt.title("Disparity Map (%dx%d)" % np.shape(disp_map_highres)) cc = plt.imshow(disp_map_highres, cmap=cm.viridis, interpolation="none") plt.colorbar(cc, shrink=cb_shrink) fig_name = os.path.join(data_folder, "scene.png") plt.savefig(fig_name, dpi=200, bbox_inches='tight') fig.clf() plt.close(fig)
# data_folders.append('platonic') # data_folders.append('rosemary') # data_folders.append('sideboard') # data_folders.append('table') # data_folders.append('tomb') # data_folders.append('town') # data_folders.append('vinyl') cv = np.zeros([2, 512, 512, 3]) dispgt = np.zeros([2, 512, 512]) n = 0 for lf_name in data_folders: data_folder = os.path.join(data_source, lf_name) LF = file_io.read_lightfield(data_folder) LF = LF.astype(np.float32) disp = file_io.read_disparity(data_folder) disp_gt = np.array(disp[0]) disp_gt = np.flip(disp_gt, 0) dispgt[n, :, :] = disp_gt cv[n, :, :, :] = lf_tools.cv(LF) n = n + 1 stack_h, stack_v = refocus_cross(cv, dispgt, 9) # for k in range(0,9): # plt.figure(k) # plt.imshow(stack_h[k, :, :, :])
# maxshape=(nviews, py, px, 3, None)) # dset_HS = np.random.normal(0, 0.1, [py_LR_s4, px_LR_s4, h_dim]) # dset_HS = np.ones([py_LR_s4, px_LR_s4, h_dim])/10 index = 0 idx_folder = 0 for folder in data_folders_all: if folder == 'Benchmark': data_folders = os.listdir(data_source + folder + '/') for lf_name in data_folders: data_folder = os.path.join(data_source, lf_name) print("now %i / %i" % (idx_folder + 1, len(data_folders))) idx_folder = idx_folder + 1 data_path = data_source + folder + '/' + lf_name LF_temp = file_io.read_lightfield(data_path) LF_temp = LF_temp.astype(np.float32) # write out one individual light field # block count cx_HR = np.int32((LF_temp.shape[3] - px_LR_s4) / sx_LR_s4) + 1 cy_HR = np.int32((LF_temp.shape[2] - py_LR_s4) / sy_LR_s4) + 1 for by in np.arange(0, cy_HR): sys.stdout.write('.') sys.stdout.flush() for bx in np.arange(0, cx_HR): x_LR_s2 = bx * sx_LR_s2 y_LR_s2 = by * sx_LR_s2