Hyperspectral image analysis with Python made easy

Antón Garcia
Abraia
4 min readFeb 22, 2021

--

In this article, we show how to speed up the management and analysis of HSI images with Python and even how to test and adopt HSI without previous experience. We’ll see how to open a HSI datacube, how to explore the images corresponding to different spectral bands and how to create a pseudocolor image that captures the structure present across the different spectral bands.

Hyperspectral image analysis

We’ll do it on Jupyter notebooks using MULTIPLE -a seamless API interface that combines state-of-the-art python libraries-, while moving our pictures to the cloud. This approach also has big advantages for collaborative and remote workflows.

HSI analysis advantages and challenges

Hyperspectral image (HSI) analysis combines the power of spectrospy and image processing and analysis. It seeks to catch spectral and structural signatures related to specific elements, chemicals, or chromatic properties. From the use of hyperspectral imaging for quality inspection of industrial products or food, to remote sensing or biomedical imaging- the range of potential applications is enormous.

This advantage of HSI pictures comes with strings attached. They have many chromatic bands. This means that common photographic image formats with efficient compression cannot be used. As a result, HSI pictures tend to be heavy and difficult to handle.

But even visualization for visual examination is not straightforward, since our eyes can only see three bands at a time in the form of color images. And inspecting over one hundred bands one by one for a single scene does not seem a practical option.

The Multiple HSI analysis toolbox

We’ll use the MULTIPLE HSI analysis toolbox that can handle HSI pictures in different standard and propietary formats (like TIFF, .mat or ENVI). The toolbox integrates and simplifies different python libraries in a single API interface. It also provides functionalities for cloud storage and management of HSI pictures.

The operations presented here are provided in a Jupyter notebook for basic HSI analysis that can be conveniently launched and run from any device using google colab.

First, we should start by installing the toolbox.

We should get our ABRAIA KEY and configure it as environment variable

Reading HSI data

Reading an HSI image -regardless the format in which it is stored- is as simple as.

The load_image function loads the image in a numpy array with dimensions (width, height, # of bands), ready for further processing. The function will use the metadata available to determine the image reconstruction processing, if needed.

Basic HSI visualization

The very basic visualization of an HSI image consists of directly accesing and viewing specific spectral bands. For a first exploration of a datacube, we may get some bands from the cube and check the content. With the following function we get 6 random bands.

Then we can simply use matplotlib to visualize the bands extracted, which should provide a first glimpse on the picture content.

hyperspectral image bands
Some hyperspectral image bands

Dimensionality reduction and HSI pseudocolor visualization

An alternative to gain a quick insight on the content of an HSI datacube is to reduce the dimensionality of our data to just three components. With just three components we can build a pseudocolor image that our eyes can see. Again this only requires a single line of code.

Now that we have the false color image we also visualize again with matplotlib.

hyperspectral false color image
Pseudocolor image extracted through PCA analysis

As we can see, the use of principal components to build the pseudocolor image unveils much of the structure present across the different bands. It gives a much more complete view than viewing individual bands alone.

In this short article we presented the MULTIPLE Python API for HSI processing. It shows how to handle and read HSI pictures and how to make a first and quick visual analysis. By storing the datacubes on the cloud and working on cloud-based Jupyter notebooks, we may speed up the analysis of our HSI images, avoiding the waste of time on software installation and setting.

--

--

Antón Garcia
Abraia

Providing tools to analyse, process, transcode, and deliver images and videos, on the shoulders of state-of-the-art cloud, media and AI technology.