Introduction to Spectral Python (SPy) 0.19

As announced, here comes a short introduction to Spectral Python:

What is Spectral Python?

Spectral Python or SPy is a Python module for hyperspectral image processing. It works with Python 2.6/3.3 or higher versions (Python 3.6.2 is available since yesterday! 😉).
You can read, write, visualize and classify data with SPy. It is in a quite early development stage (version 0.19), but it is worth to give it a try!


I recommend to work with Python in a Linux environment – so all following instructions were carried out on Ubuntu Linux bash.

You need to have Python installed, moreover the package manager pip or pip3.
First let’s install the dependencies with pip. We need to have the packages numpy, pillow, matplotlib and ipython installed:

sudo pip install numpy pillow matplotlib ipython

After that, we install Spectral Python:

sudo pip install spectral

If it is successfully installed, you should get the following message:

Collecting spectral
 Downloading spectral-0.19.tar.gz (141kB)
 100% |████████████████████████████████| 143kB 1.9MB/s 
Requirement already satisfied: numpy in /usr/lib/python2.7/dist-packages (from spectral)
Installing collected packages: spectral
 Running install for spectral ... done
Successfully installed spectral-0.19

Next steps

Now it is time to code! Some basic Python knowledge is very helpful therefore.
If you have never worked with Python before, I recommend a basic course. There are a lot of sources out there, that help you with the process of learning a programming language. Personally I started with Codecademy some years ago. The learning curve is steep and it is quite entertaining, because of the “gamification” of the courses.

When I started to write this blog-post I stopped at the official Spectral Python web-portal. Looking at the official documentation I realized that it was tailored more or less like an easily understandable tutorial – in a higher quality than I could provide to you here in a quickly written post.
-> User Guide <-

However, SPy does not yet read GeoTiff files. So you will have to use ENVI, AVIRIS or ERDAS/LAN files.
You can simply convert your tiff files with gdal_translate like that:

gdal_translate -of LAN input.tif output.lan

Finally a short example of a NDVI calculation from a small HySpex imagery subset:




































Whatever your requirements on image manipulations/analysis are – you can extend your Python code with manifold capabilities of packages like NumPy etc.

About This Author

Simon is a research assistant in the field of remote sensing at Technical University of Munich (TUM). Currently he is working on methods to describe reed ecosystem parameters with the help of hyperpectral and LiDAR data. Besides geoinformatics he loves to do outdoor activities such as hiking and climbing.


You can post comments in this post.

  • I u have some plant and leaf related hyperspectral images then plz share on this email-id .

    Meenal Udapure 6 years ago Reply

  • My interest is to extract hyperspectral images fron a CMOS camara using Phyton or another scientific software. Some advice for this?

    DENY BAYONA 6 years ago Reply

    • As far as I know, it is not possible to extract real (!) hyperspectral data from RGB CMOS sensor. Please correct me if I’m wrong.

      Simon 6 years ago Reply

  • I want to classify a .hdr hyperspectral image with the help of spectral library.
    any suggestion ?
    Is there a way to convert .hdr file to .lan file..

    vijay singh 5 years ago Reply

  • I am trying to classify hyperspectral images (.bin files) with the help of spectral libraries of Python.
    Do you have any ideas for handling .bin or .hdr instead of .lan files?

    Jay Shah 5 years ago Reply

Post A Reply