Overview
This is a sample Python script that utilizes Opticks and the Python Scripting Extension. This script demonstrates one way to process a batch of files in Opticks.
What Will I Learn?You will learn the following about the Python scripting extension for Opticks:
|
What Do I Need?
|
The Script
We'll look at the bright_mask.py script and discuss it in this section. This script loads a number of files from a directory and generates a mask of pixels which appear bright in the image then saves the mask to disc. First, we need a way to load data into Opticks from Python. The most flexible way to do this is to use the Import Data Set plug-in. However, there is another function available in the SimpleAPI which will load data and is easier to use. This function does not return the loaded data set and only loads the default data sets in a file but is useful for our example. It is not exposed to Python so we'll expose it using the following code.
Now we will create a loop which loads all the JPEG files in a specified directory and processes each in turn.
Next we will derive a threshold layer from the first band of the data which is usually the red color band in standard RGB images.
Now we will derive an AOI from the thresholded data.
Export the AOI using the AOI Model Exporter plug-in. This code creates and export file descriptor and calls the exporter plug-in.
Finally, some code to close the data and cleanup, ready for the next file.
Using the code
You can create a wizard with a Run Interpreter Commands wizard item pointing to the script file then execute the wizard. Alternately, you can import this script into the Opticks scripting window. Previous howtos have demonstrated these techniques and may be referenced if needed.