subset
データストアまたは FileSet のサブセットの作成
説明
例
イメージの datastore オブジェクトを作成してから、そのイメージ データストアのサブセットを作成します。
サンプル フォルダー内のすべてのイメージ ファイル用のイメージ データストア imds を作成します。次に、imds の Files プロパティを表示します。
folders = fullfile(matlabroot,'toolbox','matlab',{'demos','imagesci'}); exts = {'.jpg','.png','.tif'}; imds = imageDatastore(folders,'LabelSource','foldernames','FileExtensions',exts); imds.Files
ans =
8×1 cell array
{'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'}
{'...\matlab\toolbox\matlab\demos\example.tif' }
{'...\matlab\toolbox\matlab\demos\landOcean.jpg' }
{'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' }
{'...\matlab\toolbox\matlab\demos\street1.jpg' }
{'...\matlab\toolbox\matlab\demos\street2.jpg' }
{'...\matlab\toolbox\matlab\imagesci\corn.tif' }
{'...\matlab\toolbox\matlab\imagesci\peppers.png' }imds の最初の 4 つのファイルを含むサブセット データストア subimds を作成し、subimds の Files プロパティを確認します。
indices = 1:4; subimds = subset(imds,indices); subimds.Files
ans =
4×1 cell array
{'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'}
{'...\matlab\toolbox\matlab\demos\example.tif' }
{'...\matlab\toolbox\matlab\demos\landOcean.jpg' }
{'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' }イメージ データストアを作成してから、元のデータストアから指定の割合でランダムに選択されたファイルのみを含むサブセット データストアを作成します。
サンプル フォルダー内のすべてのイメージ ファイル用に imageDatastore を作成し、Files プロパティを表示します。このデータストアには 8 つのファイルが含まれています。
folders = fullfile(matlabroot,'toolbox','matlab',{'demos','imagesci'}); exts = {'.jpg','.png','.tif'}; imds = imageDatastore(folders,'LabelSource','foldernames','FileExtensions',exts); imds.Files
ans =
8×1 cell array
{'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'}
{'...\matlab\toolbox\matlab\demos\example.tif' }
{'...\matlab\toolbox\matlab\demos\landOcean.jpg' }
{'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' }
{'...\matlab\toolbox\matlab\demos\street1.jpg' }
{'...\matlab\toolbox\matlab\demos\street2.jpg' }
{'...\matlab\toolbox\matlab\imagesci\corn.tif' }
{'...\matlab\toolbox\matlab\imagesci\peppers.png' }ファイルの 60% を含み、ランダムに選択されたサブセットを表すインデックスのセットを作成します。
nFiles = length(imds.Files); RandIndices = randperm(nFiles); nSixtyPercent = round(0.6*nFiles); indices = RandIndices(1:nSixtyPercent)
indices =
8 6 4 5 1indices を使用してサブセット データストア submids を作成し、その Files プロパティを確認します。
subimds = subset(imds,indices); subimds.Files
ans =
5×1 cell array
{'...\matlab\toolbox\matlab\imagesci\peppers.png' }
{'...\matlab\toolbox\matlab\demos\street2.jpg' }
{'...\matlab\toolbox\matlab\demos\ngc6543a.jpg' }
{'...\matlab\toolbox\matlab\demos\street1.jpg' }
{'...\matlab\toolbox\matlab\demos\cloudCombined.jpg'}粒度の粗い分割と粒度の細かいサブセットを比較します。
ビデオ ファイル xylophone.mp4 のすべてのフレームを読み取り、反復処理するための ArrayDatastore オブジェクトを作成します。結果のオブジェクトには 141 個のフレームがあります。
v = VideoReader("xylophone.mp4"); allFrames = read(v); arrds = arrayDatastore(allFrames,IterationDimension=4,OutputType="cell",ReadSize=4);
隣接するフレームの特定のセットを抽出するために、arrds の粒度の粗い分割を 4 個作成します。35 個のフレームをもつ、2 番目の分割を抽出します。
partds = partition(arrds,4,2); imshow(imtile(partds.readall()))

粒度の細かいサブセットを使用して、指定されたインデックスにおける 6 個の隣接しないフレームを arrds から抽出します。
subds = subset(arrds,[67 79 82 69 89 33]); imshow(imtile(subds.readall()))

入力引数
入力のデータストアまたはファイル セット。datastore、FileSet、DsFileSet、または BlockedFileSet オブジェクトとして指定します。
サブセットに含めるファイルのインデックス。インデックスのベクトルまたは logical ベクトルとして指定します。
インデックスのベクトルには、サブセット
subdsに含めるファイルのインデックスを含めなければならない。logical ベクトルの長さは、入力
dsのファイル数と同じでなければならない。subsetメソッドは、値trueをもつ logical ベクトルの要素に対応するファイルを含むサブセットsubdsを作成します。
indices の要素は一意でなければなりません。
データ型: double | logical
拡張機能
使用上の注意および制限:
スレッドベースの環境では、次のデータストアでのみ
subsetを使用できます。ImageDatastoreオブジェクトcombineまたはtransformを使用してImageDatastoreオブジェクトから作成するCombinedDatastore、SequentialDatastore、またはTransformedDatastoreオブジェクト
Parallel Computing Toolbox™ がある場合は、他のデータストアで
subsetを使用できます。これを行うには、backgroundPoolまたはThreadPoolを使用する代わりに、プロセスベースの並列プールを使用して関数を実行します (ProcessPoolまたはClusterPoolを使用します)。
詳細については、スレッドベースの環境での MATLAB 関数の実行を参照してください。
バージョン履歴
R2019a で導入
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)