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 setup.py install for spectral ... done Successfully installed spectral-0.19
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.