主要内容

成像

Datastore for image data

描述

采用an成像目的to manage a collection of image files, where each individual image fits in memory, but the entire collection of images does not necessarily fit. You can create an成像对象使用成像功能,指定其属性,然后使用对象函数导入和处理数据。

创建

描述

IMD= imagedatastore(地点creates a datastoreIMD从图像数据的集合中指定地点

例子

IMD= imagedatastore(地点,,,,名称,价值指定其他参数和properties为了IMD使用一个或多个名称值对参数。

输入参数

展开全部

数据存储中包含的文件或文件夹,指定为FileSet对象,作为文件路径或dsfileset目的。

  • FileSet对象 - 您可以指定地点作为一个FileSet目的。指定ing the location as aFileSet与指定路径或dsfileset目的。有关更多信息,请参阅matlab.io.datastore.FileSet

  • 文件路径 - 您可以将单个文件路径指定为字符向量或字符串标量。您可以将多个文件路径指定为字符向量的单元格数组或字符串数​​组。

  • dsfileset对象 - 您可以指定dsfileset目的。有关更多信息,请参阅matlab.io.datastore.dsfileset

文件或文件夹可以是本地或远程:

  • Local files or folders — Specify local paths to files or folders. If the files are not in the current folder, then specify full or relative paths. Files within subfolders of the specified folder are not automatically included in the datastore. You can use the wildcard character (*) when specifying the local path. This character specifies that the datastore include all matching files or all files in the matching folders.

  • 远程文件或文件夹 - 将远程文件或文件夹的完整路径指定为表单的统一资源定位器(URL)hdfs:///path_to_file。有关更多信息,请参阅Work with Remote Data

When you specify a folder, the datastore includes only files with supported file formats and ignores files with any other format. To specify a custom list of file extensions to include in your datastore, see thefileextensions财产。

成像功能支持具有金宝appImformats格式。

例子:"file1.jpg"

例子:"../dir/data/file1.png"

例子:[“ c:\ dir \ data \ file1.tif”,“ c:\ dir \ data \ file2.tif”]

例子:"C:\dir\data\*.jpg"

名称值对参数

指定可选的逗号分隔对名称,价值参数。姓名是参数名称和Valueis the corresponding value.姓名必须出现在引号中。您可以按任何顺序指定几个名称和值对参数NAME1,Value1,...,Namen,Valuen

例子:imds = imagedatastore(“ c:\ dir \ imagedata”,“ fileextensions”,[。jpg',“。tif”])

子文件夹包含标志,指定为由名称值参数组成的"IncludeSubfolders"andtrueor错误的。指定true在每个文件夹中包括所有文件和子文件夹,或错误的to include only the files within each folder.

如果您不指定"IncludeSubfolders",那么默认值为错误的

例子:"IncludeSubfolders",true

数据类型:逻辑|双倍的

图像文件扩展名,指定为逗号分隔对“ fileextensions”以及字符向量,字符向量的单元格数组,字符串标量或字符串数​​组。指定的扩展名不需要Imformats格式,您可以使用空语“”表示没有扩展的文件。如果您不指定“ fileextensions”, 然后成像automatically includes all images withImformatsextensions in the specified path. If you want to include extensions thatImformats不识别,然后指定所有扩展。

例子:“ fileextensions”,,,,".jpg"

例子:“ fileextensions”,[。jpg“,”。

数据类型:char|cell|细绳

替代文件系统根路径,指定为由名称值参数组成的"AlternateFileSystemRoots"以及字符串向量或单元格数组。采用"AlternateFileSystemRoots"when you create a datastore on a local machine, but need to access and process the data on another machine (possibly of a different operating system). Also, when processing data using the Parallel Computing Toolbox™ and theMATLAB®Parallel Server™,并且数据存储在您的本地计算机上,并具有在不同平台云或群集机上可用的数据的副本,您必须使用"AlternateFileSystemRoots"关联根路径。

  • 要关联一组彼此等效的根路径,请指定"AlternateFileSystemRoots"作为字符串向量。例如,

    [“ z:\ datasets”,“/mynetwork/dataSet”]

  • 要关联到数据存储的多组根路径,请指定"AlternateFileSystemRoots"作为包含多行的单元格数组,其中每一行代表一组等效的根路径。将单元阵列中的每一行指定为字符串向量或字符向量的单元格数组。例如:

    • 指定"AlternateFileSystemRoots"作为字符串向量的单元格数组。

      {["Z:\datasets", "/mynetwork/datasets"];... ["Y:\datasets", "/mynetwork2/datasets","S:\datasets"]}

    • 或者,指定"AlternateFileSystemRoots"作为一个cell array of cell array of character vectors.

      {{{'z:\ dataSets','/mynetwork/dataSets'}; ... {'y:\ dataSets','/mynetwork2/dataSets','s:\ dataSets'}}}

这value of"AlternateFileSystemRoots"必须满足这些条件:

  • 包含一个或多个行,每行指定一组等效的根路径。

  • 每行指定多个根路径,每个根路径必须至少包含两个字符。

  • Root paths are unique and are not subfolders of one another.

  • 至少包含一个指向文件位置的根路径条目。

有关更多信息,请参阅设置用于处理不同机器或群集上的数据存储

例子:[“ z:\ datasets”,“/mynetwork/dataSet”]

数据类型:细绳|cell

提供标签数据的来源,指定为名称值参数,由“ Labelsource”两者"none"or"foldernames"。If"none"is specified, then the标签property is empty. If"foldernames"已指定,然后根据文件夹名称分配标签,并存储在标签财产。You can later modify the labels by accessing the标签属性直接。

“ Labelsource”name-value argument is not usable if a FileSet object is used as the file or folder location.

数据类型:char|细绳

In addition to these name-value pairs, you also can specify any of the properties on this page as name-value pairs, except for theFiles财产。

特性

展开全部

成像属性描述数据并指定如何从数据存储中读取数据。您可以指定的值成像创建数据存储对象时使用名称值参数的属性。要在创建对象后查看或修改属性,请使用点符号。

例如,您可以创建一个成像对象并指定“ readfcn”范围:

imds = imagedatastore("peppers.png",,,,“ readfcn”,,,,@customreader);
或者,您可以分配“ readfcn”to@customreader创建之后成像
imds = imagedatastore("peppers.png");imds.readfcn = @customreader;

Files included in the datastore, resolved as a character vector, cell array of character vectors, string scalar, or string array. Each character vector or string is a full path to a file. The地点argument in the成像and数据存储函数定义Files创建数据存储时。

例子:{“ c:\ dir \ data \ file1.jpg”;“ c:\ dir \ data \ file2.jpg”}

数据类型:char|cell|细绳

此属性仅阅读。

文件夹用于构建数据存储,作为字符向量的单元格数组返回。单元阵列将其定向为列向量。每个字符向量都是包含数据文件的文件夹的路径。这地点argument in the成像and数据存储函数定义文件夹创建数据存储时。

数据类型:cell

在呼叫中读取的图像文件数量read函数,指定为正整数标量。每个电话read功能最多读取读取尺寸图片。

数据存储中文件的文件标签,指定为向量,单元格数组或字符串数​​组。数组中标签的顺序对应于数据存储中关联文件的顺序。如果指定“ LabelSource”,“ foldernames”when creating the成像对象,然后文件的标签名称是包含它的文件夹的名称。如果您不指定“ LabelSource”,“ foldernames”, 然后标签是一个空的单元格数组或字符串数​​组。如果您更改Files创建数据存储后的属性,然后标签property is not automatically updated to incorporate the added files.

数据类型:分类|cell|逻辑|双倍的|single|细绳

读取图像数据的功能,,,,specified as a function handle. The function must take an image file name as input, and then it outputs the corresponding image data. For example, iffustrreaderis the specified function to read the image data, then it must have a signature similar to this:

函数数据= fustreader(文件名)...结束
If more than one output argument exists, then成像仅使用第一个参数并忽略其余的。

笔记

使用ReadFcn不建议转换或预处理2-D图像。用于识别的文件格式Imformats,指定ReadFcn减慢了表现成像。有关更有效的转换和预处理图像的方法,请参见深度学习的预处理图像(深度学习工具箱)

例子:@customreader

数据类型:function_handle

此属性仅阅读。

返回的格式写作,支持列表金宝appa row vector of strings. This property specifies the possible output formats when usingwriteall从数据存储器编写输出文件。

数据类型:细绳

此属性仅阅读。

默认输出格式,返回为字符串标量。此属性在使用时指定默认格式writeall从数据存储器编写输出文件。

数据类型:细绳

对象功能

countEachLabel 在Imagedatastore标签中计数文件
hasdata 确定数据是否可读取
数字 数据存储分区的数量
partition Partition a datastore
预览 数据存储中的数据子集
read Read data in datastore
读取 在数据存储中读取所有数据
读数 从数据存储中读取指定的图像
writeall 将数据存储写入文件
重启 将数据存储重置为初始状态
shuffle 在数据存储中洗牌所有数据
SpliteachLabel 按比例拆分iMagedatastore标签
子集 Create subset of datastore or file-set
transform 变换数据存储
combine 组合来自多个数据存储的数据
isPartitionable 确定数据存储是否可以分区
可观 确定数据存储是否可以改组

例子

全部收缩

创建一个成像与所有关联的对象。tiffiles in the MATLAB® path and its subfolders. Use the folder names as label names.

imds = imagedatastore(fullfile(matlabroot,“工具箱”,,,,“ matlab”),。。。"IncludeSubfolders",,,,true,“ fileextensions”,,,,“ .tif”,,,,“ Labelsource”,,,,"foldernames"
IMD=具有属性的成像:文件:{'... \ matlab \ toolbox \ matlab \ demos \ example.tif';'... \ matlab \ toolbox \ matlab \ imagesci \ corn.tif'}文件夹:{'... \ matlab \ toolbox \ toolbox \ matlab'}标签:[demos;imagsCI]备用Filesystemroots:{} readSize:1 supportEdOu金宝apptputformats:[“ png”“ jpg”“ jpeg”“ jpeg”“ tif”“ tiff”] defaultOutTuptuptorformat:“ png” readfcn:@readdataTastoreImage

Create aFileSet包含四个图像的对象。创建一个成像目的。

fs = matlab.io.datastore.FileSet([“ street1.jpg”,,,,"street2.jpg",,,,"peppers.png",,,,"corn.tif")))
fs = with with属性的文件集:numfiles:4 numfilesread:0 fileinfo:显示所有4个文件的fileinfo fileinfo:nternatefilesystemrotsroots:{}
imds = imagedatastore(fs)
IMD=具有属性的成像:Files: { '...\matlab\toolbox\matlab\demos\street1.jpg'; '...\matlab\toolbox\matlab\demos\street2.jpg'; ' ...\matlab\toolbox\matlab\imagesci\peppers.png' ... and 1 more } Folders: { '...\matlab\toolbox\matlab\demos'; '...\matlab\toolbox\matlab\imagesci' } AlternateFileSystemRoots: {} ReadSize: 1 Labels: {} SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"] DefaultOutputFormat: "png" ReadFcn: @readDatastoreImage

预览第一个图像。

imshow(preview(imds));

仅读取第二和第三张图像,一次。

为了i = 2:3 img =读取(imds,i);结尾

阅读所有四个图像并查看第三张图像。

imgs = readall(imds);imshow(imgs {3})

Limitations

  • 使用ReadFcn不建议转换或预处理2-D图像。用于识别的文件格式Imformats,指定ReadFcn减慢了表现成像。有关更有效的转换和预处理图像的方法,请参见深度学习的预处理图像(深度学习工具箱)

扩展功能

Introduced in R2015b