Some OTB 8 users reported us the fact that it was impossible to orthorectify an image that was computed by Superimpose application.
The use-case can be describe as following :
[optional] Extract an ROI of some georeferenced data
superimpose that data onto a PHR image in its raw sensor geometry
orthorectify that image
=> we expect that final step to produce an image co-registered with our initial data.
This problem can be reproduced for example with OTB PHR images from Workshop Data. With OTB 7.4, the behaviour was correct but with OTB 8.x, the image issued from Superimpose does not contain the right metadata to compute orthorectification.
Steps to reproduce
To reproduce that problem on different images, I wrote that little script :
OTB 8 doesn't write the RPC model in the image if the projection is available (see here). In the use case you provide, the projection is available, so the RPC model is not saved, and the Orthorectification can't find it.
You may want to use the extended filenamewriterpctags to force the writing of RPC tags in TIFF files. I tried it, and it didn't work. I will try and fix this.
I tried your example script using this branch, and the orthorectification doesn't crash with the error "No information in the metadata, please set an image with non empty metadata".
@julienosman : Here are the logs for SuperImpose + Orthorectification : superimpose doest not fail, but then the orthorectification cannot process the image since no projection information had been saved.
2022-07-06 09:09:41 (INFO): Loading metadata from official productWarning 1: WorkshopData/preprocessing/phr_xs_osr_mipy.tif.ovr: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.2022-07-06 09:09:41 (INFO): Loading metadata from attached geom file WorkshopData/preprocessing/phr_xs_osr_mipy.geom2022-07-06 09:09:41 (WARNING) Superimpose: Forcing PHR mode with PHR data. You need to add "-mode default" to force the default mode with PHR images.2022-07-06 09:09:41 (WARNING) Superimpose: Forcing PHR mode with PHR data. You need to add "-mode default" to force the default mode with PHR images.2022-07-06 09:09:41 (INFO) Superimpose: Default RAM limit for OTB is 256 MB2022-07-06 09:09:41 (INFO) Superimpose: GDAL maximum cache size is 12854 MB2022-07-06 09:09:41 (INFO) Superimpose: OTB will use at most 48 threads2022-07-06 09:09:41 (INFO) Superimpose: Elevation management: setting default height above ellipsoid to 0 meters2022-07-06 09:09:41 (INFO): Estimated memory for full processing: 122.961MB (avail.: 256 MB), optimal image partitioning: 1 blocks2022-07-06 09:09:41 (INFO): File Workshop_Results/Tests_OTB_8.1patch/step3_superimpose/xt_sensor.tif will be written in 1 blocks of 2000x2000 pixelsWriting Workshop_Results/Tests_OTB_8.1patch/step3_superimpose/xt_sensor.tif...: 100% [**************************************************] (0s)2022-07-06 09:09:41 (INFO) OrthoRectification: Elevation management: setting default height above ellipsoid to 0 meters2022-07-06 09:09:41 (INFO): Loading metadata from official product2022-07-06 09:09:41 (FATAL) OrthoRectification: itk::ERROR: ImageToGenericRSOutputParameters(0x8a1230): No information in the metadata, please set an image with non empty metadata
OTB 8 doesn't write the RPC model in the image if the projection is available (see here). In the use case you provide, the projection is available, so the RPC model is not saved, and the Orthorectification can't find it.
It's an important feature of OTB !! I don't remember it had been documented in OTB 8. And it was working fine with previous version.
Do you mean that if one doen't use "writerpctag", Superimpose never writes geometry/projection information ? From my point of view, Superimpose should always write images that contain such information...
OTB 8 only keeps the "highest level" of geometry/projection information. If the projection is known, the RPC model is considered obsolete, so it is not written in the image. One can force the writing of the RPC model using the extended filename (when fixed).
If the users find this behavior disturbing, we can change it. In this case, we need to discuss the expected behavior.
That's quite weird : as I understand it, when users use superimpose, they should keep their reference image (in its sensor geometry) to deal with the resampled image... I would prefer that the result of superimpose is always a stand-alone product.
In my own test, the output of Superimpose has missing or incorrect metadata.
See the "ReadImageInfo" output on a PHR sensor image, and a other image that had been projected into that PHR image geometry.
[tanguyy@visu01 Toulouse_OCS]$ otbcli_ReadImageInfo -in /work/OT/siaa/Work/Masque_CO3D/WORK/Images/Toulouse/PHR_SENSOR_Toulouse_PXS.tif2022-07-06 13:32:07 (INFO) ReadImageInfo: Default RAM limit for OTB is 256 MB2022-07-06 13:32:07 (INFO) ReadImageInfo: GDAL maximum cache size is 12854 MB2022-07-06 13:32:07 (INFO) ReadImageInfo: OTB will use at most 48 threads2022-07-06 13:32:07 (INFO): Loading metadata from attached geom file /work/OT/siaa/Work/Masque_CO3D/WORK/Images/Toulouse/PHR_SENSOR_Toulouse_PXS.geom2022-07-06 13:32:07 (INFO) ReadImageInfo:Image general information: Number of bands : 4 Data type : unsigned_short No data flags : Band 1: 0 Band 2: 0 Band 3: 0 Band 4: 0 Start index : [0,0] Size : [26307,34170] Origin : [0.5,0.5] Spacing : [1,1] Estimated ground spacing (in meters): [0.50578,0.501228]Image acquisition information: Sensor :Image default RGB composition: [R, G, B] = [0,1,2]Ground control points information: Number of GCPs = 0 GCPs projection =Output parameters value:indexx: 0indexy: 0sizex: 26307sizey: 34170spacingx: 1spacingy: 1originx: 0.5originy: 0.5estimatedgroundspacingx: 0.5057804585estimatedgroundspacingy: 0.5012280941numberbands: 4datatype: unsigned_shortid:time:town:country:rgb.r: 0rgb.g: 1rgb.b: 2projectionref:gcp.count: 0gcp.proj:gcp.ids:gcp.info:gcp.imcoord:gcp.geocoord:metadata:[tanguyy@visu01 Toulouse_OCS]$ otbcli_ReadImageInfo -in step3_superimpose/xt_sensor.tif2022-07-06 13:36:42 (INFO) ReadImageInfo: Default RAM limit for OTB is 256 MB2022-07-06 13:36:42 (INFO) ReadImageInfo: GDAL maximum cache size is 12854 MB2022-07-06 13:36:42 (INFO) ReadImageInfo: OTB will use at most 48 threads2022-07-06 13:36:42 (INFO): Loading metadata from official product2022-07-06 13:36:42 (WARNING): The SensorTransform factory could not find a compatible Sensor Transform2022-07-06 13:36:42 (WARNING): The SensorTransform factory could not find a compatible Sensor Transform2022-07-06 13:36:42 (WARNING): The SensorTransform factory could not find a compatible Sensor Transform2022-07-06 13:36:42 (INFO) ReadImageInfo:Image general information: Number of bands : 2 Data type : float No data flags : Band 1: 0 Band 2: 0 Start index : [0,0] Size : [26307,34170] Origin : [0.5,0.5] Spacing : [1,1] Estimated ground spacing (in meters): [1190.49,305.48]Image acquisition information: Sensor :Image default RGB composition: [R, G, B] = [0,1,2]Ground control points information: Number of GCPs = 0 GCPs projection =Output parameters value:indexx: 0indexy: 0sizex: 26307sizey: 34170spacingx: 1spacingy: 1originx: 0.5originy: 0.5estimatedgroundspacingx: 1190.486206estimatedgroundspacingy: 305.4797668numberbands: 2datatype: floatid:time:town:country:rgb.r: 0rgb.g: 1rgb.b: 2projectionref:gcp.count: 0gcp.proj:gcp.ids:gcp.info:gcp.imcoord:gcp.geocoord:metadata:
If the image contains the coordinate system [*] (which is a geometry information), then the RPC model is not kept. But the Orthorectification application requires the RPC model specifically, not the coordinate system. So the best solution is to add the extended filename writerpctags which force OTB to keep the RPC model.
[*] When you do a gdalinfo it looks like this:
Coordinate System is:PROJCRS["WGS 84 / UTM zone 31N", BASEGEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]], CONVERSION["UTM zone 31N", METHOD["Transverse Mercator", ID["EPSG",9807]], PARAMETER["Latitude of natural origin",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8801]], PARAMETER["Longitude of natural origin",3, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8802]], PARAMETER["Scale factor at natural origin",0.9996, SCALEUNIT["unity",1], ID["EPSG",8805]], PARAMETER["False easting",500000, LENGTHUNIT["metre",1], ID["EPSG",8806]], PARAMETER["False northing",0, LENGTHUNIT["metre",1], ID["EPSG",8807]]], CS[Cartesian,2], AXIS["(E)",east, ORDER[1], LENGTHUNIT["metre",1]], AXIS["(N)",north, ORDER[2], LENGTHUNIT["metre",1]], USAGE[ SCOPE["unknown"], AREA["World - N hemisphere - 0°E to 6°E - by country"], BBOX[0,0,84,6]], ID["EPSG",32631]]
Furthermore, I've not found a unitary test that validates the projection of a georeferenced image into a sensor geometry : I think it deserves a test !
Furthermore, I've not found a unitary test that validates the projection of a georeferenced image into a sensor geometry : I think it deserves a test !
Most of the tests (if not all) that validate the direct transform also validate the inverse transform from the ground geometry to the sensor geometry. Is this your question?
Most of the tests (if not all) that validate the direct transform also validate the inverse transform from the ground geometry to the sensor geometry. Is this your question?
Not really, I mean there's no such test in Superimpose application tests. And it used to work with older versions of OTB. I'll pursue my tests next week.
With OTB 7.4, the RPC model was always written to the output image.
With OTB 8.0, the RPC model is not written if there is a coordinate system. The user has the possibility to force OTB to write the RPC model with the extended filename writerpctags set to "true". Indeed, when an image already has a coordinate system, OTB doesn't need the RPC model anymore. This is why we decided to avoid writing it in the outpout image.
This issue shows the RPC model can still be useful in some cases. Applications like SuperImpose or BundleToPerfectSensor should always include the RPC model in the output image.
The solutions are:
go back to the behavior of OTB 7.4 (always write the RPC model in the output image)
keep the behavior of OTB 8.0, except for SuperImpose and BundleToPerfectSensor which are forced to write the RPC model in any case without having to set the extended filename.
Other proposition?
I would be interested in people's opinion on the question :)
I'm in favor of solution 2. When processing involves geometric changes (Orthorectification, PanSharpening, ...), exporting MTD following OTB 7.4 behavior, results sometimes in weird products (which contains for example projection code (cartographic UTM or geographic WGS84 for example) and RPC).
In my opinion :
In superimpose application, the final product should inherits reference product geometry (projection code if reference product is projected, or RPC if product is in sensor geometry).
BundleToPerfect sensor output should be associated to PAN RPC
I also agree with solution 2 : the output of Superimpose should contain the reference product geometry ("-inr" parameter) and users should not have to add the "writerpctag" to force it.
I've tested OTB 8.1rc1 with different PHR images (some from workshop data and others from recent PHR products)
-> with MR !920 (merged) it's now possible de superimpose a georeferenced image into another geometry (here, raw image geometry), by using the extended filename writerpc=true