def main(): if not os.path.exists(args.in_path): print("Input file does not exist.") return if os.path.exists(args.out_path): overwrite = input("Overwrite? y/n: ") if overwrite != 'y': print("Aborting.") return im = cv2.imread(args.in_path, -1) # OpenCV uses BGR. im = im[:, :, [2, 1, 0]] print("Saving to {}".format(args.out_path)) pfm_write(args.out_path, im)
def save(self, path): reverse_path = os.path.join(path, 'out', 'reverse') if not os.path.exists(reverse_path): os.makedirs(reverse_path) pfm_write(os.path.join(reverse_path, MAP_DIFF_FNAME), self.diffuse_map) pfm_write(os.path.join(reverse_path, MAP_SPEC_FNAME), self.specular_map) pfm_write(os.path.join(reverse_path, MAP_SPEC_SHAPE_FNAME), self.spec_shape_map) pfm_write(os.path.join(reverse_path, MAP_NORMAL_FNAME), self.normal_map) with open(os.path.join(reverse_path, MAP_PARAMS_FNAME), 'w') as f: f.write("{} {}".format(self.alpha, 0.0))
def main(): if not os.path.exists(args.in_path): print("Input file does not exist.") return if os.path.exists(args.out_path): overwrite = input("Overwrite? y/n: ") if overwrite != 'y': print("Aborting.") return panorama = pfm_read(args.in_path, transposed=True) cubemap = panorama_to_cubemap(panorama) cross = stack_cross(cubemap) if args.display: plt.subplot(121) plt.imshow(np.clip(panorama, 0, 1)) plt.subplot(122) plt.imshow(np.clip(cross, 0, 1)) plt.show() print("Saving to {}".format(args.out_path)) pfm_write(args.out_path, cross)
def main(): parser = argparse.ArgumentParser() parser.add_argument(dest='path', type=str) parser.add_argument('-o', '--out', dest='out_path', type=str, required=True) args = parser.parse_args() if not os.path.exists(args.path): print("File does not exist.") return im = misc.imread(args.path) print(im.min(), im.max()) if im.dtype == np.uint8: im = im.astype(np.float32) / 255.0 print("Saving PFM to {}".format(args.out_path)) pfm.pfm_write(args.out_path, im)
def __init__(self, path=None, diffuse_map=None, specular_map=None, spec_shape_map=None, normal_map=None, alpha=None, cdf_sampler=None, pdf_sampler=None, sigma_min=None, sigma_max=None, suppress_outliers=True, transposed=False): if path is not None: if not os.path.exists(str(path)): raise FileNotFoundError( 'The path {} does not exist'.format(path)) self.path = str(path) data_path = os.path.join(self.path, 'out/reverse') with open(os.path.join(data_path, MAP_PARAMS_FNAME), 'r') as f: line = f.readline() self.alpha, _ = [float(i) for i in line.split(' ')] tic = time() self.diffuse_map = pfm_read(os.path.join(data_path, MAP_DIFF_FNAME), transposed=transposed) self.specular_map = pfm_read(os.path.join(data_path, MAP_SPEC_FNAME), transposed=transposed) self.normal_map = pfm_read(os.path.join(data_path, MAP_NORMAL_FNAME), transposed=transposed) self.spec_shape_map = pfm_read(os.path.join( data_path, MAP_SPEC_SHAPE_FNAME), transposed=transposed) logger.info("Loaded \'{}\', shape={}, alpha={} ({:.04f}s)".format( self.name, self.diffuse_map.shape, self.alpha, time() - tic)) tic = time() is_cdf_path = os.path.join(data_path, IS_CDF_FNAME) is_pdf_path = os.path.join(data_path, IS_PDF_FNAME) is_sigma_range_path = os.path.join(data_path, IS_SIGMA_RANGE_FNAME) if os.path.exists(is_cdf_path): self.cdf_sampler = pfm_read(is_cdf_path) self.pdf_sampler = pfm_read(is_pdf_path) with open(is_sigma_range_path, 'r') as f: line = f.readline() self.sigma_min, self.sigma_max = [ float(i) for i in line.split(' ') ] logger.info("Loaded existing importance sampling params. " "({:.04f}s)".format(time() - tic)) else: sigma, self.pdf_sampler, self.cdf_sampler = \ self.compute_is_params() self.sigma_min = sigma.min() self.sigma_max = sigma.max() logger.info("Saving CDF sampler to {}".format(is_cdf_path)) pfm_write(is_cdf_path, self.cdf_sampler) logger.info("Saving PDF sampler to {}".format(is_pdf_path)) pfm_write(is_pdf_path, self.pdf_sampler) with open(is_sigma_range_path, 'w') as f: f.write("{} {}".format(self.sigma_min, self.sigma_max)) logger.info("Computed importance sampling params. " "({:.04f}s)".format(time() - tic)) else: self.diffuse_map = diffuse_map self.specular_map = specular_map self.spec_shape_map = spec_shape_map self.normal_map = normal_map self.alpha = alpha if pdf_sampler is not None and cdf_sampler is not None: self.cdf_sampler = cdf_sampler self.pdf_sampler = pdf_sampler self.sigma_min, self.sigma_max = sigma_min, sigma_max else: sigma, self.pdf_sampler, self.cdf_sampler = \ self.compute_is_params() self.sigma_min, self.sigma_max = sigma.min(), sigma.max() if suppress_outliers: tic = time() self.diffuse_map = images.suppress_outliers(self.diffuse_map, thres=4.5) self.specular_map = images.suppress_outliers(self.specular_map, thres=4.5) logger.info("Suppressing outliers in diffuse and specular maps. " "({:.04f}s)".format(time() - tic))