Explore Hyperspectral Data in the Hyperspectral Viewer
This example shows how to explore hyperspectral data using the Hyperspectral Viewer app. Using the capabilities of the app, you can view the individual bands of a hyperspectral data set as grayscale images. You can also view color composite representations of the data set as RGB, color infrared (CIR), and false-color images. You can also visualize hyperspectral indices of the data. In addition to exploring these visual representations of the spatial dimensions of the data, you can create plots of individual points or small regions of the data along the spectral dimension. These plots, called spectral profiles, can identify elements in the hyperspectral data.
This example requires the Image Processing Toolbox™ Hyperspectral Imaging Library. You can install the Image Processing Toolbox Hyperspectral Imaging Library from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons. The Image Processing Toolbox Hyperspectral Imaging Library requires desktop MATLAB®, as MATLAB® Online™ and MATLAB® Mobile™ do not support the library.
Load Hyperspectral Data into Workspace
For this example, load an aerial hyperspectral data set of an area called Jasper Ridge, captured via the airborne visible/infrared imaging spectrometer (AVIRIS). The data set contains areas of water, land, road, and vegetation. Load the hyperspectral data set into a
hypercube object in the MATLAB® workspace.
hcube = hypercube('jasperRidge2_R198.img');
This command creates a
hypercube object in the workspace called
hcube object contains a 100-by-100-by-198 cube of hyperspectral data.
View Hyperspectral Data in Hyperspectral Viewer
Open the Hyperspectral Viewer app. First, click the Apps tab on the MATLAB toolstrip. Then, in the Image Processing and Computer Vision section, click the Hyperspectral Viewer button.
With the app open, load the hyperspectral data into the app. On the app toolstrip, click Import and select Hypercube Object. In the Import from Workspace dialog box, select the
hypercube object you loaded into the workspace,
hcube. Alternatively, you can also specify a data set when you open the app using the command:
The app displays several views of the Jasper Ridge hyperspectral data. The Bands pane displays the bands of the hyperspectral data as a stack of grayscale images. A second pane includes color composite representations of the hyperspectral data, displaying the False Color tab by default. The Histogram pane displays a histogram of the band currently displayed in the Bands pane. The Spectral Plot pane displays a plot of the spectral dimension of the data by wavelength or by band. (You can rearrange these panes by clicking and dragging them inside the app. To return to the standard pane arrangement, click Default Layout on the app toolstrip.)
Explore the Spectral Bands
Explore the spectral bands of the Jasper Ridge data set as a stack of grayscale images in the Bands pane. Use the slider at the bottom of the pane to navigate through the images. Because each band isolates a specific range of wavelengths, aspects of the scene might be clearer in some bands than others.
To get a closer look at a band, click Zoom In or Zoom Out in the axes toolbar that appears when you point the cursor over the image.
To improve the contrast of a band image, click Adjust Contrast on the app toolstrip. When you do, the app overlays a contrast adjustment window on the histogram of the image, displayed in the Histogram pane. To adjust the contrast, move the window over the histogram or resize the window by clicking and dragging the handles. The app adjusts the contrast using a technique called contrast stretching. In this process, pixel values below a specified value are displayed as black, pixel values above a specified value are displayed as white, and pixel values in between these two values are displayed as shades of gray. The result is a linear mapping of a subset of pixel values to the entire range of grays, from black to white, producing an image of higher contrast. To return to the default view, click Snap Data Range. To remove the contrast adjustment window from the histogram, click Adjust Contrast.
Explore Color Representations of Hyperspectral Data
Explore the Jasper Ridge hyperspectral data as a color composite image. To create these color images, the Hyperspectral Viewer automatically chooses three of the bands in the hyperspectral dataset to use for the red, green, and blue channels of a color image. The choice of which bands the app uses depends on the type of color representation. The app supports three types of color composite renditions: False Color, RGB, and Color Infrared (CIR). It can be useful to view all of the color composite images because each one uses different bands and can highlight different spectral details, thus increasing the interpretability of the data.
By default, the app displays a false-color representation of the data. False-color composites visualize wavelengths that the human eye cannot see. The tab of the pane identifies the type of the color image, False Color, and the bands that the app used to form it, (145,99,19), in red-green-blue order. The Spectral Plot pane in the app indicates which bands are used. To change these band selections, click and drag the handle of the band indicator in the Spectral Plot. If you choose a different band, the app updates the text in the tab with the new bands and adds the word "Custom", such as, False Color-Custom.
To create the RGB color composite image, the app chooses bands in the visible part of the electromagnetic spectrum. The resulting composite image resembles what the human eye observes naturally. For example, vegetation appears green and water is blue. While RGB composites can appear natural to our eyes, it can be difficult to distinguish subtle differences in features. Natural color images can be low in contrast.
To create the CIR color composite image, the app chooses red, green, and near-infrared wavelengths. Near infrared wavelengths are slightly longer than red, and they are outside of the range visible to the human eye.
Create Spectral Profile Plots of Pixels and Regions
After exploring the grayscale and color visualizations of the hyperspectral data, you can plot points or small regions of the data along the spectral dimension to create spectral profiles. You can plot a single pixel or a region up to 10-by-10 pixels square. Use the Neighborhood Size slider to specify the region size. When you select a region, the app uses the mean of all the pixels in the region to plot the data. Plotting a region, rather than an individual pixel, can smooth out spectral profiles.
To create a spectral plot, click Add Spectral Plot on the app toolstrip, move the cursor over a visualization in the app, and click to select the point or region. You can make your selections on any of the visualizations provided by the app. Your choice of which visualization to use can depend on which one provides the best view of the particular feature of the data you are interested in. When you make a selection, the app puts a point icon at that position on all of the visualizations. To select additional points, click Add Spectral Plot and repeat the process. To delete a point, right-click the point and choose Delete Point from the pop-up menu. To delete all of the points you have selected, click Clear All on the app toolstrip.
For example, the following figure shows four points selected in each visualization, each point representing a particular type of data: water, vegetation, road, and land.
As you select each point, the app plots the data on the Spectral Plot, using a different color to identify each plot. By default, the Spectral Plot also includes a legend identifying the plot for each point. To toggle off inclusion of the legend, click Show Legend.
Visualize Spectral Indices of Hyperspectral Data
You can visualize spectral indices of the hyperspectral data by selecting the desired spectral index from the Spectral Indices section of the app toolstrip. Only the spectral indices that are applicable to the imported hyperspectral data are active.
For example, to visualize the simple ratio (SR) index, select SR from the spectral indices. The app opens a separate pane to visualize the selected spectral indices.
You can create a mask from the spectral index image by using the slider below the image to specify lower and upper thresholds. To go back to the spectral index image without thresholds, first slide the lower threshold to minimum and then the upper threshold to the maximum.
You can also select the Custom index, and define a custom spectral index for the imported hyperspectral data. You must define a custom index compatible with the
customSpectralIndex function. Specify the custom index formula as a function handle and the wavelengths for the custom index computation as a numeric vector. The wavelengths must be unique, must be specified in nanometers, and must lie within the range of wavelengths within the hyperspectral data cube.
Export Bands, Spectral Indices and Masks to Workspace
Select the Export to Workspace option in the app toolstrip. In the Export to Workspace tab, select the color representations, spectral indices and thresholded spectral index masks that you want to export to the workspace. The selected images are exported the workspace as numeric arrays.