img_path_name.sort() for i in range(len(img_path_name)): # load rgb images rgb = cv2.imread(img_path_name[i]) rgb = cv2.cvtColor(rgb, cv2.COLOR_BGR2RGB) rgb = np.float32(rgb) / 255.0 rgb = np.expand_dims(np.transpose(rgb, [2, 0, 1]), axis=0).copy() print(img_path_name[i].split('/')[-1]) _, img_res = reconstruction_patch_image_gpu(rgb, model, 128, 128) _, img_res_overlap = reconstruction_patch_image_gpu( rgb[:, :, 128 // 2:, 128 // 2:], model, 128, 128) img_res[128 // 2:, 128 // 2:, :] = (img_res[128 // 2:, 128 // 2:, :] + img_res_overlap) / 2.0 rgbFlip = np.flip(rgb, 2).copy() _, img_resFlip = reconstruction_patch_image_gpu(rgbFlip, model, 128, 128) _, img_res_overlapFlip = reconstruction_patch_image_gpu( rgbFlip[:, :, 128 // 2:, 128 // 2:], model, 128, 128) img_resFlip[128 // 2:, 128 // 2:, :] = (img_resFlip[128 // 2:, 128 // 2:, :] + img_res_overlapFlip) / 2.0 img_resFlip = np.flip(img_resFlip, 0) img_res = (img_res + img_resFlip) / 2 mat_name = img_path_name[i].split('/')[-1][:-14] + '.mat' mat_dir = os.path.join(result_path, mat_name) save_matv73(mat_dir, var_name, img_res)
mat_path0_name.sort() mat_path1_name.sort() mat_path2_name.sort() mat_path3_name.sort() for i in range(len(mat_path1_name)): hf0 = h5py.File(mat_path0_name[i]) data0 = hf0.get('cube') res0 = np.transpose(np.array(data0), [2, 1, 0]) hf1 = h5py.File(mat_path1_name[i]) data1 = hf1.get('cube') res1 = np.transpose(np.array(data1), [2, 1, 0]) hf2 = h5py.File(mat_path2_name[i]) data2 = hf2.get('cube') res2 = np.transpose(np.array(data2), [2, 1, 0]) hf3 = h5py.File(mat_path3_name[i]) data3 = hf3.get('cube') res3 = np.transpose(np.array(data3), [2, 1, 0]) res = 0.25 * res0 + 0.25 * res1 + 0.25 * res2 + 0.25 * res3 print(mat_path0_name[i].split('/')[-1], mat_path1_name[i].split('/')[-1], mat_path2_name[i].split('/')[-1], mat_path3_name[i].split('/')[-1]) mat_dir = os.path.join(save_path, mat_path1_name[i].split('/')[-1]) save_matv73(mat_dir, 'cube', res)