Research and Application of Fruit Segmentation Algorithm Based on Fuzzy Theory and Mathematical Morphology

This study puts forward an improved fruit segmentation algorithm based on fuzzy theory and mathematical morphology and constructs the morphological filter to filter the images based on mathematical generalized morphological open-close and close-open operations in the algorithm. Furthermore, it conducts fruit segmentation by using fuzzy theory and determines the segmentation threshold according to the characteristics of standard S function and combining with ambiguity. Experimental results show that this algorithm is effective and has achieved ideal effect in practical application.


INTRODUCTION
The imaging process of fruit is a multiple to one mapping process, which determines the fuzziness of the fruit itself; such fuzziness is unable to be solved by the classical mathematical theory. Fuzzy theory does not need to establish an accurate mathematical model and it is able to better describe this uncertainty of the image. Pal and King (1980) introduced fuzzy technology into the study of fruit processing. Since then, fuzzy technology has been more widely applied and researched in the field of fruit segmentation, attracted more and more attention and have achieved ideal results (Pal et al., 1983;Huang and Wang, 1995).
Threshold method is most commonly used as a method of fruit segmentation, characterized by simplicity, practicality and less calculation. Pal et al. (1983) proposed the fuzzy threshold method (Maragos and Schafer, 1987); introduced the fuzzy mathematical description of gray-scale image; selected the fruit segmentation threshold through calculating the fuzzy entropy of image and qualitatively discussed the impact of window width of membership function on threshold selection. Murthy (Li, 2014;Li and Bai, 2012) pointed out that the threshold not only relates to the window width of membership function, but also relates to its distribution characteristics and demonstrated the boundary conditions and symmetric conditions which shall be met by membership function. Liu and Lin (2008) proposed a threshold selection algorithm based on ambiguity, which selects the optimal threshold based on minimum ambiguity.
Nonlinear filter can remove the noise and keep maximum high frequency details at the same time (Zhang and Liu, 2006), which can make the fruit clear and vivid, thus triggering in-depth study. At present, there are many classical nonlinear filtering algorithms, such as median filtering (Wuying, 2012), morphological filtering (He et al., 2013;Wang, 2012), stack filtering and some improved filtering algorithms based on median filtering.
Morphological filter is a new type of nonlinear filtering method derived from mathematical morphology and its signal processing, fruit processing and fruit analysis have been widely used. At present, the morphological filters used by people mainly include morphological open and close operation filters and their cascading combination form. Maragos and Schafer (1987) proposed a type of morphological open-closing and close-opening filter, which can inhibit the positive and negative impulse noise in signals simultaneously. Zhao (2012) proposed the generalized morphological open connected closing and close connected opening operations, which can effectively overcome the disadvantages existing in traditional morphological filters by using multiple structuring elements and adaptive weighted average technology and better inhibit the mixture noise composed of impulse noise and Gauss noise.
At present, schemes of fruit segmentation conducted by using mathematical morphology and combining fuzzy theory are still rare and the theory and practice are still not perfect through the comprehensive analysis of studies on fruit processing at home and abroad. Therefore, based on the existing research results at home and abroad, this study puts forward an improved fruit segmentation algorithm based on fuzzy theory and mathematical morphology by taking the polystyrene production die fruit of a petrochemical enterprise in Guangdong as the research object. First of all, it conducts filtering processing of fruit by using mathematical morphological theory; then, it conducts fruit segmentation by using fuzzy threshold method. This algorithm has achieved ideal effect in practical application.

MATERIALS AND METHODS
Basic idea: Fruit segmentation is a key step from fruit processing to fruit analysis, as well as the main problem in low level vision in the field of computer vision. First of all, this study uses the method that combines fuzzy theory and morphology to conduct mathematic morphological filtering processing; then, it uses the fuzzy threshold method to conduct fruit segmentation; this effectively improves the quality of fruit segmentation. The algorithm idea is as shown in Fig. 1.

Threshold segmentation algorithm based on ambiguity:
The threshold segmentation algorithm based on ambiguity consists of three parts: construction of fuzzy set membership function, definition of ambiguity expression and solution of optimal threshold.

Construction of fuzzy set membership function:
Fuzzy set is described by the membership function. Based on the fuzzy set theory, fuzzy set A within domain X can be expressed as the membership function µ A (x); values within 0≤µ A (x) ≤1 reflect the degree of membership of the elements in X for A, namely when µ A (x) = 1, X completely belongs to A; when µ A (x) = 0, X does not belong to A completely. The closer to 1 A (x) is, the greater the degree of x belonging to A will be. For any given x ∈X, there is a corresponding uniquely determined membership function µ A (x) ∈ (0, 1), namely µ A (x) is from a mapping of X to (0, 1) and it uniquely determines the fuzzy set A.
According to fuzzy set theory, an fruit A of M×N and with L gray levels can be regarded as a fuzzy matrix of M×N order and then fruit X can be expressed as: where, X mn represents the gray level of (m, n) pixel; µ A (X mn ) represents the membership function of gray-scale fuzzy set of (m, n) pixel in the matrix, indicating the degree belonging to a gray level and 0≤µ A ≤1. Then, membership function µ A (X mn ) can be obtained by spatial domain (Xmn) through extraction according to standard S function. The standard model S function is as follows: ( ) x a where, parameter b = (a+c) /2: When X mn = b, µ A (X mn ) = S (X mn , a, b, C) = S (b, a, b, C) = 0.5. b is the segmentation threshold.

