Main Content

selectLabelsByGroup

Select labels by group in ground truth data for spectral image

Since R2026a

    Description

    Add-On Required: This feature requires the Hyperspectral Imaging Library for Image Processing Toolbox add-on.

    gTruthNew = selectLabelsByGroup(gTruth,labelGroups) returns a new groundTruthSpectralImage object, gTruthNew, with the same data as gTruth, but with label data for the labels in only the groups specified by labelGroups.

    example

    Note

    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

    Create a ground truth object for a hyperspectral image.

    source = "indian_pines.dat";                                        
    labelName = ["VegType1"; "VegType2"; "Water"];
    labelColor = {[0 1 0]; [0 1 0]; [0 0 1]};
    labelID = [1; 2; 3];
    labelGroup = ["Vegetation"; "Vegetation"; "Water"];
    variableNames = ["LabelName","LabelColor","LabelID","LabelGroup"];
    labelDefs = table(labelName,labelColor,labelID,labelGroup,VariableNames=variableNames);
    vegType1ROI = struct(ROIName='ROI1',ROI=polyshape([1 0 1 1],[4 3 3 4]));
    vegType2ROI = struct(ROIName='ROI2',ROI=polyshape([3 2 3 3],[2 1 1 2]));
    waterROI = struct(ROIName='ROI3',ROI=polyshape([5 4 5 5],[3 2 2 3]));
    labelData = table(vegType1ROI,vegType2ROI,waterROI,VariableNames=labelName);
    gTruth = groundTruthSpectralImage(source,labelDefs,labelData)
    gTruth = 
      groundTruthSpectralImage with properties:
    
              DataSource: [1×1 hyper.labeler.loading.SpectralImageSource]
        LabelDefinitions: [3×5 table]
               LabelData: [1×3 table]
              Resolution: []
    
    

    Create a new ground truth object with labels from only the Vegetation label group.

    gTruthNew = selectLabelsByGroup(gTruth,"Vegetation")
    gTruthNew = 
      groundTruthSpectralImage with properties:
    
              DataSource: [1×1 hyper.labeler.loading.SpectralImageSource]
        LabelDefinitions: [2×5 table]
               LabelData: [1×2 table]
              Resolution: []
    
    

    Input Arguments

    collapse all

    Ground truth data, specified as a groundTruthSpectralImage object.

    Label groups to select, specified as a string scalar, character vector, string array, or cell array of character vectors.

    Data Types: char | string | cell

    Output Arguments

    collapse all

    New ground truth data with the selected labels, returned as a groundTruthSpectralImage object.

    Version History

    Introduced in R2026a