DataStore, change labels in R2020a

15 ビュー (過去 30 日間)
James Latshaw
James Latshaw 2021 年 12 月 13 日
編集済み: Yongwon Jang 2023 年 7 月 20 日
Hello,
Is there a way to change all labels in an imageDataStore to an appended version of the current label?
I have my images saved in folders with the folder name being the label. Once I load these into an ImageDataStore, I would like to split them into two smaller datastores and then I would like to change each label to be "current label" + "_A".
In psudo code:
For every label in data store 1, rename to be label + "_A".
For every label in data store 2, rename to be label + "_B".
Is this possible?
Thank you!

回答 (1 件)

yanqi liu
yanqi liu 2021 年 12 月 14 日
yes,sir,may be use subset and string contract to generate,such as
imds = imageDatastore(fullfile(matlabroot,'toolbox','matlab'),...
'IncludeSubfolders',true,'FileExtensions','.tif','LabelSource','foldernames')
imds =
ImageDatastore with properties: Files: { '/MATLAB/toolbox/matlab/demos/example.tif'; '/MATLAB/toolbox/matlab/imagesci/corn.tif' } Folders: { '/MATLAB/toolbox/matlab' } Labels: [demos; imagesci] AlternateFileSystemRoots: {} ReadSize: 1 SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage
imds.Labels=categorical(erase(string(imds.Labels), ' ') + repmat('_A', size(imds.Labels, 1), 1))
imds =
ImageDatastore with properties: Files: { '/MATLAB/toolbox/matlab/demos/example.tif'; '/MATLAB/toolbox/matlab/imagesci/corn.tif' } Folders: { '/MATLAB/toolbox/matlab' } Labels: [demos_A; imagesci_A] AlternateFileSystemRoots: {} ReadSize: 1 SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage
  2 件のコメント
Paween Pongsomboon
Paween Pongsomboon 2022 年 4 月 1 日
@yanqi liu You save my life. Thank you. I'm gonna cry I have been struggled with this problem for three days and now you don't know how much I wanna hug you.
Yongwon Jang
Yongwon Jang 2023 年 7 月 20 日
編集済み: Yongwon Jang 2023 年 7 月 20 日
Thank you. It was very helpful.
For my case, erased total labels and reassigned new labels.
I utilized it and edited for my purpose.
Indeed, You are angel.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by