Measure spectral similarity using spectral information divergence
measures the spectral similarity between the spectrum of each pixel in the hyperspectral
score = sid(
inputData and the specified reference spectrum
refSpectrum 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 spectrum
score = sid(
testSpectrum and reference spectrum
by using the SID method. Use this syntax to compare the spectral signature of an unknown
material against the reference spectrum 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 spectrum 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); refSpectrum = endmembers(:,1); testSpectra = endmembers(:,2:end); for i = 1:numEndmembers-1 testSpectrum = testSpectra(:,i); score(i) = sid(testSpectrum,refSpectrum); end
Find the test spectrum that exhibit maximum similarity (minimum distance) to the reference spectrum. Then find the test spectrum that exhibit minimum similarity (maximum distance) to the reference spectrum.
[minval,minidx] = min(score); maxMatch = testSpectra(:,minidx); [maxval,maxidx] = max(score); minMatch = testSpectra(:,maxidx);
Plot the reference spectrum, maximum similarity test spectrum, and the minimum similarity test spectrum. The test spectrum with the minimum score has the highest similarity to the reference endmember. On the other hand, the test spectrum with maximum score has the highest spectral variability and characterises the spectral behaviour of two different materials.
figure plot(refSpectrum) hold on plot(maxMatch,'k') plot(minMatch,'r') legend('Reference spectrum','Maximum match test spectrum','Minimum match test spectrum',... 'Location','Southoutside'); title('Similarity Between Spectra') annotation('textarrow',[0.5 0.5],[0.6 0.65],'String',['Min score: ' num2str(minval)]) annotation('textarrow',[0.7 0.7],[0.4 0.45],'String',['Max score: ' num2str(maxval)],'Color','r') 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.
testSpectrum— Test spectrum
Test spectrum, specified as a C-element vector. The test spectrum is the spectral signature of an unknown region or material.
refSpectrum— Reference spectrum
Reference spectrum, specified as a C-element vector. The reference spectrum is the spectral signature of a known region or material. The function matches the test spectrum against these values.
score— SID score
SID score, returned as a scalar or matrix. The output is a
scalar — If you specify the
testSpectrum 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 spectrum 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 spectrum as:
Calculate the distribution values for the test spectrum 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.