transform
转换数据存储
句法
Description
transforms one or more input datastores using the transformation functiondsnew.
=变换(ds1,ds2,...,dsN
那@fcn
的)fcn
and 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
Apply Transformation to Collection of Images
创建一个数据存储的数据存储,用于图像集合,并将相同的转换应用于数据存储区中的所有图像。例如,将集合中的所有图像调整为指定的目标大小。
创建一个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');
Transform Multiple Datastores
创建多个数据存储对象并对所有数据存储应用相同的转换。例如,将多个图像组合到一个矩形平铺图像中。
创建一个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
ds1,ds2,...,dsN
-Input datastores
数据存储对象
Input datastores. For a complete list of built-in datastores, seeSelect Datastore for File Format or Application。您还可以指定自定义数据存储。
@fcn
-Function that transforms data
功能手柄
将数据转换为函数句柄的函数。该函数将数据作为输入作为输入,并根据所定义的转换返回变换数据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.
includentinfo.
-包括来自read
function
true
|错误的
包括来自read
function, specified as eithertrue
or错误的
。Theread
function returns information about the extracted data in an信息
结构。有关更多信息,请参阅read
function page.
设置值时includentinfo.
到true
,您必须使用变换功能的替代签名fcn
。
输出参数
dsnew.
- 具有转换数据的新数据存储
TransformedDatastore
目的
具有转换数据的新数据存储,返回为aTransformedDatastore
目的。
扩展能力
基于线程的环境
使用MATLAB®在后台运行代码backgroundPool
或使用并行计算工具箱™加速代码ThreadPool
。
Usage notes and limitations:
In a thread-based environment, you can use
transform
only with the following datastores:ImageageAtastore.
对象ConventDatastore.
orTransformedDatastore
对象you create fromImageageAtastore.
对象by usingcombine
ortransform
You can use
transform
如果您有并行计算工具箱™,则使用其他数据存储。为此,请使用进程备份的并行池而不是使用运行函数backgroundPool
orThreadPool
(使用processpool.
orclusterpool.
的)。
For more information, see在基于线程的环境中运行matlab函数。
版本历史记录
matlab명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오.웹브라우저는matlab명령을지원하지않습니다。
Select a Web Site
选择一个网站,以便在可用的地方进行翻译内容,并查看本地活动和优惠。根据您的位置,我们建议您选择:。
You can also select a web site from the following list:
如何获得最佳网站性能
选择中国网站(以中文或英文)以获得最佳网站性能。其他MathWorks国家网站未优化您所在地的访问。
Americas
- América Latina(Español)
- Canada(English)
- United States(English)