Contenuto principale

changeFilePaths

Change file paths in ground truth data for spectral images

Since R2026a

    Description

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

    unresolvedFilePaths = changeFilePaths(gTruth,alternateFilePaths) changes the file paths stored in the DataSource property of the groundTruthSpectralImage object gTruth. The alternateFilePaths argument specifies both the current file path and the path to which to change it. The function returns any unresolved paths in unresolvedFilePaths. An unresolved path is a current path not found in gTruth or an alternative path not found on your machine. In both cases, unresolvedFilePaths returns only the corresponding current path.

    Use this function to update groundTruthSpectralImage objects if you move their data sources to a new folder. If you receive groundTruthSpectralImage objects that were created on a different computer, use this function to point to the data location on your local machine.

    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 hyperspectral image source file.

    hcube = imhypercube("jasperRidge2_R198.img");
    filename = "jasperRidgeData.mat";
    savePath = fullfile("C:","Users","Public");
    saveFilePath = fullfile(savePath,filename);
    save(saveFilePath,"hcube")

    Create a ground truth object for the hyperspectral image source.

    currentPath = savePath;
    dataSource = fullfile(currentPath,filename);
    labelName = ["Vegetation"; "Water"];
    labelColor = {[0 1 0]; [0 0 1]};
    labelID = [1; 2];
    variableNames = ["LabelName","LabelColor","LabelID"];
    labelDefs = table(labelName,labelColor,labelID,VariableNames=variableNames);
    gTruth = groundTruthSpectralImage(dataSource,labelDefs)
    gTruth = 
      groundTruthSpectralImage with properties:
    
              DataSource: [1×1 hyper.labeler.loading.SpectralImageSource]
        LabelDefinitions: [2×5 table]
               LabelData: [0×2 table]
              Resolution: []
    
    

    Create a subfolder within the current location of the hyperspectral image source.

    mkdir(savePath,"hyperspectralData")

    Change the file path in the ground truth object to the new file path of the subfolder. Observe that the new file path is unresolved because the file does not yet exist in the new path.

    newPath = fullfile(currentPath,"hyperspectralData");
    unresolvedFilePath = changeFilePaths(gTruth,[currentPath newPath])
    unresolvedFilePath = 
    "C:\Users\Public\jasperRidgeData.mat"
    

    Move the hyperspectral image source to the subfolder.

    currentFilePath = fullfile(currentPath,filename);
    newFilePath = fullfile(newPath,filename);
    movefile(currentFilePath,newFilePath)

    Change the file path in the ground truth object to the new file path of the subfolder. Observe that the new file path is resolved because the file exists in the new path.

    unresolvedFilePath = changeFilePaths(gTruth,[currentPath newPath])
    unresolvedFilePath =
    
         []
    

    Input Arguments

    collapse all

    Ground truth data, specified as a groundTruthSpectralImage object or a vector of groundTruthSpectralImage objects.

    Alternative file paths, specified as an n-by-2 string array, where n is the number of paths to update. Each row specifies a current location and its corresponding new location in the format [currentPath newPath]. Use the same file separators (/ or \) as present in gTruth. You can specify paths as full path names to specific files, or as the beginning portion of a file path. If you use partial paths, the function replaces only that portion of the file path. The paths must include only folder names and not filenames. Both the current and alternate path must point the same data source.

    Data Types: string

    Output Arguments

    collapse all

    Unresolved file paths, returned as a string array. If the function cannot find either the specified current path in gTruth or the specified alternative path location, then it returns the corresponding current path. If the function finds and resolves all file paths, then it returns unresolvedFilePaths as an empty string array.

    Version History

    Introduced in R2026a