diff --git a/Documentation/Cookbook/rst/recipes/python.rst b/Documentation/Cookbook/rst/recipes/python.rst index cbb119372dab87e687c015f08f467ad9ac62f69a..eaff6e537dc9dbf85b7979e65813f6f9f4bdb1ce 100644 --- a/Documentation/Cookbook/rst/recipes/python.rst +++ b/Documentation/Cookbook/rst/recipes/python.rst @@ -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,35 +47,36 @@ 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() -Numpy array processing +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 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 (PIL) and convert it to +NumPy array. The 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 writing output to a +temporary file. :: @@ -105,7 +106,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. @@ -118,9 +119,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 @@ -167,7 +168,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() @@ -211,23 +212,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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^