Main Content

TransformedDatastore

基となるデータストアを変換するためのデータストア

説明

TransformedDatastore オブジェクトを使用して、元のデータストアから読み取ったデータを変換または処理します。

作成

関数 transform を使用して TransformedDatastore オブジェクトを作成することができます。たとえば、dsnew = transform(ds1_data,ds2_data,...dsN_data,@fcn) で作成されるデータストアは、変換関数 fcn を使用して 1 つ以上のデータストア ds1_data,ds2_data,...dsN_data を変換します。

プロパティ

すべて展開する

基となるデータストア。datastore オブジェクトの cell 配列として返されます。

変換関数のセット。関数ハンドルの cell 配列として指定します。

データ型: cell

関数 read からの情報を含めるかどうか。logical ベクトルとして指定します。true をとる IncludeInfo の各値について、変換されるデータストアは、transformSet 内の対応する変換関数の代替シグネチャを使用します。

関数 read は、抽出されたデータに関する情報を info struct に返します。詳細については、関数 read のページを参照してください。

データ型: logical

この プロパティ は読み取り専用です。

書き込みでサポートされる形式。string の行ベクトルとして返されます。このプロパティは、writeall を使用してデータストアから出力ファイルを書き込む際に使用可能な出力形式を指定します。

オブジェクト関数

combine複数のデータストアのデータを統合
hasdataデータが読み取り可能かどうかを判別
previewデータストア内のデータのサブセットをプレビュー
readデータストアのデータの読み取り
readallデータストアのすべてのデータの読み取り
writeallファイルへのデータストアの書き込み
resetデータストアの初期状態へのリセット
transformデータストアの変換
numpartitionsデータストアの区画数
partitionデータストアを分割する
shuffleデータストア内のすべてのデータをシャッフルする
isPartitionableデータストアが分割可能かどうかを判別
isSubsettableDetermine 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')

Figure contains 2 axes objects. Axes object 1 with title Resized Street1.jpg contains an object of type image. Axes object 2 with title Resized peppers.png contains an object of type image.

複数の 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)

Figure contains an axes object. The axes object contains an object of type image.

バージョン履歴

R2019a で導入