Main Content

subtractDarkPixel

Subtract dark pixel value from spectral data

Since R2020b

    Description

    correctedData = subtractDarkPixel(inputData) subtracts the minimum pixel value of each band from all pixels in that band of the hyperspectral or multispectral data, inputData. The pixels with minimum intensity values are the dark pixels of the spectral data.

    correctedData = subtractDarkPixel(inputData,darkPixels) subtracts the specified value, darkPixels, from each spectral band. You can specify a single value to subtract across all bands of the data cube, a separate value for each band, or separate values for each pixel in each band. After subtraction, the function sets all negative pixel values to 0.

    example

    correctedData = subtractDarkPixel(___,BlockSize=blocksize) specifies the block size for block processing of the spectral data. (since R2021a)

    The function divides the input image into distinct blocks, processes each block, and then concatenates the processed output of each block to form the output matrix. Spectral images are multi-dimensional data sets that can be too large to fit in system memory in their entirety. This can cause the system to run out of memory while running the subtractDarkPixel function. If you encounter such an issue, perform block processing by using this syntax.

    For example, subtractDarkPixel(inputData,darkPixels,BlockSize=[50 50]) divides the input image into non-overlapping blocks of size 50-by-50 and then performs dark pixel subtraction on each block.

    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.

    Examples

    collapse all

    Read hyperspectral data into the workspace.

    hcube = imhypercube("paviaU");

    Subtract a dark pixel value from all pixels of all bands.

    hcubeCorrected = subtractDarkPixel(hcube,500);

    Display the RGB images of the original hyperspectral data and the hyperspectral data after correction.

    colorImg = colorize(hcube,Method="rgb");
    colorImgCorrected = colorize(hcubeCorrected,Method="rgb");
    figure
    imagesc([colorImg colorImgCorrected])

    Figure contains an axes object. The axes object contains an object of type image.

    Input Arguments

    collapse all

    Input spectral data, specified as one of these options:

    • hypercube object.

    • multicube object.

    • M-by-N-by-C numeric array — M and N are the number of rows and columns of pixels in the spectral data, respectively. C is the number of spectral bands.

    If inputData is a multicube object, all its spectral bands must have the same data resolution. If all spectral bands of the multicube object do not have the same resolution, resample the bands using the resampleBands function, or select bands with uniform resolution using the selectBands function.

    Value to subtract from the pixels of each band, specified as a numeric scalar, a C-element numeric vector, or a 3-D numeric array. C is the number of bands in the spectral data. If you specify darkPixels as a scalar, the function subtracts that value from every pixel of each band in the data cube. If you specify darkPixels as a C-element vector, then, for each element of the vector, the function subtracts the specified value from every pixel of the corresponding band in the data cube.

    If you specify darkPixels as a 3-D numeric array, the size of its third dimension must be C. If the size of darkPixels is Md-by-Nd-by-C and the size of the data cube is M-by-N-by-C, the function subtracts the values of darkPixels from the data cube pixels using these conditions.

    • If Md = M and Nd = N, the function subtracts each value of darkPixels from the corresponding pixel of the data cube.

    • If MdM and NdN, the function creates a 1-by-1-by-C array by using the operation mean(mean(darkPixels,1),2), and subtracts each value of the array from the pixels of the corresponding band of the data cube.

    • If MdM and Nd = N, the function creates a 1-by-N-by-C array by using the operation mean(darkPixels,1), and subtracts the value of each column of the array from the pixels of the corresponding column of that band of the data cube.

    • If Md = M and NdN, the function creates a M-by-1-by-C array by using the operation mean(darkPixels,2), and subtracts the value of each row of the array from the pixels of the corresponding row of that band of the data cube.

    Size of the data blocks, specified as a 2-element vector of positive integers. The elements of the vector correspond to the number of rows and columns in each block, respectively. The size of the data blocks must be less than the size of the input image. Dividing the spectral images into smaller blocks enables you process large data sets without running out of memory.

    • If the blocksize value is too small, the memory usage of the function reduces at the cost of increased execution time.

    • If the blocksize value is large or equal to the input image size, the execution time reduces at the cost of increased memory usage.

    Example: BlockSize=[20 20] specifies the size of each data block as 20-by-20.

    Output Arguments

    collapse all

    Corrected spectral data, returned as a hypercube or multicube object or M-by-N-by-C numeric array with data cube dimensions equal to those of the input data inputData.

    References

    [1] Souri, A. H. and M. A. Sharifi. "Evaluation of Scene-Based Empirical Approaches for Atmospheric Correction of Hyperspectral Imagery." Paper presented at the 33rd Asian Conference on Remote Sensing, Pattaya, Thailand, November 2012.

    Version History

    Introduced in R2020b

    expand all