画像フォルダを読み取る際に、不要なファイルを名前で指定する方法
5 views (last 30 days)
Show older comments
画像ファイルが複数入っているフォルダをimageDatastoreに保存したが、画像ファイル名称の先頭に"._"(ドットアンダーバー)がついているファイルを削除できません。
~ismemberを使用しましたが、「クラス cell の入力 A とクラス cell の入力 B は、一方が文字ベクトルでない限り、文字ベクトルのセル配列でなければなりません。」というエラーが出てしまいます。
ImageDataStoreのFilesは1230×1のcell配列になっており、原因がわかりません。
よろしくお願いします。
imagefile = imageDatastore("imagefolder");
imagefile = imagefile(~ismember({imagefile.Files},{'._'}));
0 Comments
Accepted Answer
Shunichi Kusano
on 17 Jan 2023
startsWith関数が便利そうです。
filelist = {'1.jpg';'data.jpg';'.temp.jpg';'XXX.jpg'} % 適当にimds.Filesにあたるリストを作成
dotIdx = startsWith(filelist,'.')
ロジカル配列が取得できたので、subset関数を使ってdatastoreからドットから始まるファイルを除いたdatastoreを作成できます。
subimds = imageDatastore(imds,~dotIdx);
2 Comments
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!