<figure><img src="image_1.png" /></figure>

HAL
open science

# Identifying Apple Surface Defects Based on Gabor Features and SVM Using Machine Vision

Wenqian Huang, Chi Zhang, Baihai Zhang

► To cite this version:

Wenqian Huang, Chi Zhang, Baihai Zhang. Identifying Apple Surface Defects Based on Gabor Features and SVM Using Machine Vision. 5th Computer and Computing Technologies in Agriculture (CCTA), Oct 2011, Beijing, China. pp.343-350, 10.1007/978-3-642-27275-2_39. hal-01361158

HAL Id: hal-01361158

https://inria.hal.science/hal-01361158

Submitted on 6 Sep 2016

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_2.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Identifying Apple Surface Defects Based on Gabor
features and SVM using Machine Vision¹

Wenqian Huang¹, ²,*, Chi Zhang², Baihai Zhang¹

1 School of Automation, Beijing Institute of Technology, Beijing 100081, China

2 Beijing Research Center of Intelligent Equipment for Agriculture, Beijing
Academy of Agriculture and Forestry Sciences, Beijing, 100097, China

*Corresponding author: huangwq@nercita.org.cn

**Abstract.** In this paper, a novel method to recognize defect regions of apples based on Gabor wavelet transformation and SVM using machine vision is proposed. The method starts with background removal and object segmentation by threshold. Texture features are extracted from each segmented object by using Gabor wavelet transform, and these features are introduced to support vector machines (SVM) classifiers. Experimental results exhibit correctly recognized 85% of the defect regions of apples.

**Keywords:** defect identification, Gabor wavelet, SVM, apple quality grading

# 1 Introduction

Tons of apples are produced, harvested and consumed throughout the world each year. Visual inspection of these apples is traditionally done by human experts. Even so, automation of this process is necessary to increase speed of inspection as well as to eliminate human inspection error and variation introduced. In recent years machine vision systems have been widely applied to evaluate external quality of apples [1-3]. However, these systems can't provide robust and accurate results yet, because high variability of defect types and skin color as well as presence of stem/calyx areas increases complexity of the problem. Computer vision systems are mostly confused in discriminating defect regions of apples from stem/calyx regions due to their similarity in appearance. In most machine vision based automated apple grading and sorting systems, it is important to distinguish apple stem/calyx from defect in apple images because stem/calyx region in apple images often exhibit patterns and intensity values that are similar to defect region in apple surface and result in false alarms during defect sorting. Hence, accuracy of apple sorting decreased by false identification of defect regions of apples.

Several approaches have been introduced to recognize defects on apples using computer vision systems. T.G. Crowe et al. use structural illumination to detect apple defects, where concave dark spots are considered to be stem/calyx [4-5]. Zhiqing Wen et al. develop a rules-based NIR system and histogram densities are used to discriminate stem/calyx from defect areas [6]. Recognition rates of stems and calyxes are 81.4% and 87.9%, respectively. Their system is less reliable when stem/calyx regions are closer to the edge of fruit. Wen Z. et al. use an NIR and a middle-infrared (MIR) camera for apple detection, where image from the latter is used to segment

¹ Young Scientists' Foundation of Beijing Academy of Agriculture and Forestry Sciences (Project No. QN201119) and National High-Tech Research and Development Program of China (863 Program) (Project No. 2011AA100703)
ROI and about 99% of them are correctly recognized [7]. However, cost of cameras, which is not discussed by the authors, is an important problem for practical implementation of this method. Kleynen et al. utilize correlation-based pattern matching technique to detect stem/calyx on apples in a multispectral vision system [8]. Recognition rates for stems and calyxes are 91% and 92%, respectively. And 17% of defects are misclassified as stem/calyx. Pattern matching method has been widely applied for object recognition, but its main disadvantage is high dependency on the template used.

2-D Gabor wavelets have been successfully applied to face recognition. Its advantages are better time-frequency localization feature and better signal resolution in time and frequency domain which can be achieved by adjusting Gabor filter's direction and base-frequency width and central frequency. Tai Sing Lee extended 1-D compact wavelet to 2-D Gabor wavelet in 1996 [9]. Multi-channel filter technology, that is, a set of Gabor wavelets with different time-frequency characteristics are adopted in image transform, each channel can achieve some local feature from input image, so the input image can be analyzed on different-sized granularity. In all, Gabor wavelets optimally represent the texture structure with different locations and orientations. Because Gabor wavelets transform is better than others on texture feature extraction, it is adopted in this work for apple stem/calyx and defect characteristics extraction.