Definition of ambiguity:
There are many definitions in the fuzzy theory, of which the ambiguity defined by De et al. (1997) are generally recognized. The ambiguity defined by Maji and Pal (2010) is as follows. Assume domain X = {x 1 , x 2 , ..., x n }; for any fuzzy set: Is the Hamming ambiguity of A. A 0. 5 (x i ) is the cut matrix of fuzzy set A on 0.5. The Haming ambiguity is extended to two-dimensional form: where, µ A (x ij ) : The fuzzy matrix of fruit X µ 0.5 (X ij ) : The cut matrix of fuzzy matrix on 0.5, namely: Formula (5) shows that, the further from 0.5 µ A (X ij ) is, the smaller the d (A) will be and the clearer the set will be; the closer to 0.5 µ A (X ij ) is, the greater the d (A) will be and the clearer the set will be D (A) value is greater and the fuzzier the set will be. Therefore, the minimum ambiguity principle can be used to determine edge threshold b, namely: Therefore, function S relates to b and ∆b and then µ A (x ij ) and d (A) relates to b and ∆b: where, arg represents that seek inverse function, namely seek coordinate b at the maximum extreme point of function d (b, ∆b). In the practical calculation and processing, take a fuzzy bandwidth ∆b; scan each gray value in the possible value range of b; seek corresponding Hamming ambiguity and then seek the minimum value; finally, the segmentation threshold corresponding to the minimum ambiguity can be determined. When ∆b takes different values in the dynamic range, different segmentation thresholds can be got.

Fruit filtering based on mathematical morphology:
Theoretically, fuzzy threshold method is an ideal method for fruit segmentation. However, in fact, some difficulties still exist, which mainly reflect that for a true image, much noise still exists since target and background gray scale are mixed; on the histogram, there is much clutter and envelope itself is not very smooth besides corresponding peak envolope of the target and background. Therefore, it is necessary to conduct some pretreatment. This study uses mathematical morphological method to conduct smoothing, in order to display the useful peak envelope in the histogram clearly.
It is indispensable to filter the noise in fruit during fruit pretreatment with the purpose of filtering the noise in fruit generated due to various reasons, in order to keep the useful information being damaged. There are many filtering methods, including spatial domain, frequency domain, transform domain and morphological filtering. Morphological filtering is exactly the morphological smoothing and makes full use of morphological opening and closing operations to conduct repeated morphological erosion and dilation for fruit (in fact, it is the morphological opening and closing operation of image), in order to facilitate the separation of fruit target, remove noise, smooth the gray level within the target body and improve gray level of image.
Basic principle: The basic operations of mathematical morphology filtering include dilation, erosion, opening and closing operations.
Assume an fruit is f (x, y) and the set of structural element is b; conduct gray level dilation for image f (x, y) with structural element b, which is expressed as: Conduct gray level erosion for image f (x, y) with structural element b, which is expressed as: Opening operation of gray level image: Closing operation of gray level image: Construction of morphological filter: In practice, opening operation is generally used to eliminate the smaller bright details compared with the structural element, while basically maintaining unchanged of overall grey value of the fruit and larger bright areas; closing operation is generally used to eliminate the smaller dark details compared with the structural element, while basically maintaining unchanged of overall grey value of the fruit and larger dark areas. In order to remove all kinds of noise in bright areas and dark areas simultaneously, opening and closing operations should be combined to constitute a morphological Open-Close (OC) filter: Morphological Open-Close (OC) filter has translation invariance, progressive increase, duality and idempotent properties, etc.

Selection of structural elements:
The selection of structural elements is the key of fruit maintaining detail filtering; make the structure elements cover the important lines in fruit as much as possible, in order to remove the noise, while effectively maintaining the linear details in all directions of image. However, only one structure element is generally used in many morphological applications, thus often failing to produce satisfactory results. This study uses the composite filter consisting of multi-directional structural elements to conduct filtering processing for image. Taking  Use the morphological filter in formula (13) and conduct filtering for the fruit with 4 structural elements respectively to obtain results in 4 directions of the

Realization of fruit segmentation algorithm:
Assume fruit X has M×N dimensions and L different gray levels and the dynamic range of fuzzy bandwidth ∆b is [∆b min , ∆b max ], a ∈ [L min , L max -∆b], c ∈ [L min + △b, L max ].
The algorithm based on mathematical morphological filtering and minimum ambiguity segmentation threshold is as follows: Step 1: Conduct filtering processing for the fruit by suing mathematical morphological method.
Step 2: Set ∆b based on experience and calculate the fuzzy characteristic matrix according to formula (3).
Step 3: Calculate the ambiguity corresponding to different gray levels according to formula (5).
Step 4: Calculate the gray level corresponding to the minimum ambiguity as the threshold according to formula (8).
Step 5: Segment the image.

RESULTS AND DISCUSSION
Compile software by using VC#6.0 to process the die strip image and the algorithm flow chart is as shown in Fig. 2. The above algorithms are applied to Video fruit processing of the die strip in a chemical enterprise, in order to monitor the number of polystyrene tie strip, as shown in Fig. 3, where (a) is the original fruit of die strip, with the size of 128*128 and gray level of 256; (b) is the histogram of original image, which can display a lot of narrow pulse interference; (c) is the result after fuzzy threshold segmentation subject to morphological filtering; the binary fruit not only segments main target die strips, but also preserves many important details, which achieves better effect.

CONCLUSION
This study uses the composite filter consisting of multi-directional structural elements to conduct filtering processing for image, which achieves obvious filtering effect; the algorithm based on ambiguity threshold selection is an effective, simple and intuitive threshold segmentation method. The experimental results show that better effect can be achieved through combining both methods and using fuzzy threshold method to conduct fruit segmentation after filtering by using mathematical morphology.