Inspecting Glass Bottles and Jars
Introduction
Despite the popularity of plastic containers, glass bottles and jars remain important for sealing and preserving food products, toiletries and pharmaceuticals. The raw materials are abundant and inexpensive. Although it is brittle, glass is strong and chemically inert, resistant to microbial attack and impervious to water, oil, alcohol, etc. It can be moulded to form a wide variety of useful shapes. It also has the attractive feature of being transparent, which allows the contents to be presented in a visually appealing way. It can also be coloured for cosmetic effect.
- Malformations (These are often due to moulding faults as when molten glass is injected into the mould when it is too hot, or sticks to the mould as it opens.)
- Cracks, checks and crizzles (The latter do not penetrate right through the glass wall.)
- Inclusions (These might typically be stone-like fragments of refractory materials that have broken off the lining of the crucible holding the liquid glass.)
- Air bubbles
- Loose glass fragments (For example, a vial breaks during manufacture and scatters flakes and slivers, contaminating nearby containers.)
- Spikes (These are "stalagmites" of glass, found typically in jars and other items that are made by pressing or a press-blow manufacturing process. They occur on the base or side walls of a jar.)
- Bird-swings (These are horizontal filaments of glass that span across the inside of a bottle. Physically, they resemble stalagmites and stalactites that have joined together. They result from a faulty blow-blow manufacturing process. They occur only on the side walls of a bottle.)
This is a much simplified catalogue of defects that are known to arise in everyday bottles, jars, tumblers. Loose glass fragments, in the form of thin strands, flakes and slivers can occur virtually anywhere. In this short chapter we can only consider a few of these defects; our intention is to highlight the potential for applying Machine Vision, even in an area, such as this where the product is often difficult to illuminate and view. Some defects are euphemistically called critical in the glass industry: in lay terms dangerous!
Many of the faults that occur in glassware can only be detected properly by optical means. They cannot, for example, be detected by touch. However, a modern manufacturing line produces bottles at a speed that exceeds a human being's ability to inspect them reliably. Recall the cartoon in Chap.1, showing a (male) human inspector distracted by a fair damsel. (Female inspectors are also susceptible to distraction!) Thus, there is a need for automated visual inspection equipment that can meet this need. In this chapter we briefly explore the subject and will consider some of the topics that a vision engineer designing an inspection system for glass-ware must address.
Lighting and Viewing
- Back-illumination. The light source, bottle and camera are in line.
- Dark-field illumination (Fig. 31.1 ).
- Injecting light into the fully formed product from a small number of carefully chosen "point" sources.
- Observing self-emission in the Near-Infra Red wave band, from hot glasss (i.e. after moulding but before annealing.
![]() |
| Fig. 31.1 Dark-field illumination. (a) Area-scan camera. (b) Line-scan camera |
These are all described in detail and illustrated in Chap. 40 and will not be discussed further. From a vision engineer's perspective, one of the most important features of glass is its clarity and refractive properties (refractive index is about 1.5-1.7). Care must always be taken to shield a glass object from ambient light during inspection. This rule should be followed whether it is being examined automatically or by eye. Failure to do so will result in poor quality images with highlights occurring in a host of unexpected places. This is caused by direct surface reflection and "ducting" of light by total internal reflection through the body of the product.
![]() |
| Fig. 31.2 During inspection a round bottle is held between two contra-rotating belts. If the speed of these belts is carefully chosen, the bottle rotates rapidly as it advances slowly along the belt. (It is transported by the side belts and slips on the conveyor.) Hence, a line-scan camera is able to sense local features, such as bird-swings, stones, cracks, etc., wherever they occur around the cylindrical surface of a jar or bottle. |
![]() |
| Fig. 31.3 Preliminary processing steps, tracing the outer edge of a bottle. (a) Original image. Back lighting. (b) Background intensity changes over a wide range. Numerals indicate intensity values in the original image. (c) Posterised image, emphasises the variable background intensity. (d) Edge detector. (e) Noise removal. (f) "Shadow" projecting to the right [QT: rox]. (g) Shadow projecting to the left. (h) ANDing the two "shadow" images. (i) Effects of noise pixels outside the bottle profile. This shows why kgr is needed. |
![]() |
| Fig. 31.4 Testing algorithm robustness. The bottom row relates to a brown vial with dark-field illumination. Notice the parallax effect, which is particularly pronounced in the third row. Highlights due to glinting (second row) have no effect on the profile but would if they appeared at the edge of the bottle |
Bottle Shape
Shape and size measurement is an obvious requirement for both bottles and jars. We shall illustrate various ideas with reference to a back-illuminated bottle. First, however, we must consider how we generate a binary image on which appropriate dimensional measurements can be taken. Consider the bottle shown in Fig. 31.3a . This a typical circularly symmetrical bottle and will serve to illustrate how we derived a suitable algorithm, using the QT interactive image processing system (Chap. 21). As we shall show later, the same procedure has subsequently been applied quite successfully to other glass containers and to images obtained using dark-filed illumination.
Pre-processing
| lnb, |
% Largest neighbour |
| sub, |
% Subtract. This & previous command forms edge detector. Other options available |
| neg, |
% Negate |
| enc, |
% Enhance contrast |
| thr(100), |
% Threshold ( Fig. 31.3d ) |
| kgr(100), |
% Keep only big blobs ( Fig. 31.3e ). Figure 31.3i shows benefits of this operation) |
| rox, |
% Row maximum ( Fig. 31.3f ) |
| wri, |
% Save image |
| swi, |
% Switch Current & Alternate images |
| lrt, |
% Flip image horizontally |
| rox, |
% Row maximum |
| lrt, |
% Flip image horizontally ( Fig. 31.3g ) |
| rei, |
% Read image saved earlier |
| mni, |
% AND images together ( Fig. 31.3h ) |
Having established an effective algorithm for generating a "solid" profile image, we can now begin to measure the shape of the bottle.
Vertical Sides
- Are the sides straight?
- Are the sides parallel?
- Are the sides vertical?
- Is the seperation between the sides correct?
An important point to note is that, at any given moment, we know what type of bottles the factory is making. Hence, we know the ideal dimensions of the bottles we are inspecting. Hence we can use absolute position measurements in the vertical direction.
![]() |
(31.1) |
![]() |
| Fig. 31.5 Measuring the angle and straightness of the side walls. Y1 and Y2 are fixed in the knowledge of the product dimensions. To check the straightness of the side wall, draw a thick line [QT: vpl(X1,Y1,X2,Y2,255), dil(tolerance)]. The edge of the bottle should be confined to this thick line |
![]() |
(31.2) |
Ideally, this should be 90°.
- Draw a white line between [X1,Y1] and [X2,Y2].
- Expand this line using binary dilation.
- The amount of dilation determines the tolerance band.
- The edge of the bottle should lie entirely within this thickened line.
![]() |
| Fig. 31.6 Using regression analysis to fit a straight line to (the left-hand edge of) a bottle. (a) Edge pixel coordinates within the limits indicated by the two black lines formed the input for the regression analysis program. (b) Straight line fitted to the edge pixels. Numbers indicate coordinate values, relative the top-left corner of the image [QT: pft(780,1320,50,1)] |
Neck and Shoulder
![]() |
| Fig. 31.7 Fitting circles to the neck-shoulder region using just three pixels. (a) Shoulder. This circle was fitted using just three edge pixels. [QT: fcd] (b) Neck. (c) 3rd-order polynomial function. This and (b) were generated using bottle, listed in the text |
![]() |
| Fig. 31.8 Fitting curves. (a) Original image. The black lines indicate sampling limits. (b) 3rd-order polynomial function [QT: pft(390,650,50,3)] |
| function bottle |
|
| % Demonstration: Fit 3rd order polynomial & circle to neck/shoulder region of a bottle. [1/0] |
|
| global current |
% Standard QT declaration |
| global alternate |
% Standard QT declaration |
| rni(31) |
% Read standard image |
| enc |
% Enhance contrast |
| thr |
% Threshold at mid-grey |
| neg |
% Negate |
| binary = current; |
% Keep result of all this hard work for use again later |
| [x,y,r] = fce(49,30,30); |
% Fit circle; 'hardwired' parameters since we know the bottle |
| s = ['Circle parameters: X = ',int2str(x),', Y = ',int2str(y),', R = ',int2str(r)]; |
|
| rni(31) |
% Read standard image again |
| swi, |
% Interchange Current & Alternate images |
| adi, |
% Add Current & Alternate images |
| mxi |
% Maximum intensity in Current & Alternate images |
| alt = current; |
% Keep result |
| current = binary; |
% Restore image saved earlier |
| [x,y] = hzs(80,275, 25); |
% Find X values from 25 scan lines in Y-interval [80,275] |
| p = polyfit(y,x,3); |
% Polynomial fitting program (MATLAB function) |
| q = polyval(p,y); |
% Evaluate polynomial (MATLAB function) |
| zer |
% Black image - same size as Current image was |
| [u,v] = size(y); |
% How big is the image? |
| for i = 2:v |
% Draw curve as liece-wise linear function |
| vpl(round(q(i)),round(y(i)), round(q(i-1)),round(y(i-1)),255) |
|
| end |
|
| % Next line: Formatting message for the user |
|
| t = ['; Polynomial: (',num2str(p(1)),'*y^3) + (', num2str(p(2)),'*y^2) + ... (',num2str(p(3)),'*y) + (',num2str(p(1)),')']; |
|
| rni(31) |
% Read standard image yet again |
| swi, |
% Interchange Current & Alternate images |
| adi, |
% Add Current & Alternate images |
| mxi |
% Maximum intensity in Current & Alternate images |
| alternate = alt; |
% Recover intermediate result, ready to display it |
| subplot(1,2,1) , imshow(current) |
% Display image |
| subplot(1,2,2) , imshow(alternate) |
% Display image |
Symmetry, Tilt and Gross Misshapes
| yxt |
% Interchange X and Y axes because mch works on vertical chords |
| mch |
% Mid point of vertical chord |
| mch |
% Repetition is necessary because mch does not finish the job on large images |
| yxt |
% Interchange X and Y axes - restore image to original orientation |
![]() |
| Fig. 31.9 Central axis, used for verifying that the bottle is tilted and symmetrical |
![]() |
| Fig. 31.10 Checking whether a bottle is symmetrical. Flipping the binary image about the axis of symmetry shows the differences between the two sides of the bottle. Simply counting the black pixels gives a crude measure of symmetry |
![]() |
| Fig. 31.11 Bottle width measurements |
![]() |
| Fig. 31.12 Lower portion of the edge of a bottle with a serious fault: a "fin" caused by the mould not closing properly. (a) Original image. Dark-field illumination. (b) Binary image generated by the algorithm as described in Sect. 31.3.1 |
Other Features
In addition to shape, there is a variety of other important features on bottles, jars, tumblers and other glass containers. It is impossible to cover these in full here. Hence, we shall simply demonstrate that Machine Vision can be used effectively in other ways.
Measuring Filling Level
![]() |
| Fig. 31.13 Filling level in small clear glass vial. (a) Original image. Back lighting. (b) Plot of total intensity in each row [QT: rin, csh, wgx,sub, thr]. (c) Centre line of the dark horizontal streak due to the meniscus [QT: rin, thr(X), thn finds the centre line] |
![]() |
| Fig. 31.16 Detecting changes in stripe width/spacing using morphology. (a) Original image. The poor definition of the edges of the broad black stripe does not adversely affect this method. (b) Filling level detected [QT: wri, enc, thr, eri(200,1), [x,y] = tlp; zer, [w,h] = dgw; vpl(1,y,w,y,255), rei, swi,adi,mxi] |
![]() |
| Fig. 31.14 Distortion of a striped background pattern by a partially filled cylindrical tumbler with vertical straight sides, a thick bottom of solid glass but no embossing. Notice that the width and spacing of the dark stripes is changed by the water, which forms a cylindrical lens |
![]() |
| Fig. 31.15 Second method for finding the filling level. (a) Original image. A single black stripe is magnified by the glass-air "lens" so that it fills the whole width of the jar. The background stripe is visible at the very top of the image. (b) The white line is the output of jar_fill_level |
| function y = jar_fill_level |
|
| % Find the the filling level in a jar. [1/0] |
|
| global current |
% Standard QT declaration |
| global alternate |
% Standard QT declaration |
| original = current; |
% Save original image |
| enc |
% Enhance contrast |
| thr(0,127) |
% Threshold at mid-grey |
| kgr(1000) |
% Eliminate blobs with area < 1000 pixels |
| yxt |
% Interchange X and Y axes |
| rlc |
% Run-length code |
| thr(250) |
% Threshold |
| big |
% Select biggest blob |
| yxt |
% Interchange X and Y axes |
| [x,y] = tlp; |
% Top-left-most point |
| zer |
% Black image |
| [w,h] = dgw; |
% Picture dimensions |
| vpl(1,y,w,y,255) |
% Draw horizontal white line at height |
| alternate = original; |
% Recover original image |
| subplot(1,2,1) , imshow(current) |
% Display Current image |
| subplot(1,2,2) , imshow(alternate) |
% Display Alternate image |
An alternative algorithm detects changes in the width and spacing of the stripes using morphology. The structuring element should be in the form of a horizontal line, one pixel high. Figure 31.16 illustrates this.
Bird-swings, Spikes, Embossing
A bird-swing is a critical defect that occurs in bottles. It consists of a filament of glass that spans the interior of the bottle and is attached at two diametrically opposed points on the side wall. The roots of the filament are conical. This is important as the roots deflect back-lighting and cause a dark shadow. A spike is like a stalagmite of glass attached at only one end and may occur on the base or side wall of a jar. Once again, the root has a conical form. Bottles are made by a blow-blow process and jars by a press-blow process. Hence, they are susceptible to different types of defect. A bird-swing/spike, in a stationary bottle/jar is easily detectable by human eye. However in a factory, when the product is moving at a high rate (perhaps exceeding ten bottles/jars per second), this is not so easy. People get bored and tired on repetitive inspection tasks and are easily distracted. For these reasons, a human inspector will not detect all critical defects with resulting product safety and liability concerns.
![]() |
| Fig. 31.17 Critical defects due to excess glass. Back illumination. (a) Bird-swing viewed from the side. Notice the conical roots of the filament, which can be several millimetres thick or as fine as a human hair. The latter is more dangerous. (b) Bird-swing, viewed near end-on. This is the preferred viewing angle. (c) Bird-swing. The dark vertical streak is the shadow of the moulding seam. (d) Bird-swing. The dark patch at the bottom is the image of the table-top. (e) Spike (The author's daughter narrowly missed injury from this defect, which occured in a milk-bottle. The tail of the spike is finer than a human hair.) |
![]() |
| Fig. 31.18 Dark-field illumination produces total internal reflection on bird-swings and spikes. The high contrast produced in this way makes simple fixed-parameter thresholding straightforward. (a) Original image: bird-swing. (b) Original image: bird-swing. (c) Original image: spike. (d) Bird-swing, thresholded. (e) Bird-swing, thresholded. (f) Spike, thresholded |
Cracks
![]() |
| Fig. 31.19 Crack, plain-sided tumbler. (a) Original image. Notice that the crack, which is continuous, sometimes appears dark, bright or totally disappears. (b) Dark and light streaks highlighted separately [QT: crack2(11,135,50,4)] |
The morphological closing operator (QT: crk) is an effective way of detecting dark (or bright) streaks produced by cracks. Here is a more complete algorithm that includes noise-reduction filtering.




