SVM is a strong classifier which can identify two classes [10], and defect identification is to tell the ROI image is defect or stem/calyx. Therefore SVM is suitable for this problem. In fact, SVM is also of some advantages. SVM is on the basis of Vapnik-Cheervonenkis (VC) dimension theory in SLT (Statistic Learning Theory) and structure risk minimization principle. In order to achieve the best generalization, SVM makes the compromise between model complexity and generalization. Compared to other classical learning methods, SVM can overcome traditional learning flaws, such as over-learning and less-learning and driven to local minimum as well. For the situation which input samples can't be separated in a linear space, SVM can carry on a non-linear transform and change this inseparable problem into a divisible question in a high-dimensioned space and figure out its optimal classification surface in this space. Classification can be realized through inner product computation with SVM core function in a high dimensioned space, but computation complexity is not increased.

## 2 Identifying Apple Surface Defects using Gabor Transform

This section describes the method for the identification of the defect on apple surface using Gabor transform. First, Gabor wavelet representation of apple images derives desirable features characterized by spatial frequency, spatial locality, and orientation. Second, the Gabor wavelet features of apple images are used as the input space in SVM.

### 2.1 Gabor Transform

The Gabor wavelets can be defined as follows:
$$ \psi_{\mu,\nu}(z) = \frac{\| k_{\mu,\nu} \|^2}{\sigma^2} e^{-\frac{\|k_{\mu,\nu}\|^2 \|z\|^2}{2\sigma^2}} \left[ e^{i k_{\mu,\nu} z} - e^{-\frac{\sigma^2}{2}} \right] \quad (1) $$

Where $z = (x,y)$ are the spatial coordinates, the parameter $\mu$ and $\nu$ define the orientation and scale of the Gabor kernels, $\|\cdot\|$ denotes the norm operator, and $k_{\mu,\nu}$ is defined as follows:

$$ k_{\mu,\nu} = k_{\nu} e^{i\phi_{\mu}} \quad (2) $$

Where $k_{\nu} = k_{\max} f$ and $\phi_{\mu} = \pi\mu/8$. $k_{\max} = \frac{\pi}{2}$, and $f = \sqrt{2}$.

In most cases one would use Gabor wavelets of eight orientations, $\mu \in \{0,...,7\}$, and five different scales, $\nu \in \{0,...,4\}$. Fig.1 shows the real part and magnitude of Gabor wavelets kernel under five scales and eight orientations. The Gabor wavelets exhibit desirable characteristics of spatial frequency, spatial locality, and orientation selectivity.

<figure><img src="image_3.png" /><figcaption>**Fig. 1** Gabor Wavelets. (a) The real part of the Gabor wavelets at five scales and eight orientations. (b) The magnitude of the Gabor wavelets at five different scales.</figcaption></figure>

The Gabor wavelet representation of an image is the convolution of the image with a family of Gabor wavelets as defined by Equation 1. Let $I(x,y)$ be the gray level distribution of an image, the convolution of image $I$ and a Gabor wavelet is defined as follows:

$$ O_{\mu,\nu} = I(z) * \psi_{\mu,\nu}(z) \quad (3) $$

Where $z = (x,y)$, and $*$ denotes the convolution operator, and $O_{\mu,\nu}(z)$ is the convolution result corresponding to the Gabor wavelets at orientation $\mu$ and scale $\nu$. Therefore, the set $S = O_{\mu,\nu}(z) : \mu \in \{0,...,7\}, \nu \in \{0,...,4\}$ forms the Gabor wavelet representation of the image $I(z)$.

Applying the convolution theorem, we can derive each $O_{\mu,\nu}(z)$ from Equation 3 via the Fast Fourier Transform:
$$ \mathcal{F}\{O_{\mu,v}(z)\} = \mathcal{F}\{I(z)\}\mathcal{F}\{\psi_{\mu,v}(z)\} \qquad (4) $$

and

