# Hyperspectral Python: HypPy
## 2 Design and Implementation
### Viewers  
#### 2.3.1 Image Viewer  
The image viewer of HypPy offers a no-frills display for viewing hyperspectral images and retrieving spectra. The image viewer was designed for a quick interactive assessment of image quality and the retrieval of endmember spectra. Its simplicity makes it easy to use for novice users of hyperspectral data. Sliders can be used to change the display from one band to another. In color mode, three sliders are available, one for each of the RGB channels of the display. A status bar at the bottom of the window presents information on wavelengths of bands, cursor position, and more. Using the sliders and the left mouse button, the bands and the spectra of the input image can be assessed on quality and information content. Figure 2 shows the hyperspectral image of a rock sample. This particular rock sample 15-91-FE is part of the Fen Complex in Norway, which comprises a carbonatite intrusion [16].  
Figure 2: Image viewer showing a false color composite of sample 15-91-FE. Red channel 876 nm, green 734 nm, and blue 611 nm. The sliders for the red, green, and blue can be used to change the bands for the RGB color channels.  
Under the file menu, two options can be set to control whether the bands must be sorted prior to reading or to use the BBL of an image.  
The display program can open two images at the same time. The first image is always visible in the viewer. The second image, called the'shadow image', is never visible. However, when the shadow image is present, spectra are obtained from the shadow image rather than the visible image. This is like a GIS in which the first layer is on top, and the second layer is hidden below the first image. This option is useful for loading a classification image or mask image in the first layer while spectra are taken from the shadow image, making is possible to assess whether a calculated classification or mask image makes sense. Furthermore, this option is useful for exploring a wavelength map together with a hyperspectral image from which the wavelength map was derived.  
The stretch menu offers a number of standard methods for stretching the image [17]. Methods like 1-99% and histogram equalization are implemented. On top of that, the image can be inverted, saturation-enhanced on-the-fly, or pseudo-colored with a number of available color schemes.  
A left-click anywhere on the image will bring up a plot window with a graph representing the spectrum of the pixel at this location, see Figure 3. Further clicking on the image will bring up more graphs in the plot. By removing the plot window, the process starts all over with a clear plot window. In this way, the spectra of different points in the image can be visualized together.  
Using the 'Values Window', these spectra can also be saved as a text file, endmembers, or spectral libraries, or imported into other software for visualization and further processing. A directory of endmember spectra can be used as a spectral library in HypPy's classifiers, spectral angle  
Figure 3: Plot window showing the spectrum of pixel location 595, 3002. The spectrum shows two absorption features at 740 and 800 nm. These features are due to rare earth elements (in particular neodymium) contained by monazite crystals. The spectrum below 450 nm is noisy due to the low sensitivity in the blue of the hyperspectral VNIR camera. The toolbar at the bottom of the window is a standard matplotlib figure toolbox and has buttons for navigating the figure: home, back, forward, pan/zoom, zoom-to-rectangle, and subplot configuration. The save button on the right can be used to save the figure to various formats such as png or pdf.  
The HypPy image display program uses the Image and ImageTk modules from the Python Imaging Library (PIL, now called Pillow [18]) for displaying images and matplotlib for making 2D graphs of spectra.