Main Content

gather

Read data cube of spectral image into workspace

Since R2025a

    Description

    datacube = gather(spcube) reads the data cube of the hyperspectral or multispectral data spcube from its blocks and returns the complete 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("jasperRidge2_R198.img");

    Read the hyperspectral data cube from the hypercube, and inspect the size of the data cube.

    hdatacube = gather(hcube);
    size(hdatacube)
    ans = 1×3
    
       100   100   198
    
    

    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);

    Read the multispectral data cube from the multicube, and inspect the size of the data cube.

    mdatacube = gather(mcube);
    size(mdatacube)
    ans = 1×3
    
            7721        7651          11
    
    

    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.

    Output Arguments

    collapse all

    Output data cube, returned as a 3-D numeric array.

    Data Types: double

    Version History

    Introduced in R2025a