Using another geom file in Orthorectification with otbApplication?

Hi,

I would like to know if somebody knows how to use another .geom file in the Orthorectification application, when called from the python API.
I know how to do this with strings (e.g. ortho.SetParameterString("io.in", "file.tif?&geom=new.geom") but I wonder how I can use SetParameterInputImage instead, and using another .geom file.
Is this possible?

Thanks!

Hello RĂ©mi,

I don’t think this is possible, because geom files are parsed by the ImageFileReader and ImageFileWriter classes, not by the otb::Image class. When using SetParameterInputImage you are manipulating a SWIG wrapper around an otb::Image and therefore there is no way to provide a geom file.

It is possible to transfer the image metadata from an image to another with the Python API (see this section), maybe it is possible to read the geom with a dummy application, and transfer the metadata to the input of orthorectification ?

CĂ©dric

Hello @Cedric,

In the doc, I see how to get the metadata, but I wonder how I can “assign” it to a OutputImageParameter (or InputImageParameter).
I’ll give some tries.

Thanks

I’m not sure, ImportImage and ExportImage can be use to import and export images from a dictionary containing a numpy array and metatadata (origin, requested region, proj ref, itk::ImageMetadata). But we don’t want to use numpy arrays here. Maybe the SetupImageInformation can be used (it is not documented …)

I’m trying to write a script to see if it works.

See the following script. The geom is read by the ReadImageInfo application. The metadata are then copied into the output image of a smoothing application, and used as input of Orthorectification. It seems to work, but I only tested with a develop build. This should be tested with 7.2 too.

import otbApplication as otb
from sys import argv

inImageFilename = argv[1]
geomFilename = argv[2]
outImageFilename = argv[3]

# Read the geom file
readInfoWithGeom = otb.Registry.CreateApplication("ReadImageInfo")
readInfoWithGeom.SetParameterString("in", inImageFilename + "?&geom=" + geomFilename)
readInfoWithGeom.Execute()

# Get the image metadata
imd = readInfoWithGeom.GetImageMetaData("in")

# Try to use it in a pipeline
smoothing =  otb.Registry.CreateApplication("Smoothing")

smoothing.IN = inImageFilename
smoothing.Execute()

imagePtr = smoothing.GetParameterOutputImage("out")

# GetBufferedRegion is not exposed in the wrapper (?) but the buffered region 
# is required in SetupImageInformation. Set a default region instead
bufferedRegion = otb.itkRegion()

smoothing.SetupImageInformation(imagePtr, 
                                 smoothing.GetImageOrigin("out"),
                                 smoothing.GetImageSpacing("out"),
                                 smoothing.GetImageSize("out"),
                                 bufferedRegion,
                                 imd)

#Print output geom
"""
readInfoOut = otb.Registry.CreateApplication("ReadImageInfo")
readInfoOut.SetParameterInputImage("in", imagePtr)
readInfoOut.Execute()
"""

orthoRectification =  otb.Registry.CreateApplication("OrthoRectification")

orthoRectification.SetParameterInputImage("io.in", imagePtr)
orthoRectification.SetParameterString("io.out", outImageFilename)

orthoRectification.ExecuteAndWriteOutput() 
2 Likes

Many thanks. This is perfect!