def save_tiles(tile_size, num_tiles=5, scale=4, threshold=180): print(f'\n\nsave {tile_size} tiles') hr_ROI = paired_001 / f'roi_hr_{tile_size}' lr_ROI = paired_001 / f'roi_lr_{tile_size}' lr_ROI_small = paired_001 / f'roi_lr_up_{tile_size}' for (id, depth), hr_fn in progress_bar(list(hr_file_map.items())): lr_fn = lr_file_map[(id, depth)] if id in train_ids: sub_dir = 'train' else: sub_dir = 'valid' base_name = f'{tile_size}_{id}_{depth}.tif' helpers.tif_to_tiles(lr_fn, hr_fn, base_name, hr_ROI / sub_dir, lr_ROI / sub_dir, lr_ROI_small / sub_dir, size=tile_size, num_tiles=num_tiles, scale=scale, threshold=threshold)
def save_tiles(tile_size, untiled_files, num_tiles=5, scale=4, threshold=100): for sub_dir in ['train', 'valid']: print(f'\n\nbuild tiles {sub_dir}/{tile_size}\n\n') hr_ROI = dpath / f'roi_hr_{tile_size}' / sub_dir lr_ROI = dpath / f'roi_lr_{tile_size}' / sub_dir lr_up_ROI = dpath / f'roi_lr_up_{tile_size}' / sub_dir #print('\n', hr_ROI, '\n', lr_ROI, '\n', lr_up_ROI) print('Creating ROIs with tile size ' + str(tile_size)) hrdir = hr_path / sub_dir lrdir = lr_path / sub_dir for hr_fn in progress_bar(list(hrdir.iterdir())): #print('Processing ' + hr_fn.name + ', tile_size is ' + str(tile_size) + '.') lr_fn = lrdir / hr_fn.name helpers.tif_to_tiles(lr_fn, hr_fn, hr_fn.stem, hr_ROI, lr_up_ROI, lr_ROI, size=tile_size, num_tiles=num_tiles, scale=scale, threshold=threshold, untiled_ls=untiled_files)
max_per_movie=False) for tile_size in [128, 256, 512]: hr_ROI = mitomovies_001 / f'roi_hr_{tile_size}' / subdir lr_ROI = mitomovies_001 / f'roi_lr_{tile_size}' / subdir lr_up_ROI = mitomovies_001 / f'roi_lr_up_{tile_size}' / subdir print(hr_ROI, '\n', lr_ROI, '\n', lr_up_ROI) for hr_fn in progress_bar(list(hr_dir.iterdir())): lr_fn = lr_dir / hr_fn.name helpers.tif_to_tiles(lr_fn, hr_fn, hr_fn.stem, hr_ROI, lr_up_ROI, lr_ROI, size=tile_size, num_tiles=num_tiles, scale=scale, threshold=threshold, untiled_ls=untiled_files) with open(mitomovies_001 / 'valid_untiled_filelist.txt', 'w') as f: for item in untiled_files_valid: f.write("%s\n" % item) with open(mitomovies_001 / 'train_untiled_filelist.txt', 'w') as f: for item in untiled_files_train: f.write("%s\n" % item) test_dir = mitomovies_001 / 'test' test_dir.mkdir(parents=True, exist_ok=True, mode=0o775)