def solve_intrinsics(dir): os.chdir(dir) for file in glob.glob("*rgb.png"): print(file) input = IntrinsicInput.from_file(file) solver = IntrinsicSolver(input, IntrinsicParameters()) r, s, decomposition = solver.solve() name = file.split(".")[0] image_util.save(dir + "/" + name + "_r.png", r, rescale=True) image_util.save(dir + "/" + name + "_s.png", s, rescale=True)
def decompose_single_image(image_file, feat_net, rref_net, nystrom_file=None, srgb=True, save_reflectance_file=None, save_shading_file=None): """ Input: image_file - file path to the input image feat_net - caffe net for extracting dense local features rref_net - caffe net for relative reflectance judgment Output: Estimated reflectance and shading layers of the input image """ if nystrom_file is not None: W_ns = pickle.load(open(nystrom_file, 'rb')) else: W_ns = nystrom_single_image(image_file, feat_net, rref_net) input = IntrinsicInput.from_file(image_file, image_is_srgb=srgb) params = IntrinsicParameters() solver = IntrinsicSolver(input, params, W_ns) reflectance, shading, decomposition = solver.solve() if save_reflectance_file is not None: image_util.save(save_reflectance_file, reflectance, rescale=True, srgb=srgb) if save_shading_file is not None: image_util.save(save_shading_file, shading, rescale=True, srgb=srgb) return reflectance, shading
print("Applying texture to model") proc_texture = subprocess.Popen([ os.path.join(OMVS_BIN, "TextureMesh"), "scene_dense_mesh_refine.mvs", "-w", MVS_DIR ]) proc_texture.wait() print("----------/nINTRINSIC DECOMPOSITION") in_name = raw_input("Image filename: ") base, _ = os.path.splitext(in_name) r_name = base + "-R.png" s_name = base + "-S.png" in_img = IntrinsicInput.from_file(os.path.join(INPUT_DIR, in_name)) params = IntrinsicParameters() params.logging = True solver = IntrinsicSolver(in_img, params) reflect, shading, decomp = solver.solve() image_util.save(r_name, reflect, mask_nz=in_img.mask_nz, rescale=True, srgb=True) image_util.save(s_name, shading, mask_nz=in_img.mask_nz, rescale=True, srgb=True)
mask_filename=mask_filename, judgements_filename=judgements_filename, ) print('mask_nnz: %s' % input.mask_nnz) print('rows * cols: %s' % (input.rows * input.cols)) # load parameters if parameters_filename: params = IntrinsicParameters.from_file(parameters_filename) else: params = IntrinsicParameters() params.logging = not args.quiet # solve solver = IntrinsicSolver(input, params) r, s, decomposition = solver.solve() # save output image_util.save(r_filename, r, mask_nz=input.mask_nz, rescale=True, srgb=sRGB) image_util.save(s_filename, s, mask_nz=input.mask_nz, rescale=True, srgb=sRGB) if args.show_labels: labels_vis = decomposition.get_labels_visualization() r_path, r_ext = os.path.splitext(r_filename) image_util.save('%s_labels%s' % (r_path, r_ext), labels_vis, mask_nz=solver.input.mask_nz, rescale=True) # compute error if judgements_filename: print 'WHDR: %.1f%%' % (input.compute_whdr(r) * 100.0)