Sunteți pe pagina 1din 16

Detection of Defective Pharmaceutical

Tablets using Digital Image Processing


Towards the Partial Fulfillment of
Requirements of
Bachelors of Technology in Information Technology
And Mathematical Innovation
(September 2014 November 2014)

Aditi Chawla | Akshee Jain|Parul Madaan


CLUSTER INNOVATION CENTRE | UNIVERSITY OF DELHI

CERTIFICATE

It is certified that the project work reported by Ms. Aditi Chawla, Ms. Akshee Jain and Ms.
Parul Madaan was carried out under my guidance towards partial fulfillment of the
requirements for the award of B.Tech degree in Innovation with Mathematics and IT.

Ms. Nirmal Yadav


Assistant Professor
Cluster Innovation Centre,
University of Delhi

ACKNOWLEDGEMENT

The successful completion of a project work requires efforts of several intellectual minds. It has been a
great learning experience for which we would like to thank our mentor Ms. Nirmal Yadav. We are
grateful to her for her support and guidance.

We would also like to thank our family and friends for their undying support.

Aditi Chawla
Akshee Jain
Parul Madaan

Contents
CERTIFICATE .................................................................................................................................................. 1
ACKNOWLEDGEMENT .................................................................................................................................. 2
Chapter-1 Introduction ................................................................................................................................. 4
1.1 Introduction ............................................................................................................................................ 4
1.2 Literature Survey .................................................................................................................................... 4
Chapter -2 Methodology............................................................................................................................... 6
2.1 Proposed Work ....................................................................................................................................... 6
2.2 Pre-Requisites ......................................................................................................................................... 6
2.3 Process Flow ........................................................................................................................................... 7
2.4 Otsus Method ........................................................................................................................................ 8
Chapter-3 Implementation .......................................................................................................................... 9
3.1 Steps Involved ......................................................................................................................................... 9
Stage 1: Thresholding the Image .............................................................................................................. 9
Stage 2: Removal of Noise ........................................................................................................................ 9
Stage 3: Encircling tablets perfectly circular in shape............................................................................... 9
Conclusion ................................................................................................................................................... 12
References .................................................................................................................................................. 13
Appendix ..................................................................................................................................................... 14

Chapter-1
Introduction
1.1 Introduction
Medicines have helped to make our lives easier. Drug industry is a developing industry in terms of
production as well as consumption. Medication has become very important in everyones life as we are
affected by so many diseases. But sometimes, these medicines might get defected during the
production process such as one or more tablets in the strip might be broken or there might be a missing
tablet in a strip. These defective tablets cannot be sold in the market and thus account for an additional
cost to the manufacturer. These irregularities in the tablet strip can be detected using image processing,
and can help in improving the quality management system.
Digital image processing techniques and algorithms are very efficient in detection of error in a given
strip of medicines. Image processing includes many techniques like pattern recognition, feature
extraction, template matching and edge detection to process digital images. They help in faster
manipulation of digital images. Manual inspection is automated using image processing techniques and
this automation helps in quality assurance of the manufactured good.

1.2 Literature Survey


(A) Edge Detection in Digital Image Using Statistical Method
Huvaida Manzoora and Dr.Yogeshwer Singh Randhawa say that digital image processing
techniques and algorithms are applied on images in order to remove error. They have done
some mathematical manipulation in MATLAB to detect defect in the tablet. They have applied
morphological operations on binary image of circular tablets to remove the noise after which
the roundness of the tablet is checked. They have assumed that the round tablets have a fixed
area and deviation from this roundness will detect the error.
(B) Detection of Broken Pharmaceutical Drugs using Enhanced Feature Extraction Technique
Ramya.S, Suchitra.J and Nadesh R.K state that image processing provides greater contribution to
science and technology as the digital images have a greater impact on modern society. They
have used the technique of image enhancement to detect defective tablets. Image
enhancement involves removal of noise from the image using thresholding (conversion of gray
scale to binary image). This dilated noise free image is then compared with a template which is
free of defects. Now, if the template image pixel is greater than the input image pixel then there
is a defect.

(C) Inspection of Defective Pharmaceutical Capsules using Harris Algorithm


