How to make image labeler pixel label output file name same as the imput file name?

4 Ansichten (letzte 30 Tage)
I have a folder contained images with file names 1, 2, 3...png. After labelling using image labeler app in image processing toolbox I am expecting the image pixel label to have same file names as the original image but stored in a separate folder.
Presently the label files are having file names as label_1_1.png. This is causing issues with image-label correspondence while training CNN models because sort order of image files and labels files is not coming same. Is it possible for matlab to output labels with same file name as the original image?

Akzeptierte Antwort

Shlok
Shlok am 12 Jul. 2024
Bearbeitet: Shlok am 12 Jul. 2024
Hi,
I understand that you want the image pixel label files to have the same name as the original image files.
The PNG files within the output folder (PixelLabelData, for example) are typically stored using a specific naming convention. This naming convention usually follows the format "Label_<X>_<ImageName>.png", where "X" represents a number associated with the sequence in which the image was imported in the Image Labeler App.
This is a default behaviour, and hence we need a workaround to achieve the custom output filename. The logic is to run an additional script to remove the prefix “Label_<X>_” from each file name present in the PixelLabelData" folder.
% Define the folder where the exported pixel label files are located
folderPath = 'Your_Path_To_Pixel_Label_Data';
% Get a list of all files in the folder
fileList = dir(fullfile(folderPath, '*.png'));
% Loop through each file in the folder
for k = 1:length(fileList)
% Get the current file name
oldFileName = fileList(k).name;
% Use regular expression to remove the prefix "Label_<X>_"
newFileName = regexprep(oldFileName, '^Label_\d+_', '');
% Rename the file
oldFilePath = fullfile(folderPath, oldFileName);
newFilePath = fullfile(folderPath, newFileName);
movefile(oldFilePath, newFilePath);
end
You can refer to the following documentation link to learn more about Pixel Label Data Storage:
Hope this helps.
Regards,
Shlok

Weitere Antworten (0)

Produkte


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by