$$ O_{\mu,v} = \mathcal{F}^{-1}\{\mathcal{F}\{I(z)\}\mathcal{F}\{\psi_{\mu,v}(z)\}\} \qquad (5) $$

In order to obtain the input feature vector, we concatenate all these representation results and derive an augmented feature vector X. Before the concatenation, we first downsample each $O_{\mu,v}$ by a factor $\rho$ to reduce the space dimension and normalize it to zero mean and unit variance. We then construct a vector out of the $O_{\mu,v}(z)$ by concatenating its columns. Now, let $X_{\mu,v}$ denote the normalized vector constructed from $O_{\mu,v}$, the augmented Gabor feature vector X is then defined as follows:

$$ X = (X_{0,0}X_{0,1}\dots X_{4,7}) \qquad (6) $$

The augmented Gabor feature vector thus encompasses all the elements (down-sampled and normalized) of the Gabor wavelet representation as important discriminating information.

## 2.2 Defect Identification on Apple Surface

An image of apples is shown in Fig 2a. In order to obtain apple region, the background region has to be removed. In addition, each apple is a region of interest (ROI) and needs to be extracted individually. In this work, we use threshold method to extract apple image. That is, the R channel in RGB color channels is taken into account. The apple region can be obtained by using the following equation:

$$ I(x, y) = \begin{cases} \text{background pixel} & R < 118 \\ \text{apple pixel} & \text{otherwise} \end{cases} \qquad (7) $$

If $I(x,y)$ is identified as a background pixel, we let $I(x,y)$ be equal to 255. The segmented image is shown in Fig 2b. Each apple in a single image can be easily extracted from the segmented image individually.

<figure><img src="image_4.png" /><figcaption>Fig. 2 (a) Original image of apples. (b) The segmented image.</figcaption></figure>
In order to get the defect region in apple surface, we first convert the segmented color apple image into grayscale image by using the following equation:

$$I_{Gray} = 0.299I_{Red} + 0.584I_{Green} + 0.114I_{Blue} \quad (8)$$

Where $I_{Red}$, $I_{Green}$, and $I_{Blue}$ are the 8-bit color value of a given pixel in the segmented image.

Then a threshold is used to extract dark areas within apples, such as defects, stem, and calyxes, as region of interesting. However, in our experiments, we find this method of extracting ROI in apple surface can't obtain all dark areas within apples.

In this study, a new method is proposed to extract dark areas within apples. We first use the following equation to get the grayscale of each apple.

$$I_{Gray} = \text{MAX}\{I_{Red}, I_{Green}, I_{Blue}\} \quad (9)$$

Then a threshold $\theta$ is used to get dark ROI in apple surface.

$$I_{Binary} = \begin{cases} 0 & I_{Gray} < \theta \\ 255 & \text{otherwise} \end{cases} \quad (10)$$

Finally, morphological operation is employed to refine the segmentation.

After segmentation operation is completed, we can utilize the central coordinate $(x,y)$ of dark ROI to extract a 64x64 region in original color apple image that centers on $(x,y)$. The extracted color ROI in apple surface is shown in Fig 3:

<figure><img src="image_5.png" /><figcaption>**Fig. 3** The segmented region of interesting in an apple image.</figcaption></figure>

In this work, Gabor wavelet filter is used to extract Gabor wavelet features from ROI image. Two downsampling operations are employed to the features. So a 64x64 feature image becomes a 16x16 feature image. We then construct feature vector by concatenating its columns. The feature vector is used as input vector for SVM.

There are four following basis kernels of SVM: linear, polynomial, radial basis function (RBF), and sigmoid. In this paper, we use SVM with the linear function kernel as a black box classifier over the labeled set of feature vectors. Doing so yields support vectors in the feature space.

## 3 Experiments and Results

