Measure spectral similarity using spectral information divergence
measures the spectral similarity between the spectra of each pixel in the hyperspectral data
score = sid(
inputData and the specified reference spectra
refSpectra by using the spectral information divergence (SID)
technique. Use this syntax to identify different regions or materials in a hyperspectral
measures the spectral similarity between the specified test spectra
score = sid(
testSpectra and reference spectra
using the SID method. Use this syntax to compare the spectral signature of an unknown
material against the reference spectra or to compute spectral variability between two
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.
Distinguish different regions in a hyperspectral data cube by computing the spectral information divergence (SID) between each pixel spectra and the endmember spectra of the data cube.
Read hyperspectral data in to the workspace.
hcube = hypercube('jasperRidge2_R198.hdr');
Specify the number of spectrally distinct bands to identify in the data cube.
numEndmembers = 7;
Extract endmember spectral signatures from the data cube by using the NFINDR algorithm.
endmembers = nfindr(hcube,numEndmembers);
Plot the spectral signatures of the endmembers.
figure plot(endmembers) xlabel('Band Number') ylabel('Data Value') legend('Location','Bestoutside')
Compute the spectral information divergence between each endmember and the spectra of each pixel in the data cube.
score = zeros(size(hcube.DataCube,1),size(hcube.DataCube,2),numEndmembers); for i= 1:numEndmembers score(:,:,i) = sid(hcube,endmembers(:,i)); end
Compute the minimum score value from the distance scores obtained for each pixel spectra with respect to all the endmembers. The index of each minimum score identifies the endmember spectra to which a pixel spectra exhibits maximum similarity. An index value, n, at the spatial location (x, y) in the score matrix indicates that the spectral signature of the pixel at spatial location (x, y) in the data cube best matches the spectral signature of the nth endmember.
[~,matchingIndx] = min(score,,3);
Estimate an RGB image of the hyperspectral data cube by using the
colorize function. Display both the RGB image and the matrix of matched index values.
rgbImg = colorize(hcube,'Method','RGB'); figure('Position',[0 0 1100 500]) subplot('Position',[0 0.2 0.4 0.7]) imagesc(rgbImg) axis off colormap default title('RGB Image of Hyperspectral Data') subplot('Position',[0.5 0.2 0.4 0.7]) imagesc(matchingIndx); axis off title('Indices of Matching Endmembers') colorbar
Read hyperspectral data into the workspace.
hcube = hypercube('jasperRidge2_R198.hdr');
Find 10 endmembers of the hyperspectral data cube by using the N-FINDR method.
numEndmembers = 10; endmembers = nfindr(hcube,numEndmembers);
Consider the first endmember as the reference spectra and the rest of the endmembers as the test spectra. Compute the SID score between the reference and test spectra.
score = zeros(1,numEndmembers-1); refSpectra = endmembers(:,1); for i = 2:numEndmembers testSpectra = endmembers(:,i); score(i-1) = sid(testSpectra,refSpectra); end
Find the test spectra that exhibit maximum similarity (minimum distance) to the reference spectra. Then find the test spectra that exhibit minimum similarity (maximum distance) to the reference spectra.
[minval,minidx] = min(score); maxMatch = endmembers(:,minidx); [maxval,maxidx] = max(score); minMatch = endmembers(:,maxidx);
Plot the reference spectra, maximum similarity test spectra, and the minimum similarity test spectra. The test spectra with the minimum score has the highest similarity to the reference endmember. On the other hand, the test spectra with maximum score has the highest spectral variability and characterises the spectral behaviour of two different materials.
figure plot(refSpectra) hold on plot(maxMatch,'k') plot(minMatch,'r') legend('Reference spectra','Minimum match test spectra','Maximum match test spectra',... 'Location','Southoutside'); title('Similarity Between Spectra') annotation('textarrow',[0.3 0.3],[0.4 0.52],'String',['Min score: ' num2str(minval)]) annotation('textarrow',[0.6 0.6],[0.4 0.55],'String',['Max score: ' num2str(maxval)]) xlabel('Band Number') ylabel('Data Values')
inputData— Input hyperspectral data
hypercubeobject | 3-D numeric array
Input hyperspectral data, specified as a
object or a 3-D numeric array containing the data cube. If the input is a
hypercube object, the data is read from the
DataCube property of the object.
testSpectra— Test spectra
Test spectra, specified as a C-element vector. The test spectra is the spectral signature of an unknown region or material.
refSpectra— Reference spectra
Reference spectra, specified as a C-element vector. The reference spectra is the spectral signature of a known region or material. The function matches the test spectra against these values.
score— SID score
SID score, returned as a scalar or matrix. The output is a
scalar — If you specify the
testSpectra input argument.
The function matches the test spectral signature against the reference spectral
signature and returns a scalar value. Both the test and the reference spectra must
be vectors of same length.
matrix — If you specify the
inputData input argument. The
function matches the spectral signature of each pixel in the data cube against the
reference spectral signature and returns a matrix. If the data cube is of size
M-by-N-by-C and the
reference spectra is a vector of length C, the output matrix is
of size M-by-N.
A smaller SAM score indicates a strong match between the test signature and the reference signature.
The spectral information divergence (SID) method computes spectral similarity based on the divergence between the probability distributions of the two spectra. Let r and t be the reference and test spectra respectively. Calculate the distribution values for the reference spectra as:
Calculate the distribution values for the test spectra as:
Then, compute the SID value by using the probability distributions of the reference and the test spectra:
 Chein-I Chang. “An Information-Theoretic Approach to Spectral Variability, Similarity, and Discrimination for Hyperspectral Image Analysis.” IEEE Transactions on Information Theory 46, no. 5 (August 2000): 1927–32. https://doi.org/10.1109/18.857802.