How to Inspect Closures with Machine Vision

An explanation of the “template” and “features” methods of closure inspection and the role of vision systems in automating the process.


A complete cap liner inspection system: The red laser dot is used measure the height of the liner to detect lifted liners or missing liners. Source: DalsaClosures, such as plastic caps for food, cosmetic, and pharmaceutical containers, must be individually inspected for defects. Possible defects include out-of roundness, short shots (missing material), liner defects, or contamination. The inspection rate can be as much as 1,200 closures per minute, so a machine vision inspection system is required.

There are two common approaches to closure inspection. “Template” methods compare images from a known good part, a “golden template,” to an image of a part being inspected and report differences. “Features” methods measure such parameters as part dimensions and intensity distributions and use these measures to make a good/ bad decision. Both methods start by taking a digital image of the parts to be inspected.

A bottle cap liner is analyzed for circularity. Source: DalsaThere are many factors in getting an acceptable digital image of the parts, including strong and steady illumination of the parts and a camera with a fast shutter speed to reduce image blurring caused by part motion. For the purposes of the explanations presented in this article, let’s assume an acceptable image has been acquired.

Template method

Considered attractive because the inspection can be set up by showing the machine vision system (MVS) 30 or 40 known good parts (also known as “Train by Showing”), template methods are fairly common in industry. In this method, the MVS builds a golden template consisting of an “average image” of the known good part images and a “variance image” that specifies the “natural” or allowed variation of the part’s intensity (or color) at each point in the image.

Each part is located in the input image and its precise location and angle are determined. The average and variance images are then moved and rotated to precisely fit over the part input image. The input part image and average image are subtracted to show any differences that could be defects, and then the variance image is used, pixel-by-pixel, to detect differences that are greater than the natural variation at that part point. Template methods are easy to set up and work well when the input part can be precisely aligned with the average and variance images, and when the natural variation of the part is small. In applications where the liner or seal ring on a circular closure can easily be aligned (no need to compute a rotation angle) and the inspection area has low variance, template methods work well. One of the more common applications of the template method is for print inspection.

Template methods don’t work well when the part cannot be precisely aligned, the natural variation of the part is large, or precise measures must be taken. The rotation to align the template with the part image is slow and adds re-sampling noise, so template methods are typically not used where computational resources are limited.

Feature method

Extracting measures or features from the part image and comparing these measures with measures taken from known good parts is known as the feature method. This method is appropriate for measuring things such as closure dimensions, roundness (ovality), seal or bead width and can be designed without the precise alignment characteristics used in template methods. Some feature methods are capable of handling large changes in part appearance or natural variation. For example, features based on part edges (edges appear in an image as a sudden intensity change) are tolerant to changes in part reflectivity and color, as well as to changes in the part illumination.

Rotationally invariant features, such as intensity or color histograms, moments, ovality, and perimeters, can quickly pinpoint contamination, flags, and other defects in a closure. With the feature method, you can’t tell where the defect is located on the part (as can be done with the template method), but defect location is not something that concerns most manufacturers. The greater advantage of the feature method is that no rotational alignment is required, meaning that the features are fast to compute and are the method of choice on smart cameras (such as Dalsa’s BOA).

Feature methods can require more work to set up, as measures and tolerances specific to the type of closure must be programmed into the MVS. Modern MVS software has made this type of programming easier through the use of graphical user interfaces. (Dalsa’s iNspect and Sherlock software are examples of this kind of software.)

In the “Bottle cap analysis” image, feature methods measure the circularity of a bottle cap liner. The approximate center of the cap liner is found. Then a “spoke tool” (green lines) measures liner edge positions at 16 locations (red crosses on the green lines). A circle is fit and circularity is computed as (minimum radius/maximum radius) * 100, where the minimum and maximum radii are measured during the circle fit.

