Main Content

assignData

Assign new data to spectral image data cube

    Description

    newspcube = assignData(spcube,row,column,band,data) assigns the specified data to a hyperspectral or multispectral data cube. The function reads the data cube stored in the hypercube or multicube object spcube, assigns the new data to the spectral bands band at the locations specified by row and column, and returns a new hypercube or multicube object.

    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 from an ENVI format file.

    hcube = imhypercube("paviaU.dat");

    Normalize the reflectance values to the range [0, 1].

    datacube = gather(hcube);
    data = rescale(datacube);

    Assign the normalized reflectance values to the data cube.

    newhcube = assignData(hcube,":",":",":",data);

    Specify the row and column indices of a region of interest (ROI). Assign all indices within the ROI a value of zero.

    row = 180:220;
    column = 125:160;
    newhcube = assignData(newhcube,row,column,":",0);
    newdatacube = gather(newhcube);

    Display the original and the modified versions of a spectral band.

    fig = figure(Position=[0 0 800 500]);
    axes1 = axes(Parent=fig,Position=[0.06 0.05 0.45 0.8]);
    imagesc(datacube(:,:,10),Parent=axes1);
    title("Original Data")
    colorbar
    axis off
    axes2 = axes(Parent=fig,Position=[0.55 0.05 0.45 0.8]);
    imagesc(newdatacube(:,:,10),Parent=axes2);
    title("Modified Data")
    colorbar
    axis off
    colormap gray  

    Figure contains 2 axes objects. Hidden axes object 1 with title Original Data contains an object of type image. Hidden axes object 2 with title Modified Data contains an object of type image.

    Download Landsat 8 multispectral data.

    zipfile = "LC08_L1TP_113082_20211206_20211215_02_T1.zip";
    landsat8Data_url = "https://ssd.mathworks.com/supportfiles/image/data/" + zipfile;
    hyper.internal.downloadLandsatDataset(landsat8Data_url,zipfile)
    filepath = fullfile("LC08_L1TP_113082_20211206_20211215_02_T1","LC08_L1TP_113082_20211206_20211215_02_T1_MTL.txt");

    Read a multispectral image into the workspace, and resample it to a uniform resolution..

    mcube = immulticube(filepath);
    mcube = resampleBands(mcube,30);
    datacube = gather(mcube);

    Specify the row and column indices of a region of interest (ROI). Assign all indices within the ROI a value of zero.

    row = 3500:3700;
    column = 3500:3700;
    bands = 7:10;
    newmcube = assignData(mcube,row,column,bands,0);
    newdatacube = gather(newmcube);

    Display the original and the modified versions of a spectral band.

    fig = figure(Position=[0 0 800 500]);
    axes1 = axes(Parent=fig,Position=[0.06 0.05 0.45 0.8]);
    imagesc(datacube(:,:,10),Parent=axes1);
    title("Original Data")
    colorbar
    axis off
    axes2 = axes(Parent=fig,Position=[0.55 0.05 0.45 0.8]);
    imagesc(newdatacube(:,:,10),Parent=axes2);
    title("Modified Data")
    colorbar
    axis off
    colormap gray  

    Input Arguments

    collapse all

    Input spectral data, specified as a hypercube or multicube object. If spcube 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.

    Row indices of the data cube, specified as a positive integer or a vector of positive integers.

    To select a particular row or rows, specify the row index as a positive integer or vector of positive integers respectively. If the data cube is of size M-by-N-by-C, the specified row index values must all be less than or equal to M. To specify a range of row indices, or indices at a regular interval, use the colon operator. For example, row = 1:10.

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

    Column indices of the data cube, specified as a positive integer or a vector of positive integers.

    To select a particular column or columns, specify the column index as a positive integer or vector of positive integers respectively. If the data cube is of size M-by-N-by-C, the specified column index values must all be less than or equal to N. To specify a range of column indices, or indices at a regular interval, use the colon operator. For example, column = 1:10.

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

    Spectral band numbers, specified as a positive integer or a vector of positive integers.

    To select a particular band or bands, specify the band number as a positive integer or vector of positive integers respectively. If the data cube is of size M-by-N-by-C, the specified band number values must all be less than or equal to C. To specify a range of band numbers or numbers at a regular interval, use the colon operator. For example, band = 1:10.

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

    Values to assign, specified as a scalar, vector, matrix, or 3-D array depending on the values of the row, column, and band inputs.

    If row isIf column isIf band isdata must be
    scalarscalarscalarscalar
    M- element vectorscalarscalarM- element row vector or M-by-1 matrix or M-by-1-by-1 array
    scalarN-element vectorscalarN- element column vector or 1-by-N matrix or 1-by-N-by-1 array
    scalarscalarC-element vector1-by-1-by-C array
    M- element vectorN-element vectorscalarM-by-N matrix or M-by-N-by-1 array
    M- element vectorN-element vectorC-element vectorM-by-N-by-C array

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

    Output Arguments

    collapse all

    Output spectral data, returned as a hypercube or multicube object.

    Version History

    Introduced in R2020a