Main Content

imageSet class

Define collection of images


imgSet = imageSet(imageLocation)
imgSetVector = imageSet(imgFolder,'recursive')


imgSet = imageSet(imageLocation) returns an object for storing an image data set or a collection of image data sets. You can use this object to manage your image data. The object contains image descriptions, locations of images, and the number of images in your collection.


You can use the imageDatastore object with greater data management capability instead of imageSet.

imgSetVector = imageSet(imgFolder,'recursive') returns a vector of image sets found through a recursive search starting from imgFolder. The imgSetVector output is a 1-by-NumFolders vector, where NumFolders is the number of folders that contain at least one image.

Input Arguments

expand all

Image file location, specified as a character vector or a cell array. The vector must specify the folder name that contains the images. The image files name extensions must be supported by imread. The cell array must contain image locations.

Example 1. Image file location

{'imagePath1','imagePath2', ..., 'imagePathX'}, where each imagePath represents the path to an each image.

Start recursive image search folder, specified as a character vector. The function searches the folder structure recursively, starting from imgFolder.


expand all

Information about the image set, specified as a character vector. When you create an image set by recursively searching folders or by specifying a single folder location, the Description property is set to the folder name. When you specify individual image files, the Description property is not set. You can set the property manually.

Data Types: char

Number of images in image set.

Data Types: double | single

Image locations, given as a cell array of character vectors.

Data Types: cell


partitionDivide image set into subsets
readRead image at specified index
selectSelect subset of images from image set
Common to All System Objects

Allow System object™ property value changes


collapse all

Read the folder of images.

imgFolder = fullfile(toolboxdir('vision'),'visiondata','stopSignImages');
imgSet = imageSet(imgFolder);

Display the first image in the image set collection.


Identify the path to the image sets.

imgFolder = fullfile(matlabroot, 'toolbox','vision',...

Recursively scan the entire image set folder.

imgSets = imageSet(imgFolder,'recursive')
imgSets=1×2 object
  1x2 imageSet array with properties:


Display the names of the scanned folders.

ans = 1x2 cell
    {'books'}    {'cups'}

Display 2nd image from the 'cups' folder.


Specify individual images.

As an alternative to the method below, you can pick the files manually using imgetfile: imgFiles = imgetfile('MultiSelect',true);

imgFiles = { fullfile(matlabroot,'toolbox','vision','visiondata','stopSignImages','image001.jpg'),...
             fullfile(matlabroot,'toolbox','vision','visiondata','stopSignImages','image002.jpg') };

Create image set.

imgSet   = imageSet(imgFiles);
Introduced in R2014b