# Introduction ood Industry is one of the industries in which packaging of agriculture produce is an important task that largely depends upon grading methods. Therefore, grading of agriculture produce is required to be very fast & accurate as far as the quality of produce is concerned. In order to accomplish this task, highly efficient algorithms are needed invariably in machine vision based inspection systems. The basis of fruit gradation is external factors including size, shape, color, defect and external damage, etc. However, consumer choice is always to have fruits with equal size. In fact, this is the basis of sorting of fruits based on their size. Proper sorting of fruit ensures uniformity in fruit size, reduce packaging and transportation costs and also provides an optimum packaging configuration. Thus in packaging industry, grading of fruits based on size is one of the important tasks that are performed. Though human graders can do this task but machine vision has proved to be a great tool that can replace human sorters for consistent and reliable judgment in estimating and comparing size of the fruits. Human graders may make different judgments on the same product at different instances and also if done by human graders it will be time consuming also. Therefore, in order to replace human graders, machine vision is the most effective and non-destructive evaluation technique. Assessment of apple quality based on its size is highly subjective due to a number of factors that may influence the crop maturity during cultivation such as geographical location, weather conditions, rainfall density, nurturing ingredients, disease and industrial effluence, etc. Due to highly subjective nature of the apple quality, it is indeed extremely difficult to make any benchmark or standards for size-based quality assessment. Most of the fruit packaging industries, in fact, largely depend upon the decision of the human experts in assessing or assigning the grade to a particular size of the apple. However, manual grading is obviously a very cumbersome process as far as efficiency and accuracy are concerned. In order to circumvent these difficulties, machine vision based intelligent systems are required urgently to replace human graders for assessing fruit quality. An attempt is made in the present work to replace human grader with a virtual grader for assessing the apple quality based on its size using machine vision. The knowledge or intelligence acquired by the human grader with experience in grading apple based on its size is, in fact, imbibed artificially in the proposed virtual grader. Different algorithms had been developed for size determination of fruits, cereals, vegetables and food products under the realm of image processing in the past, which are detailed below. Emphasis on important aspects of image processing technique along with review of the most recent developments throughout the food industry was already reported [1]. Another review of recent work reported on food and agricultural products along with in depth introduction to machine vision system and its components was also available [2]. Different techniques for apple processing were studied and features such as hue angle, shape defect, circumference, firmness, weight, blush percentage, russet, bruise content and number of natural defects were defined [3].Reviews in the progress of computer vision in the agricultural and food industry was done and areas for further research and wider application of the technique were identified [4]. Correlation and regression analysis was performed in order to determine the relationships among fruit quality parameters [5]. Image analysis was done to distinguish Arthur from Arkan based upon different parameters namely perimeter, area, length, feret diameter but proper positioning of kernels was G . e-mails: ajaypal@sliet.ac.in, aps.aps67@gmail.com. mandatory [6]. Pattern recognition was employed to discriminate between wheat and nonwheat and between weed seeds and stones in nonwheat part of grain samples but manual orientation of kernel was required [7].Fast Fourier transform analysis was derived from Fourier harmonics in conjunction with machine vision system for potatoes size inspection based on elongation ratio [8]. To classify several cereal grains, size and shape features including kernel length, width, projected area and aspect ratio were used [9].Fourier descriptor technique [10], a method of using boundary radius and its Fourier transform to spectrum domain, was studied for size description. A color vision sorter capable of performing full color spectral sorting of different varieties of fruits and vegetables including apples, peaches, tomatoes and citrus was developed for color, size and shape, with a capacity of up to 44 tons per hour [11]. However, much of the above work had not been used in commercial apple sorting systems because of the constraints in speed, accuracy and flexibility. Correct classification rates (CCR) were calculated from the confusion matrix. The overall accuracy was 94 %.Three methods were discussed for apple size determination by applying known geometrical models [12]. A simplified Machine vision system was developed for estimating size of pomegranates [13]. It allows the estimation of volume, surface area and weight of fruit using prediction equations developed from the relationship between projected area, shape and size. An automatic detection system for finding out surface quality parameters and defects of fruits like apples was designed [14].But this paper mainly deals with mechanical aspects. Image processing method with the disk approximation technique was employed to estimate the volume of cantaloupes of varying sizes from sets of two surface images captured with a digital camera [15]. Algorithm to grade papaya samples according to their size using estimated weight information with 90% classification accuracy was reported [16].A technique was developed using fuzzy sets to correlate the attributes of size, color, shape and abnormalities, obtained from tomato images, with the inner quality of the tomato samples [17]. Another automatic strawberry sorting system was developed [18] with average shape and size accuracies of 98 and 100%, respectively, regardless of the fruit orientation angle with judgment time within 1.18 s. Physical features of chocolate chip biscuits, including size, shape baked dough color, and fraction of top surface area using image analysis were measured and four fuzzy models were developed to predict consumer ratings based on these features [19]. Kohanz apple fruit area, perimeter and eccentricity were extracted by image processing to suggest an appropriate package design [20]. High Correlation between the maximum size and weight of fruit prove that the weight could become a proper quality index for apples [21].An algorithm for sorting lemon based on color and size was developed and implemented in visual basic environment [22]. The correct classification rates were 95.45 %, 100%, and 86.67% for grade 1, 2 and 3 respectively. A fuzzy image analysis method based upon size and color had been reported for mango fruit quality grading [23].The recent techniques and features of external grading systems for non-destructive operation and performance of automated quality verification systems for agriculture products were discussed [24]. After having rigorous literature review, it is concluded that above methods work well only for a particular quality of a fruit or vegetable or cereal with efficiency less than 100 % and also they fail to address the effect of an important parameter that is intensity of fruit surface illumination. However based on the successful results of these studies, the authors of present paper decided to estimate fruit quality based on size using K-nearest neighbor (K-NN) classifier while considering intensity as one of the important deterministic parameters. The performance of different variants of K-NN classifier is also examined at different values of fruit surface exposures by the authors of the present paper in their earlier work on quality assessment of red delicious apples using color features [25]. An intelligent virtual grader was also developed based on the architecture of Euclidean metric oriented K-NN classifier for estimation of quality of red delicious apples using color features [26]. Similarly, another type of virtual grader was also developed for assessing apple quality using shape features [27]. In line with this strategy, the use of K-NN classifier is extended in the present work to develop an intelligent virtual grader for estimation of apple fruit quality using size features. In fact, the work reported in the present paper is a part of the complete machine vision based apple gradation system for assessing apple quality using information related to fruit size, shape, color and surface defect. # II. # K-Nearest Neighbor (K-NN) Classifier The main goal of a classifier is to assign an object to a predefined class using the given features. Machine vision systems usually use specially designed digital image processing software to accomplish the task of classification. Size is considered to be one of the important factor on the basis of which grading of apple is done. K-NN algorithm is a widely used technique that found many applications in classification. In the present work, the concept of classification is extended to determine accurately the apple fruit quality based on its size. However, in some applications, it may fail to produce adequate results owe to lack of in depth knowledge in its implementation, yet the fact is that it is easy to fine-tune to a variety of situations because it has only one parameter, that is, the number of neighbors (k). The image processing software, the heart of the proposed virtual grader, was executed in the form of a size-classifier using NI Vision Builder for Automated Inspection in combination with Lab VIEW. NI Vision Builder for Automated Inspection was chosen for the development of image processing software in Lab VIEW environment, as it provides an effective graphical user interface with interactive features. K-NN algorithm using Euclidian distance metric was used to execute the sizeclassifier. The size-classifier calculates the size features by carefully extracting the features from the acquired image and computes the statistical information associated with the size including perimeter and hydraulic radius. # Global Journal of Computer # IV. Experimental Validation The proposed virtual grader was designed to operate in a real time environment, however, in a highly user-interactive manner. Its operation was controlled under the supervision of specially designed Algorithm of Control & Computations executed in the form of block diagram as back-end programming. # a) Samples Preparation Covering a wide range of size, two hundred apples of red delicious variety were taken. Three human experts trained in the field of size-based manual grading of this particular variety of apples were given the samples. So four grades A, B, C and D having 25 samples each was selected. Fifteen samples in each grade were taken as reference samples that were commonly agreed upon by all the experts. These samples were used for training the K-NN based sizeclassifier as per the following details. The inspection image contains multiple samples. These were fed to the executed size classifier for training. The proposed size classifier was executed on the architecture of K-NN algorithm powered with Euclidean metrics. The executed size classifier was operated in three phases including training phase, classifying phase and validation phase. A known sample consists of a region in the image containing the apple size that the classifier needs to learn. The size-classifier calculates a size features and assigns the associated class label to the computed features, for each and every sample added during the training phase. Eventually, all the trained samples added to the size-classifier were saved into a file which represents a trained sizeclassifier. After training the classifier, regions were classified into their corresponding classes for size identification in apple quality. The Region of Interest (ROI) toolbar was used to define a region which was useful for training. The Annulus ROI tool was chosen for apple, because it adjusts the inner and outer radii, and also adjusts the start and end angles. Experimentation was conducted using database of 60 training samples selected by three human experts, with 15 samples in each category and at five different intensities of apple surface illumination including 170 lux, 253 lux, 310 lux, 405 lux and 486 lux. However, the optimal number of training samples (k) and illumination intensity were determined after rigorous experimental trials using executed size-classifier. In the training phase, the sizeclassifier was provided with samples of each grade, that is, A, B, C and D varying from 1 to 15 respectively. In order to do so, in training phase, the size classifier was trained first with one sample of each grade and its performance was examined at five different illumination intensities of ambient light source (natural day light) taken at different instance of time. Then the experiment was repeated again fourteen times by varying sample of each grade from two to fifteen. From repeated experimental trials, it was established that the proposed size-classifier works effectively at an illumination intensity of 310 Lux when k-NN was trained with eight (k = 9) number of training samples, each with four different grades. It was also established that when the fruit under examination was not properly exposed with proper illumination intensity, the results obtained with the proposed classifier were less accurate. Reason behind this was that when light intensity varies ambient occlusion plays its affect. Ambient occlusion adds visual realism to the image without being physically correct. The effect of ambient occlusion can well be seen in the results presented in tables 1 and 2.The range of perimeter and hydraulic radius for a grade varies with intensity. phase were again given to the proposed virtual grader one by one (choosing k = 9 and illumination intensity 310 lux), however, operated in an automatic mode, which classifies and grade them according to their size content. In the classifying phase, the size classifier calculates the size features of the sample that need to be identified and classifies it among trained samples using K-NN Algorithm. The classification process was responsible to classify the input or user selected fruit by using K-NN algorithm. This measure the distance between features values of the stored fruit under test. Afterward the K-NN finds out among the stored fruit the one having shortest distance with the input and identifies and assigns the class to the input fruit. # d) Size classifier validation Again covering a wide range of size, one thousand apples of red delicious variety were taken. Three human experts trained in the field of size-based manual grading of this particular variety were provided each with the same number of samples to have an individual trial of each. After having individual judgment from them, they were each asked to choose 200 apples of each of the four grades out of a set of one thousand apples. Then out of these four sets, 100 samples in each grade were taken as reference samples that were commonly agreed upon by all the experts. In this way, four sets of fruits containing 100 fruits in each set were selected with corresponding A, B, C and D grades. In the validation phase, the selected 100 validation samples selected by human experts were given to the proposed virtual grader operated at illumination intensity of 310 lux and keeping k=9, which classifies and grade them according to their size content. Accordingly, the performance of the virtual grader was found to be quite satisfactorily as confirmed from the results presented in the following section. # V. Results and Discussion The proposed virtual grader was used practically to estimate the quality of red delicious apple fruits based on their size. In order to examine the performance of the proposed virtual grader, it was brought in the operational mode by switching it on. In operational mode, the size-classifier operates in the classifying phase while acquiring images automatically. As soon as the image of the apple under inspection was acquired, it automatically displays its grade along with other related parameters on the Front Panel. After having repeated experimental trials, it was found that the proposed virtual grader works effectively at an illumination intensity of 310 lux when K-NN classifier was trained with nine numbers of training samples. It had been found experimentally that the proposed virtual G confirm the results obtained in the training and classifying phases. In fact, efficiency achieved using proposed virtual grader is 99%, if manual grading is assumed to be 100% efficient as reference level. However this1% variation was due to subjective judgment of human graders in perceiving the apple fruit during manual grading, which of course, is inevitable. Moreover, the repeatability of the proposed system was found to be 100% as confirmed after rigorous experimental validation. Achievement of 99% accuracy at repeatability of 100%, established that Euclidean distance metric based K-NN classifier was an efficient method to translate human visual perception of grading the apple based on fruit size into machine vision. However, the manual grading was always manifested with subjective tolerance. This fact was also confirmed by three human experts chosen for manual grading. According to them, it was not possible for them also to decide the border cases. Now, in order to establish empirically the reason for successful gradation of the apple fruit under inspection by the proposed virtual grader, using acquired fruit images, size features including perimeter and hydraulic radius were estimated using image processing algorithms implemented in the LabVIEW at different fruit surface exposures. # Conclusion A new type of virtual grader is developed to estimate apple quality from its size. The implemented system is used effectively in real time environment to grade red delicious apple using fruit size features. It has been established experimentally that Euclidean distance metric based K-NN Classifier achieves promising results for this particular application. It is also found that the efficiency is the highest at a particular value of illumination intensity as well as optimal number of ![In fact, K-NN algorithm is a typical instance based learning method. Its basic idea is that an object is classified according to the majority vote of its neighbors, with the object being assigned to the class most of its k nearest neighbors belongs to. Though it has a number of invariants yet, in the present work, the Euclidean distance metric is employed for similarity computation. K-NN algorithm is described as illustrated here.Given a training set consisting of n pair (xi-yi), the algorithm firstly calculates the distance between the sample x and the training set, and then finds the closest k training samples. Thus x can be assigned to the class to which most of the k training samples are classified. The Mathematical formula to calculate Euclidean distance between samples is described by equation: Euclidean distance = ?? (?? ?? ? ?? ?? ) 2 ?? ??=1 In k-nearest neighbor classification, size of the apple under consideration is classified into a class based on a voting mechanism. III. Development of The Proposed Virtual Grader NI Vision Builder for Automated Inspection was used in combination with LabVIEW to acquire images using experimental set up as shown in Fig 1. In the proposed experimental setup, image acquisition card, industrial grade BASLER sca-1390 17fc camera and ambient light source were used to execute a computer based machine vision system. The acquired images Fig 2 displays the block diagram of system overview including fruit under inspection, experimental setup and user interactive interface. However, systematic development of the proposed virtual grader involves following steps:](image-2.png "G") 12![Figure 1: Experimental Setup](image-3.png "Figure 1 Figure 2 :G") 3![Figure 3 : User Interactive Front Panel](image-4.png "Figure 3 :") 4![Figure 4 : A Part of the Control and Computation Algorithm (Block Diagram)](image-5.png "Figure 4 :") ![Fig 4 displays a part of the Algorithm of Control and Computations executed in the form of Block Diagram as back-end programming for the complete system. In fact, it decimates the main blocks into subblocks including pre-processing, processing, postprocessing and classification. The algorithm of control and computations was designed and interlinked with the Front Panel after having careful choice of various objects available in the Vision Builder for Automated Inspection and LabVIEW. The algorithm of control and computations, in fact, controls and coordinates the functioning of various modules and objects used for the design of front Panel and Subpanels of the proposed virtual grader. For proper classification of the fruits under inspection, training and test interfaces were synthesized. The training interface was used to train the size classifier manually thus categorizing size samples into different size-classes. Similarly, test interface was used in the classifying as well as validation phases to examine the performance of the proposed virtual grader in an automated manner.](image-6.png "") ![Grader for Apple Quality Assessment using Fruit Size and Illumiation Featuresc) Size Classifier TestingIn the testing phase, all the 60 numbers of test samples selected by human experts for the training grader grades apples based upon their size accurately when tested with complete set of apples used for training and classifying phases. The results obtained in Year 2014](image-7.png "Virtual") ![operation in the validation phase further training samples. The lighting condition is one of the major factors that affect the results produced by the system. Different light exposures generate different results. The theoretical principles and practical design of the proposed virtual grader are described. The technique would be quite useful for other types of fruits possessing similar surface characteristics. In fact, the proposed technique has a potential future in the field of machine vision based inspection of agriculture produce.](image-8.png "") 1IntensityGrade-AGrade-BGrade-CGrade-D(Lux)PixelsmmPixelsMmPixelsmmPixelsmm4862485-2290 391-3602321-1991365-313 2067-1972325-3102023-1977 318-3114052413-2239 379-3522277-1946358-306 2010-1844316-2901857-1741 292-2743102347-2131 369-3352141-1908337-300 1902-1730299-2721736-1682 273-2642532329-2143 366-3372103-1895331-298 1965-1685309-2651743-1696 274-2671702361-1978 371-3112025-1717318-270 1883-1749296-2751679-1647 264-259 2IntensityGrade-AGrade-BGrade-CGrade-D(Lux)PixelsmmPixelsMmPixelsmmPixelsmm 3GradePerimeter RangeHydraulic Radius RangePixelsMmPixelsMmA2347-2131369-335165-15826-25B2141-1908337-300156-14925-23C1902-1730299-272138-12822-20D1736-1682273-264130-12120-19VI. © 2014 Global Journals Inc. (US) ## Acknowledgement The authors would like to acknowledge Department of Electronics * Improving quality Inspection of food products by computer vision systems*/a review TBrosnan DWSun Journal of food Engineering 61 2004 * Machine vision system: a tool for quality inspection of food and agricultural products KKPatel AKar SNJha MAKhan J Food SciTechnol 49 2 2012 * Evaluation of different pattern recognition techniques for apple sorting IKavd?r DEGuyer Biosystems Engineering 99 2008 * Inspection and grading of agricultural and food products by computer vision systems*/a review TBrosnan DWSun Computers and Electronics in Agriculture 36 2002 * Correlations between Fruit Size and Fruit quality in apple trees with high and standard crop load levels FR DSalvador MFisichella MFontanar Journal of Fruit and Ornamental Plant Research 14 2 2006 * Discrimination between Arthur and Arkan wheat by image analysis IZayas YPomeranz FSLai Cereal Chem 63 2 1985 * Discrimination of wheat and Nonwheat components in Grain Samples by image analysis IZayas YPomeranz FSLai Cereal Chem 66 3 1989 * Automated machine vision inspection of potatoes YTao CTMarrow PHHeinemann ASAE 1990 * An Instrument system for cereal grain classification using digital image analysis HDSapirstein MNeuman EHWright Cereal Sci 6 1987 * Boundary estimation in complex images using fourier descriptors MBJiang Merickel Proc null * Intl Conf Pattern Recognition 1988 1 * Methods and apparatus for sorting objects including stable color transformation YTao United States Patent 5 1996 * New approaches for size Determination of Apple Fruits for automatic Sorting and Grading PRao SRenganathan Iranian journal of Electrical and Computer Engineering 1 2 2002. 2002 Summer Fall * Estimation of pomegranate shape and size by Machine vision AliIHobani AAi-Janobi J. King Saud Univ 9 1 1997 Agric.Sci * On-Line machine vision system for Fast fruit colour sorting using low cost architecture JoseSFilibertopla JoseMSanchez Sanchiz SPIE system based on color and size 2010 4 * Mohd Nazari bin Abu Bakar, Khairul Adilahbt Ahmad, Ab Razak Mansor TRosli BRazak MahmodBOthman International Conference on Agricultural, Environment and Biological Sciences (ICAEBS'2012) Phuket May 26-27, 2012 Mango Grading By Using Fuzzy Image Analysis * Recent Methods and Techniques of External Grading Systems for Agricultural Crops Quality Inspection MeftabSalem Alfatni International Journal of Food Engineering 7 * Intelligent estimator for assessing apple fruit Quality AJ PSingh APSingh International Journal of Computer Applications 60 5 2012 * Development of an intelligent virtual grader for estimation of fruit quality AJ PSingh APSingh International Journal of Computer Applications 62 17 2013 * Virtual Grader for Assessing Apple Quality using Shape features AJ PSingh APSingh Wulfenia Journal 21 7 2014