TransformedDatastore
基となるデータストアを変換するためのデータストア
説明
TransformedDatastore
オブジェクトを使用して、元のデータストアから読み取ったデータを変換または処理します。
作成
関数 transform
を使用して TransformedDatastore
オブジェクトを作成することができます。たとえば、dsnew = transform(ds1_data,ds2_data,...dsN_data,@fcn)
で作成されるデータストアは、変換関数 fcn
を使用して 1 つ以上のデータストア ds1_data,ds2_data,...dsN_data
を変換します。
プロパティ
UnderlyingDatastores
— 基となるデータストア
datastore オブジェクトの cell 配列
基となるデータストア。datastore オブジェクトの cell 配列として返されます。
Transforms
— 変換関数のセット
cell 配列
変換関数のセット。関数ハンドルの cell 配列として指定します。
データ型: cell
IncludeInfo
— 関数 read
からの情報を含めるかどうか
logical ベクトル
関数 read
からの情報を含めるかどうか。logical ベクトルとして指定します。true
をとる IncludeInfo
の各値について、変換されるデータストアは、transformSet
内の対応する変換関数の代替シグネチャを使用します。
関数 read
は、抽出されたデータに関する情報を info
struct に返します。詳細については、関数 read
のページを参照してください。
データ型: logical
SupportedOutputFormats
— 書き込みでサポートされる形式
string 行ベクトル
この プロパティ は読み取り専用です。
書き込みでサポートされる形式。string の行ベクトルとして返されます。このプロパティは、writeall
を使用してデータストアから出力ファイルを書き込む際に使用可能な出力形式を指定します。
オブジェクト関数
combine | 複数のデータストアのデータを統合 |
hasdata | データが読み取り可能かどうかを判別 |
preview | データストア内のデータのサブセットをプレビュー |
read | データストアのデータの読み取り |
readall | データストアのすべてのデータの読み取り |
writeall | ファイルへのデータストアの書き込み |
reset | データストアの初期状態へのリセット |
transform | データストアの変換 |
numpartitions | データストアの区画数 |
partition | データストアを分割する |
shuffle | データストア内のすべてのデータをシャッフルする |
isPartitionable | データストアが分割可能かどうかを判別 |
isSubsettable | Determine whether datastore is subsettable |
isShuffleable | データストアがシャッフル可能かどうかを判別 |
例
イメージの集合に変換を適用
イメージの集合用のデータストアを作成し、そのデータストア内のすべてのイメージに同じ変換を適用します。たとえば、集合内のすべてのイメージを、指定したターゲット サイズに変更します。
2 つのイメージを含む ImageDatastore
を作成します。
imds = imageDatastore({'street1.jpg','peppers.png'})
imds = ImageDatastore with properties: Files: { ' .../Bdoc24a.2511836/build/matlab/toolbox/matlab/demos/street1.jpg'; ' .../Bdoc24a.2511836/build/matlab/toolbox/matlab/imagesci/peppers.png' } Folders: { ' .../filer/batfs1904-0/Bdoc24a.2511836/build/matlab/toolbox/matlab/demos'; ' .../batfs1904-0/Bdoc24a.2511836/build/matlab/toolbox/matlab/imagesci' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: {} SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage
すべてのイメージを読み取ります。データストアには異なるサイズのイメージが含まれていることがわかります。
img1 = read(imds); % reads the first image img2 = read(imds); % reads the next image whos img1 img2
Name Size Bytes Class Attributes img1 480x640x3 921600 uint8 img2 384x512x3 589824 uint8
データストア内のすべてのイメージを、指定したターゲット サイズに変換します。
targetSize = [224,224]; imdsReSz = transform(imds,@(x) imresize(x,targetSize));
イメージを読み取ってそのサイズを表示します。
imgReSz1 = read(imdsReSz); imgReSz2 = read(imdsReSz); whos imgReSz1 imgReSz2
Name Size Bytes Class Attributes imgReSz1 224x224x3 150528 uint8 imgReSz2 224x224x3 150528 uint8
サイズ変更後のイメージを表示します。
tiledlayout(1,2); nexttile imshow(imgReSz1); axis on; title('Resized Street1.jpg') nexttile imshow(imgReSz2); axis on; title('Resized peppers.png')
複数のデータストアの変換
複数の datastore オブジェクトを作成し、同じ変換をすべてのデータストアに適用します。たとえば、複数のイメージを 1 つの四角形内の整列イメージとして結合します。
1 つのイメージをもつ ImageDatastore
を作成します。
imds1 = imageDatastore({'ngc6543a.jpg'})
imds1 = ImageDatastore with properties: Files: { ' .../Bdoc24a.2511836/build/matlab/toolbox/matlab/demos/ngc6543a.jpg' } Folders: { ' .../filer/batfs1904-0/Bdoc24a.2511836/build/matlab/toolbox/matlab/demos' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: {} SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage
イメージをワークスペースに読み取り、元のイメージの各カラー チャネルからイメージ ファイルを作成します。
rgbImage = imread('ngc6543a.jpg'); imwrite(rgbImage(:,:,1),'nebula_red.jpg'); imwrite(rgbImage(:,:,2),'nebula_green.jpg'); imwrite(rgbImage(:,:,3),'nebula_blue.jpg');
各単一チャネル イメージの ImageDatastore
オブジェクトを作成します。
imdsR = imageDatastore({'nebula_red.jpg'}); imdsG = imageDatastore({'nebula_green.jpg'}); imdsB = imageDatastore({'nebula_blue.jpg'});
各データストアに格納されているイメージを読み取り、そのサイズを表示します。
imOriginal = read(imds1); img_red = read(imdsR); img_green = read(imdsG); img_blue = read(imdsB); whos img1 img_red img_green img_blue
Name Size Bytes Class Attributes img_blue 650x600 390000 uint8 img_green 650x600 390000 uint8 img_red 650x600 390000 uint8
すべてのイメージを 1 つの四角形内の整列イメージに結合して、すべてのデータストアを変換します。imds1
のカラー イメージをグレースケールに変換して、その次元を他のイメージの次元と一致させます。
tds1 = transform(imds1,imdsR,imdsG,imdsB, @(x1,x2,x3,x4) [rgb2gray(x1),x2;x3,x4]); tile = read(tds1);
タイル イメージを表示します。
imshow(tile)
バージョン履歴
R2019a で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)