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?
I don’t think this is possible, because geom files are parsed by the
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 ?
In the doc, I see how to get the metadata, but I wonder how I can “assign” it to a
I’ll give some tries.
I’m not sure,
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
geomFilename = argv
outImageFilename = argv
# Read the geom file
readInfoWithGeom = otb.Registry.CreateApplication("ReadImageInfo")
readInfoWithGeom.SetParameterString("in", inImageFilename + "?&geom=" + geomFilename)
# Get the image metadata
imd = readInfoWithGeom.GetImageMetaData("in")
# Try to use it in a pipeline
smoothing = otb.Registry.CreateApplication("Smoothing")
smoothing.IN = inImageFilename
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()
#Print output geom
readInfoOut = otb.Registry.CreateApplication("ReadImageInfo")
orthoRectification = otb.Registry.CreateApplication("OrthoRectification")
Many thanks. This is perfect!