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')
# # loop over all datasets, write out each dataset in patches # to feed to autoencoder in random order # index = 0 for lf_name in data_folders: data_file = os.path.join(data_source, lf_name) # input LF mat_content = h5py.File(data_file, 'r') LF = mat_content['LF'].value LF = np.transpose(LF, (4, 3, 2, 1, 0)) cv_gt = lf_tools.cv(LF) lf_tools.save_image(training_data_dir + 'input' + lf_name, cv_gt) # write out one individual light field # block count cx = np.int32((LF.shape[3] - px) / sx) + 1 cy = np.int32((LF.shape[2] - py) / sy) + 1 for by in np.arange(0, cy): sys.stdout.write('.') sys.stdout.flush() for bx in np.arange(0, cx): x = bx * sx y = by * sx
nan_LF_sh = np.sum(np.isnan(LF_sh) == True) nan_LF_specular = np.sum(np.isnan(LF_specular) == True) nan_disp = np.sum(np.isnan(disp_gt) == True) inf_LF = np.sum(np.isinf(LF) == True) inf_LF_albedo = np.sum(np.isinf(LF_albedo) == True) inf_LF_sh = np.sum(np.isinf(LF_sh) == True) inf_LF_specular = np.sum(np.isinf(LF_specular) == True) inf_disp = np.sum(np.isinf(disp_gt) == True) naninf_sum = nan_disp + nan_LF + nan_LF_albedo + nan_LF_sh + nan_LF_specular + inf_disp + inf_LF + inf_LF_albedo + inf_LF_sh + inf_LF_specular if naninf_sum > 0: print('inf_nan' + lf_name) lf_name = lf_name + '_inf_nan' lf_tools.save_image(data_source + '\\' + 'input_' + lf_name, lf_tools.cv(LF)) lf_tools.save_image(data_source + '\\' + 'albedo_' + lf_name, lf_tools.cv(LF_albedo)) lf_tools.save_image( data_source + '\\' + 'sh_' + lf_name + '_' + np.str(np.amax(LF_sh)), lf_tools.cv(LF_sh)) lf_tools.save_image( data_source + '\\' + 'specular_' + lf_name + '_' + np.str(np.amax(LF_specular)), lf_tools.cv(LF_specular)) # write out one individual light field # block count cx = np.int32((LF.shape[3] - px) / sx) + 1 cy = np.int32((LF.shape[2] - py) / sy) + 1 for by in np.arange(0, cy):