Deviations from circularity indicate a defective liner – one that is missing, distorted, etc. This inspection will, however, miss edge defects that are smaller than the distance between edges on the spokes, but this is rare. It does not inspect the seal surface for contamination, but this could be done by looking for pixels that are too high or low in intensity within the circle defined by the seal edges. Note that these methods are fast, in part because they are rotationally invariant.

In practice, both methods can be used for a variety of applications. For example, template methods can be used to inspect closure printing, as it is difficult to specify features to measure text or logo defects. Invariant features and measurement features are used to look for liner defects such as flags, color shifts, and foreign mater. “Train by showing” systems can be built that use both template and feature methods, but often have to be “tuned” for a particular closure type by adding additional features.

- Ben Dawson is director of strategic development at Dalsa Corporation. He can be reached at

See other machine vision tutorials and feature articles in the June/July 2010 issue of Control Engineering, Machine Vision / Inside Machines section, and:

- Academy Award winning image scanner

Dalsa's Boa smart camera brings color to end-user machine vision applications

- Sensors channel page in Control Engineering.

No comments
The Top Plant program honors outstanding manufacturing facilities in North America. View the 2013 Top Plant.
The Product of the Year program recognizes products newly released in the manufacturing industries.
The Engineering Leaders Under 40 program identifies and gives recognition to young engineers who...
Sister act: Building on their father's legacy, a new generation moves Bales Metal Surface Solutions forward; Meet the 2015 Engineering Leaders Under 40
2015 Mid-Year Report: Manufacturing's newest tool: In a digital age, digits will play a key role in the plant of the future; Ethernet certification; Mitigate harmonics; World class maintenance
2015 Lubrication Guide: Green and gold in lubrication: Environmentally friendly fluids and sealing systems offer a new perspective
Drilling for Big Data: Managing the flow of information; Big data drilldown series: Challenge and opportunity; OT to IT: Creating a circle of improvement; Industry loses best workers, again
Pipeline vulnerabilities? Securing hydrocarbon transit; Predictive analytics hit the mainstream; Dirty pipelines decrease flow, production—pig your line; Ensuring pipeline physical and cyber security
Cyber security attack: The threat is real; Hacking O&G control systems: Understanding the cyber risk; The active cyber defense cycle
Designing positive-energy buildings; Ensuring power quality; Complying with NFPA 110; Minimizing arc flash hazards
Building high availability into industrial computers; Of key metrics and myth busting; The truth about five common VFD myths
New industrial buildings: Greener, cleaner, leaner; New building designs for industry; Take a new look at absorption cooling; Offshored jobs start to come back

Annual Salary Survey

After almost a decade of uncertainty, the confidence of plant floor managers is soaring. Even with a number of challenges and while implementing new technologies, there is a renewed sense of optimism among plant managers about their business and their future.

The respondents to the 2014 Plant Engineering Salary Survey come from throughout the U.S. and serve a variety of industries, but they are uniform in their optimism about manufacturing. This year’s survey found 79% consider manufacturing a secure career. That’s up from 75% in 2013 and significantly higher than the 63% figure when Plant Engineering first started asking that question a decade ago.

Read more: 2014 Salary Survey: Confidence rises amid the challenges

Maintenance and reliability tips and best practices from the maintenance and reliability coaches at Allied Reliability Group.
The One Voice for Manufacturing blog reports on federal public policy issues impacting the manufacturing sector. One Voice is a joint effort by the National Tooling and Machining...
The Society for Maintenance and Reliability Professionals an organization devoted...
Join this ongoing discussion of machine guarding topics, including solutions assessments, regulatory compliance, gap analysis...
IMS Research, recently acquired by IHS Inc., is a leading independent supplier of market research and consultancy to the global electronics industry.
Maintenance is not optional in manufacturing. It’s a profit center, driving productivity and uptime while reducing overall repair costs.
The Lachance on CMMS blog is about current maintenance topics. Blogger Paul Lachance is president and chief technology officer for Smartware Group.