Abstract
In order to improve the working efficiency of robot promptly picking ripe apples, the harvesting robot must have the ability of continuous recognition and operation at night. Nighttime apple image has many dark spaces and shadows with low resolution, and therefore, a Retinex algorithm based on guided filter is presented to enhance nighttime image in this article. According to color feature of image, the illumination component is estimated by using guided filter which can be applied as an edge-preserving smoothing operator. And the reflection component with image itself characteristics is obtained by employing single-scale Retinex algorithm. After gamma correction, these two components of image are synthesized into a new enhanced nighttime apple image. Fifty nighttime images acquired under fluorescent lighting are selected to make experiment. Experimental results show that the image enhancement performance indexes processed by the proposed algorithm, such as average gray value, standard deviation, information entropy, average gradient, and segmentation error are superior to those of histogram equalization algorithms and Retinex algorithm based on bilateral filter. In addition, compared with the Retinex algorithm based on bilateral filter, the proposed algorithm has an average reduction of 74.56% in running time with better real-time and higher efficiency. So it can realize the continuous operation of apple harvesting robot at night.
Introduction
At present, the apple harvesting largely relies on manual operation with big labor intensity, long time, low efficiency, and even a certain risk. In recent years, apple harvesting robot receives widespread concern, and has developed rapidly. 1,2 However, with an increasing market demand and large planting for apple, the working efficiency of apple harvesting robot needs to be improved for picking ripe apples timely. As a kind of highly automatic operation machine, extending the working time of the robot by continuous operation at night is an effective way to improve the harvesting efficiency.
Accurate acquisition of nighttime image information is the precondition of the harvesting robot to realize the night operation. However, a few factors such as environment and night illumination increase the difficulty of image acquisition and image processing. Recently, little research for apple nighttime image is available. Payne et al. 3 acquired images of fruit at an earlier stage of maturation (“stone hardening” stage) for the previous study with artificial lighting at night. Then combined with color features of YCbCr and texture to calculate the number of mango and estimate the yield of mango. Font et al. 4 utilized artificial lighting at night to collect the Red, Green, Blue (RGB) images of mature grapes in the vineyard. Detecting the grapes on the surface of spherical reflection peak to calculate the number of grapes and to estimate the production of fruit. Liu et al. 5 used artificial lighting and adjusted the lighting angle to acquire the less shadow apple images at night. Improving the R-G color difference segmentation and doing the second segmentation at highlight reflective area to achieve the correct recognition of apple images. The correct recognition rate reached 83.7%. Jia et al. 6 utilized Particle Swarm Optimization-Independent Component Analysis to maximize the removal of noise pollution and realize the nighttime recognition of the apple harvesting robot. Studies mentioned above have provided great theoretical basis in night operation of the harvesting robot.
The environment is relatively complex at night. Different from the natural light during the day, the light at night is insufficient. So the collected images face with several problems of dark, fuzzy, low-contrast, unclear details, and limited dynamic range compression, which have brought new challenges to the nighttime operation of the harvesting robot. Image enhancement and denoising are two keys to night image processing. 7,8 In recent years, Retinex algorithm with rapid development better deals with the weak light image, the shadow image, and the fog image, and it performs very well in a great variety of applications, including aerospace, remote sensing image, aerial image, video monitoring, and other fields. Retinex algorithm is based on the theory of color constancy and assumed that the reflection properties of objects surface on short wave, middle wave, and long wave of light determine the color of the object. The key of Retinex algorithm is to estimate the scene illumination component from the original image, and obtain the reflection component with high-frequency information, so as to achieve the purpose of enhancement. 9,10 Along with the study of the illumination estimation methods, numerous improved Retinex algorithms have appeared. 11 Although these enhancement algorithms perform well in the nighttime image, flog image, and low-illumination color image, when estimating the illumination in the high-contrast edge region, high and low pixels near edges will influence the result of illumination estimation, which suffers from the gradient reversal artifacts in the region of the gradient sudden change 12 and then influences the enhancement effect. The linear guide filter with smoothing and edge-preserving properties can avoid the mutual influence between high and low pixels near the high-contrast edges when making illumination estimation, highlight the detail information, and smooth the image. 13,14 Therefore, the proposed method has unique advantages in dealing with low-illumination image.
So after analyzing the characteristics of the nighttime image, the article puts forward edge-preserving Retinex enhancement algorithm of nighttime image for apple harvesting robot, which utilizes linear and edge-preserving guide filter to estimate the illumination component and gamma correction to reduce illumination influence. Then, a single-scale Retinex algorithm is harnessed to realize the logarithmic transformation of image to obtain the reflection component which contains only the object itself. Also it needs to use the improved gamma transformation to correct the reflection component. Finally, the two components of the image are synthesized into a new image, which is the enhanced image.
Analysis of apple nighttime image
Apple nighttime images are collected from the apple experimental field in DaShahe of Fengxian in Xuzhou in November 2015. The light intensity in field is less than 1 Lux which is measured by Illumination tester TASI-8720 of Suzhou Teansi electronics Co. Ltd (Suzhou, China). The camera is difficult to imaging without auxiliary light source. Therefore, a white fluorescent lighting installed on the harvesting robot whose power is 32 W and color temperature is over 5000 K is applied in this experiment. Nighttime images are collected by Complementary Metal Oxide Semiconductor camera whose type is UniflyM216 and pixel is 5 million, consistent with the resolution of the camera of the harvesting robot which is independently developed by the laboratory, the collected images are adjusted to 640 × 480. Some apple images collected under the fluorescent lighting during the night time are shown in Figure 1.