The machine vision system for apple quality inspection is shown in Fig.4. It consists of a computer-controlled frame grabber that is based on the PCI Express interface and
an image sensing system, which is a digital progressive scan color CCD cameras (JAI CV-A70CL) with a C-mount lens of 8mm focal length. The color images are grabbed and analyzed by a host computer equipped with a Dalsa X64-CL Express frame grabber. A lighting chamber was designed to provide uniform illumination for the CCD sensor. The chamber size is 90(W)*100(L)*100(H) cm. In order to provide lighting, two warm-white lamps with color temperature 5400K are mounted above the conveyor. The CCD imaging sensor is mounted inside on the two sides of the chamber. A roller conveyor belt is built to hold and move apples in one lane. All apple samples are manually placed on the conveyer belt with a random orientation. The apples are rotating and moving when they pass through the view of the two CCD cameras. The whole surface of each apple can be covered by the CCD camera during the apple rotation. A drive controller and speed controller are connected with a photoelectric switch that provides precise timing signals for both on-line mechanical and electrical synchronization.

<figure><img src="image_6.png" /><figcaption>**Fig. 4** The machine vision system.</figcaption></figure>

A total of 200 color apple images are acquired. From these apple images, we can obtain 90 stem regions, 90 calyx regions and 90 defect regions. The stem/calyx and defect images that are used in our experiments are shown in Fig5: the first row is calyx image, the second row is stem image, and the last row is defect image.

<figure><img src="image_7.png" /><figcaption>**Fig. 5** The stem/calyx and defect images.</figcaption></figure>

We first segment the ROI in apple surface and convert the color ROI to grayscale image. For each gray image, Gabor wavelet filter is used to extract the texture features, and these features is employed to the input of SVM. Finally, the identification results are given by SVM. In our experiments, the training dataset includes 50 stem images,
50 calyx images and 50 defect images. The testing set includes 40 stem images, 40 calyx images and 40 defect images. The overall defect identification rate is 85%.

## 4 Conclusion

External quality grading of apple fruits by machine vision is still an open, tedious and challenging problem. Accuracy of this task depends on several subtasks, one of which is precise recognition of defect areas.

In this paper, a defect identification method based on Gabor wavelet features is introduced. Firstly, this method accurately obtains the ROI in apple surface. Then Gabor wavelet filter is used to extract the texture features of ROI, and these features are employed to the input of SVM. Finally, in the experiments were conducted and the overall defect identification rate is 85%.

**Acknowledgments.** Our project is supported by Young Scientists' Foundation of Beijing Academy of Agriculture and Forestry Sciences (Project No. QN201119) and National High-Tech Research and Development Program of China (863 Program) (Project No. 2011AA100703).

## References

1. P.H. Heinemann, Z.A. Varghese, C.T. Morrow, H.J. Sommer III, R.M. Crasswelle. Machine Vision Inspection of 'Golden Delicious' Apples. Applied Engineering in Agriculture, Vol.11(6):901-906(1995)

2. Ingrid Paulus, Eddie Schrevens. Shape Characterization of New Apple Cultivars by Fourier Expansion of Digitized Images. J. Agric. Engng Res, Vol.72:113-118(1999)

3. Zou Xiao-bo, Zhao Jie-wen, Li Yanxiao, Mel Holmes. In-line detection of apple defects using three color cameras system. Computers and Electronics in Agriculture, Vol.70:129-134(2010)

4. T. G. Crowe, M.J. Delwiche. Real-time defect detection in fruit part I: Design concepts and development of prototype hardware. Transactions of the ASAE, Vol.39(6):2299-2308(1996)

5. T. G. Crowe, M.J. Delwiche. Real-time defect detection in fruit-part II: an algorithm and performance of a prototype system. Transactions of the ASAE, Vol.39(6):2309-2317(1996)

6. Zhiqing Wen, Yang Tao. Building a rule-based machine-vision system for defect inspection on apple sorting and packing lines. Expert Systems with applications, Vol.16(3):307-313 (1999)

7. Wen, Z., Tao, Y. Dual-camera nir/mir imaging for stem-end/calyx identification in apple defect sorting. Transactions of the ASAE, Vol.43(2): 449-452 (2000)

8. Kleynen Olivier, Leemans Vincent, Destain, Marie-France. Development of a multi-spectral vision system for the detection of defects on apples. Journal of food engineering, Vol.69(1): 41-49 (2005)

9. Tai Sing Lee. Image representation using 2d gabor wavelets. Pattern Analysis and Machine Intelligence, IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol.18(10): 959-971 (1996)

10. Christopher J. C. Burges. A Tutorial on Support Vector Machines for Pattern Recognition. Data Mining and Knowledge Discovery, Vol.2(2):121-167(1998)