This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Count files in ImageDatastore labels


T = countEachLabel(imds)



T = countEachLabel(imds) returns a summary table of the labels in imds and the number of files associated with each.


collapse all

Create an ImageDatastore object and label each image according to the folder it is in.

imds = imageDatastore(fullfile(matlabroot, 'toolbox', 'matlab', {'demos','imagesci'}),...
'LabelSource', 'foldernames', 'FileExtensions', {'.jpg', '.png', '.tif'})
imds = 

  ImageDatastore with properties:

      Files: {
             ' ...\matlab\toolbox\matlab\demos\cloudCombined.jpg';
             ' ...\matlab\toolbox\matlab\demos\example.tif';
             ' ...\matlab\toolbox\matlab\demos\landOcean.jpg'
              ... and 5 more
     Labels: [demos; demos; demos ... and 5 more categorical]
    ReadFcn: @readDatastoreImage

List the file count for each label.

T = countEachLabel(imds)
T = 

     Label      Count
    ________    _____

    demos       6    
    imagesci    2    

Input Arguments

collapse all

Input datstore, specified as an ImageDatastore object. To create an ImageDatstore from your image data, use the imageDatastore function.

Output Arguments

collapse all

Table of label counts, returned as a two-column table containing the name of each label in imds and the number of files associated with each label.

Data Types: table

Introduced in R2016a