Apple nighttime images.
From Figure 1, it can be seen that there are numerous dark regions in the background of the nighttime image with low resolution. Despite the target fruits are bright in the nighttime images, there are some highlight reflective areas, shadows, and fuzzy edges.
By programming in the MATLAB 2010b, image histograms of Figure 1 are shown in Figure 2. The image histograms of the nighttime are mainly distributed in [0, 0.4], which indicate that dark areas occupy the main part of the images and the contrasts are low. Therefore, nighttime image recognition, different from day image recognition, needs to adopt image enhancement method to make apple stand out from the dark. The outline and details of apple are distinct after the image enhancement, which provide guarantees for subsequent steps for image segmentation and feature extraction.

Image histogram of apple nighttime image.
In order to further examine the change of gray level of the apple edge, the gradient vector diagrams of three nighttime apple images are drew in Figure 3(a), (c), and (e). Figure 3(b), (d), and (f) shows the partially enlarged view of the block in Figure 3(a), (c), and (e), respectively. There the direction of the arrow represents the gradient direction. In other words, it is the direction of the gray level maximum change rate which reflects the gray level change on the edge of the image. The length of the arrow represents the gradient value, namely, the size of the gray level change rate. In the figure, the gradient values on the edge significantly are greater than the ones around the neighborhood. Obviously, there are numerous large gradient pixels and dramatically changeable gray levels on the edge. The figure further shows that the gradient sudden change on the edge of the target apple fruit is apparent.

