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
    • EBOOK
    • 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 & Sensors

Machine Vision Image Processing

LEARN HOW TO COUNT OBJECTS THAT TOUCH EACH OTHER.

By Klara Steinschneider
January 7, 2015

The counting of objects or parts is—one should think—no big challenge for image processing any more. For such applications to count objects, special attention is given to the suitable illumination, so that the contours of the object are clearly visible and to create a dividing line between the objects. Nevertheless sometimes it takes a particular skill or in the current case a combination of visual filters, which eventually make it possible to flawlessly count objects which are similar in shape and color and in addition touch each other.

TECH TIPS

Sometimes it takes a particular skill to make it possible to flawlessly count objects that are similar in shape and color and also touch each other.

The first challenge is the search for the right illumination or to get a high-contrast image.

There are several options to separate objects such as screws or other objects that are identical in shape and color. 

The facts of the case are as follows: small screws, which are located on the x-coordinate on a belt conveyor. The screws are huddled close together and touch each other. Also their position on the y-coordinate can vary. Those screws should be counted while they are on the belt conveyor. This works for all types of objects, which have to be separated before they can be counted.

The first challenge is the search for the right illumination or to get a high-contrast image. Furthermore, the shadows that the objects cast should get eliminated as best as possible because if there is too much of a shadow left, the separation of the objects from the background and from each other can get blurred. So the best possible contour is needed for segmentation and finally for counting objects.

To achieve that, it is important to take further considerations into account. Due to the lens and illumination a separation between the screws on the belt conveyor can be generated. For that two options were thought of.

First, the screws (such as in the image) are brightly lit, while the belt conveyor should remain black. This option offers the advantage that the contour of the screws are highlighted better. The disadvantage is that also the crease of the screws’ threads’ surface are highlighted and therefore it will get difficult to separate them.

The second option is to illuminate the screws in such a way that black objects will lie on a white belt conveyor. In contrast to the first option, it is now possible to harmonize the surface of the creased thread, although the contour of the objects is less visible. And furthermore, shadows can emerge.

Although the contour of the objects is less visible, the second option is better.

To separate objects such as screws, or other objects used for engine construction, tool manufacturing, automotive engineering, etc. that are identical in shape and color, various morphological operations were taken into consideration.

The two basic operations, which are used in machine vision, are “dilation” and “erosion.” With the help of those two operations all other morphological operations can be realized. Both operations usually use a structuring element for probing and expanding the shapes contained in the input image.

The “dilation” and “erosion” operations are typically applied to binary images, but in this case we use it for our grayscale images.

Dilation adds pixels to the boundaries of objects in an image, while erosion removes pixels on object boundaries. The number of pixels added or removed from the objects in an image depends on the size and shape of the above mentioned structuring element used to process the image. It is this structuring element that determines the precise effect of the dilation or erosion on the input image. The smallest structuring element is 3 x 3 pixels.

In the morphological dilation and erosion operations, the state of any given pixel in the output image is determined by applying a rule to the corresponding pixel and its neighbors in the input image.

With the dilation operation the value of the output pixel is the maximum value of all the pixels in the input pixel’s neighborhood. With the erosion operation the value of the output pixel is the minimum value of all the pixels in the input pixel’s neighborhood.

For segmentation of the screws, one can use the “watershed” algorithms, which are morphological operations based on the above mentioned “dilation” and “erosion” operations. With the help of markers the image is “flooded” and where the “water” of two sources converge, a “watershed” is created. This watershed develops into a division line between the objects.

Here is the idea behind the watershed transformation: A grayscale image is interpreted as a topographical relief and in this digital image a regional minimum is assigned to each point. To achieve this flooding is simulated, where water pours out of the regional minima and fills the basins (the minima). The points are assigned to a minimum, by highlighting them with the corresponding number of the catchment basin. Due to the rising water level, zones of influence of the minima are calculated. If two basins converge, the points at the contact are marked as dams. Those dams are the watershed lines, which are possible object boarders.

But one should be careful. Often the use of the watershed transformation results in over-segmentation. This risk can be reduced by preprocessing methods. For reducing the over-segmentation afterwards, the regions can be merged together along special criteria.

As in our case the objects are segmented with homogeneous gray values, the watershed algorithms are used on a gradient image, by treating it as a surface where light pixels are high and dark pixels are low.

So, how to start?

We recommend a marker-controlled watershed segmentation. This means that the transformation works better if you can identify, or “mark,” foreground objects and background locations.

First, you need an image whose dark regions are the objects you are trying to separate. In this example, it would be the screws.

If you have a color image you will have to convert it into a grayscale image. Then read in the grayscale image.

Second, use a Gradient filter for the outline. The gradient is high at the borders of the screws and mostly low inside the objects.

Please notice that you cannot use the watershed transformation directly on the gradient image, as this usually results in “over-segmentation.”

Third, mark the foreground objects. There are a variety of procedures that could be applied here to find the foreground markers, which must be connected blobs of pixels inside each of the foreground objects. In our example we use “opening” and “closing” operations.

An “opening” is used for cutting the connection between two structures. This is achieved by using an erosion. As soon as the connection disappears in the image, you can use dilation to recover the original structures, this time without the connection.

Fourth, define the background markers. These are pixels that are not part of any object. We do not want the markers to be too close to the edges of the screws we are trying to segment. The background has to be “thin.”

 Now we are ready to apply the watershed segmentation. The screws are separated and can be counted by a simple blob command in almost any machine vision software. In certain software, two images are necessary for carrying out the watershed transformation: the input image, preferably monochrome and an image with the markers, which have to be in different colors.  

KEYWORDS: image processing machine vision

Share This Story

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

Klara Steinschneider is the marketing manager at EVT Eye Vision Technology GmbH. For more information, call 0049 721 626 905 82, e-mail [email protected] or visit www.evt-web.com.

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

This image shows a person seated next to a Bobcat T66 compact track loader.

Supercharging Digital Gauging at Bobcat North America

a professional in the aviation field performing maintenance, repair, and overhaul (MRO) work

Manufacturing Retention: Strategies for Improving Company Culture, Engagement and Skill Development

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
Quality Podcast Channel Custom Content

Related Articles

  • VS 0523 Machine Vision 101 Fig 1 Image Processing Sequence

    Image Processing for Machine Vision – How Did We Get Here?

    See More
  • imaging processing

    Image Processing

    See More
  • Battery inspection coating

    Image Processing in Battery Cell Manufacturing

    See More

Related Products

See More Products
  • Machine Vision and Error Proofing DVD

See More Products

Related Directories

  • Phoenix Imaging Machine Vision

    Porosity Inspection of machined metal components using 3D image acquisition. High resolution laser-based scanning optimizes Porosity detection. Phoenix-Middle-Man™ software package provides image storage and database, SQL query and visual display of defects. High-Speed Surface Inspection Systems from Keyence, Omron and Phoenix Imaging for the tough ICE, BEV & Battery projects.
  • Machine Vision Store

    Machine Vision Store has a laser-sharp focus on machine vision imaging. We deliver a select group of components - cameras, lenses, lights, industrial vision PC's - from leading manufacturers known for quality. Components we understand, support and stand behind. Components and consulting services that will power your success.
×

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