Main Content

subtractDarkPixel

Subtract dark pixel value from hyperspectral data cube

Since R2020b

    Description

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

    example

    correctedData = subtractDarkPixel(inputData,darkPixels) subtracts the specified value, darkPixels, from each hyperspectral 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.

    correctedData = subtractDarkPixel(___,'BlockSize',blocksize) specifies the block size for block processing of the hyperspectral data cube by using the name-value pair argument 'BlockSize'. You can specify the 'BlockSize' name-value pair argument in addition to the input arguments in the previous syntaxes.

    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. Hyperspectral 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

    To perform block processing by specifying the 'BlockSize' name-value pair argument, you must have MATLAB® R2021a or a later release.

    Note

    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.

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

    Examples

    collapse all

    Read hyperspectral data into the workspace.

    hcube = hypercube("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])

    Input Arguments

    collapse all

    Input hyperspectral data, specified as one of the following.

    • hypercube object. The DataCube property of the hypercube object stores the hyperspectral data cube.

    • M-by-N-by-C numeric array — M and N are the number of rows and columns in each band of hyperspectral data. C is the number of spectral bands in the hyperspectral dataset.

    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 hyperspectral data set. 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 hyperspectral 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 hyperspectral data, returned as a hypercube 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