Main Content

transform

转换数据存储

Description

例子

dsnew.=变换(ds1,ds2,...,dsN@fcn的)transforms one or more input datastores using the transformation functionfcnand returns the transformed datastoredsnew.fcn可以在呼叫中的所有输入数据存储之前或之后放置transform功能。

dsnew.=变换(ds1,ds2,...,dsN@fcn那'IncludeInfo',includentinfo.的)使用变换功能的替代定义fcn。The alternative definition enables you to use the additional information returned by theread数据存储的功能。

Examples

collapse all

创建一个数据存储的数据存储,用于图像集合,并将相同的转换应用于数据存储区中的所有图像。例如,将集合中的所有图像调整为指定的目标大小。

创建一个ImageageAtastore.with two images.

imds = imageageataStore({'street1.jpg''peppers.png'})
imd = ImageDatastore属性:文件:{....../devel/bat/Bdoc22a/build/matlab/toolbox/matlab/demos/street1.jpg'; ' .../devel/bat/Bdoc22a/build/matlab/toolbox/matlab/imagesci/peppers.png' } Folders: { '/mathworks/devel/bat/Bdoc22a/build/matlab/toolbox/matlab/demos'; '/mathworks/devel/bat/Bdoc22a/build/matlab/toolbox/matlab/imagesci' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: {} SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage

阅读所有图像。请注意,数据存储区包含不同大小的图像。

IMG1.= read(imds);%读取第一张图像IMG2.= read(imds);%读取下一个图像谁是IMG1.IMG2.
Name Size Bytes Class Attributes img1 480x640x3 921600 uint8 img2 384x512x3 589824 uint8

将数据存储区中的所有图像转换为指定的目标大小。

targetsize = [224,224];IMDSRESZ =变换(IMDS,@(x)IMResize(x,targetsize));

阅读图像并显示它们的大小。

IMGRESZ1.= read(imdsReSz); imgReSz2 = read(imdsReSz); whosIMGRESZ1.IMGRESZ2.
名称大小字节类属性imgresz1 224x224x3 150528 uint8 imgresz2 224x224x3 150528 uint8

Display the resized images.

subplot(121); imshow(imgReSz1); axison; title('Resized Street1.jpg');子图(122);imshow(imgresz2);轴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.

创建多个数据存储对象并对所有数据存储应用相同的转换。例如,将多个图像组合到一个矩形平铺图像中。

创建一个ImageageAtastore.有一个图像。

imds1 = imageageataStore({'ngc6543a.jpg'})
IMDS1.= ImageDatastore with properties: Files: { ' .../devel/bat/Bdoc22a/build/matlab/toolbox/matlab/demos/ngc6543a.jpg' } Folders: { '/mathworks/devel/bat/Bdoc22a/build/matlab/toolbox/matlab/demos' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: {} SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage

Read the image into the workspace to create an image file from each color channel in the original image.

rgbImage = imread('ngc6543a.jpg');IMWRITE(RGBIMAGE(:,:,1),'nebula_red.jpg');IMWRITE(RGBIMAGE(:,:,2),'nebula_green.jpg');IMWRITE(RGBIMAGE(:,:,3),'nebula_blue.jpg');

创建一个ImageageAtastore.目的for each single-channel image.

imdsr = imagedataStore({'nebula_red.jpg'});imdsg = imagedataStore({'nebula_green.jpg'});imdsb = imagedataStore({'nebula_blue.jpg'});

阅读存储在每个数据存储器中的图像并显示其大小。

imoriginal =读(IMDS1);IMG_RED =读(IMDSR);IMG_GREEN =读(IMDSG);IMG_BLUE =读取(IMDSB);谁是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

通过将所有图像组合成一个矩形瓷砖图像来转换所有数据存储。转换彩色图像IMDS1.灰度尺寸使其尺寸与其他图像的维度相匹配。

tds1 = transform(imds1,imdsR,imdsG,imdsB, @(x1,x2,x3,x4) [rgb2gray(x1),x2;x3,x4]); tile = read(tds1);

Display the tiled image.

imshow(tile)

图包含轴对象。轴对象包含类型图像的对象。

Input Arguments

collapse all

Input datastores. For a complete list of built-in datastores, seeSelect Datastore for File Format or Application。您还可以指定自定义数据存储。

将数据转换为函数句柄的函数。该函数将数据作为输入作为输入,并根据所定义的转换返回变换数据fcn

变换功能必须具有此签名和ds1_data,ds2_data,...dsN_data必须与使用的数据相同read功能。

functiondataout = transformfcn(ds1_data,ds2_data,......dsN_data)。。结尾

或者,您可以定义变换功能fcn到use additional information about the data returned by theread功能。要使用此替代定义,必须指定值includentinfo.成为true。在这种情况下,转换函数必须具有此签名。

function[dataout,InfoOut] = TransformFCN(DS1_DATA,DS2_DATA,......dsn_data,ds1_info,ds2_info ... dsn_info)。。结尾

Example:@transformfcn.

数据类型:function_handle.

包括来自readfunction, specified as eithertrueor错误的。Thereadfunction returns information about the extracted data in an信息结构。有关更多信息,请参阅readfunction page.

设置值时includentinfo.true,您必须使用变换功能的替代签名fcn

输出参数

collapse all

具有转换数据的新数据存储,返回为aTransformedDatastore目的。

扩展能力

版本历史记录

在R2019A引入