Quality Magazine logo
search
cart
facebook twitter linkedin youtube
  • Sign In
  • Create Account
  • Sign Out
  • My Account
Quality Magazine logo
  • NEWS
  • PRODUCTS
    • FEATURED PRODUCTS
    • SUBMIT YOUR PRODUCT
  • CHANNELS
    • AUTOMATION
    • MANAGEMENT
    • MEASUREMENT
    • NDT
    • QUALITY 101
    • SOFTWARE
    • TEST & INSPECTION
    • VISION & SENSORS
  • MARKETS
    • AEROSPACE
    • AUTOMOTIVE
    • ENERGY
    • GREEN MANUFACTURING
    • MEDICAL
  • MEDIA
    • A WORD ON QUALITY PUZZLE
    • EBOOKS
    • PODCASTS
    • VIDEOS
    • WEBINARS
  • EVENTS
    • EVENT CALENDAR
    • IMTS
  • DIRECTORIES
    • BUYERS GUIDE >
      • Supplier Insights
    • NDT SOURCEBOOK
    • VISION & SENSORS
    • TAKE A TOUR
  • INFOCENTERS
    • Digital Quality Management Systems
    • NEXT GENERATION SPC & QUALITY ANALYTICS
  • AWARDS
    • ROOKIE OF THE YEAR
    • PLANT OF THE YEAR
    • PROFESSIONAL OF THE YEAR
  • MORE
    • Expert Columns
    • NEWSLETTERS
    • QUALITY STORE
    • INDUSTRY LINKS
    • SPONSOR INSIGHTS
  • EMAG
    • eMAGAZINE
    • ARCHIVES
    • CONTACT
    • ADVERTISE
  • SIGN UP!
Vision & SensorsMedical

Vision & Sensors - Image Analysis

Counts

Using algorithms to extract quantitative information from an image.

By Ben Dawson
May 14, 2013
Counting objects in an image seems like an easy task, which can be automated through machine vision and image analysis, but it becomes difficult when objects touch, move randomly, or are hard to distinguish from their background. Image analysis algorithms extract quantitative information from an image.  These algorithms run on a machine vision system (MVS) consisting of lighting, cameras, computers and software.  In this article we’ll look at using machine vision to solve counting tasks of increasing difficulty.
 
Humans can rapidly count about four or less objects, a process called subitizing1. With more than four objects counting slows from 50 to 100 milliseconds per additional object to about 250 to 350 milliseconds per additional object and counting accuracy decreases.  When you add reaction time2, our counting rate is probably less than five objects a second.  Our accuracy is limited and gets worse as counting speed increases and as we get tired and bored.
 
Image analysis running on a MVS can count objects much faster and more accurately than a human.  Objects that are moving, touching, or similar to their background require careful task set up and selection of image analysis algorithms to be accurately counted.  Human vision easily and subconsciously does these tasks, although much slower.
 

Counting Objects Arranged in Single File

A photoelectric sensor can count objects that are arrange in single file and are separate from each other.  A bottling line is a good example.  Bottles on a conveyer pass in single file and are counted when the neck of a bottle interrupts a photoelectric sensor’s light beam.  If the bottle moves backward, it could be counted twice.  Backward motion can occur during production line starts and stops or if the bottle rocks while it moves.  Two or more side-by-side sensors and timing logic can be used to decrement the count on backward motion, but setting the sensor spacing and timing can be difficult.
 
A MVS using image analysis is a simpler solution to set up and to understand.  A rectangular Count Window is placed around the bottle neck and some of the space on either side.  A Count Line is set in the center of the window.  As the bottle enters the Count Window, say from left to right, image analysis detects an identifying feature on the bottle cap, say the center of the black cap, and increments a counter when that feature crosses the Count Line.  Backward motion, from right to left, across the count line decrements the counter.  The key operations are the identification and tracking of an identifying object feature.  This allows the counting algorithm to know the object’s position and direction.  The additional cost of a MVS might be justified by also using the system to inspect the seal, fill level, label application, etc. of the bottle3.
 
Tasks that count multiple objects in ordered or in random positions and moving or not, require a MVS.  One of these tasks is counting bottles in crates.  Consider counting bottles in shrink-wrapped cartons of 12 with the task of totaling the number of bottles made on a line.  A side view with a photoelectric sensor won’t work, as cartons can touch and the first row of bottles may obscures the bottles behind it.
 
