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

48 次查看(过去 30 天)
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?

采纳的回答

Shlok
Shlok 2024-7-12,6:44
编辑:Shlok 2024-7-12,9:27
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by