Computer Vision based Model for Fruit Sorting using K-Nearest Neighbour classifier

Page 1

Int. Journal of Electrical & Electronics Engg.

Vol. 2, Spl. Issue 1 (2015)

e-ISSN: 1694-2310 | p-ISSN: 1694-2426

Computer Vision based Model for Fruit Sorting using K-Nearest Neighbour classifier Seema Department of Physics National Institute of Technology Kurukshetra-136119, India E-mail:er.seema5@gmail.com

A. Kumar Department of Physics National Institute of Technology Kurukshetra-136119, India E-mail: ashavani@yahoo.com

Abstract— Food grading and estimation has been observed as a key aspect in the field of food and agriculture. Increasing awareness towards quality of food has opened new opportunities of research in this area. Fruit grading and classification is also an important procedure to increase the quality evaluation in fruits grading which affects the export market. Computer vision plays an important role in automation of fruit classification. Total six varities of fruits and vegetable, i.e. red delicious apples, golden apples, green apples, oranges, bananas and carrots are analyzed. The system uses two image databases, one image database for training on the system and other for implementation of query images. In the packaging industry, color and morphological features are the most important feature for classification of fruits. After preprocessing, segmentation is done to extract the region of interest. In this paper, k mean clustering method is used for segmentation to extract region of interest from background. Color features are extracted from the RGB image and HSI image. Morphological features are calculated from RGB segmented image. In this paper, fruits are classified using the nearest neighbor classifier. Euclidean Distance Metric based kNearest Neighbor Classifier is developed for this particular application. The overall accuracy of the system is 100%. Keywords— Computer Vision; HSI color model; Euclidean distance; k means clustering; k-Nearest Neighbor

I. INTRODUCTION Agro industry means industry, which is connected with agriculture. These industries focus the post-harvest process such as processing the agricultural products after harvest and storing the products for domestic applications. This process also includes cleaning, sorting, grading and packaging. Sorting and grading is one of the post-harvest process which classifies the products based on appearance, size and shape which determines the quality of food products. Sorting is also done by human experts, but is more tedious, time taking process. The above mentioned disadvantages can be overcome by automatic sorting technique through machine vision which is fast, accurate and cost effective. Machine vision includes the capturing the images, analysis and processing of images, making easy to achieve the region of interest and make easy to determine visual quality characteristics in food products. In recent years, many of the agricultural and food industries which include sorting and grading fields of fruits use the image processing and machine vision techniques. The quality

49

G. S. Gill Department of Instrumentation Kurukshetra University Kurukshetra-136119, India E-mail: gsgill@kuk.ac.in

attributes such as shape, size, color and other external features are analyzed using machine vision techniques. Computer Vision is used to capture images from the real world and gather from these. It includes image acquisition, preprocessing, analyzing and understanding the sample images to gather the information in symbolic form or numerical value. The main aim of computer vision is to reproduce the effect of human vision by electronically perceiving and understanding the images [1]. Color is the most striking feature for grading and sorting of fruits and vegetables. Leemans et al. Suggested apple grading method and two types of apple, Golden Delicious and Jonagold were used. Shape and color features were extracted. This method for apple external quality grading gave 72% accuracy for Golden Delicious and 78% Jonagold apples. The grading of healthy fruits was better and an error rate decreases to 5 and 10%, respectively [2]. Liming et al. suggested a system for automatic grading of strawberry. In this L*a*b* color images were obtained from RGB images. Major axis length was calculated and gave information about the size of the sample and color features were extracted from the dominant color model on a* channel. K-means clustering method was used for classification purpose and it gave 90% classification accuracy for shape and 88.8% accuracy for color based grading [3]. Suresha et al. presented automatic grading of apple by support vector machines. In this paper, apple images were captured. These were in the RGB color space and threshold based segmentation was used to extract the region of interest from the background. HSV color model is obtained by RGB color model and average red and green color components were determined for classification. This classifier gave 100% accuracy in grading [4]. Shape or size are also the most important feature for sorting of fruits. Kavdir et al. suggested a method for apple grading by color and size features extraction from apple images. This gave 89% accuracy [5]. Khojastehnazhand et al. presented an approach for sorting and classification of lemon fruits in Visual Basic 6 based upon the color and size. Volume of sample image had been estimated and HSI images were obtained from RGB images. HSI values were extracted and these values were stored in a database. During testing of query image, calculated volume and color of testing image are compared with the saved information in the database. The system gave 94.04% accuracy [6].

NITTTR, Chandigarh

EDIT-2015


Int. Journal of Electrical & Electronics Engg.

Vol. 2, Spl. Issue 1 (2015)