We must view the bottles from above, using some aspect of the bottle caps as an identifying feature.  The identifying feature might be color, reflectivity, height, etc. We use pattern matching algorithms, also called search, to find the bottle caps.  The MVS learns the pattern of the bottle caps, and then searches for similar patterns in subsequent input images. There are multiple caps in the camera’s view but the MVS can still identify and track the bottle caps because they move in vertical columns. So instead of one Count Window, we have four.
 

Counting Objects with Random Placement, Size or Spacing

If objects have random placement, size, and spacing or close spacing, the Count Line methods might not work.  This method assumes only one identifying feature appears in each Count Window at a time, thus making tracking simply a matter of checking if the identifying feature is on one side or the other of the Count Line.
 
To deal with some randomness in object size, placement and spacing, image analysis algorithms find an identifying feature on each object; say its center of gravity.  An object is counted when it is fully in the Count Window, and then it is tracked out of the Count Window so it is not counted again.  The Count Window has to be larger than the largest object and large enough that the entire object appears for at least one image frame.
 
We use counting breaded chicken patties as an example.  The patties are differentiated from the background conveyer belt based on color – so red-brown against a white belt.  The image values are converted to black (background) and white (patty) and connectivity analysis, sometimes known as blob analysis, is used to group touching (connected) white pixels into “blobs” representing the different patties.  The centroid (center of gravity) of each blob is used as its identifying feature and is tracked through the Count Window.  Blobs touching the edges of the Count Window are discarded.
 

Dealing with Touching Objects

When objects touch they must be visually separated to be accurately counted.  This applies to moving objects or static (non-moving) objects, say parts in a tray. Sometimes image analysis provides an identifying feature for each object that effectively separates them.  For example, the printing on a touching row of cartons might be used to identify each carton.  If not we might apply image analysis algorithms to visually separate the objects.  For example, two chicken patties might touch at one or a few points and so would be counted as one object rather than two.
 
Touching parts can sometimes be visually separated using image morphology algorithms.  These non-linear operations change the visual shape of an object. They are fundamental to and often used in image analysis.  A full description or morphology is well beyond the scope of this article but, with apologies to the experts, here is a simplified version of binary morphology.
 
Erosion removes bright pixels from the edges of bright (in the image) objects; dilation adds bright pixels to the edges of bright objects.  If the objects are represented by white pixels, as with the chicken patties, each application of the erosion operator removes a shell of white pixels from the object representation.
 
This breaks apart touching objects.  Of course, repeated erosions can cause an object to break into what looks like smaller parts or disappear altogether, so you must experiment to find the proper number of repetitions.
 

When Morphology Fails

When objects overlap too much or are interlocking, morphology might not be able to separate them.  For example, in counting pills (pharmaceuticals) you might have two caplets touching along their long edges and then erosion (or dilation, depending on the part intensity) could make the parts disappear altogether before they are separated.  If you know the size of the parts then you can use connectivity (blob) analysis to find the combined area and can know that this represents two or more touching parts.  The same issue arises in counting surface-mount components such as capacitors.
 
If objects overlap the counting problem becomes even harder.  This is the classic “bin of parts” problem that has been studied for over 40 years.  One possible solution path is to look for junctions between object outlines that have different angles and positions than those found on the part.  For example two overlapping bolts will have thread edges that intersect – we hope they don’t mesh!  Another approach is to use height or 3-D measurements to find objects at different levels.
 
Of course, if a part totally obscures another, there is little you can do.  Perhaps X-ray vision? 
 
References:
http://en.wikipedia.org/wiki/Subitizing 
http://en.wikipedia.org/wiki/Mental_chronometry 
http://www.taptone.com/
KEYWORDS: image analysis machine vision morphology

Share This Story

Looking for a reprint of this article?
From high-res PDFs to custom plaques, order your copy today!

Ben Dawson is Director of strategic development for Teledyne DALSA Industrial Products Inc. [email protected].

Recommended Content

JOIN TODAY
to unlock your recommendations.

