You are on page 1of 4

International Journal of Signal and Image Processing (Vol.1-2010/Iss.

1)
Abbasgolipour et al. / Implementation of an Efficient Image Processing Algorithm / pp. 31-34

Implementation of an Efficient Image


Processing Algorithm for Grading Raisins*
M. Omid*, M. Abbasgolipour, A. Keyhani and S.S. Mohtasebi

Department of Agricultural Machinery, Faculty of Agricultural


Engineering and Technology, University of Tehran, Karaj Iran.
tel/fax: +98 261 2801 038
* e-mail: omid@ut.ac.ir

Submitted: 22/10/2009
Accepted: 12/01/2010
Appeared: 16/01/2010
HyperSciences.Publisher

Abstract— In order to extract useful features of captured images of bulk raisins by image processing
technique, an efficient algorithm was developed and implemented in visual basic language. The proposed
machine vision system consists of a video camera, a capture card, a lighting adjustable tunnel, a personal
computer, and mechanical part. The developed algorithm initially extracts the raisins by removing the
background from the taken images. It then sorts the raisins according to their RGB color and size
features. By a suitable combination of length and RGB color values raisins are graded it two classes.
Final step in the algorithm is the calculation of the center of gravity of each raisin to be later used for
automatic sorting and rejection of bad raisins. The proposed system was developed and tested and results
show that its accuracy is about 96%.
Keywords: Grading, Bulk raisin, Image processing, Machine vision, RGB, Color features, Software.
abolish inconsistent manual evaluation, and reduce
dependence on available manpower. Researches in this area
NOMENCLATURE indicate the feasibility of using machine vision systems to
CCR correct classification rate improve product quality while freeing people from the
traditional hand sorting of agricultural materials. Raji and
CCD charge-coupled device
Alamutu (2005) reviewed recent developments and
CoG canter of gravity applications of image analysis and computer machine vision
GUI graphical user interface in sorting of agricultural materials and products in the food
L length of each raisin industries. Basic concepts and technologies associated with
NBP number of bad raisins computer vision, a tool used in image analysis and automated
sorting were highlighted.
NGP number of good raisins
RGB Red-Green-Blue color coordinate system Computer vision has been used for quality inspection of
Ratio color ratio fruits. Quality inspections of fruits have two different
objectives: quality evaluation and defect finding. Machine
X G , YG coordinates of canter of gravity vision is the most important tool for external feature
Yi coordinate of the entering point measurements such as color intensity, color homogeneity,
Ymid the middle of the column bruises, size, shape and stem identification (Lee et al., 1999;
coordinate of the exit point Majumdar and Jayas, 2000; Shahin and Symons, 2001;
Yo
Paliwal et al., 2003; Shigeta et al. 2004). In a series of papers,
Njoroge et al. (2003) described the operations and
1. INTRODUCTION performance of an automated quality verification system for
agricultural products. Kondo et al. (2005) proposed a multi-
Raisin is one of the important and valuable exported products product grading system for agricultural products.
in Iran. Manual evaluation and sorting of raisin is costly and In recent years our research team have been conducting
inherently unreliable due to its subjective nature. The poor considerable research in the design and fabrication of sorting
classification and sorting methodology has caused a reduction machines. Omid, et al. (2009) developed an automatic
of exported product. Automatic raisin sorting system based trainable classifier, based on artificial neural network, for
on machine vision can improve the quality of the product, separating four different varieties of pistachio nuts. The

*
The financial support provided by the University of Tehran, Iran.

Copyright © 2010 HyperSciences_Publisher. All rights reserved 31 www.hypersciences.org


International Journal of Signal and Image Processing (Vol.1-2010/Iss.1)
Abbasgolipour et al. / Implementation of an Efficient Image Processing Algorithm / pp. 31-34

developed system, because of none destructivity, does not By studying and composing physical properties of the
cause damage to the open shell pistachio kernels, and machine vision system it can be understood that what is
therefore does not cause rejection by the consumer. Hence it defined as color by human. Color spaces are mathematical
can boost the exports. Lorestani et al. (2006) applied fuzzy perception of these properties. All color spaces are three
logic as a decision support system to grade golden delicious dimensional right angled coordinate systems that are shown
apples. Features such as color and size are measured through in Red, Green and Blue (RGB) spaces as intensities of red,
a data acquisition system consisted of apple’s sorter, webcam green and blue lights. Each color pixel in digital image
and a PC. Khojastehnazhand et al. (2009) developed a possesses a value between 0 to ( 2 24 − 1 ). For every pixel the
machine vision system to automatically determine the volume RGB values are determined by Eq (1):
and surface area of orange. This image processing procedure
can be readily applied to other axi-symmetric agricultural P( X , Y ) = B × 216 + G × 2 8 + R (1)
products such as eggs, pearl, pepper, carrot, limes and onions.
In order to grade the raisins into several groups (classes), a
The objective of this paper was to develop an efficient new algorithm was devised. For the sack of simplicity, here
algorithm for grading bulk raisins. In the following sections the case of sorting raisins in two classes of desirable and
the design and implementation of algorithm is presented and undesirable are presented. The RGB values are determined
discussed. using the following VB code for all pixels of background:
2. MATHERIALS AND METHODS Private Sub RGBcolor (ByVal Point As Long)
Blue = Point \ 256 ^ 2
2.1 Total system description Temp = Point Mod 256 ^ 2
Green = Temp \ 256
Color and size are the most important features for accurate Red = Temp Mod 256
grading of bulk raisins. Accordingly, a machine vision
system for grading raisins by color and size features was End Sub
designed and implemented. A picture of the prototype sorter
is shown in Fig. 1. 2.2 Machine vision algorithm

