Skip to end of metadata
Go to start of metadata

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:

  • How to load files in Python.
  • How to derive new layers from existing layers.
  • How to call other plug-ins from Python.

What Do I Need?

  • Opticks - you will need 4.5.0 or later.
  • Python Scripting Extension For Opticks - installation of the Python 2.6.X version of the extension.
  • You will need to have a local install of Python.
  • Imagery data. This example runs well on JPEG files taken with a commercial digital camera. Due to the availability of standard RGB JPEG files, we will assume the user can locate sample data.
  • Download the bright_mask.py file and note the location on your computer.

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.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.