1. Introduction
Performing segmentation operations in accordance with the desired purpose has different complexities. In principle, segmentation operations in agriculture and horticulture are more complex than other sectors. This complexity is because of crowded backgrounds with various objects. In applications such as site-specific spraying and combat weeds, segmentation is the first step in the design of machine vision systems [
1,
2,
3,
4]. The segmentation involves various steps depending on the complexity of the background of the image and may include a combination of several methods. Therefore, the programmer skill is very important in this field. Generally, the conventional methods of segmentation are color index-based segmentation, threshold-based segmentation and learning-based segmentation [
5] that in this research we used threshold-based segmentation method as one method that combine with other method. Bai et al. [
6] believed that segmentation of vegetation cover from field images is a necessary issue. For this reason, they proposed a new segmentation method based on particle swarm optimization clustering and morphological modeling in a color space of L*a*b*. In this regard, they captured images at 10, 12 and 14 o’clock.
The proposed method has two stages of offline learning and online segmentation. In the offline learning process, the number of optimized clusters was determined based on the training sample set. In the second step, each pixel was classified as vegetation class or non-vegetation class. In the last step, 200 images were used to test the proposed system. The results showed that the average segmentation quality of the images was 88.1% to 91.7%. Because of the successive droughts in the world and the consequent reduction in groundwater levels, as well as due to increased population, the need for agricultural water management is quite felt. One way to deal with water shortage is to use water only in areas where the crop has been cultivated, because it will only be consumed by the product and thus the amount of waste of water will be minimized. In large-scale lands, the possibility to achieve this without the use of new technologies is almost zero. For this reason, it is possible to detect places with crops using machine vision systems. In this regard Hernandez et al. [
7] believed that in order to achieve precision agriculture goals, not only new technologies but also software development were necessary. Therefore, they provided a new application of the machine vision system in the form of an automated segmentation system of plants from background to monitor the cabbage during growth, to provide product information that is needed to estimate the amount of water required for the crop. Their proposed system consisted of three main steps: 1) imaging and cutting, 2) analyzing the image, and 3) recording information. In order to imaging, wooden frames were installed inside the farm, and then the images were taken. In order to train the proposed system, 1106 cabbage samples were used. The results showed that the proposed system had a 20% error in counting the cabbage.
In another study Tang et al. [
8] provided a multi-inference trees segmentation method to better manage farms. The algorithm worked out based on image features and user requirements. In fact, the algorithm learns the related rules according to these two, and then applies the color space, the transformation to the gray image method, the de-noising method, the local segmentation method, and the morphology processing method after applying each rule. To train the proposed algorithm, 2082 images with a resolution of 1932 × 2576 were captured. A manual method was also used to evaluate intelligent results. The results showed that the intelligent processing assessment rate for more than 80 points was above 83% with an average of 75%. The processing time of each image needs about 23 seconds.
Liu et al. [
9] developed a machine vision system for segmentation of apple fruit based on color and position information. This system performs segmentation based on artificial light with low brightness. The proposed method had two main steps: the first step included the training of artificial neural network using RGB and HIS color space components and finally, it included the providing a model for apple fruit segmentation. Due to the presence of shadows in some parts of the apple (due to the no uniformity of light), the segment is not performed properly in this step, therefore, in order to complete the segmentation, a second stage, which also considers the color and position of the pixels surrounding the segmented area, is added. In their study, 20 apple fruits were used. The results showed that the proposed system has acceptable results in the segmentation of these apples.
As it was observed, the research focused on segmentation in two simple background states, such as separating the plant from the soil or having a segment on the artificial background. On the other hand, all research focused on analyzing the images taken. To formulate an appropriate segmentation algorithm for apple fruits under natural light conditions and a completely natural background in the presence of various objects such as leaves of tree, thin branches, thick branches, tree trunk, blue sky, cloudy sky, green plants, yellow plants, harvested fruits, and baskets, there is no possibility to use the results of researches done because of two reasons: 1. backgrounds are very complex and have different objects with different colors. 2. Camera movement in gardens needs for different operations, such as site-specific spraying, for this reason, the frames have no good quality. Therefore, the purpose of this study is to develop a segmentation algorithm for working in a completely natural environment both in terms of light and in terms of backgrounds using video processing, with emphasis on the segmentation of apples on trees.
In the last years horticulture has been one of the most important research objects in many universities in the world. We have found that the main works are directed to the recognition of fruits, counting, detection of plants, monitoring of irrigation, etc.
2. Materials and Methods
Each machine or computer vision system for development needs to have different stages, such as the filming stage, the stage of analysis, and so on. In this study, as same as other machine vision system, the steps have been designed to train the system. Some of these steps can be filming, examining different color models, extracting various texture features, employing different morphological operators and using the intensity transformation method.
2.1. Data Collection
In this study, a digital camera (DFK 23GM021 specification, CMOS, 120 f/s, Imaging Source GmbH, Bremen, Germany) was used to filming from apple gardens in Kermanshah province-Iran. In
Table 1, shows the related details of one of the videos from these gardens. As observed, there is a video more than 12 minutes that contains more than 22,000 frames that has been recorded in different days, times of the day, and weather conditions. Since the capability of performing of the segmentation system in different light intensities is an essential principle, the video was provided in full natural light conditions throughout the day with a completely natural background. Some light intensities were 398 lux, 1096 lux, 692 lux, 1591 lux, 1923 lux, 894 lux, 2010 lux, 918 lux, 798 lux, 493 lux and 579 lux.
We collected several films of orchards, but we used only 12 min (22,001 frames) of them for the training of the algorithm. We had filming in four stages of ripening, including Unripe (20 days before maturity), Half-ripe (10 days before maturity), Ripe and Overripe (10 days after maturity), that combined them for the training of algorithm.
The distance from the trees was between 0.5 and 2 m, the speed was around 1 m/s, and the viewing angle was nearly parallel to the ground. The camera was manually held, simulating a low-medium height flight of a drone. With the system described, which has a horizontal viewing angle around 80o an apple about 7 cm would be observed with a size of 20 pixels at a distance about 3 m over the trees.
Apple variety was Malus Domestica L., var. Red Delicious. We had filming in 4 stages of ripening include Unripe, Half-ripe, Ripe and Overripe.
2.2. Various Color Models
An image in different color models has different colors. In fact, different objects in one image, in each color model, will have different colors. This feature can be used to distinguish between different background objects and apples. For this investigation, 17 color spaces were investigated [
10,
11], which are shown in
Table 2.
2.3. Extraction of Texture Features
Intuitively, the texture of a region can be described by roughness and softness. In fact, different regions in one image can be formed from a very rough to very soft modes. Mathematically, there are several methods for describing the texture. One of these methods is the texture features based on the gray level co-occurrence matrix (GLCM) extracted from the position of the pixels with same values. In fact, this method presents an average of the entire area in which the texture is examined. Therefore, this study is not applicable because here it is necessary to examine the texture of all pixels. Another method is to measure the spectral range of the texture based on the Furrier spectrum. This spectrum describes periodic or nearly periodic two-dimensional patterns in an image. The Furrier spectrum performs spectral measurement in a polar coordinate system (i.e., based on radius and angle), since spectral properties are interpreted by describing the spectrum in polar coordinates as a simple function of S (
r, θ). In this function S is the spectral function and r and θ are variables of the polar system. Therefore, the function of S (
r, θ) can be considered as two one-dimensional functions of Sθ(
r) and Sr(θ) for each direction θ and each frequency r. Sθ(
r) for the constant values of θ shows the behavior of the spectrum along the radius, while S
r(θ) for the constant values of r shows the behavior of the spectrum along a circle with the center of origin [
10]. This method, like the previous method, provides the mean value for the entire area. In the third method, textural descriptors are applied to the entire image pixels, and finally, the results are also observed intuitively. Therefore, in this study, the texture features of local entropy, local standard deviation and local range were investigated.
2.4. Application of Morphological Operators
Outdoor operations under natural light with complex backgrounds are particularly sensitive, as unpredictable noise and effects can make it difficult to achieve the desired goal. One of the most important methods for removing these noise and unpredicted factors is the use of morphological operators. These operators include a wide range of operators, such as opening, closing, filling holes, deleting border pixels, removing objects with pixels less than threshold values, thinning, thickening, and others. In the proposed segmentation algorithm, opening, closing, filling holes and deleting objects with a number of pixels less than 100 were used at different stages. This threshold value was selected with trial and error and with the consideration of not removing the apple pixels.
The process of mathematical morphology in computational terms, consists of moving all the pixels of the image from left to right and from top to bottom in order to find isolated pixels, which are considered noise [
12]. This noise is eliminated by applying erosion and dilation with the following equations:
The operation open, disappears the fine points or fine structures and the operation close, fill the black holes of a certain size.
2.5. The Importance of Using Intensity Transformation
In segmentation, we are looking for methods that eliminate background objects and prevent the removal of target object pixels. The use of the intensity transformation method by limiting the pixel intensity variation in the desired range provides more differences between different objects. Therefore, in this study, a part of the segmentation operation was performed by changing the intensity from 0 and 1 to 0 and 0.6 with applying the threshold of 95. Since image were in uint8 data class pixels were multiplied in 225.
2.6. Different Stages in the Elaboration of Segmentation Algorithm
In
Figure 1 shows the main steps in creating a segmentation algorithm. As observed, there are 11 main stages in this algorithm.
4. Conclusions
In this study, a new method was developed for segmentation of apple fruits on trees under natural light conditions without using any artificial background with emphasis on video processing. The most important results are:
The most important challenges for the development of segmentation algorithm were the presence of different objects with different colors in a background. For example, a number of these objects include trees trunk in the shade, trunks of trees in the sun, tiny brunches in the shade, tiny brunches in the sun, tiny branches connected to trunks, green leaves in the sun, green leaves in the shade, pestle leaves, green plants, yellow plants, cloudy sky, sunny sky, artificial objects such as nylon, baskets, harvested apples, flakes and so on.
Appropriate color model among 17 color models examined was Luv. In fact, this model eliminates many leaves in the first stage.
The proper feature for performing the second stage of segmentation among the three texture features of local range, local entropy and local standard deviation was the local range.
The use of the intensity transformation method eliminated a large part of the pixels related to the trunk and tree branches.
The use of morphological operators in different stages of segmentation is necessary.
The use of color thresholds in the final stage of segmentation eliminates objects that have remained in the previous stages.
Results showed that the percentage of total detection of segmentation algorithm was 99.013%.
The highest sensitivity was related to apple class with the value of 99.242% and the highest specificity was related to the class of background objects with a value of 99.458%.
The results showed that the processor speed was about 0.825 seconds for the segmentation of a frame.
For future work, a fruit recognition system should be implemented and vegetables to improve recognition functionality and flexibility for wider use.
The process should be improved by extending its functions to process and recognize more variety of different fruit images. Besides that, a texture-based analysis technique could be combined with the existing three features analysis technique on the system in order to gain better discerning of different fruit images.