Main Content

removeBands

Remove spectral bands from spectral image

    Description

    newhcube = removeBands(hcube,Wavelength=wlrange) removes spectral bands from the data cube within the specified wavelength range. The function returns a new hypercube object with the remaining wavelengths, their metadata information, and the corresponding spectral bands from the original data cube.

    example

    newhcube = removeBands(hcube,BandNumber=band) removes the spectral bands with the specified spectral band numbers from the hyperspectral data cube.

    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™ and MATLAB Mobile™ do not support the library.

    example

    Examples

    collapse all

    Read hyperspectral data into the workspace.

    hcube = imhypercube("paviaU.dat");

    Inspect the properties of the hypercube object.

    hcube
    hcube = 
      hypercube with properties:
    
         ImageDims: "[610x340x103 double]"
        Wavelength: [103×1 double]
          Metadata: [1×1 struct]
         BlockSize: [610 340]
    
    

    Find the spectral wavelength range of the hyperspectral data cube.

    range = [min(hcube.Wavelength) max(hcube.Wavelength)]
    range = 1×2
    
       430   838
    
    

    Specify the ranges of wavelengths to be remove from the hyperspectral data cube.

    wlrange = [410 450; 620 850];

    Remove the spectral bands that lie in the specified wavelength ranges. The function returns a new hypercube object without the removed bands.

    newhcube = removeBands(hcube,Wavelength=wlrange)
    newhcube = 
      hypercube with properties:
    
         ImageDims: "[610x340x42 double]"
        Wavelength: [42×1 double]
          Metadata: [1×1 struct]
         BlockSize: [610 340]
    
    

    Plot the original and the new wavelength values.

    figure
    plot(hcube.Wavelength,"o")
    hold on
    plot(newhcube.Wavelength,"or")
    xlabel("Band Number")
    ylabel("Wavelength")
    legend("Original Values","New Values",Location="SouthEast")

    Figure contains an axes object. The axes object with xlabel Band Number, ylabel Wavelength contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Original Values, New Values.

    Read a hyperspectral data into the workspace.

    hcube = imhypercube("paviaU.dat")
    hcube = 
      hypercube with properties:
    
         ImageDims: "[610x340x103 double]"
        Wavelength: [103×1 double]
          Metadata: [1×1 struct]
         BlockSize: [610 340]
    
    

    Compute five spectrally distinct endmembers of the hyperspectral data cube by using the ppi function.

    endmembers = fippi(hcube,5);

    Determine the 10 most informative bands of the input data cube based on the endmembers spectra.

    [~,informativeband] = selectBands(hcube,endmembers,NumberOfBands=10);

    Find the band numbers of the noninformative bands of the data cube by using the band numbers of the informative bands.

    datacube = gather(hcube);
    band = setdiff(1:size(datacube,3),informativeband);

    Remove the noninformative bands from the hyperspectral data cube. The function returns a new hypercube object with only the most informative bands.

    newhcube = removeBands(hcube,BandNumber=band)
    newhcube = 
      hypercube with properties:
    
         ImageDims: "[610x340x10 double]"
        Wavelength: [10×1 double]
          Metadata: [1×1 struct]
         BlockSize: [610 340]
    
    

    Plot the original and the new wavelength values.

    figure
    plot(hcube.Wavelength,"o")
    hold on
    plot(newhcube.Wavelength,"or")
    xlabel("Band Number")
    ylabel("Wavelength")
    legend("Original Values","New Values",Location="SouthEast")

    Figure contains an axes object. The axes object with xlabel Band Number, ylabel Wavelength contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Original Values, New Values.

    Input Arguments

    collapse all

    Input hyperspectral data, specified as a hypercube object.

    Wavelength range to remove, specified as a K-by-2 matrix. K is the number of wavelength ranges to remove from the input data. Each row is of form [Wmin Wmax]. Wmin and Wmax are the minimum and the maximum wavelengths of the ranges to remove. At least one specified wavelength range must overlap the wavelength value of at least one spectral band within the input hypercube object.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Spectral band number to remove, specified as a positive integer or vector of positive integers. All of the specified band numbers must be less than or equal to the number of spectral bands in the input hyperspectral data.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Output Arguments

    collapse all

    Output hyperspectral data, returned as a hypercube object.

    Version History

    Introduced in R2020a