II. METHODOLOGY The proposed method has training and testing sets. In the training phase, from a given set of training images features are extracted and used to train the system using the K-nearest neighbor classifier. In classification phase a given test fruit image is segmented and then the same features are extracted which are used for training the system for classification purpose. These features are queried to K-nearest neighbor classifier to label an unknown fruit. The block diagram of the method is given in Fig 1.

e-ISSN: 1694-2310 | p-ISSN: 1694-2426

Step2. The image is transformed into L*a*b* color space from RGB color space as all of the color information is present in a* and b* layers only. Step3. Colors are classified using K-means clustering in a*b* space, with Euclidean distance to measure the distance between two colors. Step4. Each pixel is labeled in the images from the result of K-means clustering with its cluster index. Step5. Different images are generated from each cluster. Segmentation results of banana image are shown by Fig 2.

(a)

(c)

A. Image Database In this paper, a total of 120 images of fruits is taken, twenty images of each fruit sample, i.e. red apple, green apple, golden apple, orange, carrot and banana. The images have a size of 260 and having an aspect ratio unchanged and all are in JPEG format. Although they are on a white background, lighting varied between different images and shadows are almost always existed around the samples. In order to extract the regions of interest (ROI), segmentation is necessary step. B. Image Segmentation K-means clustering method is an unsupervised clustering method which classifies the input data objects into multiple classes on the basis of their distance from each other. A vector space is formed from the data features and clustering algorithm identifies natural clustering with them. The objects around the centroids µii = 1, 2…k are clustered which are computed by minimizing the following objective k

(1)

i 1 x j  si

Where k is the number of clusters, i.e. Si, i = 1, 2… k and µi is the mean point or centroid of all the points xj ϵ Si [7]. Algorithm followed for K mean clustering for image segmentation [8] is illustrated below: Step1. The input image is read into MATLAB.

NITTTR, Chandigarh

(d)

Fig 2 (a) Original image, (b) segmented image from cluster 1, (c) segmented image from cluster 2, (d) segmented image from cluster 3

Fig 1 Block Diagram of Methodology

V    ( x j  i ) 2

(b)

EDIT -2015

C. Feature Extraction Feature extraction is core of fruit grading and sorting system. In this present work, color and morphological features are extracted which are explained below: 1) Morphological Feature: Morphological feature plays an important role in classification purpose. Analysis of morphological features starts with detection of the fruit boundary [9]. There are many morphological features that can be extracted. Roundness is one of the morphological features and it is dimensionless. It can be used to differentiate between two categories. In first category, three types of apples and orange lies and in second category, banana and carrot lies. But in a category morphological features produce misclassification. Hence color features are also extracted. 2) Color Feature: Color is also an important feature which human uses for object discrimination. Roundness produces error to identify the objects having same roundness like to distinguish between banana and carrot and to distinguish different types of apple and orange. In this paper, both RGB and HSI color space are used. a) RGB Model: RGB is the most common color model in digital image processing and it is based on the primary color components, i.e. red (R), green (G) and blue (B), which the human eye can perceive. The RGB color space is shown as a cube. It is based on a Cartesian coordinate system and each color (red, green, blue) denotes one of the three orthogonal

50


Int. Journal of Electrical & Electronics Engg.

Vol. 2, Spl. Issue 1 (2015)

coordinate axes in 3D space as shown in Fig 3. Points along the main diagonal are assigned to gray values from black at origin to white at that point. Every image can be separated into its respective red, green and blue planes and the mean of each component is calculated [10]. This computation helps to estimate the most dominant or least dominant primary color of the image.

e-ISSN: 1694-2310 | p-ISSN: 1694-2426

1  R  G   R  B   2   cos 1  1  2  R  G   R  B G  B  2 

     

(3)

Saturation is represented by equation 4 S  1

3 min R, G, B  ( R  G  B)

(4)

Intensity is represented by equation 5 I 

Fig 3. RGB color model

b) HSI Model: View of an object is described by its hue, saturation and intensity by humans. Hue is a measure that describes a pure color, whereas saturation tells about the degree to which a pure color is diluted by white light. The HSI color model is an ideal tool for developing digital algorithms based on color descriptions that are natural and perceived by human [10]. HSI model is shown in Fig 4.

1 R  G  B  3

(5)

D. K-Nearest Neighbor (K-NN) Classifier The main aim of a classifier is to assign a predefined class to an object using the given features. Machine vision systems usually use specially designed soft computing techniques to accomplish the task of classification. Size and color are considered to be important factors on the basis of which fruits can be sorted. K-NN algorithm is a widely used technique that is used for classification purpose and easy to implement. In the present paper, the concept of classification is extended to determine fruit type based on its size and color. However, it may fail to produce adequate results in some applications due to lack of in depth knowledge in its implementation, yet it is the fact is that it is easy to train K-NN to a variety of situations because it has only one parameter, that is, the number of neighbors (k) [11]. K-NN algorithm is a typical distance based supervised learning method. Its basic idea is that an object is classified according to the proximity major of its neighbors and the object being assigned to the class with whom most of its k nearest neighbors belongs as shown in Fig 5.

