def main(): parser = argparse.ArgumentParser( description="Convert rawls folder into png images folder") parser.add_argument('--folder', type=str, help="folder with rawls images") parser.add_argument('--output', type=str, help="output expected folder") args = parser.parse_args() p_folder = args.folder p_output = args.output # load all rawls images path of folder images = [img for img in sorted(os.listdir(p_folder)) if '.rawls' in img] number_of_images = len(images) if not os.path.exists(p_output): os.makedirs(p_output) for i, img in enumerate(images): img_path = os.path.join(p_folder, img) output_img_path = os.path.join(p_output, img.replace('.rawls', '.png')) # load and save image as png Rawls.load(img_path).to_png(output_img_path) write_progress((i + 1) / number_of_images) print()
def main(): parser = argparse.ArgumentParser( description="Convert rawls folder into png images folder") parser.add_argument('--folder', type=str, help="folder with rawls images") parser.add_argument('--output', type=str, help="output expected folder") parser.add_argument('--step', type=int, help="step number of samples") parser.add_argument('--ext', type=str, help="extension image choice", choices=['rawls', 'png'], default='png') args = parser.parse_args() p_folder = args.folder p_output = args.output p_step = args.step p_ext = '.' + args.ext # load all rawls images path of folder images = [img for img in sorted(os.listdir(p_folder)) if '.rawls' in img] number_of_images = len(images) if not os.path.exists(p_output): os.makedirs(p_output) merged_img = None for i, img in enumerate(images): img_path = os.path.join(p_folder, img) if merged_img: current_img = Rawls.load(img_path) merged_img = Rawls.fusion(current_img, merged_img) else: merged_img = Rawls.load(img_path) if merged_img.details.samples % p_step == 0: # build output images index index_str = str(merged_img.details.samples) while len(index_str) < 5: index_str = "0" + index_str # build output image path name and path output_image_name = p_output + '_' + index_str + p_ext output_img_path = os.path.join(p_output, output_image_name) # load and save image as png merged_img.save(output_img_path) # update progress information write_progress((i + 1) / number_of_images) print()
def extract(scene_folder, output): files = os.listdir(scene_folder) if scene_folder[-1] == '/': scene_folder = scene_folder[:-1] print(os.path.split(scene_folder)) # build output data folder output_normals_scene_folder = os.path.join(output, normals_file, os.path.split(scene_folder)[-1]) if not os.path.exists(os.path.join(output_normals_scene_folder)): os.makedirs(output_normals_scene_folder) output_zbuffer_scene_folder = os.path.join(output, zbuffer_file, os.path.split(scene_folder)[-1]) if not os.path.exists(os.path.join(output_zbuffer_scene_folder)): os.makedirs(output_zbuffer_scene_folder) for filename in files: if normals_file in filename and current_extension in filename: file_path = os.path.join(scene_folder, filename) # build expected output files outfile_path = os.path.join(output_normals_scene_folder, filename.replace(current_extension, save_extension)) print('extracts normals from', file_path, 'and save it into', outfile_path) # open file and normalize data normals_rawls = Rawls.load(file_path) # not necessary already normalized # normals_rawls.normalize() normals_rawls.data = normals_rawls.data * 255 # do not apply gamma conversion normals_rawls.save(outfile_path, gamma_convert=False) if zbuffer_file in filename and current_extension in filename: file_path = os.path.join(scene_folder, filename) # build expected output files outfile_path = os.path.join(output_zbuffer_scene_folder, filename.replace(current_extension, save_extension)) print('extracts zbuffer from', file_path, 'and save it into', outfile_path) # open file and normalize data zbuffer_rawls = Rawls.load(file_path) zbuffer_rawls.normalize() zbuffer_rawls.data = zbuffer_rawls.data * 255 # do not apply gamma conversion zbuffer_rawls.save(outfile_path, gamma_convert=False)
def extract(scene_folder, output): files = os.listdir(scene_folder) if scene_folder[-1] == '/': scene_folder = scene_folder[:-1] print(os.path.split(scene_folder)) # build output data folder output_scene_folder = os.path.join(output, os.path.split(scene_folder)[-1]) if not os.path.exists(os.path.join(output_scene_folder)): os.makedirs(output_scene_folder) for filename in files: if (normals_file not in filename and zbuffer_file not in filename) and current_extension in filename: file_path = os.path.join(scene_folder, filename) # build expected output files outfile_path = os.path.join(output_scene_folder, filename.replace(current_extension, save_extension)) print('extracts image from', file_path, 'and save it into', outfile_path) # open file and normalize data images_rawls = Rawls.load(file_path) # do not apply gamma conversion images_rawls.save(outfile_path)
def save_png(name_scene): """ save a png image from a rawls repertory """ if not os.path.exists("static/images/" + name_scene + ".png"): for f in os.listdir(folder_rawls_path + "/" + name_scene): first_file = f break rawls_img = Rawls.load(folder_rawls_path + "/" + name_scene + "/" + first_file) rawls_img.save("static/images/" + name_scene + ".png")
def read_image(img_path): image_extension = img_path.split('.')[-1] if image_extension == 'png': return np.array(Image.open(img_path)) if image_extension == 'rawls': return Rawls.load(img_path).data return None
def png(name_scene=None): if name_scene not in scene_list: return render_template("error.html", error=errors[0]) if not os.path.exists("static/images/" + name_scene + ".png"): for f in os.listdir(folder_rawls_path + "/" + name_scene): first_file = f break rawls_img = Rawls.load(folder_rawls_path + "/" + name_scene + "/" + first_file) rawls_img.save("static/images/" + name_scene + ".png") return render_template("png_image.html", name_scene=name_scene, image_png="images/" + name_scene + ".png")
def main(): parser = argparse.ArgumentParser( description="Convert to expected png format") parser.add_argument('--folder', type=str, help='folder path with all estimator data', required=True) parser.add_argument('--output', type=str, help='output prediction file', required=True) args = parser.parse_args() p_folder = args.folder p_output = args.output if not os.path.exists(p_output): os.makedirs(p_output) rawls_images = glob.glob(f'{p_folder}/**/**/*.rawls') for img_path in rawls_images: output_image_path = img_path.replace(p_folder, p_output).replace( '.rawls', '.png') output_image_folder, image_name = os.path.split(output_image_path) if not os.path.exists(output_image_folder): os.makedirs(output_image_folder) if not os.path.exists(output_image_path): print(f'Convert .rawls image into `{image_name}`') Rawls.load(img_path).save(output_image_path)
def main(): parser = argparse.ArgumentParser( description="Convert rawls folder into png images folder") parser.add_argument('--folder', type=str, help="folder with rawls images") parser.add_argument('--output', type=str, help="output expected folder") parser.add_argument('--flip', type=str, help="flip choice", choices=['h', 'v']) parser.add_argument('--ext', type=str, help="extension image choice", choices=['rawls', 'png'], default='png') args = parser.parse_args() p_folder = args.folder p_output = args.output p_flip = args.flip p_ext = '.' + args.ext # load all rawls images path of folder images = [img for img in sorted(os.listdir(p_folder)) if '.rawls' in img] number_of_images = len(images) if not os.path.exists(p_output): os.makedirs(p_output) for i, img in enumerate(images): img_path = os.path.join(p_folder, img) output_img_path = os.path.join(p_output, img.replace('.rawls', p_ext)) # load and save image as png current_img = Rawls.load(img_path) if p_flip == 'h': current_img.h_flip() elif p_flip == 'v': current_img.v_flip() current_img.save(output_img_path) write_progress((i + 1) / number_of_images) print()
def extracts_linear_indices_rawls(images_path, n_expected=50, i_indices_step=20, o_indices_step=20, start_at=20, smooth_arr=False, gamma=False): default_add = start_at - 20 # by default if i_indices_step == 1: default_add = 0 n_start_images = int(start_at / i_indices_step) n_counter = 0 # extract variance for each image path var_arr = [] prev_rawls = None n_images = len(images_path) for p in sorted(images_path): if prev_rawls is None: temp = Rawls.load(p) if gamma: temp.gammaConvert() prev_rawls = temp else: temp = Rawls.load(p) if gamma: temp.gammaConvert() prev_rawls = Rawls.fusion(prev_rawls, temp) write_progress((n_counter + 1) / n_images) n_counter += 1 if n_counter >= n_start_images: # only get center variance of image (800 per 800) width, heigth, _ = prev_rawls.shape n_w, n_h = (800, 800) # new expected size # get center of image middle_w = int(width / 2) middle_h = int(heigth / 2) # start coordinates s_w = middle_w - int(n_w / 2) s_h = middle_h - int(n_h / 2) # end coordinates e_w = middle_w + int(n_w / 2) e_h = middle_h + int(n_h / 2) var_arr.append(np.var(prev_rawls.data[s_w:e_w, s_h:e_h])) # normalize variance values norm_arr = np.array(utils.normalize_arr_with_range(var_arr)) if smooth_arr: norm_arr = utils.normalize_arr_with_range( savgol_filter(norm_arr, 201, 3)) # window size 7, polynomial order 3 # get expected linear step (using n_expectec output images) linear_steps = utils.normalize_arr_with_range( (1 - (np.arange(n_expected) / n_expected))) # get image indices from variance convergence and linear # => when linear step is reached we store the index found from variance values indices_found = [] for i in linear_steps: find_index = len(linear_steps) - 1 for index, y in enumerate(norm_arr): if i <= y: find_index = index indices_found.append(find_index + 1) indices = np.array(indices_found) * i_indices_step # add tricks to avoid same indice # => when index is same as previous, then add number of samples expected by step # Example with step of 20 : [20, 20, 20, 100, 200] => [20, 40, 60, 100, 200] final_indices = [] for index, i in enumerate(indices): value = indices[index] if index > 0: if i <= indices[index - 1]: value = indices[index - 1] + o_indices_step indices[index] = value final_indices.append(value) return np.array(final_indices) + default_add