GFZ / arosics

AROSICS - Automated and Robust Open-Source Image Co-Registration Software
https://git.gfz-potsdam.de/danschef/arosics
Apache License 2.0
137 stars 26 forks source link

AROSICS error ... RuntimeError: One of the input images does not have sufficient gray value information (non-no-data values) #15

Closed tildigg closed 1 year ago

tildigg commented 1 year ago

Description

I am trying to use AROSICS package (https://danschef.git-pages.gfz-potsdam.de/arosics/doc/usage/input_data_requirements.html) to align an RBG image taken from a drone and a canopy height model extracted from lidar collect from the same drone.

When I run the code in Jupyter to align the two images an error occurs saying one of the images does not have sufficient 'gray value information' but I can't work out what the 'gray value information' is.

What I Did

The code being run is found here: (https://danschef.git-pages.gfz-potsdam.de/arosics/doc/usage/global_coreg.html(

from arosics import COREG
im_reference = '/Users/mathildadigby/OneDrive-UniversityofBristol/Masters/Projects/CrownAssessments/DRC/site14/03rderived/chm_crs.tif'
im_target = '/Users/mathildadigby/OneDrive-UniversityofBristol/Masters/Projects/CrownAssessments/DRC/site14/03rderived/rgb_crs_1res2.tif'
CR = COREG(im_reference, im_target, wp=(683775, 9424525), ws=(1,-1))
CR.calculate_spatial_shifts()

When i run this i get this error

Polygonize progress     |==================================================| 100.0% Complete  => 0:00:00
Polygonize progress     |==================================================| 100.0% Complete  => 0:00:00
Calculating footprint polygon and actual data corner coordinates for reference image...
Bounding box of calculated footprint for reference image:
    (683639.0, 9424374.0, 683939.0, 9424674.0)
Calculating footprint polygon and actual data corner coordinates for image to be shifted...
Bounding box of calculated footprint for image to be shifted:
    (683639.0, 9424374.1, 683939.0, 9424674.1)
Matching window position (X,Y): 683775/9424525
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/var/folders/3d/42pd9m1s7tn5_hzv56nv9ntr0000gn/T/ipykernel_42761/460766914.py in <module>
      2 im_reference = '/Users/mathildadigby/OneDrive-UniversityofBristol/Masters/Projects/CrownAssessments/DRC/site14/03rderived/chm_crs.tif'
      3 im_target = '/Users/mathildadigby/OneDrive-UniversityofBristol/Masters/Projects/CrownAssessments/DRC/site14/03rderived/rgb_crs_1res2.tif'
----> 4 CR = COREG(im_reference, im_target, wp=(683775, 9424525), ws=(1,-1))
      5 CR.calculate_spatial_shifts()

~/opt/anaconda3/lib/python3.9/site-packages/arosics/CoReg.py in __init__(self, im_ref, im_tgt, path_out, fmt_out, out_crea_options, r_b4match, s_b4match, wp, ws, max_iter, max_shift, align_grids, match_gsd, out_gsd, target_xyGrid, resamp_alg_deshift, resamp_alg_calc, footprint_poly_ref, footprint_poly_tgt, data_corners_ref, data_corners_tgt, nodata, calc_corners, binary_ws, mask_baddata_ref, mask_baddata_tgt, CPUs, force_quadratic_win, progress, v, path_verbose_out, q, ignore_errors)
    439         if not self.q:
    440             print('Matching window position (X,Y): %s/%s' % (self.win_pos_XY[0], self.win_pos_XY[1]))
--> 441         self._get_clip_window_properties()  # sets self.matchBox, self.otherBox and much more
    442 
    443         if self.v and self.path_verbose_out and self.matchBox.mapPoly and self.success is not False:

~/opt/anaconda3/lib/python3.9/site-packages/arosics/CoReg.py in _get_clip_window_properties(self)
    967             if winBox.imDimsYX[0] < 16 or \
    968                winBox.imDimsYX[1] < 16:
--> 969                 self._handle_error(
    970                     RuntimeError("One of the input images does not have sufficient gray value information "
    971                                  "(non-no-data values) for placing a matching window at the position %s. "

~/opt/anaconda3/lib/python3.9/site-packages/arosics/CoReg.py in _handle_error(self, error, warn, warnMsg)
    471 
    472         if not self.ignErr:
--> 473             raise error
    474 
    475     def _set_outpathes(self,

RuntimeError: One of the input images does not have sufficient gray value information (non-no-data values) for placing a matching window at the position (683775, 9424525). Matching failed.

Both files are .tif files - could this be the issue? The documentation states the file types are supported (https://gdal.org/drivers/raster/index.html) and includes GeoTIFF so maybe this isn't the issue.

I have tried:

Maybe a different file type will work but not sure what to convert the image and CHM to.

Hope this makes some sense

Many thanks MD

danschef commented 1 year ago

RuntimeError: One of the input images does not have sufficient gray value information (non-no-data values) for placing a matching window at the position (683775, 9424525). Matching failed.

Generally, the error message says, that there are too many no-data pixels within the matching window centered at (683775, 9424525).

CR = COREG(im_reference, im_target, wp=(683775, 9424525), ws=(1,-1))

However, you set the size of the matching window to 1 pixel (default is 256), which does not make sense, because a single pixel cannot be used to compute any co-registration. Use the default value or enlarge the matching window size depending on the expected shift length. For example, if you expect a shift of 500 pixels, then a window with 256x256 pixels is too small to cover the shift length. You need to enlarge it to, lets say, at least 1000x1000 pixels and adjust the max_shift parameter.

tildigg commented 1 year ago

That's great, thank you for your help. I thought this wanted the image pixel size.

May I also ask how to export the shifted file after completing the shift calculation?

I have added the out_path section to export the shifted GeoTIFF but it doesn't seem to be exporting to the directory. I have tried typing in the directory with the file name also. Here is what I used:

from arosics import COREG as cor im_reference = '/dir/to/file/chm_plot_buffer_1.tif' im_target = '/dir/to/file/drc_site14_plot1_rgbclip.tif' CR = COREG(im_reference, im_target, wp=(683775, 9424525), ws=(256,256), path_out = 'auto', fmt_out = 'GTiff') CR.calculate_spatial_shifts()

The output gives the shift values and a 'success' message but no file is exported.

Thanks

danschef commented 1 year ago

You need to call CR.correct_shifts() as documented here.

tildigg commented 1 year ago

Thank you so much!