Hardeep Kaur and Er.Nidhi Garg say that in pharmaceutical industry, zero defect quality
products are highly required in competitive markets as it effects reputation of any
manufacturing industry. The most common and currently affordable method of detecting these
flaws is visually. The paper proposed the work on defect detection of capsules as no proper
algorithm was applied for complete defect detection of capsules. The first step was to filter the
image and remove noise, which was done through median filtering (image enhancement). Then,
Region based Statistic like biggest area is computed from region based properties so that object
from the image is extracted and further processing can be done. On this, Harris algorithm is
applied. Harris Algorithm is used for feature extraction and Pattern Recognition. Using this
algorithm Corners are detected where the window detect change in intensity in all directions.
These are matched with a template image and if there is correlation mismatch then defects are
detected. According to Hardeep Kaur and Er.Nidhi Garg, this algorithm can detect all possible
defects of the capsules like holes, cracks, scratches, broken cap, double cap and missing cap.

Chapter -2
Methodology
Proposed Work
Statistical Method has been used to find the defect in the circular shaped tablets. As we know,
circular tablets have a particular area and if there is a defect in the tablet due to its shape or size, it
would deviate from its standard roundness metric. The defected tablet then can be found by
comparing its roundness with that of a standard tablet.

2.2 Pre-Requisites

Tablets should be circular in shape


Image background should be static
Tablet cover must be transparent (not made of foil or very dark color)
The illumination in the input image should be uniform

Process Flow

RGB Image

Take an RGB image of


the tablet strip as
input.

PreProcessing

Covert the RGB image into greyscale


and then into binary.

Boundary
detection

Analyzing images using image


thresholding techniques (Otsu
Method)

Noise
Removal

Morphlogy opening is used to remove


noise from the binary image and obtain
tablets with well-defined boundaries

Compute
Roundness
metric

Calculte area and perimeter of each tablet


and thus the roundness metric
Also, Calculate the number of tablets from
the image to verify with the standard no.
of tablets in a strip

Display
Result

If metric is very close to 1, tablet


is circular.
If metric is very less than 1, tablet
is not circular and might be
broken.

Figure 1: Process Flow for defect detection


1

For the purpose of detection of tablets in the image, it is important to partition the image into
foreground and background. To do so, the technique of image thresholding has been used. Image
thresholding is a simple, technique which segments the image so as to isolate objects by converting
grayscale images into binary images. Image thresholding is most effective in images with high levels of
contrast.
Common image thresholding algorithms include histogram and multi-level thresholding. In this project,
we have used Otsus Method for thresholding which uses histogram algorithm.

http://in.mathworks.com/discovery/image-thresholding.html

2.4 Otsus Method

This approach assumes that the image is divided in two main classes: The background and
the foreground. It exhaustively searches for the threshold that minimizes the intra-class variance (the
variance within the class), defined as a weighted sum of variances of the two classes.
It follows the following algorithm:
1. Compute histogram and probabilities of each intensity level
2. Set up initial (0) and (0), where (0) is the class probability and (0) is the mean.

3. Step through all possible thresholds t=1,2, maximum intensity


i.
Update and
ii.
Compute 2 ()
4. Desired threshold corresponds to the maximum 2 ()

2
2
5. Compute two maxima (and two corresponding thresholds). 1
() is the greater max and 2
() is
the greater or equal maximum

6. Desired threshold =

1 +2
2

Chapter-3
Implementation
3.1 Steps Involved
Stage 1: Thresholding the Image
1. Read the original image
2. Convert the RBG image into Grayscale

Figure 2: Grayscale image of the tablet strip

3. Threshold the grayscale uses 2Otsu's method, which chooses the threshold to minimize the
intra-class variance of the black and white pixels. This will help us in tracing the boundaries of
the tablets.

Stage 2: Removal of Noise


4. Taking the thresholded image as the input, find out circular discs which are smaller than tablets.
5. Remove all the objects obtained having number of pixels less than 30 pixels by filling in black
color.
6. In the above step, we might still obtain contours within contours. In this step, contours in the
within the boundary of the tablets are eliminated to obtain the well-defined boundaries.

Stage 3: Encircling tablets perfectly circular in shape


7. Calculation of the area and perimeter of the objects obtained.
8. Now, objects which are circular in shape are to be identified. For this, roundness is used
which can be defined as:
4
=
2

9. This metric mentioned in the above equation is equal to one only for a circle and it is less than
one for any other shape. On the basis of this, circular shaped objects are separated from other

Otsu, N., "A Threshold Selection Method from Gray-Level Histograms," IEEE Transactions on Systems, Man, and
Cybernetics, Vol. 9, No. 1, 1979, pp. 62-66.