Already have an account? Sign In

  • 2024 Quality Rookie of the Year Justin Wise 1440x750px banner with "Quality Rookie of the Year" logo inset

    Meet the 2024 Quality Rookie of the Year: Justin Wise

    Justin Wise is an exceptional individual who has been...
    Aerospace
    By: Michelle Bangert
  • Man with umbrella and coat stands outside while it rains at night looking at a building.

    Nondestructive Testing: Is there an ethics problem?

    I was a whistleblower who exposed fraudulent activities...
    NDT
    By: Dale Norwood
  • Unraveling Deflategate: Football stadium with closeup of football on field

    Unraveling the Tom Brady Deflategate

    The Deflategate scandal erupted following the 2014 AFC...
    Measurement
    By: Greg Cenker and Henry Zumbrun
Manage My Account
  • eMagazine Subscriptions
  • Newsletters
  • Online Registration
  • Subscription Customer Service
  • Manage My Preferences

More Videos

Sponsored Content

Sponsored Content is a special paid section where industry companies provide high quality, objective, non-commercial content around topics of interest to the Quality audience. All Sponsored Content is supplied by the advertising company and any opinions expressed in this article are those of the author and not necessarily reflect the views of Quality or its parent company, BNP Media. Interested in participating in our Sponsored Content section? Contact your local rep!

close
  • Key Takeaways for Quality Leaders
    Sponsored byComplianceQuest

    Key Takeaways for Quality Leaders from the 2026 Gartner Magic Quadrant™ for QMS

  • This image shows a person seated next to a Bobcat T66 compact track loader.
    Sponsored byPolyWorks by InnovMetric

    Supercharging Digital Gauging at Bobcat North America

  • Dorsey Calibration Lab photo by Tom LaBarbera Picture this Studios
    Sponsored byDorsey Metrology International

    Ensuring Product Quality in a Competitive Manufacturing Landscape

Popular Stories

iStock-1352825159-jpg.jpg

U.S. Should Substantially Boost Support for Manufacturing USA Program, Issue National Industrial Manufacturing Strategy, Says New Report

a factory floor during what appears to be a training session or a daily briefing

The Root Cause of Defects We Rarely Name or Address

Dorsey Calibration Lab photo by Tom LaBarbera Picture this Studios

Ensuring Product Quality in a Competitive Manufacturing Landscape

2026 Quality Professional of the Year!

Events

June 22, 2026

Automate 2026

Automate is North America's largest robotics and automation event — and the best place to take your ideas from insight to impact.
 
Our show floor features the world’s leading automation solutions, from AI and robotics to motion control, vision systems, and more. Plus, our educational conference is second to none, led by the brightest minds in automation today.
 
Ready to transform the way you work? Take the next step at Automate.
July 14, 2026

Quality Leaders Forum: Better Communication, Better Quality Data

The Quality Leaders Forum is a quarterly, editor-moderated fireside chat series hosted by Quality Magazine, featuring candid conversations with senior manufacturing and operations executives shaping enterprise-level quality.

View All Submit An Event

Products

Lean Manufacturing and Service Fundamentals, Applications, and Case Studies

Lean Manufacturing and Service Fundamentals, Applications, and Case Studies

See More Products
Rookie of the Year Custom Content

Related Articles

  • Quality Counts

    See More
  • Face of Quality: Motive Counts

    See More
  • Image Morphology

    See More
×

Stay in the know with Quality’s comprehensive coverage of
the manufacturing and metrology industries.

Newsletters | Website | eMagazine

JOIN TODAY!
  • RESOURCES
    • Advertise
    • Contact Us
    • Directories
    • Manufacturing Division
    • Store
    • Want More
  • SIGN UP TODAY
    • Create Account
    • eMagazine
    • Newsletters
    • Customer Service
    • Manage Preferences
  • SERVICES
    • Marketing Services
    • Market Research
    • Reprints
    • List Rental
    • Survey/Respondent Access
  • STAY CONNECTED
    • LinkedIn
    • Facebook
    • YouTube
    • X (Twitter)
  • PRIVACY
    • PRIVACY POLICY
    • TERMS & CONDITIONS
    • DO NOT SELL MY PERSONAL INFORMATION
    • PRIVACY REQUEST
    • ACCESSIBILITY

Copyright ©2026. All Rights Reserved BNP Media, Inc. and BNP Media II, LLC.

Design, CMS, Hosting & Web Development :: ePublishing