1. EPE 462 Industrial Machine Vision
Group Assignment
Title: Inspection System in Bottle of Medicine
Liquid in Production Line
Name : Ang Kok Wei (108467)
Lecturer: Prof. Mani Maran a/l Ratnam
Dr. Yen Kin Sam
Date of Submission: 11th
December 2013
School of Mechanical Engineering
2. Inspection System in Bottle of Medicine Liquid in
Production Line
K.W.Ang
School of Mechanical Engineering
Univeristi Sains Malaysia, 14300 Nibong Tebal, Penang, Malaysia
akw_90@hotmail.com
ABSTRACT
This paper presents the utilization of machine vision-based inspection system which is also
known as Automatic Optical Inspection (AOI) in doing the quality inspection of the medical
bottles. There are two inspections in this study, which are the water level of the medical liquid
and the presence of the cap. Inspection results performed on the samples have proven the
effectiveness & reliability of the algorithms in MATLAB software. With the aid of high
resolution camera in terms of image capture, proper scene constraints applications & further
image processing using MATLAB software, the quality & variety of the product can be easily
determined.
1.0 Introduction
In the medical industrial, the finish products are being inspected before packaging into the box.
The machine vision is known as a cost-effective, high repeatability & reliability system which
is suitable to be installed in this packaging line for inspection purposes. Nowadays, numerous
applications of machine vision technology have been applied into the manufacturing
environment. This paper shows a setup of inspection and classification system in the beverage bottle
production line, which the main tasks of the system, are to inspect the water level and to inspect the
bottle cap
Hui Shi and Wenyong Yu [1], has stated that to implementing a machine vision system,
several factors should be taken into consideration:
I. Product material
The texture of materials has to be carefully selected. Materials with high reflectivity
will increase the challenges faced during inspection process & further image processing.
II. Camera
The object focusing area & resolution of the camera should be taken into account as
well. This is to ensure that the image captured is clear enough during image acquisition
& at the same time shortening the image pre-processing time required as well as to
reduce the manufacturing lead time if possible.
III. The background of object
The background of the object being captured should be chosen properly to ensure that
the captured images will be easily differentiated from the foreground.
Duan et al. [2] present a machine vision based for beer bottle inspection. The method based on the
histogram of edge points is applied for real- time determination of the inspection area. For the defect
detection of bottle wall and bottle bottom, an algorithm based on local statistical characteristic is
proposed. In bottle finish inspection, two artificial neutral networks are used for low- level inspection
and high- level judgment, respectively. Inspection of beer bottle by human inspectors will result in a
low speed and efficiency because the whole inspection process is subjective and very tedious. Therefore,
as a replacement of human inspector, beer bottle inspector equipped with specific high speed image
capture and processing system enable the inspection done automatically and in high speed and accuracy.
Inspection algorithm presented in this paper is able to achieve high correct inspection rate both to
3. defective bottled and good ones. In addition, artificial neutral networks are adopted in bottle finish
inspection, which has proved to be very convenient for users to adjust the system for their specific
applications.
Ballard [3] mention that computer vision is the construction of explicit and meaningful descriptions of
physical objects from images. Machine vision also recognized as the integrated use of devices for non-
contact optical sensing and computing and decision processes to receive and interpret an image of a real
scene automatically.
According to Brosnan [4] computer vision is a rapid, economic, consistent and objective inspection
technique, which has expected into many diverse industries. Its speed and accuracy satisfy ever-
increasing production and quality requirements, hence aiding in the development of totally automated
processes. The adaption of computer vision for quality evaluation of processed foods is the area for the
greatest potential uptake of this technology, as analysis can be used on a standard requirement in already
automated controlled conditions.
Malamas [5], has state that they are two independent ways for classification are being proposed, one
is according to the inspection features of the industrial product or process involved while another one
is according to the inspection independent characteristic of the inspected product or process.
2.0 EXPERIMENTAL SETUP
2.1 Physical Setup of the Inspection and Classification System
The system consists of a CCD camera, a light field and light sources. The light field which is made a
white colour paper is used to provide a uniform light field as background for the system so that the
image captured can be produced easily. The light sources consist of 2 pendaflour lights. The distance
between the CCD camera and beverage is adjusted so that the beverage can be captured by the CCD
camera. The overall system setup are shown as Figure 1
Figure 1: Overall system setup
Light source
Light field
Specimen
USB 2.0
Webcamera
4. 2.2 System Integration
In this experiment, the web camera is first used to capture the picture from a scene. The sensor inside
the camera isused to convert the optical signals (light) from the scene to analog electrical signals. Then,
the analog signal will convert to digital electrical signals and then store the data in the memory of the
frame grabber. The computer will read the data from the frame grabber memory through bus line and
store the data in computer memory. In this operation, light field illumination was used to capture the
bottle. The bottle is placed between the light box and camera. After that, the system operation was
controlled and integrated with a personal computer consist of MATLAB software. Input images from
the camera were sent to a frame grabber and processed by the software to detect image focus. The
operational schematic diagram of the system is shown in Figure 2.
Figure 2 : the schematic system of the sytem
3.0 Inspection implementation
3.1 The standard for algorithm
After the image had been capture, the image will be load into the personal computer. The Matlab
program is used to process the image in order to do the image processing. The goal of this inspection
system is to quality inspection of the water level and bottle cap. The system will reject either the water
level is within in standard and the missing of the cap. The standard has been capture and processed to
identify the specification of the specimen.
Figure 3: The standard image
Computer with
Matlab
WebcamSpecimenLight field
Light
source
5. 3.2 Inspection Algorithm
3.2.1 Binarizing and filtering the image
The image is firstly displayed in white plane, as shown in Figure 4(a). This process is to
mitigate the effects of colour of the bottle on the gray values since the colours for the medecine
are black in colour & the cap is red in colour. The image is then undergone a morphological
operation to cancel out the noise, as shown as Figure 4(b). The white plane image is then being
binarized. From Figure 4 (c), it is clearly shown that the suitable threshold value is set at 90
which are 0.353 in Matlab ,as shown as Figure 4(d). After that, the image is inverting so that
the bottle is in colour and the different filtering process is used. This filtering process is used to
remove the unwanted noise by removes binary image of connected components (objects) that
have fewer than 8000 pixels, as shown as Figure 4(e).
(a) (b)
(c)
6. (d) (e)
Figure 4: (a) Image after using apply gray scale, (b) Image after noise cancelling, (c) Histogram of the
white plane image, (d) Binary image with threshold value of 90, (e) Image after inverting and
filtering.
3.2.2 Identify the water level
The standard of this medicine liquid is 28ml. In this case, the white area of the binary image becomes
an interest of study. The algorithm will identify white area correspond to the water level of the sample
by remove the cap, as shown in Figure 5.After that, 3 samples are used to determine the average area of
the white region in the binary image. The standard set is 8000 pixels which as shown at Table 1.Thus,
the area measured should have more than 8000 pixels which correspond to the acceptable water level
due to the noise.
Figure 5: Image after remove the cap
Sample Pixel number(pixel) Difference with the
standard (pixel)
Percentage of difference with
the standard (%)
1 32476 476 1.4875
2 32331 331 1.034375
3 34021 2021 6.315625
4 32000 - -
Table 1: Comparison with different sample of the medicine liquid level
7. 3.2.3 Identifying Bottle Cap
The inspection needs to make sure that the bottle cap is attached on the bottle. The similar
algorithm that identifies the water level is applied to identify the bottle cap. However, the upper image
is cropped initially so that only the bottle cap area is inspected, as shown in Figue 6(a). The algorithm
will identify the bottle cap of the sample and compare it with the standard. 4 samples are used to
determine the average area of the white region in the binary image, which is shown in Figure 4(b), 4(c)
and 4(d). The standard set in this experiment is pixels which as shown at Table 2, with a tolerance of
5000 pixels to the standard. The tolerance is applied because some pixels of the image may be filtered
when removing the noise. Figure 5 shows the acceptable bottle cap while Figure 6 shows the missing
bottle cap. Since the comparison is done by comparing the area, the algorithm accepts the bottle with the
area more than 5000 pixels.
(a) (b)
(c)
(d) (e)
Figure 6: (a) Image after cropping, (b) Image after filtering, (c) Histogram of the white plane image,
(d)Image after binaries, (e) Image after inverting and remove noise
8. The standard of this medicines’ bottle is 1cm in height and 2.5 cm for the diameter. In this case, the
white area of the binary image becomes an interest of study. The algorithm will identify white area
correspond to the front area of the bottle, as shown in Figure 8(a).After that, 3 samples are used to
determine the average area of the white region in the binary image. The standard set is 5000 pixels
which as shown at Table 2.Thus, the area measured should have more than 5000 pixels which
correspond to the acceptable water level due to the noise., as shown in Figure 8.
Sample Pixel number(pixel) Difference with the
standard (pixel)
Percentage of difference with
the standard (%)
1 5103 103 2.06
2 5117 117 2.34
3 5034 34 0.68
4 5000 - -
Table 1: Comparison with different sample area of the cap
(a) (b)
Figure 8: Binary images of (a) acceptable bottle cap, (b) rejected bottle cap. The white area of image
corresponds to the bottle cap.
3.3 Flow of algorithm
The algorithm undergoes 4 important processes: Image Acquisition, Identify medicine liquid
Level, , Identify Bottle Cap and Display Inspection Result. The standard is set so that the unknown
beverage bottle can be identified. An unknown beverage bottle will be identified at the end of the
algorithm, whether it passes the inspection or is rejected at certain inspection. The flow chart of the
algorithm is shown as Figure 9.
9. Inspection of
medicine
Bottle
Production
Image Acquisition:
The image of the
water bottle is read
into the
program.
Identify the Water Level:
1. Converting the image into
green screen image
2. Thresholding the image into
binary image
3. Removing noise on the object
4. Removing noise on the
background
5. Measuring the water level of
the bottle
6. Comparing the water level
with standard
Identify the Bottle Cap:
1. Cropping the image
2. Thresholding the image into
binary image
3. Removing noise on the object
4. Removing noise on the
background
5. Measuring the bottle
6. Comparing the bottle cap with
standard
Show Result of the Inspection:
1. Water Level (Passed, Failed)
2. Bottle Cap (Passed, Failed)
3. Overall QC (Passed, Failed)
Water level >
32000 pixels
Bottle cap >
5000 pixels
Water level passed
& Bottle cap passed
Water level failed
Water level passed
Bottle cap passed
Bottle cap failed
End
Yes
No
Yes
No
Figure 9 : Algorithm for the process
10. 4. RESULTS AND DISCUSSION
Computer vision has been widely used for inspection because it offer the potential to automate
manual grading practices and thus to standardize techniques and eliminate tedious inspection task. The
result presented hare demonstrate the ability of the integration of machine vision with MATLAB to
detect water level, bottle cap and water color. At first, the MATLAB code will detect the water level
then follow by the detection of the bottle cap. The MATLAB code was set in specific condition to
detect whether the liquid level of medicine is in within the standard and then detect bottle cap. Liquid
Level and bottle cap must fulfill the condition set at the MATLAB code, if not then the beverage bottle
will be rejected from the production line. 4 samples are tested in this experiment and the results are
shown in the Table 3. Only S1 is passed the inspection system. S2 failed the water level while S3 failed
the bottle cap. S4 failed both the bottle cap and water level. The test shows 100% feasibility of the
inspection system.
Picture Result Picture Result
Sample 1 Sample 2
Sample 3 Sample 4
Table 3: Result of the specimen test
5. CONCLUSION
The experiments done are success due to its high reliability and high accuracy. The feasibility of
the inspector is proved by inspecting the water level, presence of bottle cap and water colors. The
inspector is also able to inspect and differentiate both Cola and Syrup. So, there will be no mixing in
between these beverages. Furthermore, user can adjust the inspector to meet their requirements for
specific application. The Table 4 below summarizes the system that inspects the water level and bottle
cap.
11. 6.0 Appendix
%%%%%%preprocessing %%%%%%%%%%%%
clc; clear all; close all;
file='bottle.jpg'; % declare the file
P1= imread(file);
figure, imshow(P1) % show the picture
I1=P1(:,:,3);
figure, imshow(I1)
I2=I1;
%filtering
strl=strel('diamond',5);
I3=imopen(I2,strl);
figure, imshow(I2)
I4=I3;
figure,imshow(I4)
figure, imhist(I4) % histogram used to find
the thresholding
%%%%%% segmentation %%%%%%%%%%%%%
%binarize
I5=im2bw(I4,0.349);
figure, imshow(I5);
%remove noise
F1=bwareaopen(I5, 500);
figure,imshow(F1)
F2=~F1;
F3=bwareaopen(F2, 1700);
figure, imshow(F3);
%Identify water level
F4 = bwareaopen(F3,8000); % removing the cap
Data1 = regionprops(F4); % measure the
properties of the white area
Water_Level = Data1.Area; % showing the pixel
area (by removing ;)
disp(['Area for the water is :
',Water_Level]);
%%%% feture extraction %%%%%%
%to find area
Water_Level = Data1.Area; %showing the pixel
area (by removing ;)
if(Water_Level>32000) % accept the water
level if the area > 32000
water_level_qc = 'Passed';
else
water_level_qc = 'Failed';
end;
%identify bottle cap
I6 = imcrop(I1,[130 10 420 120]); % cropping
the image
figure,imshow(I6)
%filtering
str2=strel('diamond',5);
I7=imopen(I6,str2);
figure, imshow(I7)
figure, imhist(I7) % histogram used to find
the thresholding
%binarize
I8 = im2bw(I6,0.349); % thresholding at 0.349
into binary image
figure,imshow(I8)
%remove noise
F4=bwareaopen(I8, 500);
figure,imshow(F4)
F5=~F4;
F6=bwareaopen(F5, 1700);
figure, imshow(F6);
%to find area
Data2 = regionprops(F6); % measure properties
of the white area
Cap = Data2.Area; % showing the pixel area
if(Cap>5000) % there is cap if area is > 5000
bottle_cap_qc = 'Passed';
else
bottle_cap_qc = 'Missing';
end;
%Display result
if ((Water_Level>32000)&&(Cap>500)) % passed
if correct water level & cap
qc = 'Passed';
else
qc = 'Rejected';
end;
[pathstr, name, ext] = fileparts(file); %
define the file parts
disp(['Specimen number : ',name]); % display
the specimen name
disp(['Water Level : ',water_level_qc]);%
display water level result
disp(['Bottle Cap : ',bottle_cap_qc]); %
display bottle cap result
disp(['Overall : ',qc]); % show the result of
inspection
7.0 References
[1] Hui Shi and Wenyong Yu (2011), "High speed web printing inspection with multiple linear
cameras", Proc. SPIE 8006, 800624; doi:10.1117/12.901868.
[2] Duan, F, A machine vision inspector for beer bottle. Engineering Applications of Artificial
Intelligence, 2007. 20(7): p. 1013-1021.
[3] Ballard, D.A., & Brown, C.M. (1982). computer vision. Englewood cliffs, NJ, USA: Prentice-Hall
[4] Brosnan, T. and D.-W. Sun, Inspection and grading of agricultural and food products by
computer vision systems—a review. Computers and Electronics in Agriculture, 2002. 36(2-3): p.193-213.
[5] Malamas, E.N, “A survey on industrial vision systems, applications and tools”, Image and
Vision Computing, 2003. 21(2): p. 171-188.