objects. Since the tablets in the images need not be perfectly circular, the threshold is not equal
to one. Instead, it has been kept to be as 0.90. The following three cases were obtained:
Case1: Non-defective tablet strips
When the tablets are round in shape and there are no missing tablets. Here, since the metric is
greater than 0.90 for all the tablets, the number of tablets detected by the matlab code is 10.

Figure3: Perfectly circular tablets

Case2: Defective tablet strips


The tablet strips are considered to be defective if the pattern of the strip deviates from the
pattern of the strip observed in Case1. In a strip, either there can be a missing tablet, or a
broken tablet or both.
i) Missing tablet
Only those tablets that have roundness metric greater than 0.90 are counted and the total
number obtained is displayed. In the following image, the code displays the number of
tablets to be 9.

Figure 4: Missing tablets

10

ii) Broken tablets


Only those tablets having roundness metric greater than 0.90 are counted. In the following
image, the code displays the number of tablets to be 9.

Figure 5: Broken tablets

11

Conclusion
Quality Management is a very critical component of operations of any company especially
manufacturing units. Quality check of medicines is of cardinal importance as Human life depends on
these drugs. This project demonstrates how image processing can be used to detect missing or broken
tablets in the pharmaceutical industry. Using image analysis, it has been shown that the number of
tablets can be identified which can be used to benchmark the strip against the standard ones.
A similar procedure can be applied to detect anomalies in capsules or any other shaped tablet.

12

References
1. tefanOprea, IoanLi, Mariana Jurianu, Daniel AlexandruVian, Ion BogdanCioc, Digital Image Processing
Applied in Drugs Industry for Detection of Broken Aspirin Tablets Electronics, Communications and
Computers Department, University of Pitesti Str.Targul din Vale Nr. 1 Pitesti, Romania,2008
2. Huvaida Manzoora Dr.Yogeshwer Singh Randhawa, Edge Detection in Digital Image Using Statistical
Method
3. Ramya.S, Suchitra.J and Nadesh R.K, Detection of Broken Pharmaceutical Drugs using Enhanced Feature
Extraction Technique, School of Information Technology and Engineering, VIT University, Vellore, Tamilnadu:
India
4. Dawei Qi, Yuanxiang Li and Lei Yu The Application of Mathematical Morphological Optimization Algorithm in
Edge Detection of Defected Wood Image , Proceedings of the IEEE International Conference on Automation
and Logistics Qingdao, China September 2008.
5. Hardeep Kaur and Er.Nidhi Garg, Inspection of Defective Pharmaceutical Capsules using Harris Algorithm
6. http://in.mathworks.com/help/images/examples/correcting-nonuniformillumination.html#zmw57dd0e1191

13

Appendix
MATLAB Code:
clear all;
clc;
%STEP 1: READ IMAGE
a = imread('tablet.jpg');
imshow(a);
%THRESHOLD THE IMAGE
%Convert the image to black and white in order to prepare for
I = rgb2gray(a);
threshold = graythresh(I);
bw = im2bw(I,threshold);
imshow(bw)
%REMOVE THE NOISE
% remove all object containing fewer than 30 pixels
bw = bwareaopen(bw,30);
% fill a gap
se = strel('disk',2);
bw = imclose(bw,se);
% the area enclosed by each of the boundaries
bw = imfill(bw,'holes');
imshow(bw)
%Step 4: Find the Boundaries
[B,L] = bwboundaries(bw,'noholes');
% Display the label matrix and draw each boundary
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
stats = regionprops(L,'Area','Centroid');
% loop over the boundaries
for k = 1:length(B)
% obtain (X,Y) boundary coordinates corresponding to label 'k'
boundary = B{k};
% compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
% obtain the area calculation corresponding to label 'k'
area = stats(k).Area;
end
stats = regionprops(L,'Area','Centroid');

14

threshold = 0.90;
count=0;
% loop over the boundaries
for k = 1:length(B)
% obtain (X,Y) boundary coordinates corresponding to label 'k'
boundary = B{k};
% compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
% obtain the area calculation corresponding to label 'k'
area = stats(k).Area;
% compute the roundness metric
metric = 4*pi*area/perimeter^2;
% display the results
metric_string = sprintf('%2.2f',metric);
% mark objects above the threshold with a black circle
if (metric > threshold)
count=count+1;
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
end
text(boundary(1,2)+5,boundary(1,1),metric_string,'Color','k',...
'FontSize',14,'FontWeight','bold');
end
fprintf('Number of tablets');
count
title(['Metrics closer to 1 indicate that ',...
'the object is approximately round']);

15

S-ar putea să vă placă și