Fig 5. Graphical Representation of K-NN

Fig 4. HSI Color Model

RGB to HSI color transform: Hue is represented by equation 2, ifB  G H  360  ifB  G

51

(2)

Although there are a number of invariants yet in this paper, the Euclidean distance metric is used for similarity computation. K-NN algorithm is described here. A training set is given consisting of n pair (xi–yi). In this algorithm, first of all distances between the sample x and the training set is calculated and then finds the closest k training samples. In which class most of the k training samples are classified, x can

NITTTR, Chandigarh

EDIT-2015


Int. Journal of Electrical & Electronics Engg.

Vol. 2, Spl. Issue 1 (2015)

be assigned to that class. Euclidean distance between samples is described below by mathematical formula equation:

d ( M , S )  i 1 xi  yi  k

2

(6)

Where M= [M1, M2, . . .MN ] and S= [S1, S2, . . . SN] are the feartures vectors. In K-NN input feature vector is classified into class CJ, based on a voting mechanism [12]. III. RESULT AND CONCLUSION It was observed that the color profile for bananas, oranges, carrots, green apples and golden apples were almost uniform throughout the surface area for the object under evaluation. However, in case of red apple, it has been observed that with increase in surface area under yellow patches, the probability of the fruit to be classified as an orange increase. This may be due to the fact that the increase in yellow component shifts towards the color profile of an orange. Since apple and orange shares almost similar geometrical profile when viewed in two dimensionally, the probability of erroneous classification increases. On the contrary, if red apples have uniform profile throughout as in case of test apples taken for present experiment. The classification efficiency of 100% can be achieved. In present work, 100% classification efficiency has been achieved for above mentioned 6 varieties of fruits and vegetable. REFERENCES [1]

[2]

T. Bronsnan, D. W. Sun, “Improving quality inspection of food products using computer vision- a review,” in Journal of food engineering, vol. 61, pp. 3-16, 2004. V. Leemans, H. Mageinb, M.F. Destain, “On-line Fruit Grading according to their External Quality using Machine Vision”, Journal of

NITTTR, Chandigarh

EDIT -2015

e-ISSN: 1694-2310 | p-ISSN: 1694-2426

Automation and Emerging Technologies, Belgium. Biosystems Engineering, pp. 397–404, 2002 [3] Xu Liming and Zhao Yanchao, "Automated strawberry grading system based on image processing," in Computers and Electronics in Agriculture, vol. 71(1), pp. S32-S39, April 2010. [4] M. Suresha, N.A. Shilpa, B. Soumaya, “Apples Grading based on SVM classifier,” in International Journal of Computer Applications on National Conference on Advanced Computing and CommunicationNCACC,pp. 27-30, April 2012. [5] I. Kavdir, D.E. Guyer, “Apple Grading using Fuzzy Logic,” in Journal of Agric Turk, vol. 27, pp. 375-382, 2003. [6] M. Khojastehnazhand, M. Omid, A. Tabatabaeefar, “Development of Lemon Sorting System based on Color and Size,” in African Journal of Plant Science vol. 4(4), pp. 122-127, April 2010. [7] S. R. Dubey, P. Dixit, N. Singh, J. P. Gupta, “Infected Fruit Part Detection using K-Means Clustering Segmentation Technique”, International Journal of Artificial Intelligence and Interactive Multimedia, vol. 2(2),pp 65-72, 2013. [8] V. Ashok, D. S.Vinod, “Using K-Means Cluster And Fuzzy C Means For Defect Segmentation In Fruits”, in International Journal of Computer Engineering and Technology (IJCET),vol. 5 (9), pp.11-15, September 2014. [9] N. B. A. Mustafa, K. Arumugam, S. K. Ahmed,Z. A. M. Sharrif, “Classification of Fruits using Probabilistic Neural NetworksImprovement using Color Features”, IEEE International Conference on TENCON, 2011. [10] R. C. Gonzalez and R. E. Woods, Digital Image Processing. Prentice Hall, 2nd ed., 2002. [11] A. P. S. Chauhan & A. P. Singh, “Virtual Grader for Apple Quality Assessment using Fruit Size and Illumiation Features”, in Global Journal of Computer Science and Technology (G) Interdisciplinary, vol 14(4), 2014. [12] A. P. S. Chauhan & A. P. Singh,“Intelligent Estimator for Assessing Apple Fruit Quality”, in International Journal of Computer Applications, vol 60(5),pp. 35-41, December 2012.

52


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.