Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
swdmike opened this issue Sep 13, 2023 · 4 comments
Open

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

swdmike opened this issue Sep 13, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@swdmike
Copy link

swdmike commented Sep 13, 2023

  • arosics version: 1.9.2
  • Python version: 3.10.9
  • Operating System: debian:11

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
Copy link
Collaborator

danschef commented Sep 13, 2023

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).

@danschef danschef added the help wanted Extra attention is needed label Sep 13, 2023
@swdmike
Copy link
Author

swdmike commented Sep 14, 2023

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
Copy link
Collaborator

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
Copy link

roelofvandijkO commented Feb 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants