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

co-registration of two images with different band counts? #29

Open swdmike opened 10 months ago

swdmike commented 10 months ago

Description

To perform co-registration of two images with different band counts using AROSICS. ref image is 3 bands geotiff, while another is 4 bands geotiff.

What I Did

kwargs = {
        'grid_res'     : 200,
        'window_size'  : (256,256),
        'path_out'     : 'auto',
        'projectDir'   : 'my_project',
        'fmt_out'      : 'GTIFF',        
    }

  CRL = COREG_LOCAL(ref, src, **kwargs)
  CRL.calculate_spatial_shifts()

got error:

File "/usr/local/lib/python3.10/site-packages/geoarray/metadata.py", line 260, in get_subset
    meta_sub.band_meta = self.band_meta.copy()
  File "/usr/local/lib/python3.10/site-packages/geoarray/metadata.py", line 112, in band_meta
    raise ValueError("The length of the given lists must be equal to the number of bands. "
ValueError: The length of the given lists must be equal to the number of bands. Received a list with 3 items for 'STATISTICS_APPROXIMATE'.

Is it possible to use AROSICS to perform co-registration of two images with different band counts? How may I do that?

danschef commented 10 months ago

Sure, it is possible. For AROSICS, it does not matter how many bands the reference and target images have, the tie points used for co-registration are always computed from a single band of each image and then applied to the entire target image (including all bands).

The above error is caused by unplausible metadata in of your input images. In particular, the STATISTICS_APPROXIMATE metadata value indicates a different number of bands than the image actually has. To solve that, either remove the pre-computed image statistics from your input image or recompute them (I think by running gdalinfo -stats or gdalinfo -approx-stats).

swdmike commented 10 months ago

Thanks for your prompt response. I did gdalinfo -stats -mm, but same error again. Then I removed the alpha band and it's working.

Also, do I have to set nodata? If I do not, there is an error:

File "/usr/local/lib/python3.10/site-packages/arosics/CoReg_local.py", line 820, in correct_shifts
    self.calculate_spatial_shifts()
  File "/usr/local/lib/python3.10/site-packages/arosics/CoReg_local.py", line 490, in calculate_spatial_shifts
    self._tiepoint_grid.get_CoRegPoints_table()
  File "/usr/local/lib/python3.10/site-packages/arosics/Tie_Point_Grid.py", line 405, in get_CoRegPoints_table
    results = results.get()
  File "/usr/local/lib/python3.10/multiprocessing/pool.py", line 774, in get
    raise self._value
ValueError: The given no-data value (256.0) is out range for data type uint8.

Thanks again.

danschef commented 10 months ago

Ok, would be interesting to know why there was an alpha band which was not represented in the image metadata.

Regarding nodata value: Looks like one of the input datasets has unsigned integer 8bit as data type AND has a nodata value of 256 already set in the metadata, which makes no sense since uint8 only covers values between 0 and 255. By explicitly providing a nodata value, the nodata value set in the dataset is ignored. That´s why it works this way.

roelofvandijkO commented 4 months ago

You can use gdal_edit.py -unsetstats img.tif.

This fixed the the issue for me.

https://gdal.org/programs/gdal_edit.html#cmdoption-unsetstatshttps://gdal.org/programs/gdal_edit.html#cmdoption-unsetstats