def run_global_coreg(args): COREG_obj = COREG(args.path_ref, args.path_tgt, path_out=args.path_out, fmt_out=args.fmt_out, r_b4match=args.br, s_b4match=args.bs, wp=args.wp, ws=args.ws, max_iter=args.max_iter, max_shift=args.max_shift, align_grids=args.align_grids, match_gsd=args.match_gsd, out_gsd=args.out_gsd, resamp_alg_calc=args.rsp_alg_deshift, resamp_alg_deshift=args.rsp_alg_calc, data_corners_ref=args.cor0, data_corners_tgt=args.cor1, nodata=args.nodata, calc_corners=args.calc_cor, CPUs=None if args.mp else 1, force_quadratic_win=args.quadratic_win, binary_ws=args.bin_ws, mask_baddata_ref=args.mask_ref, mask_baddata_tgt=args.mask_tgt, progress=args.progress, v=args.v, path_verbose_out=args.vo, q=args.q, ignore_errors=args.ignore_errors) COREG_obj.correct_shifts()
def test_coreg_init_from_inMem_GeoArray(self): # get GeoArray instances self.ref_gA = GeoArray(self.ref_path) self.tgt_gA = GeoArray(self.tgt_path) # assure the raster data are in-memory self.ref_gA.to_mem() self.tgt_gA.to_mem() # get instance of COREG_LOCAL object self.CRL = COREG(self.ref_gA, self.tgt_gA, **self.coreg_kwargs)
def coregister(self, src_path, dst_path): try: logging.debug("Coregistering image: " + str(dst_path)) if not dst_path.exists() or self.overwrite_products: compress_option = 'COMPRESS=NONE' # This is only used for the intermediate file and does not need compression # Remember to set nodata value to 0 when saving the ortofoto reference_im_path = Path('data/reference') im_reference = str(reference_im_path / 'ortofoto_reference_epsg32632.tif') im_target = str(src_path) kwargs = { 'mask_baddata_ref': str(reference_im_path / 'ortofoto_reference_epsg32632_nodata_mask.tif'), 'path_out': str(dst_path), 'fmt_out': 'GTIFF', 'out_crea_options': [compress_option], 'ws': (4096, 4096), 'q': False, 'v': False } CR = COREG(im_reference, im_target, **kwargs) CR.calculate_spatial_shifts() logging.info("Shift reliability is " + str(round(CR.shift_reliability, 2)) + "% for " + str(src_path.name)) CR.correct_shifts() self.create_cog(dst_path, compression='DEFLATE') coreg_info = CR.coreg_info return coreg_info else: logging.debug("Coregistered image already exist: " + str(dst_path)) except: logging.error("Coregistration error with file: " + str(src_path)) CR = 'coreg_error' return CR
def georeference(base_image, target_image, outfile=None): # Get image paths base_filepath = os.path.dirname(base_image) + '/' base_filename = os.path.basename(base_image) target_filepath = os.path.dirname(target_image) + '/' target_filename = os.path.basename(target_image) im_reference = base_filepath + base_filename im_target = target_filepath + target_filename # Specify correct output filepath if outfile: path_out = outfile else: path_out = target_filename.split(sep=".")[0] + "_GeoRegistered.tif" # Coregister imagery # wp and ws Set as bounding box around Deering Airstrip CR = COREG(im_reference, im_target, wp=(600578.602641986, 7328849.357436092), ws=(965, 1089.7365), path_out=path_out) # Calculate spatial shifts CR.calculate_spatial_shifts() # Correct shifts CR.correct_shifts() print('Saving Georegistered image as', path_out, ":", end=" ") return target_filepath + path_out
def run_shift_detection_correction(self, ref, tgt, **params): # get instance of COREG_LOCAL object CR = COREG(ref, tgt, **params) # calculate global X/Y shift CR.calculate_spatial_shifts() # test shift correction and output writer CR.correct_shifts() self.assertTrue( os.path.exists(params['path_out']), 'Output of global co-registration has not been written.') return CR
def Arosics_test_global(ref_img, tgt_img, kwargs): """ testing function for local registration in Arosics :param ref_img: str; full path and filename of the reference image :param tgt_img: str; full path and filename of the target image :param kwargs: dict; dictionary containing the detailed arguments for local correction. :return: """ from arosics import COREG start = default_timer() CR = COREG(ref_img, tgt_img, **kwargs) CR.calculate_spatial_shifts() CR.correct_shifts() end = default_timer() print(end - start) return CR
def arosics_test(): """ 测试几何校正工具 See https://gitext.gfz-potsdam.de/danschef/arosics https://www.mdpi.com/2072-4292/9/7/676 """ # Global coregistration test from geoarray import GeoArray from arosics import COREG im_reference = r'I:\sentinel\unzip\T49QEE_20180930T030541_B08.jp2' im_target = r'I:\sentinel\unzip\T49QEE_20181005T030549_B08.jp2' # im_target = r'D:\T50QKM_geo.tif' # get a sample numpy array with corresponding geoinformation as reference geoArr = GeoArray(im_reference) ref_ndarray = geoArr[:] # numpy.ndarray with shape (10980, 10980) ref_gt = geoArr.geotransform # GDAL geotransform ref_prj = geoArr.projection # projection as WKT string # get a sample numpy array with corresponding geoinformation as target geoArr = GeoArray(im_target) tgt_ndarray = geoArr[:] # numpy.ndarray with shape (10980, 10980) tgt_gt = geoArr.geotransform # GDAL geotransform tgt_prj = geoArr.projection # projection as WKT string # pass an instance of GeoArray to COREG and calculate spatial shifts geoArr_reference = GeoArray(ref_ndarray, ref_gt, ref_prj) geoArr_target = GeoArray(tgt_ndarray, tgt_gt, tgt_prj) CR = COREG(geoArr_reference, geoArr_target, path_out='D:/T49QEE_20181005_correct.tif', wp=(595951, 2480095), ws=(256, 256), v=True, max_iter=20, max_shift=100) CR.calculate_spatial_shifts() CR.correct_shifts()
# get a sample numpy array with corresponding geoinformation as target geoArr = GeoArray(im_target) tgt_ndarray = geoArr[:] # numpy.ndarray with shape (10980, 10980) tgt_gt = geoArr.geotransform # GDAL geotransform tgt_prj = geoArr.projection # projection as WKT string # pass an instance of GeoArray to COREG and calculate spatial shifts geoArr_reference = GeoArray(ref_ndarray, ref_gt, ref_prj) geoArr_target = GeoArray(tgt_ndarray, tgt_gt, tgt_prj) CR = COREG(geoArr_reference, geoArr_target, path_out='D:/T49QEE_20181005_correct.tif', wp=(595951, 2480095), ws=(256, 256), v=True, max_iter=20, max_shift=100) CR.calculate_spatial_shifts() CR.correct_shifts() # Local coregistration test # from arosics import COREG_LOCAL # kwargs = { # 'grid_res' : 200, # 'window_size' : (64,64), # 'path_out' : 'auto', # 'projectDir' : 'D:/temp', # 'q' : False,
def test_coreg_init_from_disk(self): self.CRL = COREG(self.ref_path, self.tgt_path, **self.coreg_kwargs)
DISASTER='santa-rosa-wildfire' IMAGEID='00000030' XBD='/home/catskills/Desktop/dataxv2/xBD' im_reference=XBD+'/'+DISASTER+'/images/'+DISASTER+'_'+IMAGEID+'_pre_disaster.png' im_target=XBD+'/'+ DISASTER+'/images/'+DISASTER+'_'+IMAGEID+'_post_disaster.png' from arosics import COREG CR = COREG(im_reference, im_target) CR.calculate_spatial_shifts()