readimage

Read specified image from datastore

Syntax

img = readimage(imds,I)
[img,fileinfo] = readimage(imds,I)

Description

example

img = readimage(imds,I) reads the Ith image file from the datastore imds and returns the image data img. The size and data type of the img array depends on the image formats of the files in the datastore. The image formats supported by readimage function are those formats supported by imread. For more information on the supported formats, see imread.

example

[img,fileinfo] = readimage(imds,I) also returns a struct fileinfo that contains two file information fields:

  • Filename — Name of the file from which the image is read.

  • FileSize — Size of the file in bytes.

Examples

collapse all

Create an ImageDatastore object containing two images, and then read and view the second image.

imds = imageDatastore({'street1.jpg','street2.jpg'});
img = readimage(imds,2);
imshow(img)

Create a datastore object containing two images and read the second image.

imds = imageDatastore({'street1.jpg','street2.jpg'});
[img,info] = readimage(imds,2);

The info structure contains the following information for the second image: Filename, FileSize, and Label. To display the filename and path, type info.Filename in the command window. To display the file size, type info.FileSize.

Input Arguments

collapse all

Input datastore. You can use the imageDatastore function or the datastore function to create a datastore object from your data.

Image file index, specified as a positive integer.

Data Types: double

Output Arguments

collapse all

Image data, returned as a multidimensional array of integers. The size of img depends on the image format:

  • m-by-n array for grayscale images

  • m-by-n-by-3 array for truecolor images

  • m-by-n-by-4 array for CMYK Tiff images

The readimage function supports the image formats that imread supports. For more information on the supported formats, see imread.

Data Types: double

File information, returned as a structure array containing two fields:

  • Filename — Name of the file from which the image is read.

  • FileSize — Size of the file in bytes.

Data Types: struct

Introduced in R2015b