Main Content

countObjects

Count objects using CounTR deep learning model

Since R2025a

Description

count = countObjects(counter,I) counts objects within an image I based on exemplar image patches containing objects.

Note

This functionality requires Deep Learning Toolbox™ and the Automated Visual Inspection Library for Computer Vision Toolbox™. You can install the Automated Visual Inspection Library for Computer Vision Toolbox from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

count = countObjects(counter,ds) counts the number of objects within images in a datastore ds based on exemplar patches containing objects.

count = countObjects(___,Name=Value) specifies options using additional name-value arguments in addition to any combination of arguments from previous syntaxes. For example, MiniBatchSize=4 specifies the mini-batch size as 4.

Input Arguments

collapse all

CounTR object counter model, specified as a counTRObjectCounter object.

Image in which to count objects, specified as one of these values:

Image TypeData Format
GrayscaleH-by-W numeric matrix
BinaryH-by-W logical matrix
RGBH-by-W-by-3 numeric array

Datastore of images, specified as a datastore such as an ImageDatastore or CombinedDatastore object, in which to count objects. If calling the datastore with the read function returns a cell array, then the image data must be in the first cell.

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: countObjects(counter,ds,MiniBatchSize=4) specifies the mini-batch size as 4.

Options for All Image Formats

expand all

Hardware resource on which to process images with the network, specified as one of the execution environment options in this table.

ExecutionEnvironmentDescription
"auto"Use a GPU if available. Otherwise, use the CPU. The use of a GPU requires Parallel Computing Toolbox™ and a CUDA® enabled NVIDIA® GPU. For information about the supported compute capabilities, see GPU Computing Requirements (Parallel Computing Toolbox).
"gpu"Use the GPU. If a suitable GPU is not available, the function returns an error message. Using a GPU requires Parallel Computing Toolbox and a CUDA enabled NVIDIA GPU. If Parallel Computing Toolbox or a suitable GPU is not available, then the function returns an error. For information about the supported compute capabilities, see GPU Computing Requirements (Parallel Computing Toolbox).
"cpu"Use the CPU.

Options for Datastore Inputs

expand all

Number of observations returned in each batch, specified as a positive integer. If you set a higher MiniBatchSize, computation requires more memory, which can cause errors if your system does not have sufficient memory.

You can specify this argument only when you specify an input datastore of images, ds.

Visible progress display, specified as a numeric or logical 1 (true) or 0 (false).

You can specify this argument only when you specify an input datastore of images, ds.

Output Arguments

collapse all

Object count, returned as a positive numeric scalar for a single image input, or an R-by-1 vector for a datastore input. R is the number of images in the input datastore, ds.

Version History

Introduced in R2025a