Tablet correction system using Matlab

Call for Papers - April 2019

Download Full-Text PDF Cite this Publication

Text Only Version

Tablet correction system using Matlab

Siddharth Valluvan1, Rahul T. Singp, Chirag B. Solanki3, Rohit T. Yadav4, Prof. Niket Amoda5

Electronics & Telecommunication

K C college of Engineering & Management Studies and Research Mumbai, India,,,

Abstract We propose an inspection mechanism, by capturing an image and performing its analysis so that judgments can be made based upon this analysis. The image that is fed into the mechanism/database is of an unpacked tablet since this inspection is performed before packaging. For this project, the machine is used for sorting faulty tablets from the normal tablets. It allows the normal tablets to pass through, but pushes the faulty tablets into a scrap bin if too many faults are detected within the tablets. All these operations are performed automatically using a PC and MATLAB software, without any manual controlling.

This device is designed only to detect faulty capsules or tablets. The detection process takes place with the help of a webcam and an Image Processing algorithm. The unpackaged tablet is placed on the conveyor belt, driven with the help of two L293 motor drivers. When the webcam detects an object on the belt, it stops the motors to capture an image and then sends it to the PC for fault analysis. The numerous faults that are checked for using the Image Processing algorithm include deformities like unusual color, holes or the absence of the tablet itself. If more than one fault is detected on the package, it is discarded. But if only one fault is detected, then it is replaced with the help of a pneumatic arm, which takes the faulty tablet away and replaces it with a fresh tablet.

Keywords Key WordsImage Processing, Tablet, Blisters, Medical, Pills.


In the pharmaceutical industry nonprescription drugs are often packaged in blister packs that, once opened, cannot be reclosed. This packaging makes it easy for consumers to discern whether a package has already been opened or, in the case of some drugs, whether the consumer is following the proper drug regimen.

The packaging is made up of a molded PVC base with raised areas called blisters that contain the medication. Once the drugs have been inserted into the blisters, the package is covered with a foil laminate. Consumers remove the tablets by either breaking the blisters or by peeling away the laminate foil strip. In filling and sealing these packages, drug companies often need to detect whether a single tablet is present within each blister. To address this problem we will develop a camera system with image processing that can perform both tasks relatively simply and easily.

This inspection machine is designed and used for inspecting capsule or tablet which is broken, or has incomplete structure or not standard by vision through mechanically rotating the capsule over 360 degrees or turning the tablet from one

