Main Content

spectralIndices

Compute hyperspectral indices

Description

example

indices = spectralIndices(hcube) computes the greenness indices: enhanced vegetation index (EVI), modified chlorophyll absorption ratio index (MCARI), and simple ratio (SR) index of a hyperspectral data. The function reads the data cube and the wavelength values stored in the hypercube object hcube to compute the greenness indices.

Note

This function 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.

example

indices = spectralIndices(hcube,indexNames) computes one or more spectral indices specified by indexNames.

indices = spectralIndices(hcube,'all') computes all the supported spectral indices.

Examples

collapse all

Read hyperspectral data into the workspace.

hcube = hypercube('indian_pines.dat');

Compute the spectral indices value for each pixel in the data cube. By default, the spectralIndices function returns the simple ratio (SR) index, enhanced vegetation index (EVI), and modified chlorophyll absorption ratio index (MCARI).

indices = spectralIndices(hcube);

Inspect the index names in the output struct indices. Read the corresponding index images returned at the output.

indices.IndexName
ans = 
"Simple Ratio (SR)"
ans = 
"Enhanced Vegetation Index (EVI)"
ans = 
"Modified Chlorophyll Absorption Ratio Index (MCARI)"
srImg = indices(1).IndexImage;
eviImg = indices(2).IndexImage;
mcariImg = indices(3).IndexImage;

Estimate a contrast-stretched RGB image from the original data cube by using the colorize function.

rgbImg = colorize(hcube,'Method','RGB','ContrastStretching',true);

Display the original and the computed index images. The SR index value greater than 3 signifies vegetation. The EVI index identifies dense vegetation and the typical EVI index value for healthy vegetation lie between 0.2 and 0.8. MCARI index signifies abundance of chlorophyll in a region.

fig = figure('Position',[0 0 800 700]);

axes1 = axes('Parent',fig,'Position',[0 0.54 0.42 0.42]);
imagesc(rgbImg,'Parent',axes1);
axis off
title('RGB Image of Data Cube')

axes2 = axes('Parent',fig,'Position',[0.5 0.54 0.45 0.42]);
imagesc(srImg,'Parent',axes2);
axis off
title('SR Image')
colorbar

axes3 = axes('Parent',fig,'Position',[0 0.035 0.45 0.42]);
imagesc(eviImg,'Parent',axes3);
axis off
title('EVI Image')
colorbar

axes4 = axes('Parent',fig,'Position',[0.5 0.035 0.45 0.42]);
imagesc(mcariImg,'Parent',axes4);
axis off
title('MCARI Image')
colorbar

Read hyperspectral data into the workspace.

hcube = hypercube('jasperRidge2_R198.img');

Compute the MNDWI value for each pixel in the data cube and read the water index image.

indices = spectralIndices(hcube,'MNDWI');
mndwiImg = indices.IndexImage;

Estimate a contrast-stretched RGB image from the original data cube by using the colorize function.

rgbImg = colorize(hcube,'Method','RGB','ContrastStretching',true);

Display the original and the MNDWI image.

fig = figure('Position',[0 0 800 400]);
axes1 = axes('Parent',fig,'Position',[0 0.1 0.4 0.8]);
imshow(rgbImg,'Parent',axes1)
title('RGB Image of Data Cube')
axes2 = axes('Parent',fig,'Position',[0.45 0.1 0.47 0.8]);
imagesc(mndwiImg,'Parent',axes2)
colorbar
axis off
title('MNDWI Image')

Water regions typically have MNDWI values greater than 0.09. Perform thresholding of MNDWI image to segment the water regions. Specify the threshold value.

threshold = 0.09;

Generate a binary image with a intensity value 1 for pixels with a score greater than or equal to the specified threshold. All other pixels have a value 0. The regions in the binary image with a value of 1 correspond to the water regions in the data cube with MNDWI values greater than the threshold.

bw = mndwiImg > threshold;

Overlay the binary image on to the RGB image and display the overlaid image.

overlayImg = imoverlay(rgbImg,bw,[0 0 1]);
figure
imagesc(overlayImg)
axis off
title('Water Region Overlaid on RGB Image')

Input Arguments

collapse all

Input hyperspectral data, specified as a hypercube object. The DataCube property of the hypercube object contains the hyperspectral data cube.

Name of spectral index to compute, specified as a character vector or string scalar. You can also specify the names of multiple spectral indices as a cell array of either character vectors or string scalars. The value of the indexNames must be one of the names listed in this table.

Supported spectral indices
indexNamesDescription
'CAI'Cellulose absorption index
'CMR'Clay minerals ratio
'EVI'Enhanced vegetation index
'GVI'Green vegetation index
'MCARI'Modified chlorophyll absorption ratio index
'MIVI'Modified triangular vegetation index
'MNDWI'Modified normalized difference water index
'MSI'Moisture stress index
'NBR'Normalized burn ratio
'NDBI'Normalized difference built-up index
'NDMI'Normalized difference mud index
'NDNI' Normalized difference nitrogen index
'NDVI'Normalized difference vegetation index
'OSAVI'Optimized soil adjusted vegetation index
'PRI'Photochemical reflectance index
'SR'Simple ratio

Example: indexNames = {'NDVI,'OSAVI'}, indexNames = {"GVI","NDMI"}, indexNames = 'PRI'

Data Types: char | string

Output Arguments

collapse all

Spectral index values of the hyperspectral data, returned as a structure with two fields: IndexName and IndexImage.

FieldsDescription
IndexNameNames of the spectral indices computed for the hyperspectral data, returned as a string.
IndexImageIndex image returned as a matrix. Each pixel value is the spectral index value computed across all the spectral bands. If the size of the hyperspectral data cube specified at the input is M-by-N-by-C, the size of the index image is M-by-N.

The size of the output structure depends on the number of spectral indices computed for the hyperspectral data.

  • If the second input argument indexNames is not specified, the output is a structure array of size 1-by-3. The structure array contains the index images corresponding to EVI, MCARI, and SR index.

  • If the second input argument indexNames is specified and is of length 1-by-k, the output is a structure array of size 1-by-k. You can use dot notation to read the outputs obtained for each spectral index specified at the input.

  • If the second input argument is 'all', the output is a structure array of size 1-by-16. The structure array contains the index images corresponding to all the supported spectral indices.

Data Types: struct

See Also

|

Introduced in R2020b