This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

changeFilePaths

Change file paths in data source and pixel label data of ground truth object

Syntax

unresolvedPaths = changeFilePaths(gTruth,alterPaths)

Description

example

unresolvedPaths = changeFilePaths(gTruth,alterPaths) changes file paths in the data source and pixel label data of a groundTruth object or array of groundTruth objects, gTruth, to the specified file paths in alterPaths. You can use this function to change the file paths of ground truth data that cannot be found. The function returns the file paths from ground truth data as unresolvedPaths, when:

  • One or more file paths in the data source or pixel label data of gTruth cannot be found.

  • One or more file paths in the data source or pixel label data of gTruth cannot be resolved using the alternative file paths specified in alterPaths. In this case, the alternative file paths cannot be found.

Examples

collapse all

Load a file containing a ground truth object into the workspace. The data source and pixel label data of the ground truth object contains file paths corresponding to an image sequence. If the ground truth object contains file paths that cannot be found, a warning message is displayed.

load('gTruthSeq.mat')
Warning: The data source points to a directory that cannot be found.<br>'C:\CFP\building'<br>Update the DataSource using using <a href="matlab:doc('changeFilePaths')">changeFilePaths</a> method.

Display the data source of the ground truth object to view the file path.

gTruth.DataSource
ans = 
'C:\CFP\building'

Specify an alternative file path to replace the current file path stored in the data source of the ground truth object.

oldPathDataSource = "C:\CFP\building";
newPathDataSource = fullfile(matlabroot,"toolbox\vision\visiondata\building");

Display the pixel label data of the ground truth object to view the file path.

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

Specify an alternative file path to replace the current file path stored in the pixel label data of the ground truth object.

oldPathPixelLabel = "C:\CFP\building\PixelLabelData";
newPathPixelLabel = fullfile(matlabroot,"toolbox\vision\visiondata\building");

Create a cell array of both the current and alternative file paths for the data source and pixel label data. Use this cell array as the input of the changeFilePaths function to change the specified file paths in ground truth.

alterPaths = {[oldPathDataSource newPathDataSource];[oldPathPixelLabel newPathPixelLabel]};

Change the current file paths to the alternative file paths. The function updates these file paths in the data source and pixel label data of the ground truth object. If the any of the ground truth data is still not found using the alternative file paths, the function returns the corresponding original file paths from data source as unresolved file paths.

unresolvedPaths = changeFilePaths(gTruth,alterPaths)
unresolvedPaths = 5×1 string array
    "C:\CFP\building\PixelLabelData\Label_1.png"
    "C:\CFP\building\PixelLabelData\Label_2.png"
    "C:\CFP\building\PixelLabelData\Label_3.png"
    "C:\CFP\building\PixelLabelData\Label_4.png"
    "C:\CFP\building\PixelLabelData\Label_5.png"

Change the unresolved file path by specifying a different alternative path for replacement. If the ground truth data is found using this different alternative file path, the function returns unresolvedPaths as an empty string array.

oldPathPixelLabel = "C:\CFP\building\PixelLabelData";
newPathPixelLabel = fullfile(matlabroot,"toolbox\vision\visiondata\buildingPixellabels");
alterPaths = {[oldPathPixelLabel newPathPixelLabel]};
unresolvedPaths = changeFilePaths(gTruth,alterPaths)
unresolvedPaths = 

  0×0 empty string array

Display the data source of the ground truth object to verify that the file paths were changed.

gTruth.DataSource
ans = 
groundTruthDataSource for a video as an image sequence with properties

                      Source: {
                              ' ...\matlab\toolbox\vision\visiondata\building\building1.JPG';
                              ' ...\matlab\toolbox\vision\visiondata\building\building2.JPG';
                              ' ...\matlab\toolbox\vision\visiondata\building\building3.JPG'
                               ... and 2 more
                              }
                  TimeStamps: [5×1 duration]

Display the pixel label data of the ground truth object to verify that the file paths were changed.

gTruth.LabelData.PixelLabelData
ans = 5×1 cell array
    {'Y:\jobarchive\Bdoc18b\2018_07_17_h18m13s56_job913679_pass\matlab\toolbox\vision\visiondata\buildingPixellabels\Label_1.png'}
    {'Y:\jobarchive\Bdoc18b\2018_07_17_h18m13s56_job913679_pass\matlab\toolbox\vision\visiondata\buildingPixellabels\Label_2.png'}
    {'Y:\jobarchive\Bdoc18b\2018_07_17_h18m13s56_job913679_pass\matlab\toolbox\vision\visiondata\buildingPixellabels\Label_3.png'}
    {'Y:\jobarchive\Bdoc18b\2018_07_17_h18m13s56_job913679_pass\matlab\toolbox\vision\visiondata\buildingPixellabels\Label_4.png'}
    {'Y:\jobarchive\Bdoc18b\2018_07_17_h18m13s56_job913679_pass\matlab\toolbox\vision\visiondata\buildingPixellabels\Label_5.png'}

Input Arguments

collapse all

Ground truth data, specified as a groundTruth object or an array of groundTruth objects. The gTruth object contains the data source, label definitions, and label data which includes pixel label data related to the ground truth.

Alternative file paths, specified as a cell array of string vectors. Each string vector must be of size 1-by-2 and of the form [current alternative], where:

  • current is the current file path that you want to change. This file path is typically one from the data source or pixel label data of gTruth that cannot be found.

  • alternative is the desired file path to change the current file path to.

If you specify gTruth as an array of groundTruth objects, the same alternative file paths apply to all groundTruth objects in the array.

Example: {[oldPath_1 newPath_1];[oldPath_2 newPath_2]} changes file path oldPath_1 to newPath_1 and, similarly, oldPath_2 to newPath_2.

Output Arguments

collapse all

Unresolved file paths, returned as a string array. The returned strings are file paths from the data source and pixel label data of gTruth that cannot be found or are not resolved with the alternative file paths specified in alterPaths. The function returns unresolvedPaths as an empty string array if all the file paths of the ground truth data are found or resolved with the specified alternative file paths.

Introduced in R2018b