Main Content

changeFilePaths

Change file paths in multisignal ground truth data

Since R2020a

Description

unresolvedPaths = changeFilePaths(gTruth,alternativePaths) changes the file paths stored in a groundTruthMultisignal object, gTruth, based on pairs of current paths and alternative paths, alternativePaths. If gTruth is a vector of groundTruthMultisignal objects, the function changes the file paths across all objects. The function returns the unresolved paths in unresolvedPaths. An unresolved path is any current path in alternativePaths not found in gTruth or any alternative path in alternativePaths not found at the specified path location. In both cases, unresolvedPaths returns only the current paths.

Use this function to update the file paths of ground truth data that changes folder locations. You can change file paths for the ground truth data sources and pixel label data.

example

Examples

collapse all

Change the file paths to the data sources and pixel label data in a groundTruthMultisignal object.

Load a groundTruthMultisignal object containing ground truth data into the workspace. The data source and pixel label data of the object contain file paths corresponding to an image sequence showing a building. MATLAB® displays a warning that the path to the data source cannot be found.

load('gTruthMultiOldPaths.mat')
Warning: The data source for the following source names could not be loaded. Update the data sources using <a href="matlab:doc('changeFilePaths')">changeFilePaths</a> method.
  'C:\Sources\building'

Display the current path to the data source.

gTruth.DataSource
ans = 
  ImageSequenceSource with properties:

            Name: "Image Sequence"
     Description: "An image sequence reader"
      SourceName: "C:\Sources\building"
    SourceParams: [1×1 struct]
      SignalName: "building"
      SignalType: Image
       Timestamp: {[5×1 duration]}
      NumSignals: 1

Specify the current path to the data source and an alternative path and store these paths in a cell array. Use the changeFilePaths function to update the data source path based on the paths in the cell array. Because the function does not find the pixel label data at the specified new path, it returns the current unresolved paths.

currentPathDataSource = "C:\Sources\building";
newPathDataSource = fullfile(matlabroot,"toolbox\vision\visiondata\building");
alternativePaths = {[currentPathDataSource newPathDataSource]};
unresolvedPaths = changeFilePaths(gTruth,alternativePaths)
unresolvedPaths = 5×1 string
    "C:\Pixels\Label_1.png"
    "C:\Pixels\Label_2.png"
    "C:\Pixels\Label_3.png"
    "C:\Pixels\Label_4.png"
    "C:\Pixels\Label_5.png"

Verify that the paths in the groundTruthMultisignal object match the unresolved paths returned by the changeFilePaths function. The unresolved paths are stored in the ROILabelData property of the groundTruthMultisignal object, in the PixelLabelData column of the table for the building image sequence signal.

gTruth.ROILabelData.building.PixelLabelData
ans = 5×1 cell
    {'C:\Pixels\Label_1.png'}
    {'C:\Pixels\Label_2.png'}
    {'C:\Pixels\Label_3.png'}
    {'C:\Pixels\Label_4.png'}
    {'C:\Pixels\Label_5.png'}

Specify the current path and an alternative path for the pixel label files and change the file paths. The function updates the paths for all pixel labels. Because the function resolves all paths, it returns an empty array of unresolved paths.

currentPathPixels = "C:\Pixels";
newPathPixels = fullfile(matlabroot,"toolbox\vision\visiondata\buildingPixellabels");
alternativePaths = {[currentPathPixels newPathPixels]};
unresolvedPaths = changeFilePaths(gTruth,alternativePaths)
unresolvedPaths = 

  0×0 empty string array

To view the new data source path, use the gTruth.DataSource command. To view the new pixel label data paths, use the gTruth.ROILabelData.building.PixelLabelData command.

Input Arguments

collapse all

Multisignal ground truth data, specified as a groundTruthMultisignal object or vector of groundTruthMultisignal objects.

Alternative file paths, specified as a 1-by-2 string vector or cell array of 1-by-2 string vectors of the form [pcurrent pnew].

  • pcurrent is a current file path in gTruth. This file path can be from the data source or pixel label data of gTruth. Specify pcurrent using backslashes as the path separators.

  • pnew is the new path to which you want to change pcurrent. Specify pnew using either forward slashes or backslashes as the path separators.

You can specify alternatives paths to these files.

  • Signal data sources — The DataSource property of gTruth contains one MultiSignalSource object per signal. The changeFilePaths function updates the signal paths stored in these objects.

  • Pixel label data — The ROILabelData property of gTruth contains an ROILabelData object, which contains a table of ROI label data for each signal. For signals with pixel label data, which is stored in the PixelLabelData column of the table for that signal, the function updates the paths to the pixel label data.

If gTruth is a vector of groundTruthMultisignal objects, the function changes the file paths across all objects.

Example: ["C:\Pixels\PixelLabelData_1" "C:\Pixels\PixelLabelData_2] changes the path to the pixel label data folder. The function updates the path in all pixel label files stored in that folder.

Example: {["B:\Sources\video1.mp4" "C:\Sources\video1.mp4"]; ["B:\Sources\video2.mp4" "C:\Sources\video2.mp4"]} changes the drive letter in the paths to the data sources.

Output Arguments

collapse all

Unresolved file paths, returned as a string array. If the changeFilePaths function cannot find either the current path or new path in the string vectors specified by the alternativePaths input, then it returns the unresolved current paths in unresolvedPaths.

If the function finds and resolves all file paths, then it returns unresolvedPaths as an empty string array.

Version History

Introduced in R2020a