Gradient vector drawing of apple nighttime image. (a) Gradient vector drawing of apple nighttime image of Figure 1(a); (b) local amplification drawing of (a); (c) gradient vector drawing of apple nighttime image of Figure 1(b); (d) local amplification drawing of (c); (e) gradient vector drawing of apple nighttime image of Figure 1(c); and (f) local amplification drawing of (e).
Retinex algorithm based on guided filter for apple nighttime image enhancement
When utilizing traditional Retinex algorithm to estimate the illumination in the high-contrast edge region, the high and low pixels on both sides of the edge will affect illumination estimation value. The traditional Retinex algorithm applied directly to deal with the nighttime image with gradient sudden change is bound to result in the illumination distortion of the gradient sudden change region. While estimating the illumination by utilizing the linear guided filter, which has good edge-preserving smoothing properties, can avoid influence between the high pixels and low pixels near the high-contrast edge. Therefore, the improved Retinex algorithm which adopting the guided filter to estimate the illumination component is proposed. The specific implementation process is shown in Figure 4. First, the apple nighttime image is transformed from RGB color space to Hue, Saturation, Intensity (HSI) color space, and the color component II is achieved. Then estimating the color component II by guided filter and the illumination component is precisely estimated in the high-contrast edge region. Then gamma corrects the illumination component. Second, single-scale Retinex algorithm is applied to obtain reflection component by the logarithmic transformation, then using the improved gamma transformation to correct reflection component. Afterwards, a new image composed of the corrected illumination component and reflection component is transformed from HSI color space to RGB color space. The final enhanced image can be obtained eventually.

The flowchart of the proposed algorithm.
Select for color space model
Retinex algorithm is based on the gray world assumption; therefore, enhancing the image in RGB color space easily causes color distortion. 15 While Retinex algorithm based on intensity image II utilized to estimate the illumination component can effectively avoid the influence of the light to achieve good enhancement effect. 16 In many color space models, CIELAB color space can express any color in nature and it has larger color space than RGB. It describes the human visual sense in a digital way, the advantage is that it makes up for the deficiency of the RGB mode which depending on the device color characteristics and uneven color distribution. CIELAB is the most uniform color space at present. It has nothing to do with the device and is suitable for the occasion of close to natural lighting. Hue, Saturation, Value (HSV) color space model, which is closer to people’s experience and perception of color than RGB, corresponds to a conic subset in the cylindrical coordinate system. It is an intuitive color model for user, but it also determines that it is not suitable for use in the illumination model, and some light intensity calculation, light mixing operations, and so on, and cannot be directly implemented by HSV. HSI color space can be described by a cone space model. Compared with HSV, HSI better reflects the intuition of “saturation” and “Intensity” as two independent parameters. HSI model fully reflects the basic attribute of human perception of color, and color perception results correspond. It can eliminate the influence of the intensity component in the color information (hue and saturation) carried by the color image, thus a large number of image processing and computer vision algorithms can be easily used in HSI color space, which can be handled separately and are independent of each other. Thus, the workload of image analysis and processing can be greatly simplified in HSI color space. Therefore, this article selects HSI color space for image enhancement processing and uses the conversion equation, which is given by Zhang et al., 17 to transform the original image from RGB color space to HSI color space. After obtaining hue image IH , saturation image IS , and intensity image II , only the intensity image II is estimated by using guided filter to calculate the illumination component.
Estimate the illumination component based on guided filter
Some key assumptions of the guided filter are as follows: original image I is guidance image, intensity image II is the input image, and q is the filtering output image, namely, the illumination image L(x, y). This article will focus on the color image, so I is the multichannel image and the guided filter is applied to each independent channel of I. At this point, the guided filter can be expressed as a partial linear function model 13
where II,j is a 3 × 1 color vector and ak is a 3 × 1 coefficient vector. Setting wk as an image window with radius r, k is the center pixel of wk , and bk and qj are both scalars. This local linear model ensures that q has an edge only if I has an edge, because
In order to get ak and bk , linear regression analysis is utilized, in which the error between the input value and the output value of the expectation function is minimum, namely, equation (3) has a minimum
Using fitting approximating method based on least square for equation (3), ak and bk are gained as follows
where

Estimation result of illumination image. (a) Guidance image; (b) input image; and (c) output illumination image.
Reflection image acquisition
After obtaining the scene illumination image and removing it from original image, the reflection image, which contains the detail information, can be acquired. According to the Retinex algorithm, a given image I(x, y) can be decomposed into two different images: reflection image R(x, y) and illumination image L(x, y). R(x, y) reflects the essential attribute of the image and L(x, y) directly determines the dynamic range of the pixels in the image. So image can be seen the product of R(x, y) and L(x, y)
Usually, the logarithmic transformation is used to convert product relation to sum relation in the Retinex calculation
In practice, directly obtaining R(x, y) is not realistic. Therefore, R(x, y) can be obtained by putting L(x, y) into equation (7), as shown in Figure 6.

