def _get_filenames(self, path): file_names = [] for item in get_all_files_in_folders_and_subfolders(path): if has_extension( item, ['.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm', '.tif']): file_names.append(item) return file_names
def copy_code(output_folder): """ Makes a tar file with DeepDIVA that exists during runtime. Parameters ---------- output_folder : str Path to output directory Returns ------- None """ # All file extensions to be saved by copy-code. FILE_TYPES = ['.sh', '.py'] # Get DeepDIVA root cwd = os.getcwd() dd_root = os.path.join(cwd.split('DeepDIVA')[0], 'DeepDIVA') files = get_all_files_in_folders_and_subfolders(dd_root) # Get all files types in DeepDIVA as specified in FILE_TYPES code_files = [item for item in files if item.endswith(tuple(FILE_TYPES))] tmp_dir = tempfile.mkdtemp() for item in code_files: dest = os.path.join(tmp_dir, 'DeepDIVA', item.split('DeepDIVA')[1][1:]) if not os.path.exists(os.path.dirname(dest)): os.makedirs(os.path.dirname(dest)) shutil.copy(item, dest) # TODO: make it save a zipfile instead of a tarfile. with tarfile.open(os.path.join(output_folder, 'DeepDIVA.tar.gz'), 'w:gz') as tar: tar.add(tmp_dir, arcname='DeepDIVA') # Clean up all temporary files shutil.rmtree(tmp_dir)
def main(args): files = get_all_files_in_folders_and_subfolders(args.folder) img_shape = cv2.imread(files[0]).shape # Seed the RNG generator np.random.seed(seed=42) # Make a random noise mask if args.num_pixels is None: num_points_to_scramble = int(0.005 * img_shape[0] * img_shape[1]) else: num_points_to_scramble = args.num_pixels print('Number of scrambled points: {}'.format(num_points_to_scramble)) mask = np.random.randint(low=0, high=img_shape[0], size=(num_points_to_scramble, 2)) for file in files: # If args are moving, mask is different for each image. if args.moving == True: mask = np.random.randint(low=0, high=img_shape[0], size=(num_points_to_scramble, 2)) print(mask) apply_mask_to_image(mask, file) return
def get_list_images(dir): images = get_all_files_in_folders_and_subfolders(dir) images = [item for item in images if has_extension(item, IMG_EXTENSIONS)] return images