The hardware includes: a conveyer belt (80 cm in length and The algorithm consists of the following four steps (Fig. 2):
25 cm in width), an induction motor (MotoGen: Iran, 0.37 1. Background separation,
KW, 380V, 2.1A), a black box (lightning chamber), light 2. Program control transition,
sources, a video camera (Video Hi8, CCD-TRV128E PAL), a 3. Searching the lower and upper pixels about the
capture card (WinFast DV 2000) and a PC. middle of each column,
4. Extracting the required features and
characteristics.
In the case of raisin detection, it is essential to correctly
divide images into regions which are desired (raisins with
desired color content), undesired (raisins with undesired color
content) and background (surface of convertor).

Input Image data

Remove
Background
Fig. 1. Machine vision system for grading raisins.
Program control transition to
the middle of raisins column
As seen in Fig.1, raisins are discharged on the belt at the
entrance of the conveyer belt. The raisins pass below the
lightning chamber, located 27 cm away from the entrance. A Exploring lower and upper pixels
video camera mounted above the chamber, takes a then the middle of each column

photograph of the raisins as the pass and transfers the data to


the capture card via a cable link to PC for storage and post- Feature Extraction
processing.
End
An efficient feature extraction algorithm was designed and
implemented in Visual Basic 6.0 in order to grade the raisins. Fig. 2. Feature extraction algorithm for grading raisins.
Basically, the program receives data from video camera in
real-time and extracts the required characteristics in Segmentation is an important and perhaps the most difficult
accordance with the belt revolution speed, i.e., the program image processing task. Segmentation refers to subdividing an
classifies good and bad raisins by color and size features, the image into regions exhibiting “similar” characteristics.
location (center of gravity) of each raisin on the belt. Subsequent image interpretation tasks, such as feature

32
International Journal of Signal and Image Processing (Vol.1-2010/Iss.1)
Abbasgolipour et al. / Implementation of an Efficient Image Processing Algorithm / pp. 31-34

extraction and object recognition, rely on the quality of the NGP


segmentation results. The composite color of each pixel is Ratio = (5)
NGP + NBP
separated into the original R, G and B in the range 0-255 by
using Eq (1). where X G , YG are coordinate of canter of gravity (CoG) and
The histogram studies showed (Fig. 3) that color changes of L length of each raisin. To calculate the degree of goodness
red and green for background and raisin are very irregular of a raisin, color ratio ( Ratio ) and L are compared with their
while for the blue are regular. Therefore, we used the respected threshold values, i.e., if Ratio ≥ threshold value
following code for removing the background: and L ≥ threshold length, then the raisin is considered to be a
good one, otherwise it is a graded as a bad raisin. Finally, all
IF (Blue >Bmin-bkgd) THEN P(X,Y) = Pixel IS bkgd the examined raisin pixel values are reset to zero to avoid
recalculation and the program goes to the next raisin.
3. RESULTS AND DISCUSSION

Based on the proposed algorithm, a graphical user interface


(GUI) was designed and implemented using VB 6.0. In order
to evaluate the accuracy of the developed algorithm, its
performance on a bulk set of raisins was tested. Figure 4
shows a snap shot of the main menu of GUI.

.
Fig. 3. Histograms of blue color changes for background,
good and bad raisins.

If the considered pixel is outside the background range, the


control has reached the first pixel. Therefore, separation is
being stopped and control is entered within the range of raisin
pixels. The program saves the coordinates Yi of entering point
and explores the column until the exit point Yo is reached. By
calculating Ymid = (Yi + Yo ) / 2 , control returns to the middle
of the column. At this stage, one single unit is added to the
number of columns and control transfers to the next column.
The critical task of the algorithm is to explore lower and
upper pixels about the middle of each column. Once the
control reaches the middle point of upper and lower edges,
firstly the lower pixels are examined and the number of good
(NGP) and bad (NBP) raisins are calculated as follows:
Fig. 4. Main menu of GUI implemented in Visual Basic

IF (R >Rmin AND R<Rmax) AND (G >Gmin AND G The sample images of raisins used to test the proposed
<Gmax) THEN algorithm is shown in Fig. 5a. Result of applying the fore
NGP=NGP+1 mentioned algorithm is shown in Fig. 5b.
Else
NBP=NBP+1 From Fig. 5b it is observed that, firstly background has been
End IF segmented, secondly the bad-colored raisins are shown as
blue, and thirdly the raisins with inappropriate length are
Finally, upper pixels are examined and the total NGP and highlighted. The proper separation of background supports
NBP for a column are calculated. Useful details about an our selection of blue color for the algorithm. It is concluded
individual raisin can be obtained using the following this selection is very effective in correct raisin detection.
equations:
X + Xo Table 1 shows the confusion matrix obtained from tests on
XG = i (2) both of good and defected raisins and comparison of
2 proposed image processing algorithm with human expert.
Y + Yo The overall precision or correct classification rate (CCR) of
YG = i (3)
2 this image processing system was estimated as 96 percent by
comparison of proposed algorithm and human expert.
L = ( X o − X i ) 2 + (Yo − Yi ) 2 (4)

33
International Journal of Signal and Image Processing (Vol.1-2010/Iss.1)
Abbasgolipour et al. / Implementation of an Efficient Image Processing Algorithm / pp. 31-34

Kondo, N., Ninomiya, K., Peter, R., Kamata, J. and Fasil, A.


(2005). Development of multi-product grading system,
ASAE Annual Meeting, Paper No. 043125.
Lee, W.S., Slaughter, D.C. and Giles, D.K. (1999). Robotic
weed control system for tomatoes. Precision Agriculture,
, 1, 95 –113.
Lorestani, A.N., Omid, M., Bagheri-Shooraki, S., Borghei,
A.M. and Tabatabaeefar, A. (2006). Design and
evaluation of a Fuzzy Logic based decision support
system for grading of golden delicious apples, Int. J.
Agri. & Biology, 8, 440-444.
Majumdar, S., and Jayas, D.S. (2000). Classification of cereal
grains using machine vision: II- Color models.
(a) before grading Transaction of ASAE, 43(6), 1677-1680.
Njoroge, J.B., Ninomiya, K., Kondo, N. and Toita, H. (2002).
Automated fruit grading system using image processing,
Proceedings of the 41st SICE Annual Conference, Vol.
2, 5-7 Aug. 2002, 1346–1351.
Omid, M. Mahmoudi, A., and Omid, M.H. (2009). An
intelligent system for sorting pistachio nut varieties.
Expert Systems with Applications, 36, 11528–11535.
Paliwal, J., Borhan, M.S. and Jayas, D.S. (2003).
Classification of cereal grains using a flatbed scanner.
ASAE Annual Meeting, Paper No. 036103.
Raji, A. and Alamutu, A. (2005). Prospects of computer
vision automated sorting systems in agricultural process
(b) after grading operations in Nigeria. Agri. Eng. Int.: the CIGR Journal
of Scientific Research and Development, Vol. VII.
Fig. 5. Image of raisins; (a) before, and (b) after Shahin, M.A. and Symons, S.J. (2001). A machine vision
processing by proposed algorithm system for grading lentils. Canadian Biosystems
Table 1. Comparison of machine vision algorithm and Engineering, 7, 7-14.
human expert in grading of raisins Shigeta, K., Motonaga, Y., Kida, T. and Matsuo, M. (2004).
Distinguishing damaged and undamaged chaff in rice
Machine vision detection whole crop silage by image processing. ASAE Annual
Raisin Grade
Good Bad # CCR Meeting, Paper No. 043125.
Human Good 15 0 15 100
expert Bad 1 6 7 85.71 AUTHORS PROFILE
Total observed 16 6 Mahmoud Omid was born in Yazd, Iran. He received his BSC degree in
22/23* 0.96 1989 from Newcastle Upon-Tyne University, UK, and his MSC and PhD
(%) 93.75 100 degrees in Telecommunication Engineering from the University of Electro-
Communications, Japan, in 1994 and 1997, respectively. He is currently an
* Number of correctly classified raisins associate professor in the Faculty Agricultural Engineering and Technology
at the University of Tehran (UT), Iran. Since 2003, he has been director of
4. CONCLUSION Information &Communication Technology (ICT) Center at UT College of
Agriculture and Natural Resources. He was honored with outstanding
An efficient algorithm for grading bulk raisins was research award from UT in 2008. His special fields of interest include Soft
developed. By a suitable combination of length and RGB Computing and Data Mining, Intelligent Signal and Image Processing, and
Machine Vision. He has authored and coauthored more than 50 technical
color values raisins were graded it two classes. The results articles for international journals and conferences.
indicated, the characteristics of a set of raisins spread over a
surface (bulk material) can be effectively extracted by the
developed image processing algorithm with great accuracy.
The overall precision of the algorithm was estimated as 96
percent by comparison of proposed algorithm and human
expert. The system can be easily adapted for sorting other
agricultural goods such as lentil and almond.

REFERENCES
Khojastehnazhand, M., Omid M. and Tabatabaeefar, A.
(2009). Determination of orange volume and surface area
using image processing technique. International
Agrophysics, 23, 237-242.

34

You might also like