The reflection image.
Reflection image correction
The obtained reflection image mentioned above includes specific information of original image, which can be adjusted to improve its quality. Improved gamma correction by Rao et al. 12 is adopted to adjust the brightness of image in this article. First, the grayscale dynamic range is compressed to [0, 1], and then the following improved gamma transformation is utilized to correct it
where γ is the correction parameter, and Figure 7 shows the brightness mapping. To achieve the enhancement of the low-illumination region and avoid the over enhancement of the high brightness region simultaneously, the brightness is adjusted. Then a high-contrast image is obtained by increasing the brightness dynamic range. At this point, the brightness mapping curve is a steep upward trend.

The luminance mapping of reflection image.
Figure 7 reflects the corresponding mapping relationship of gamma transformation (γ = 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8), and the reference line y = 0.8 is drawn for observation in the diagram. When the mapping relationship between the input gray level and the output gray level meets the function y = x, the image is not corrected. When γ = 0.6, after correction, most low pixels are above y = x, less high pixels are below y = x, that is to say the low brightness area can be enhanced and the excessive exposure of the high brightness area can also be effectively suppressed. When γ = 0.8, after correction, less low pixels are above y=x, most high pixels are below y=x, that is to say this reference line has better correction effect on the overall higher brightness image.
In order to enhance the low-illumination image, the correction parameter value less than 0.6 is chosen in this article, and Figure 2(b) shows that the histograms of the nighttime image are mainly distributed in [0.1, 1], so only the correction of each transformation in the input gray level greater than 0.1 needs to be considered. When γ = 0.5, high pixels almost remain the same and have no correction. When γ = 0.1, 0.2, 0.3, and 0.4, the angle between the curve and the line y = 0.8 is higher and the curve is steeper which means that the correction effect is more obvious. Therefore, this article takes γ as 0.4. The reflection component image after gamma transformation correction is shown in Figure 8.

Reflection image after correction.
Synthesis enhancement image
Influenced by the artificial lighting, the collected image is overall darker. Actions must be taken to reduce the effect of the illumination image. Therefore, gamma transformation is harnessed to correct the illumination image
where β is the correction parameter, taking it the empirical value as β = 3. Finally, the two components of the image are synthesized into a new image which then transformed from HSI color space to RGB color space. The final target enhancement image is shown in Figure 9. Obviously, the method not only reduces the interference of background and highlights the apple fruit but also expresses details more clearly.

The enhanced result.
Guided filter parameter analysis
When using guided filter to estimate the illumination component, filter window r and adjustment parameter ε have certain effect on the filter result. While the larger r is, the guidance image will be carried out in a larger range, which makes the edge details more abundant and the transition more smoothed. But when r is too large, averageness on both sides of the edge is excessive and the edge smoothing is more obvious but not stable. Referring to the works of Tang et al., 18 r = 2, 8, 30, and 200 is chosen to make an experimental comparison, it is found that when r = 8, enhancement effect is better. The size of the input image is 640 × 480, ε is 10−3, and r is selected for 2, 8, 30, and 200 (Figure 10). Comparing four enhancement effect images, it can be seen when r is lesser, target fruit edge appears white blur. When r increases, the edge is more smoothed but with blurring effect, which indicates the edge-preserving is poor. So in this article, r is 8.

The enhanced results for different filter windows. (a) r = 2; (b) r = 8; (c) r = 30; and (d) r = 200.
When guided filter is used as the edge-preserving filter, I = II
, if ε = 0, obviously a = 1, b = 0 is the optimal solution, and from equation (1), the filter has no effect and the output value is the input value at this time. If ε > 0, in the area of small pixel intensity changes or in the monochrome area, a ≈ 0 and b ≈

