Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imageDatastore

Create ImageDatastore object for collections of image data

Syntax

imds = imageDatastore(location)
imds = imageDatastore(location,Name,Value)

Description

imds = imageDatastore(location) creates a datastore from the collection of image data specified by location. A datastore is a repository for collections of data that are too large to fit in memory. After creating an ImageDatastore object, you can read and process the data in various ways. See ImageDatastore for more information.

example

imds = imageDatastore(location,Name,Value) specifies additional parameters for imds using one or more name-value pair arguments.

Examples

collapse all

Create an ImageDatastore object associated with all .tif files in the MATLAB® path and its subfolders. Use the folder names as label names.

imds = imageDatastore(fullfile(matlabroot,'toolbox','matlab'),...
'IncludeSubfolders',true,'FileExtensions','.tif','LabelSource','foldernames')
imds = 

  ImageDatastore with properties:

       Files: {
              ' ...\matlab\toolbox\matlab\demos\example.tif';
              ' ...\matlab\toolbox\matlab\imagesci\corn.tif'
              }
      Labels: [demos; imagesci]
    ReadSize: 1
     ReadFcn: @readDatastoreImage

Input Arguments

collapse all

Files or folders to include in the datastore, specified as a character vector or cell array of character vectors. If the files are not in the current folder, then location must be 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 location. This character indicates that all matching files or all files in the matching folders are included in the datastore.

If the files are not available locally, then the full path of the files or folders must be an internationalized resource identifier (IRI), such as
hdfs://hostname:portnumber/path_to_file.

For information on using datastore with Amazon S3™ and HDFS™, see Read Remote Data.

    Note:   When reading from HDFS or when reading Sequence files locally, the datastore function calls the javaaddpath command. This command does the following:

    • Clears the definitions of all Java® classes defined by files on the dynamic class path

    • Removes all global variables and variables from the base workspace

    • Removes all compiled scripts, functions, and MEX-functions from memory

    To prevent persistent variables, code files, or MEX-files from being cleared, use the mlock function.

When location represents a folder, the datastore includes only supported image file formats and ignores any other format. Supported files have an imformats format.

Example: 'file1.jpg'

Example: '../dir/data/file1.png'

Example: {'C:\dir\data\file1.tif','C:\dir\data\file2.tif'}

Example: 'C:\dir\data\*.jpg'

Data Types: char | cell

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: imds = imageDatastore('C:\dir\imagedata','FileExtensions',{'.jpg','.tif'})

collapse all

Subfolder inclusion flag, specified as the comma-separated pair consisting of 'IncludeSubfolders' and true, false, 0, or 1. Specify true to include all files and subfolders within each folder or false to include only the files within each folder.

If you do not specify 'IncludeSubfolders', then the default value is false.

Example: 'IncludeSubfolders',true

Data Types: logical | double

Image file extensions, specified as the comma-separated pair consisting of 'FileExtensions' and a character vector or cell array of character vectors. The specified extensions do not require an imformats format, and you can use the empty quotes '' to represent files without extensions. If you do not specify 'FileExtensions', then imageDatastore automatically includes all images with imformats extensions in the specified path. If you want to include extensions that imformats does not recognize, then specify all extensions.

Example: 'FileExtensions','.jpg'

Example: 'FileExtensions',{'.jpg','.png'}

Data Types: char | cell

Source providing label data, specified as the comma-separated pair consisting of 'LabelSource' and 'none' or 'foldernames'. If 'none' is specified, then the Labels property is empty. If 'foldernames' is specified, then labels are assigned according to the folder names and stored in the Labels property. You can later modify the labels by accessing the Labels property directly.

Data Types: char

In addition to these name-value pairs, you also can specify any of the properties on the ImageDatastore page as name-value pairs, except for the Files property.

Output Arguments

collapse all

Datastore for an image file collection, returned as an ImageDatastore object. The Files property is a cell array of character vectors, where each character vector is an absolute path to a file resolved from the location argument. See ImageDatastore for more information.

Introduced in R2016a

Was this topic helpful?