surface to the other surface. The inspector can easily take out any bad capsule or tablet and collect together.


    Dispensing medications in a community pharmacy before the 1970s was a fairly time consuming operation. The pharmacist dispensed most prescriptions that were in tablet or capsule form with a simple tray and spatula. Many new medications were being developed by pharmaceutical manufacturers at an ever-increasing pace, and the price of those medications was rising steeply.

    A system of pharmacy automation was quickly adopted, innovations emerged every decade to meet the needs of the pharmacy industry to deliver medications quickly, safely and economically. A typical community pharmacist was working longer hours and often forced to hire additional staff to handle increased workloads. This extra workload did not allow the time to focus on safety issues. Early electronic counters were designed to help pharmacies replace the common (but often inaccurate) practice of counting medications by hand.

    At the turn of the millennium technical advances saw the design of a new breed of counters with a verification system. In recent times, the pharmacy companies make use of advanced counters, that include the ability to dispense hands- free. This allows pharmacies to automate their most commonly dispensed medications via calibrated cassettes. Robotics which has been employed and newer technologies allows pharmacy staff to confidently dispense hundreds of prescriptions per day and still be able manage the many functions of a busy community pharmacy. So our project based on image processing which will automatically detect whether all the tablets are present or not.


    Fig.1 Basic Block of Image Processing

    Image Acquisition Device: It consists of a web camera with suitable interface for connecting it to the PC[4].

    Processor: It consists of personal computer or a dedicated image processing unit.

    Image Analysis: Certain tools are used to analyze the content in the image captured and derive conclusions e.g. MATLAB 11.0

    Machine Control: After making the conclusion, mechanical action is to be taken e.g. using parallel port of a PC to control the conveyor system and arm.


    The various components used are PC, Opto-Isolator, Motor Driver, DC Motor, a mechanical assembly for camera motion (a robotic arm in this case) and a webcam. Input to the PC is given using a camera (webcam). Output of the PC which is in digital form is fed to the Opto-Isolator. The PC is operated at 5V whereas the motor driver is operated at 12V.

    Four isolators and 3 motors will be used; 2 motors for the conveyer belt circuit and 1 for the ejector circuitry.

    As our project is PC controlled there is a 25 Pin Parallel PC port, which is the output from PC, to which the device is connected.

    Fig.2 A Basic Block of the Entire Assembly


    1. Mechanical Assemblies: There are two mechanical assemblies present in the project, i.e. conveyor belt and robotic arms to reject if defects are detected.

    2. Webcam: A webcam captures and recognizes an object in view and tracks the users input of note in the note placing unit using computer-vision based techniques. It sends the data to the computer

    3. Computer or Laptop: The minimum requirements for this project are as follows: 1gb RAM, 10gb free hard disk, Pentium 4 processor or higher versions.

    4. MAX 232:It is used for serial communication between PC to microcontroller. It is also used to convert TTL logic into CMOS logic or vice versa. It is used for serial communication between PC to Microcontroller. MAX232 IC receives a TTL level to convert, it changes a TTL logic 0 to between +3and +15V, and changes TTL logic 1 to between -3 to -15V,and vice versa for converting from RS232 to TTL.

    5. Microcontroller: Microcontroller is low power ,high performance 8bit CMOS microcomputer with 4KB of

      EPROM. Signal from every sensors or detectors applied to the microcontroller for processing. Microcontroller gives the corresponding signal to every respected block for field operations.

    6. Motor Drivers: Motor driver 1is used to move the normal robotic arm for discarding the whole tablet chip if more than 1 tablets are damage. Motor driver 2 is used to move the pneumatics arm by the angle of 180 degree in the case of replacing a single tablet wen only one tablet is damaged,

    7. Relay Circuit: It is used to activate/deactivate the pneumatic arm

      Software Requirements:

      Image Processing with MATLAB:

      MATLAB and Image Processing Toolbox provide a flexible environment to explore design ideas and create unique solutions for imaging systems.

      MATLAB toolbox used in our project are as follows:

      1. Image Acquisition Toolbox

      2. Image Processing Toolbox

      3. GUI Builder

      1. Image Acquisition Toolbox

        The Image Acquisition Toolbox is a collection of functions that extend the capability of the MATLAB numeric computing environment. The toolbox supports a wide range of image acquisition operations, including: Acquiring images through many types of image acquisition devices, from professional grade frame grabbers to USB-based Webcam. Viewing a preview of the live video stream. Triggering acquisitions (includes external hardware triggers). Configuring callback functions that execute when certain events occur. Bringing the image data into the MATLAB workspace.

      2. Image Processing Toolbox :

        Image Processing Toolbox provides a comprehensive set of reference-standard algorithms, functions, and apps for image processing, analysis, visualization, and algorithm development. Many toolbox functions are multithreaded to take advantage of multicore and multiprocessor computers.

        Image Processing Toolbox supports a diverse set of image types, including high dynamic range, gigapixel resolution, embedded ICC profile, and tomographic. Visualization functions let you explore an image, examine a region of pixels, adjust the contrast, create contours or histograms, and manipulate regions of interest (ROIs).

      3. GUI Builder:

      A graphical user interface (GUI) is a graphical display in one or more windows containing controls, called components, that enable a user to perform interactive tasks. The user of the GUI does not have to create a script or type commands at the command line to accomplish the tasks. GUI components can include menus, toolbars, push buttons, radio buttons, list boxes, and slidersjust to name a few. GUIs created using MATLAB tools can also perform any type of computation, read and write data files, communicate with other GUIs, and display data as tables or as plots.



    Conversion to Binary:

    The grayscale image is converted into binary format with a threshold value of 0.n


    g(x, y) = T [ (x, y) ] Where, T(r) = 1 r m = 0 r <m


    MATLAB® function im2bw(x,0.3) is used for image binarization

    Edge Detection:

    The edges are then found in the resulting image using the edge detection method with the following operators:

    Gx = (z7 + 2z8 + z9 ) ( z1 + 2z2 + z3) (4)

    Gy = ( z3 + 2z6 + za ) ( z1 + 2z4 + z7 ) (5)

    It returns edges at those points where the gradient of image is maximum

  6. ALGORITHM Image processing:

    Fig.3 Flow Diagram

    Blob detection:

    Blob detection refers to mathematical methods that are aimed at detecting regions in a digital image that differ in properties, such as brightness or color, compared to areas surrounding those regions. Informally, a blob is a region of a digital image in which some properties are constant or vary within a prescribed range of values; all the points in a blob can be considered in some sense to be similar to each other. One of the first and also most common Blob detectors is based on the Laplacian of the Gaussian (LoG).

    Given an input image, f(x,y), this image is convolved by a Gaussian kernel:

    An image may be defined as a two-dimensional function, f(x,y), where x and y are spatial coordinates, and the amplitude of f at any pair of coordinates (x,y) is called the intensity or gray level of the image at that point. When x, y, and the amplitude values of f are all finite, discrete quantities, we call the image a digital image.

    Region of Interest (ROI) Selection:

    The main objective for selecting a region of interest (ROI) is

    at a certain scale 't', to give a scale space representation


    Then, the Laplacian operator:-



    to filter out undesired information present on blister. First of all, pictures of all pills on blister are captured and saved. Since the image is a matrix, so some desired rows and columns are deleted from these images and these are then saved as region of interest images. This process of selecting a portion of the original image is also known as cropping of image. MATLAB function roipoly(x) is used for selecting ROI of pills in blister.


    H = ROI (f(x, y)) f(x, y) (1)

    Conversion to Grayscale:

    The acquired image of actual pills is converted into grayscale image with histogram equalization process for improving the image contrast.


    sk = T(rk) = nj/n k= 0,1,2,,L-1 (2) j=0 (2)

    MATLAB functions rgb2gray(x) and adapthisteq(x) are utilized for this purpose.

    is computed, which usually results in strong positive responses for dark blobs of extent and strong negative responses for

    bright blobs of similar size. A main problem when applying this operator at a single scale, however, is that the operator response is strongly dependent on the relationship between the size of the blob structures in the image domain and the size of the Gaussian kernel used for pre-smoothing. In order to automatically capture blobs of different (unknown) size in the image domain, a multi-scale approach is therefore necessary.

    Fig.5 Initial Process

    The loaded image is displayed on the screen. We implement certain Image Processing commands on this acquired image.

    Fig.4 Image Processing Algorithm


    1. A webcam will be placed just above the moving conveyor belt where the tablets are placed for correction purpose.

    2. This webcam will capture the images of each tablet moving along the conveyor belt, the captured images are stored in PC which is connected further to a microcontroller via. a serial port.

    3. Microcontroller will perform the corresponding actions as per the size, color and availability of tablet in its defined position.

    4. In cases where one tablet is damaged or not in the proper condition as predefined to be then the microcontroller will turn on the relay circuit that will activate the pneumatic arm which will suck out the damaged tablet and by moving an angle of 180 degree will discard the tablet to another location and is replaced by the new tablet. This action of pneumatic arm is done by driving motor driver circuit 2.

    5. In case when more than one tablet is damaged then the complete tablet is replaced directly by using a normal robotic arm which is activated by turning on the motor driver circuit 1.

      Motor driver 1 is also used to run the conveyor belt where the tablet will be placed for correction.


    We implement the result on MATLAB using the GUI Builder. The Image is loaded onto the GUI.

    Fig.6 Loading the Image

    The image is converted into a grayscale image using the rgb2gray command

    Fig.7 Grayscale Conversion

    The grayscale image is processed into a threshold image which means that it converts the image into a binary image.

    Fig.8 Thresholding


    MATLAB v7.10: It is used to perform the Image Processing Algorithm and the analysis process for the purpose of detection and correction of faulty tablets and capsules. The complete interfacing between hardware and software is done through the GUI, which is built using the GUI Builder available in MATLAB. The Image Acquisition Toolbox and Image Processing Toolbox are used to capture and process the image, respectively. The image acquisition is done using a external hardware i.e Webcamera, connected to our device.

    Kiel: This software is used for writing the program for the microcontroller and the relay circuit. The program is burned to the IC through another software called Microwind.

    Microwind: This software is used for the IC burning process.

    Eagle: This software is used for creating the Circuit Diagrams of the Power Supply, Relay circuit, microcontroller 89S52 and the Motor Driver circuits.


    • Based on color principal locating a tablet position.

    • Robotic arm for rejection of wastage tablet packets.

    • Conveyor belt to pass tablets for further process.

    • Using simple webcam for processing .


    Our system brings variety of improvements in existing system by decreasing the workload and manufacturing cost, also increases the efficiency of the system and counters a variety of safety issues.


