imageDatastore内のimageの削除

3 ビュー (過去 30 日間)
so ss
so ss 2022 年 3 月 13 日
移動済み: Atsushi Ueno 2022 年 8 月 17 日
imageDataStoreに含まれるimageのうち上から順に5つのデータを取り除きたいです。
以下を参考にやってみたところ、Labelsが適切に作成されませんでした。
  1 件のコメント
Atsushi Ueno
Atsushi Ueno 2022 年 3 月 15 日
移動済み: Atsushi Ueno 2022 年 8 月 17 日
setdiff関数では該当するFilesフィールドのみ除かれ、その他のフィールドは除かれません。
イメージ データのデータ ストア - MATLAB - MathWorks 日本:リンク先の例を真似て下記を試してみます
  • 2枚の画像からイメージデータストアimdsを作る
  • 削除対象(例として1番目)をファイル名で検索しインデックスを得る
  • subset関数でimdsの内削除対象以外からなるサブセットsubimdsを作る
  • subimdsから削除対象が除かれたかどうか確認する
imds = imageDatastore(fullfile(matlabroot,"toolbox","matlab"),... % 2枚の画像からimdsを作る
"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
delimg = matches(imds.Files, imds.Files(1,1)) % 削除対象(例として1番目)をファイル名で検索しインデックスを得る
delimg = 2×1 logical array
1 0
subimds = subset(imds, ~delimg) % subset関数でimdsの内削除対象以外からなるサブセットsubimdsを作る
subimds =
ImageDatastore with properties: Files: { '/MATLAB/toolbox/matlab/imagesci/corn.tif' } Folders: { '/MATLAB/toolbox/matlab' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: imagesci SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage
% subimdsから削除対象が除かれたかどうか確認する ↑ 1番目のexample.tif(ラベル名demos)が除かれた
>imageDataStoreに含まれるimageのうち上から順に5つのデータを取り除きたいです。
上記の例では2つしか画像が無いですが、下記の様に検索対象を複数にすれば上から順に5つのデータが取り除けます。
% delimg = matches(imds.Files, imds.Files(1:5,1))
% -----------------------------------------↑ココ

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

回答 (0 件)

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!