counTRObjectCounter
Description
The counTRObjectCounter
object creates a Counting TRansformer
(CounTR) object counter model for counting the number of objects from arbitrary semantic
categories in an image, without the need for training. Using this object, you
can:
Create a CounTR object counter model using exemplar patches. Exemplar patches are small image patches that contain examples of the objects to be counted. These patches serve as reference examples that help the model identify and count similar objects in the larger input image.
Create a CounTR object counter model using an exemplar image with exemplar bounding box locations from which the model extracts exemplar patches.
After creating the CounTR model using the counTRObjectCounter
object,
count the number of objects in an image based on the exemplar patches you specify using the
countObjects
object function. Compute the density map of the object count in the image, based on specified
exemplar patches, using the densityMap
object
function.
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.
Creation
Syntax
Description
creates a CounTR object counter model using exemplar patches containing objects to count,
counter
= counTRObjectCounter(exemplarPatches
)exemplarPatches
.
creates a CounTR object counter model using exemplar patches of objects obtained from an
exemplar image, counter
= counTRObjectCounter(exemplarImage
,exemplarBBoxes
)exemplarImage
, at the exemplar bounding box locations, exemplarBBoxes
.
Input Arguments
Properties
Object Functions
countObjects | Count objects using CounTR deep learning model |
densityMap | Density map of object count generated using CounTR deep learning model |
Examples
Tips
To select exemplar patches from many images for the CountTR model creation, specify the patches to the
exemplarPatches
input argument. To select exemplar patches from a single image, specify the exemplar image and the object bounding boxes it contains to theexemplarImage
andexemplarBBoxes
input argument, respectively.To count objects in a datastore of images using the
countObjects
object function, or compute a count density map using thedensityMap
object function, use exemplars in the form of patches or images and bounding boxes. For best model performance, specify exemplars to thecounTRObjectCounter
object that are general enough to apply to the series of images in a datastore.
References
[1] Liu, Chang, Yujie Zhong, Andrew Zisserman, and Weidi Xie. “CounTR: Transformer-Based Generalised Visual Counting.” arXiv, June 2, 2023. https://doi.org/10.48550/arXiv.2208.13721.
[2] grand-challenge.org. “CAMELYON17 - Grand Challenge.” Accessed November 8, 2024. https://camelyon17.grand-challenge.org/Data/.
Version History
Introduced in R2025a