主要内容

merge

Merge two or more groundTruthSpectralImage objects

Since R2026a

    Description

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

    gTruthMerged = merge(gTruth1,gTruth2,...,gTruthN) merges two or more groundTruthSpectralImage objects into a new groundTruthSpectralImage object, gTruthMerged. Each groundTruthSpectralImage object must have the same data source and same resolution.

    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

    Select a spectral image data source.

    dataSource = "indian_pines.dat"; 

    Create a ground truth object for the data source with one ROI for the Vegetation label.

    labelName = "Vegetation";
    labelColor = {[0 1 0]};
    labelID = 1;
    variableNames = ["LabelName","LabelColor","LabelID",];
    labelDefs = table(labelName,labelColor,labelID,VariableNames=variableNames);
    vegetationROI1 = struct(ROIName='ROI1',ROI=polyshape([1 0 1 1],[4 3 3 4]));
    labelData = table(vegetationROI1,VariableNames=labelName);
    gTruth1 = groundTruthSpectralImage(dataSource,labelDefs,labelData)
    gTruth1 = 
      groundTruthSpectralImage with properties:
    
              DataSource: [1×1 hyper.labeler.loading.SpectralImageSource]
        LabelDefinitions: [1×5 table]
               LabelData: [1×1 table]
              Resolution: []
    
    

    Create another ground truth object for the same data source with another ROI for the Vegetation label.

    labelName = "Vegetation";
    labelColor = {[0 1 0]};
    labelID = 1;
    variableNames = ["LabelName","LabelColor","LabelID",];
    labelDefs = table(labelName,labelColor,labelID,VariableNames=variableNames);
    vegetationROI2 = struct(ROIName='ROI2',ROI=polyshape([3 2 3 3],[2 1 1 2]));
    labelData = table(vegetationROI2,VariableNames=labelName);
    gTruth2 = groundTruthSpectralImage(dataSource,labelDefs,labelData)
    gTruth2 = 
      groundTruthSpectralImage with properties:
    
              DataSource: [1×1 hyper.labeler.loading.SpectralImageSource]
        LabelDefinitions: [1×5 table]
               LabelData: [1×1 table]
              Resolution: []
    
    

    Create a third ground truth object for the same data source with an ROI for the Water label.

    labelName = "Water";
    labelColor = {[0 0 1]};
    labelID = 2;
    variableNames = ["LabelName","LabelColor","LabelID",];
    labelDefs = table(labelName,labelColor,labelID,VariableNames=variableNames);
    waterROI1 = struct(ROIName='ROI3',ROI=polyshape([5 4 5 5],[3 2 2 3]));
    labelData = table(waterROI1,VariableNames=labelName);
    gTruth3 = groundTruthSpectralImage(dataSource,labelDefs,labelData)
    gTruth3 = 
      groundTruthSpectralImage with properties:
    
              DataSource: [1×1 hyper.labeler.loading.SpectralImageSource]
        LabelDefinitions: [1×5 table]
               LabelData: [1×1 table]
              Resolution: []
    
    

    Merge the ground truth objects together.

    gTruth = merge(gTruth1,gTruth2,gTruth3)
    gTruth = 
      groundTruthSpectralImage with properties:
    
              DataSource: [1×1 hyper.labeler.loading.SpectralImageSource]
        LabelDefinitions: [2×5 table]
               LabelData: [2×2 table]
              Resolution: []
    
    

    Input Arguments

    collapse all

    Ground truth data to merge, specified as groundTruthSpectralImage objects. All specified groundTruthSpectralImage objects must have the same data source and same resolution.

    Output Arguments

    collapse all

    Merged ground truth data, returned as a groundTruthSpectralImage object.

    Version History

    Introduced in R2026a