Commit 90f16cf1 authored by Manuel Grizonnet's avatar Manuel Grizonnet

Merge branch 'review_otb_app_recipes' into 'develop'

Review OTB application recipe

See merge request orfeotoolbox/otb!28
parents 3b12c544 1c766f82
......@@ -32,10 +32,10 @@ application, changing the algorithm at each iteration.
print "Available applications: "
print str( otbApplication.Registry.GetAvailableApplications() )
# Let's create the application with codename "Smoothing"
# Let's create the application "Smoothing"
app = otbApplication.Registry.CreateApplication("Smoothing")
# We print the keys of all its parameter
# We print the keys of all its parameters
print app.GetParametersKeys()
# First, we set the input image filename
......@@ -47,13 +47,13 @@ application, changing the algorithm at each iteration.
print 'Running with ' + type + ' smoothing type'
# Here we configure the smoothing algorithm
# Now we configure the smoothing algorithm
app.SetParameterString("type", type)
# Set the output filename, using the algorithm to differentiate the outputs
# Set the output filename, using the algorithm type to differentiate the outputs
app.SetParameterString("out", argv[2] + type + ".tif")
# This will execute the application and save the output file
# This will execute the application and save the output to argv[2]
app.ExecuteAndWriteOutput()
If you want to handle the parameters from a Python dictionary, you can use the
......@@ -68,23 +68,24 @@ functions *SetParameters()* and *GetParameters()*.
Numpy array processing
----------------------
Input and output images to any OTB application in the form of numpy array is now possible in OTB python wrapping.
The python wrapping only exposes OTB ApplicationEngine module which allow to access existing C++ applications.
Input and output images to any OTB application in the form of NumPy array is now possible in OTB Python wrapping.
The Python wrapping only exposes OTB Application engine module (called *ApplicationEngine*) which allows to access existing C++ applications.
Due to blissful nature of ApplicationEngine's loading mechanism no specific wrapping is required for each application.
Numpy extension to Python wrapping allows data exchange to application as an array rather than a disk file.
Ofcourse, it is possible to load an image from file and then convert to numpy array or just provide a file as earlier via
NumPy extension to Python wrapping allows data exchange to application as an array rather than a disk file.
Of course, it is possible to load an image from file and then convert it to NumPy
array or just provide a file as explained in the previous section via
Application.SetParameterString(...).
This bridge that completes numpy and OTB makes it easy to plug OTB into any image processing chain via python code that uses
GIS/Image processing tools such as GDAL, GRASS GIS, OSSIM that can deal with numpy.
The bridge between NumPy and OTB makes it easy to plug OTB into any image processing chain via Python code that uses
GIS/Image processing tools such as GDAL, GRASS GIS, OSSIM that can deal with NumPy.
Below code reads an input image using python pillow (PIL) and convert it to numpy array. This numpy array is
used an input to the application via *SetImageFromNumpyArray(...)* method.
The application used in this example is ExtractROI. After extracting
a small area the output image is taken as numpy array with *GetImageFromNumpyArray(...)* method thus avoid wiriting
output to a temporary file.
Below code reads an input image using Python Pillow library (fork of PIL) and convert it to
NumPy array. The NumPy array is used as an input to the application via
*SetImageFromNumpyArray(...)* method. The application used in this example is
ExtractROI. After extracting a small area the output image is taken as NumPy
array with *GetImageFromNumpyArray(...)* method thus avoid writing output to a
temporary file.
::
......@@ -114,7 +115,7 @@ In-memory connection
--------------------
Applications are often use as parts of larger processing
chains. Chaining applications currently requires to write/read back
workflow. Chaining applications currently requires to write/read back
images between applications, resulting in heavy I/O operations and a
significant amount of time dedicated to writing temporary files.
......@@ -127,9 +128,9 @@ images. The last application of the processing chain is responsible
for writing the final result images.
In-memory connection between applications is available both at the C++
API level and using the python bindings.
API level and using the Python bindings.
Here is a Python code sample connecting several applications together:
Here is a Python code sample which connects several applications together:
.. code-block:: python
......@@ -176,7 +177,7 @@ Corner cases
------------
There are a few corner cases to be aware of when using Python wrappers. They are
often limitations, that one day may be solved by future developments. If it
often limitations, that one day may be solved in future versions. If it
happens, this documentation will report the OTB version that fixes the issue.
Calling UpdateParameters()
......@@ -220,23 +221,23 @@ setting the ``field`` parameter:
app.UpdateParameters()
app.SetParameterString("field", "label")
No metadata in Numpy arrays
No metadata in NumPy arrays
^^^^^^^^^^^^^^^^^^^^^^^^^^^
With the Numpy module, it is possible to convert images between OTB and Numpy
arrays. For instance, when converting from OTB to Numpy array:
With the NumPy module, it is possible to convert images between OTB and NumPy
arrays. For instance, when converting from OTB to NumPy array:
* An ``Update()`` of the underlying ``otb::VectorImage`` is requested. Be aware
that the full image is generated.
* The pixel buffer is copied into a ``numpy.array``
As you can see, there is no export of the metadata, such as origin, spacing,
projection WKT. It means that if you want to import back a Numpy array into OTB,
geographic projection. It means that if you want to import back a NumPy array into OTB,
the image won't have any of these metadata. It can be a problem for applications
doing geometry, projections, and also calibration.
Future developments will probably offer a more adapted structure to import and
export images between OTB and Python world.
export images between OTB and the Python world.
Setting of boolean parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -256,7 +257,7 @@ If you want the get the state of parameter ``keywordlist``, a boolean, use:
app.IsParameterEnabled("keywordlist")
To set this parameter ON / OFF, use the functions:
To set this parameter ON/OFF, use the functions:
.. code-block:: python
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment