Automated Sorting of Iranian Pistachio Nuts using Computer Vision

Automated Sorting of Iranian Pistachio Nuts using Computer
Vision and Particle Swarm Optimization
kernel of open shell nuts by inserting a pine needle into the
kernel meat. The hole created by the needle can give the
form of an insect tunnel, and led to rejection by the
consumer [11].
Diverse techniques including mechanical, electrical, optical
and acoustical have been used for classification and/or
sorting of pistachio nuts. Machine vision was introduced
for recognition of stained and early split pistachio nuts [10].
Ghazanfari et al. employed Fourier descriptors and gray
level histogram features of two-dimensional images to
classify pistachio nuts into one of three USDA size grades
or as having closed shells [1, 2]. Fourier descriptors are very
time-consuming and they are not suitable to real-time
applications. Pearson's system exhibits that pistachios with
either split or unsplit shells can be distinguished by means of
gray scale images. Later, an automated machine vision
system developed to recognize and remove pistachio nuts
with closed shells from processing streams. The system
includes a feeding system to feed nuts through three high
speed line-scan cameras without tumbling. The camera
output signals are input to digital signal processing boards
which educe image features characteristic of closed and open
shell pistachios. The sorting accuracy of this machine vision
system for separating open shell from closed shell nuts in
two passes is approximately 95%. Although the system has a
throughput maximum rate of 40 nuts per second, its cost is
awfully high for many producers in Iran [11].
In this study a high performance low-cost computer vision
system for automated detection of closed pistachio nuts is
designed and developed. Intelligent learning process is used
and tuned by Particle Swarm Optimization (PSO)
algorithm. The system is self-learning and is tested for
three important varieties of Pistachio nuts in Iran. Having
developed PSO, the system becomes intelligent and selftuned. In this system, PSO as a core of learning system is
used for selecting of appropriate values for separation.
Abstract- Iran is one of the most important producers
and exporters of pistachio nuts in the world. Certainly,
the quality of pistachio plays an important role for
producers and customers. Sorting of pistachio nuts is
one of the post-harvest processes which is currently
performed by destructive mechanical apparatus called
“Pin-picker”. In this paper, an intelligent low cost
system is proposed, designed and developed for
pistachio sorting using computer vision. This simple
system is mainly able to be used instead of pin-pickers.
The proposed system consists of two steps. First, the
system should be trained using particle swarm
optimization which is introduced by Eberhart and
Kennedy. Then, the trained system can sort the mixed
pistachios. The experimental result of system is
analyzed for three varieties of pistachios.
Key words: Pistachio nuts, Detection, Computer vision,
PSO.
1.
Introduction
Based on FAO statistics, Iran as the 1st producer of
pistachio nuts produced %35 of the world's pistachio in
2008 [4]. Pistachio nuts are grouped into open and closed
shells. These groups are separated in post-harvest
processing. On the other hand, Pistachios are served
principally as salted nuts and usually they are marketed for
snack food. Certainly, for many consumers closed shells
have no acceptance due to the difficult opening and the
possibility of immature kernels. Thus either separation
from open shell nuts is crucial. Therefore the detection of
closed shell pistachio nuts are an important action in the
stages of post-harvesting.
Currently, closed shell nuts are separated from open shell
product by mechanical devices called “Pin-picker”.
Although they have high capacity, they may injure the
1
PSO is a population-based stochastic optimization
algorithm modeled after the simulation of the social
behavior of bird flocks. PSO is easy to apply and has been
effectively applied to solve a wide range of optimization
problems. Thus, due to its simplicity and efficiency in
navigating large search spaces for optimal solutions, PSOs
are used in this research to develop efficient, robust and
flexible algorithms to solve a selective set of difficult
problems in the field of image processing.
2.
The camera takes an image when a pistachio crosses the ray
of imaging IR sensor. This image becomes rapidly checked
for open or closed status and then the result is appended to
result queue. In the splitting excitation the splitter picks a
first saved result from the sorting queue and splitter
changes its sorting group to read position.
Material and Methods
Taking a suitable image from pistachio nut is one of the
major problems in the classification of pistachio nuts using
computer vision. Pearson used three line-scan cameras to
take several linear images from all directions of pistachio in
free falling of pistachio to judge correctly about them. But
this imaging is very expensive. For solving this problem,
three cameras are replaced by one camera and two flat
mirrors. This alternation allows the system to vision the
every side of pistachio and it leads to eliminate of
sensitivity of system with respect to pistachio orientation.
This proposition can be seen in figure 1.
Fig2. Block Diagram of the Sorter system
4.
In the real-time applications many restrictions appear.
Thresholding segmentation of images is subset of high
speed methods in the real-time image processing
applications. In this study these methods are optimized and
implemented for pistachio sorting systems. A cheap camera
is employed and therefore highly noisy and low resolution
image is captured. Moreover, the frame rate of the camera
is confined and this restriction leads to many stiff problems
for segmentation and evaluation of image for closed or
open shell pistachio nuts. For solving these problems, the
multilevel thresholding is selected for image processing.
The high performance system of judgment is presented in
figure 3.
The unknown parameters are tuned using PSO algorithm.
Particle swarm optimization (PSO), developed by Kennedy
and Eberhart [6, 7], is one of the most well-known
evolutionary optimization techniques. PSO idea is based on
social communication such as bird flocking and fish
schooling. Similar to genetic algorithms, of course PSO is
also population-based and evolutionary; with one key
difference from genetic algorithms that it all chromosomes
or potentials in the population, endure through the entire
search process. The algorithm of PSO is demonstrated as
following steps.
Fig1. Formation of Mirrors and Camera
Sorter system should be fully automatic to achieve
appropriate process and therefore the system should have
discrete controller while it has discrete events such as
pistachio arrival in imaging housing or splitter area. The
general configuration of designed system is shown in figure
2. Proposed system has several subsystems includes:
Feeding subsystem, exposing subsystem, imaging
subsystem, electronic subsystem and separation subsystem.
3.
Learning and Image Processing Algorithm
Sequence of system application
2
Fig3. Classifying the input pistachio image as open or closed shell
Initialization: Randomly spread a population of the
potential solutions, called “particles,” and each particle is
allocated a randomized velocity.
is identified, based on its fitness, as the best particle
among the population. All particles are then accelerated
towards the global best particle as well as in the
directions of their own best solutions that have been
visited previously. While forthcoming the current best
particle from different directions in the search space, all
particles may run into unexpectedly even better particles
en route and the global best solution will finally appear.
Equation (2) shows how each particle’s position (xid) is
updated in the search of solution space.
Velocity Update: The particles thus “fly” through search
hyperspace while updating their own velocity, which is
educated by considering its own past flight and those of
its companions. The particle’s velocity and position are
dynamically updated by the following equations:
Fitness function of the learning process is based on train
dataset which fulfilled by N open and closed shell
images. Fitness function assessment is shown in equation
(3). Therefore the error of classifying is appropriate to
consider in optimization process as training process.
(1)
Fitness  
(2)
Where the acceleration coefficients C1 and C2 are two
positive constants; wi is an inertia weight and r1, r2 is a
uniformly generated random number from the range [0,
1] which in each iteration is generated consistently.
Equation (1) shows that, when calculating the new
velocity for a particle, the previous velocity of the
particle (vid), their own best location that the particles
have discovered previously (xid) and the global best
location (xgd) all contribute some influence on the
outcome of velocity update. The global best location (xgd)
Nopen
Nclose
i 1
i 1
 erri  1     erri ,
