The Opticks histogram can be a powerful analysis tool but sometimes you want to access the data outside of Opticks or in a Python script. While you can export an image of the histogram (right-click on the histogram and select Export) you'll need Python (or C++) to work directly with the histogram values. Here's how:
Working with RasterLayer statistics
First, you need a RasterLayer. Python currently supports accessing statistics for a layer channel (red, green, blue, or gray) only. This example accesses statistics for the primary raster layer in the active view, so click on the view you want to use. See the API docs for full details.
The histogram_centers member is a list of bin centers and the histogram_counts member contains the number of pixels in each bin. There are also basic statistics in the s object. You can save these to a comma separated value (CSV) file.
Working with arbitrary statistics
If you want to work with (or save) statistics for an arbitrary subset of the data you'll need a different technique. (want to access arbitrary statistics using the previous method? Add an enhancement request)
First you need to access the data for the appropriate RasterElement. Next you need to use Python to calculate the statistics. The follow example will calculate exactly the same statistics as the previous example (assuming the first band was displayed in the gray channel and the data is in BSQ format).
You can calculate statistics for arbitrary subsets of the data as well.