[1]. Abidi, M.A.,Eason R.O., and Gonzalez, R.C. [1991]."Autonomous Robotics Inspection and Manipulation" IEEE Computer, vol.24, no.4, pp.17-31.

[2]. Andrews, H.C. [1970]. Computer Techniques in Image Processing, Academic Press, New York.

[3]. Baxes, G.A. [1994]. Digital Image Processing: Principles and Applications, John Wiley & Sons, New York.

[4]. Hall, E.L. [1979]. Computer Image Processing and Recognition,

Academic Press, New York

[5]. Niket Amoda, Ramesh K Kulkarni, "Efficient Image Retrieval using Region Based Image Retrieval", International Journal of Applied Information Systems (IJAIS) ISSN : 2249-0868 Foundation of Computer Science FCS, New York, USA, (ICWAC 2013)

[6]. Niket Amoda, Ramesh K Kulkarni, "Image Segmentation and Detection using Watershed Transform and Region Based Image Retrieval", International Journal of Emerging Trends & Technology in Computer Science (IJETTCS)-Volume 2, Issue 2,

March – April 2013

[7]. Niket Amoda, Ramesh K Kulkarni, "Efficient Image Segmentation Using Watershed Transform", INTERNATIONAL JOURNAL OF COMPUTER SCIENCE & TECHNOLOGY (IJCST)-VOL IV ISSUE II, VER. 2, APR. TO JUNE, 2013

Leave a Reply

Your email address will not be published. Required fields are marked *