Main Content

resampleSignature

Resample spectral signature to required wavelengths

Since R2024a

    Description

    The resampleSignature function resamples the reflectance spectrum to the required wavelengths using interpolation. You can use spectral signature resampling to align two spectral signatures to a common spectral grid, improving the accuracy of subsequent applications like spectral matching and target detection. You can also use spectral signature resampling to reduce the spectral dimension of the reflectance spectrum according to the needs of your application, improving efficiency.

    resampledRef = resampleSignature(reflectance,reqWavelength) resamples the library spectral signature reflectance to the required wavelengths reqWavelength using interpolation.

    example

    resampledRef = resampleSignature(reflectance,reqWavelength,origWavelength) specifies the original wavelengths origWavelength of the spectral signature reflectance.

    example

    [resampledRef,commonWavelength,index] = resampleSignature(___) returns the wavelengths commonWavelength present in both the reflectance spectrum and the required wavelengths, and the start and end indices of the common wavelengths in reqWavelength, using any combination of input arguments from previous syntaxes.

    example

    Note

    This function requires the Hyperspectral Imaging Library for Image Processing Toolbox™. You can install the Hyperspectral Imaging Library for Image Processing Toolbox from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

    The Hyperspectral Imaging Library for Image Processing Toolbox requires desktop MATLAB®, as MATLAB Online™ or MATLAB Mobile™ do not support the library.

    Examples

    collapse all

    Read the spectral signature of vegetation from the ECOSTRESS spectral library, to use as the reference spectrum.

    lib = readEcostressSig("vegetation.tree.tsuga.canadensis.vswir.tsca-1-47.ucsb.asd.spectrum.txt");

    Load a hyperspectral image into the workspace.

    hcube = hypercube("paviaU.dat");

    Colorize the hyperspectral image to get an RGB image.

    rgbImg = colorize(hcube,Method="rgb",ContrastStretching=true);

    Compute the distance scores of the spectrum of the hyperspectral image pixels with respect to the reference spectrum.

    scoreBeforeResampling = spectralMatch(lib,hcube);

    Resample the reference spectrum to align with the wavelengths of the hyperspectral image.

    resampledRef = resampleSignature(lib,hcube.Wavelength);

    Compute the distance scores of the spectrum of the hyperspectral image pixels with respect to the resampled reference spectrum.

    scoreAfterResampling = spectralMatch(resampledRef,hcube);

    Visualize the RGB image of the hyperspectral image, the distance score map before resampling the reference spectrum, and the distance score map after resampling the reference spectrum. The pixels with low distance scores are stronger matches to the reference spectrum, and are more likely to belong to the vegetation region. Observe that the distance scores after resampling the reference spectrum are more accurate, as regions that do not have any vegetation cover have a significantly higher distance score after resampling the reference spectrum.

    figure
    tiledlayout(3,1)
    nexttile
    imshow(rgbImg)
    title("RGB Image")
    nexttile
    imagesc(scoreBeforeResampling)
    title("Spectral match before resampling")
    axis image off
    colormap(parula(5))
    colorbar
    nexttile
    imagesc(scoreAfterResampling)
    title("Spectral match after resampling")
    axis image off
    colormap(parula(5))
    colorbar

    Figure contains 3 axes objects. Hidden axes object 1 with title RGB Image contains an object of type image. Hidden axes object 2 with title Spectral match before resampling contains an object of type image. Hidden axes object 3 with title Spectral match after resampling contains an object of type image.

    Load a .mat file that contains the reflectance and the wavelength values of a spectrum into the workspace. Check the length of the reflectance spectrum. Note that the spectrum has reflectance values for 198 wavelengths. Check the range of wavelengths in the spectrum.

    load spectralData.mat reflectance wavelength
    length(reflectance)
    ans = 
    198
    
    min(wavelength)
    ans = 
    399.3700
    
    max(wavelength)
    ans = 
    2.4572e+03
    

    Load a hyperspectral image into the workspace. Note that the hyperspectral image has 103 spectral bands. Check the range of wavelengths in the hyperspectral image. Observe that all the wavelength range of the hyperspectral image lies within the wavelength range of the reflectance spectrum. Thus, all wavelengths of the hyperspectral image will comprise the common wavelengths between the hyperspectral image and the reflectance spectrum.

    hcube = hypercube("paviaU.dat")
    hcube = 
      hypercube with properties:
    
          DataCube: "[610x340x103 double]"
        Wavelength: [103x1 double]
          Metadata: [1x1 struct]
         BlockSize: [610 340]
    
    
    min(hcube.Wavelength)
    ans = 
    430
    
    max(hcube.Wavelength)
    ans = 
    838
    

    Resample the reflectance spectrum to align with the wavelengths of the hyperspectral image.

    [resampledRef,commonWavelength,index] = resampleSignature(reflectance,hcube.Wavelength,wavelength);

    Check the length of the reflectance spectrum and the range of the common wavelengths in nanometer. Observe that the resampled spectrum has reflectance values of 103 wavelengths, and the range of the common wavelengths is the same as the wavelength range of the hyperspectral image. Thus, the common wavelengths between the hyperspectral image and the reflectance spectrum comprise all wavelengths in the hyperspectral image. You can confirm this by inspecting the index output, which provides the indices of the first and last common wavelengths within the wavelength range of the hyperspectral image.

    length(resampledRef)
    ans = 
    103
    
    min(commonWavelength)*10^3
    ans = 
    430
    
    max(commonWavelength)*10^3
    ans = 
    838
    
    index
    index = 1×2
    
         1   103
    
    

    Find the indices in the reflectance spectrum of the wavelengths closest to the first and last common wavelengths. Observe that the common wavelength range of the reflectance spectrum consists of only 45 wavelengths. As such, the resampleSignature function uses interpolation to estimate resampled reflectance values for all 103 wavelengths in the common wavelength range.

    [~,idxMin] = min(abs(wavelength-commonWavelength(1)*10^3))
    idxMin = 
    4
    
    [~,idxMax] = min(abs(wavelength-commonWavelength(end)*10^3))
    idxMax = 
    48
    

    Input Arguments

    collapse all

    Reflectance spectrum to resample, specified as a structure or a numeric vector.

    If reflectance is a structure, it must contain Reflectance and Wavelength fields consisting of numeric vectors of equal length, such as a spectral signature read from the ECOSTRESS library using the readEcostressSig function.. The wavelengths of the reflectance spectrum in the structure must all have the same units. The wavelengths must either all be in nanometers (greater than 100 and less than 100000) or all be in micrometers (greater than 0.1 and less than 100).

    If reflectance is a numeric vector, you must specify the origWavelength input argument.

    Required wavelengths in the resampled spectrum, specified as a numeric vector. The required wavelengths either all be in nanometers (greater than 100 and less than 100000) or all be in micrometers (greater than 0.1 and less than 100).

    Data Types: single | double

    Original wavelengths in the reflectance spectrum, specified as a numeric vector. The original wavelengths must either all be in nanometers (greater than 100 and less than 100000) or all be in micrometers (greater than 0.1 and less than 100).

    If reflectance is a numeric vector, you must specify origWavelength. The length of the origWavelength vector must be the same as the length of the reflectance vector.

    Data Types: single | double

    Output Arguments

    collapse all

    Resampled spectrum, returned as a structure or numeric vector of the same size and data type as reflectance.

    Common wavelengths between the reflectance spectrum and required wavelengths, returned as a numeric vector.

    Data Types: double

    Indices of the common wavelengths in the required wavelengths vector, returned as a two-element numeric vector. The first and second elements of index are the indices of the first and last common wavelengths in reqWavelength, respectively.

    Data Types: double

    Version History

    Introduced in R2024a