Intelligent Detection Method of Fruit Based on Improved SSIM Algorithm

To detect fruits within the scope of monitoring and improve the accuracy and stability of the test results. Considering the deficiencies of the traditional method which detects slowly and has poor adaptability to environment, a detection algorithm based on improved SSIM is proposed herein. Using the characteristics of SSIM that combines three comprehensive factors: image brightness, contrast and structural similarity to calculate the similarity of the image to improve the impact of environmental factors on the monitor screen of test results. And it gives full consideration to the efficiency of algorithm and improves the shortcomings of the traditional method. The experiments proved that the improved method can detect the fruit accurately and efficiently.


INTRODUCTION
With the rapid development of China's economy, people's demand for their own safety and property security is constantly increasing (Wang et al., 2009). And it thus promotes the maturity of the monitoring technology. Most fruit detecting systems, however, are based on real-time record (Gao, 2006). Only when there is an inspector before the monitoring screen when some fruit enters the monitoring scope or the fruit changes, can they be made to alarm or process according to the change of the monitoring images, thus greatly reducing its security and practicality (Yang, 2008). Sensors and other hardware equipment are installed in some occasions which have higher demand for security to detect if some fruit enter a certain area. Despite the high safety, the cost is high. To solve this problem, this study proposes a method to detect motions of fruits within the fruit through software that detect the similarity of adjacent frames of the monitored images by improved SSIM (Structural Similarity) algorithm. And if the similarity is less than a threshold value, the monitored images can be judged to have changed (Wang, 2013).
Traditional methods are operated by pixel comparison, but this operation is too slow and affected by light and other environmental factors. The effect is not ideal. The proposed method in this study fully take into account the speed of operation and environmental factors and it can accurately determine whether the images of the surveillance fruit screen have changed. The experimental results show that the methods herein can effectively detect the motions of fruits in a complex environment (Duan et al., 2011).

MATERIALS AND METHODS
Early warning model of food safety: Determining whether there is a fruit movement in the fruit based on per-pixel comparison, is a more traditional approach. Here is the principle: firstly take the R, G, B values of pixels in the same position of adjacent frames; secondly subtract one from the other respectively to get the difference; then subtract the difference from the RGB values of the first frame to get the values and thus dividing these values by the RGB values of the first frame can get the similarity degree between two frame images and so on; the process is packaged and placed in a sub-thread, which achieves a detection whether there is some fruit or something enters the monitored area (Mi, 2014;Premaratne and Premaratne, 2014).
However, this detection method is very timeconsuming. Assuming a frame size of the image is 760*480 pix, to obtain the values of R, G, B, the software need to compute three times. And thus the amount of calculation for an image is 760*480 pix *3. Therefore, the amount of calculation of each comparison is: 760*480 pix * 3 * 2 = 2188800. It can be seen that if you use this method to determine the motion in the fruit, the running speed of the software cannot keep up. Although it can compare the sample of the pixel, the accuracy is degraded.
In addition, the traditional detection method is conducted by comparing the color value of the pixel, so when the environment changes, it has much effect on the test results. For example, when the light changes, the corresponding change in the luminance of the fruit will cause the change in the pixel color of the adjacent frames, thereby greatly affecting the accuracy of the test result. Although there is no change in the structure of the object. Or when the detected fruit is rotated by a certain angle, though there is no change in its structure, it can still cause great error in the test result (Duan et al., 2010).

Motion detection method based on the improved SSIM algorithm: SSIM (Structural Similarity) is a new
index to measure the similarity of the two images (Charrier et al., 2012). As the implementation of structural similarity theory, the structural similarity index is measured through three factors: Brightness, contrast and the structure of fruits in the image. It is often used in image processing. Especially when it is used in image de-noising processing, it is full beyond the SAR (Signal to noise Ratio) and PSNR (Peak Signal to Noise Ratio) on the image similarity evaluation. This study presents that this algorithm used to calculate the similarity between adjacent frames is used to determine whether the picture frame changes, so as to know whether there are people or things entering the monitored areas. The SSIM algorithm proposed herein is achieved mainly by MATLAB.
The principle of SSIM algorithm: When comparing two images provided by software system, firstly, the structure information of the fruits in the image should not be affected by brightness and thus the luminance information needs to be subtracted when calculating the structural information, i.e., (Shiqi et al., 2011) the mean value of the image should be subtracted. Secondly, the structural information should not be affected by image contrast and thus the variance of the images should be normalized when calculating the structural information. Finally, we can calculate the structural information of the image (Hu et al., 2011). Usually, we can simply calculate the correlation coefficients of these two images after processing. However, to obtain the degree of the difference between two pictures, the impact of the brightness information and contrast information should be taken into consideration. Therefore, to return the similarity of two images in the end is through the comprehensive calculation of the results of the brightness comparison, contrast comparison and structural information comparison. Their work flow chart is shown in Fig. 1.

Calculation process:
Mean calculation: Image brightness is essentially the luminance of each pixel in the image, the luminance of each pixel is essentially the RGB values (Huang et al., 2011). When RGB values are 0, the pixel is black and when RGB values are 255, the pixel is white, the brightest one. The image brightness is expressed by mean value in MATLAB. To read the image by transferring image path for Imread function and translate it into double precision data calculation and then make calculations; To turn the image to an HSL space by rgb2hs function; Then the two mean average. Contrast calculation: Contrast is the difference between different pixel, the greater the difference is, the more obvious the contrast is. From the viewpoint of the histogram analysis, the better the contrast of the picture is, the more obvious the curve of the histogram is, the more homogeneous the distribution appears.
Integrated computing: L (X, Y) is set as the brightness comparison function of two frames, then: Among which, E (x), E (y) is the mean of the image C (X, Y) is set as the contrast comparison function of two frames, then: Among which, D (x), D (y) is the variance of image S (X, Y) is set as the structural similarity comparison function of two frames, then: C1, C2, C3 are used to ensure the stability of the return result (Yang, 2008), usually C1 = (K1 * L) ^2, C2 = (K2 * L) ^2, C3 = C2/2, K1<<1, K2<<1, L is the maximum pixel. It is used to defined the sensitivity when analyzing the monitor screen. Finally it is concluded that the similarity is:

RESULTS AND DISCUSSION
In order to verify the effectiveness of this method, this study uses comparison test to show the experimental results. The experimental environment is as follows: In the case that the environment brightness remains unchanged, from the whole of error tolerance range and the calculation efficiency, this method is more practical and more suitable for the monitoring system that there are strict requirements on execution efficiency.
According to the experimental data, we draw the graph of the number of calculations-time and the graph of the degree of change of the monitoring environmentsimilarity of the traditional method and the method in this study, as are shown in Fig. 2 and 3.
From the graph you can directly see that with the increasing number of computing, the advantages of the method in this study become more prominent. Moreover, the impacts suffered are relatively small with the change of monitoring environment. It can be explained that, the practicality of the method in this study is improved substantially compared to the traditional method. And this method overcomes some shortages of the traditional method.

CONCLUSION
The detection method proposed in this study for detecting the fruit is based on the improved SSIM algorithm. It calculates the brightness, contrast and structure similarity of adjacent frames in the surveillance fruit by MATLAB. And finally, by combining these factors, the similarity of the two frames is returned. The moving situation of fruits in the monitor screen is judged through the return similarity. The method improves the shortcomings of traditional method, i.e., the large amount of computation, slow operation and easy affection by the environmental factors. The experimental results show that the efficiency, accuracy and stability of the method in this study are much higher than the traditional method.