(3)
Where ε is weighing function between importances of
open or close dispersion. If ε→0 all of open shells
detected as closed and thus the purity of the box of open
shells becomes high. Also, if ε→1 all of closed shells
detected as open shell and thus closed shell box turn into
pure. Selected ε is 0.7, because open shells purity is more
important than purity of closed shells.
3
5.
Training and Testing Experiments
References
Two hundred pistachio nuts were randomly selected for
each variety of Akbari, Ohadi and Kalle Ghochi in the
training process. These include 100 open-shell and 100
closed-shell pistachios. The nuts used for training
pistachio are passed through the sorting system to
acquire and save training images. The training image set
for each variety includes 400 pictures. Thereafter, the
unknown parameters of the system were tuned by PSO
algorithm for each variety. Then the unknown
parameters, tuned by PSO, sent to sorting program.
Results of training and testing are presented in table 1.
[1] A. Ghazanfari, D. Wulfsohn, and J. Irudayaraj,
"Machine vision grading of pistachio nuts using graylevel histogram", Canadian Agriculture Engineering.
40(1):61-66, 1998.
[2] A. Ghazanfari, J. Irudayaraj, and M. Romaniuk,
"Machine vision grading of pistachio nuts using fourier
descriptors", J. Agriculture Engineering Research.
68(3):247-252, 1997.
[3] C. Chen, J. Luo, and K. Parker, "Image
Segmentation via Adaptive K-means Clustering and
Knowledge-Based Morphological Operations with
Biomedical Applications", IEEE Transactions on Image
Processing, vol. 7, no. 12, pp. 1673-1683, 1998.
[4] http://faostat.fao.org.
[5] J. Haiyan, and J. Yuan, "The application study of
apple color grading by particle swarm, optimization
neural networks", In Intelligent Control and Automation,
2006. WCICA 2006. , The Sixth World Congress on,
pages 2651 – 2654, 2006.
[6] J. Kennedy, and R. Eberhart, "Particle Swarm
Optimization", Proceedings of the IEEE International
Conference on Neural Networks, Perth, Australia 1995,
pp. 1942-1945,1995.
[7] J. Kennedy, and R. Eberhart, "Swarm Intelligence",
Academic Press, 1st ed., San Diego, CA, 2001.
[8] K. Chandramouli, and E. Izquierdo, "Image
classification using chaotic particle swarm optimization",
In 2006 IEEE International Conference on Image
Processing, pages 3001 – 3004, 2006.
[9] L.S. Oliveira, Jr. Britto A.S., and R. Sabourin,
"Optimizing class-related thresholds with, particle swarm
optimization", In Neural Networks, 2005. IJCNN ’05.
Proceedings. 2005, IEEE International Joint Conference
on, pages 1511 – 1516 vol. 3, 2005.
[10] T. Pearson, "Machine vision system for automated
detection of stained pistachio nuts", Lebensm Wiss, U
Technol, 29, 203-209, 1995.
[11] T. Pearson, and N. Toyofuko, "Automated sorting
of pistachio nuts with closed shell", Applied Engineering
in Agriculture. 16(1): 91-94, 2000.
[12] T.C. Pearson, and D.C. Slaughter, "Machine vision
detection of early spilt pistachio nuts", Transactions of
ASAE. 39(3): 1203–1207, 1996.
[13] V. Kumar, VK. Garg, "Modeling and control of
logical discrete event systems", Boston, MA: Kluwer,
1995.
[14] Z. Gaing, "Particle Swarm Optimization to Solving
the Economic Dispatch Considering the Generator
Constraints", IEEE Transactions on Power Systems, vol.
18, no. 3, pp. 1187-1195, 2003.
Table1. Results of experiments
Variety
Training
Percent
Testing Percent
Open
Shell
Closed
Shell
Akbari
94%
91%
90.2%
Ohadi
91.5%
94%
73.1%
Kalle Ghochi
97%
93.1%
86.6%
6.
Discussion and Conclusion
Low cost system for sorting of pistachio nuts is designed
and implemented. Evaluation of the system in training
and testing stages indicates that the system is very
flexible for some varieties. The capacity of pistachio
sorting in initial tests is approximated by 5 pistachios per
seconds. Pearson’s system can sort 40 pistachios per
second. Since the fabrication cost of the proposed system
is estimated as 750$ and Pearson’s systems as 15000$,
thus the cost number of this system is 150($/pistachio)
while that is 375($/pistachio) for Pearson’s system.
Therefore cost number of this system is much better.
Moreover, spending more money on cameras and the
main computer, the processing speed and the pistachio
capacity can be increased in the future.
In the experiments the Akbari and Kalle Ghuchi is
simply trained and sorted. But O’hadi pistachios, are
difficult to train and of course sorting. This mighy be due
to its smallness and thin split area. The average train
percentage is 94.2% and testing is 89.9%. The results are
encouraging and the system is completely implemented
and analyzed.
4