The enhanced results for different adjustment parameters. (a) ε = 10−1; (b) ε = 10−2; and (c) ε = 10−3.
Experimental results and analysis
The computer configurations are as follows: host processor configuration: CPU Intel(R) Core(TM) i3 2.27 GHz, RAM 2 GB, graphics card: ATI Mobility Radeon HD 4500/5100Series, running environment: 32bit Windows 7, MATLAB R2010b. The pseudo-code to state the proposed algorithm is as follows:
Selecting randomly three groups nighttime apple images acquired under fluorescent lighting to make simulation experiment research compared with the proposed algorithm, histogram equalization algorithm, 13 and Retinex algorithm based on bilateral filter. 19 In this article, the relevant parameter of bilateral filter algorithm is: the size of the bilateral filter: 15 × 15, σs = 100, and σr = 0.3.
The visual effect contrast of different image enhancement methods
The experimental results are shown in Figure 12. It can be seen that the three methods have enhancement effect to some extent. After the histogram equalization algorithm is utilized, the image brightness has been greatly improved, but the reflective part of the apple has been enlarged, and the apple fruit in the dark region has not been fully displayed. After using Retinex algorithm based on bilateral filter, good edge-preserving smoothing properties like proposed algorithm in the article is obtained. But there has a circle of white halo on the edge of the apple gradient sudden change region. While utilizing the algorithm proposed in this article, the apple fruit is more prominent. The details are clearly visible in the darker area and with no over enhancement. The visual effect has been improved significantly and the outline of target fruit is clear while the halo has been well suppressed.

The contrast of enhanced processing results: (a), (e), and (i) Original image; (b), (f), and (j) histogram equalization algorithm; (c), (g), and (k) Retinex algorithm based on bilateral filter; and (d), (h), and (l) proposed algorithm. (a) to (d) First group; (e) to (h) second group; and (i) to (l) third group.
Further comparison of experimental results is made to better illustrate the superiority of this algorithm. Local amplification of the target apple of the images, which is enhanced by Retinex algorithm based on bilateral filter and this proposed algorithm, is shown in Figure 13. The left is for bilateral filter algorithm and the right is for the proposed algorithm of each group. From the target fruit edge local information: after using this algorithm proposed in this article, the edge detail information is enhanced, the outline is smoothed, and the apple is more prominent in the image. The most important of all is the gradient reversal artifacts are noticeable near some edges in the joint bilateral filter result. Notice that gradient reversal artifacts often introduce new profiles around edges.

The local amplification of apple fruit of Figure 12(c) and (d), Figure 12(g) and (h), and Figure 12(k) and (l). (left: Retinex algorithm based on bilateral filter; right: proposed algorithm).
Comparison of segmentation recognition results of enhanced image
Due to limited light range, uneven illumination, and poor stability of artificial light source, the nighttime apple images acquired under fluorescent auxiliary lighting have relatively bright colors but with highlight reflective area which makes apple recognition completely difficult. The typical R-G color segmentation algorithm is adopted separately to deal with three original images and the image processed by the proposed method. After removing the noises by morphology filtering, the threshold area elimination method, or other approaches is used, 20 and finally the target of apple segmentation recognition effect is obtained as shown in Figure 14. The left is the recognition effect without enhancement and the right is the recognition effect with enhancement by the proposed method of each group. Obviously, the dark area of the apple is displayed with clear outline. The target apple recognized is more complete which is advantageous to the fruit picking.

