def stereo_matching(tile, i): """ Compute the disparity of a pair of images on a given tile. Args: tile: dictionary containing the information needed to process a tile. i: index of the processed pair """ out_dir = os.path.join(tile['dir'], 'pair_{}'.format(i)) x, y = tile['coordinates'][:2] outputs = ['rectified_mask.png', 'rectified_disp.tif'] if os.path.exists(os.path.join(out_dir, 'stderr.log')): print('disparity estimation: stderr.log exists') print('pair_{} not processed on tile {} {}'.format(i, x, y)) return if cfg['skip_existing'] and all( os.path.isfile(os.path.join(out_dir, f)) for f in outputs): print('disparity estimation done on tile {} {} pair {}'.format( x, y, i)) return print('estimating disparity on tile {} {} pair {}...'.format(x, y, i)) rect1 = os.path.join(out_dir, 'rectified_ref.tif') rect2 = os.path.join(out_dir, 'rectified_sec.tif') disp = os.path.join(out_dir, 'rectified_disp.tif') mask = os.path.join(out_dir, 'rectified_mask.png') disp_min, disp_max = np.loadtxt(os.path.join(out_dir, 'disp_min_max.txt')) block_matching.compute_disparity_map(rect1, rect2, disp, mask, cfg['matching_algorithm'], disp_min, disp_max) # add margin around masked pixels masking.erosion(mask, mask, cfg['msk_erosion']) if cfg['clean_intermediate']: if len(cfg['images']) > 2: common.remove(rect1) common.remove(rect2) common.remove(os.path.join(out_dir, 'disp_min_max.txt'))
def stereo_matching(tile,i): """ Compute the disparity of a pair of images on a given tile. Args: tile: dictionary containing the information needed to process a tile. i: index of the processed pair """ out_dir = os.path.join(tile['dir'], 'pair_{}'.format(i)) x, y = tile['coordinates'][:2] outputs = ['rectified_mask.png', 'rectified_disp.tif'] if os.path.exists(os.path.join(out_dir, 'stderr.log')): print('disparity estimation: stderr.log exists') print('pair_{} not processed on tile {} {}'.format(i, x, y)) return if cfg['skip_existing'] and all(os.path.isfile(os.path.join(out_dir, f)) for f in outputs): print('disparity estimation done on tile {} {} pair {}'.format(x, y, i)) return print('estimating disparity on tile {} {} pair {}...'.format(x, y, i)) rect1 = os.path.join(out_dir, 'rectified_ref.tif') rect2 = os.path.join(out_dir, 'rectified_sec.tif') disp = os.path.join(out_dir, 'rectified_disp.tif') mask = os.path.join(out_dir, 'rectified_mask.png') disp_min, disp_max = np.loadtxt(os.path.join(out_dir, 'disp_min_max.txt')) block_matching.compute_disparity_map(rect1, rect2, disp, mask, cfg['matching_algorithm'], disp_min, disp_max) # add margin around masked pixels masking.erosion(mask, mask, cfg['msk_erosion']) if cfg['clean_intermediate']: if len(cfg['images']) > 2: common.remove(rect1) common.remove(rect2) common.remove(os.path.join(out_dir,'disp_min_max.txt'))