Apple segmentation recognition result before and after image enhancement (left: non-enhanced image; right: enhanced image).
The performance indexes comparison and analysis of different image enhancement methods
Performance indexes like average gray value, information entropy, standard deviation, average gradient, and running time are used to evaluate the quality of image enhancement effect for further performance comparison of different image enhancement algorithms. 21 –23 The average gray value reflects the dynamic changes of the image brightness. As the standard deviation is bigger, the range difference and the contrast are greater. Information entropy indicates how much information contained in the image. Comparing the changes of information is to determine the enhancement effect of the image. Average gradient reflects the image quality of improvement and the rate of changes of tiny details. The greater the average gradient is, the more the image level is, and the clearer it becomes. In addition, the segmentation error as an impartial measure is adopted to evaluate the apple segmentation capability intuitively in night condition after the enhancement by above three algorithms. Segmentation error e can measure the distance between experimental result and the estimated target. It is defined as 24,25
where Sa is the divided area of the target by segmentation method, and S0 is the actual area of the target, which is obtained by a computing program and Adobe Photoshop software [version CC 2014]. Segmentation error reflects the enhancement effect of the above three image-enhanced algorithms intuitively, smaller segmentation error means better nighttime image enhancement.
The above three algorithms are applied to image enhancement and segmentation recognition, and the quality of the results is shown in Table 1. Three algorithms increase the average gray value, standard deviation, information entropy, average gradient, and so on. That is to say the brightness dynamic range is increased, contrast is enhanced, and resolution is increased. The proposed algorithm has obvious advantages over other two algorithms.
The visual quality evaluation parameters of different enhancement algorithms for three images.
On the basis of the above three groups of experiments, 50 apple nighttime images acquired under fluorescent lighting are used for testing. The statistical results of objective performance indexes derived from different image enhancement methods show that the mean gray value of the 50 images after enhancement processed by the proposed algorithm, compared with the original image and histogram equalization algorithms and Retinex algorithm based on bilateral filter, increases averagely by 230.34%, 251.16%, and 7.75%, the standard deviation on average increases by 36.90%, −23.95%, and 28.00%, the information entropy increases averagely by 65.88%, 99.68%, and 17.53%, and the gradient on average increases by 161.70%, 64.71%, and 17.70%. Obviously, the details express more clearly after the proposed algorithm which increases the average gray value without noise signals processing. The information entropy of image is also improved, which makes the image more abundant. The enhancement effect is superior to other algorithms. In respect of running time of algorithm, compared with Retinex algorithm based on bilateral filter, the proposed algorithm has an average reduction of 74.56%, which reflects the real time and efficiency of this algorithm. In additional, the maximum segmentation error of the proposed method is less than 3%. Compared with two other algorithm, the segmentation error of the proposed algorithm decreases averagely by 62.71% and 26.01%.
Conclusions
In view of the characteristics of the nighttime image, this article proposes the Retinex algorithm based on guided filter for image enhancement. The proposed method utilizes linear guidance filter which has good edge-preserving smoothing properties as a function to estimate the illumination component of the image. Then the single-scale Retinex algorithm is applied to obtain the reflection component, and different gamma transforms are harnessed to adjust the illumination component and reflection component image. Finally, the two components are synthesized into a new enhanced image.
The proposed algorithm is used to enhance 50 images, and then, experimental comparison with other enhancement methods is made. Experimental results show that the average gray value, standard deviation, information entropy, average gradient, and segmentation error of the 50 images processed by this algorithm are more excellent than those traditional algorithms, such as histogram equalization algorithm and Retinex algorithm based on bilateral filter. And the image enhancement effect is better than the other algorithms.
The running time of histogram equalization algorithm is the shortest one but with poor enhancement effect. In contrast, the proposed algorithm improves the effect of image enhancement, and largely saves the time of processing, which is helpful to improve the accuracy and efficiency of the apple harvesting robot in the night.
Footnotes
Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Funding
The author(s) disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: This work was supported in part by the National Natural Science Foundation of China under grant 31571571, the Research Fund for the Doctoral Program of Higher Education of China under grant 20133227110024, the Natural Science Foundation of Jiangsu Province under grant BK20150530, a project funded by the Priority Academic Program Development of Jiangsu Higher Education Institutions, and the Professional Research Foundation for Advanced Talents of Jiangsu University under grant 14JDG077.
