A novel method of automatic peeling for Poria cocos based on image processing

: Manual peeling of Poria cocos has low efficiency and large loss, and other peeling methods are not suitable for Poria cocos peeling. To solve this problem, this study designed and fabricated a set of automatic peeling equipment for Poria cocos , which combined image processing technology with the structure and function of the vertical milling machine. This paper mainly reports the image detection algorithm of Poria cocos epidermis position for automatic peeling. Firstly, the blue marks were glued to the movable and the immovable parts of clamping parts, and the initial window was determined through them. Then, the grayscale image within the initial window was obtained with the help of the chromatic aberration |2 r － g － b | (red ( r ), green ( g ), blue ( b ) of pixels). The processing window was calculated with the aid of the distribution graph of the grayscale accumulation. Next, the grayscale image was taken into the process of the automatic binarization based on the Otsu method and the binary image was restored through dilation, erosion and denoising algorithm. Finally, pixel columns in the processing window were scanned column-by-column from the left to the right and the direction of each pixel column is from the bottom to the top. The first pixel with a value of 0 on each pixel column was set as the epidermis position of the current pixel column. The experiment results implied that, under the set light source, the average detection accuracy was 98.8%, and the average time to detect epidermis position once was 0.024 s. The detection accuracy and real-time performance of this algorithm meets the actual operation requirements of Poria cocos peeling. It lays the foundation for the automatic peeling operation of Poria cocos .


Introduction
Peeling is a crucial step in the post-harvest processes of agriculture products because of its significant impact on yield and quality [1] .However, the peeling of most agricultural products is mainly manual with much operator's workload and low peeling efficiency.As a result, it is very paramount to find a peeling method that can improve peeling efficiency, quality and yield of agricultural products which are considered to assess the peeling performance.A multitude of peeling methods have been examined as alternative methods to conventional peeling processing technologies of agriculture products.
Chemical peeling methods are mainly based on Enzymatic peeling.Enzymatic peeling is a chemical method according to enzymatic catalysis.It is superior to conventional peeling methods in terms of minimizing product damage and considered to be a novel peeling method [2] .Most research on the enzymatic peeling method are about to find out the optimal situations of the enzymatic solution.Optimal conditions of the enzymatic solution for the peeling of the mango is worked out [3][4][5][6][7][8] , the potato, the cassava tuber, the key lime and the lemon, and argued that enzyme treatment is able to improve the peeling processing in peeling efficiency and yield.There are many factors that affect the enzymatic catalysis, such as temperature, pH and the concentration of enzymatic solution which result in making it formidable to work out the optimal parameters of the enzymatic catalysis.Meanwhile, the enzymatic catalysis has absolute specificity, which limited its application for peeling.
Heating peeling methods mainly include Infrared drying peeling and Ohmic heating peeling.Infrared drying peeling is to remove the epidermis by means of making agriculture products surface drying or dehydration and widely exploited in industry.It is a potential alternative and environmentally friendly peeling method for the reason that it could address the long-term water supply and wastewater disposal issues, and reduce environmental pollution involved in the conventional lye peeling [9,10] .Infrared drying had a more pleasurable performance than the conventional peeling method in terms of peeling loss and efficiency, and final product quality [11][12][13][14][15] .The performance of infrared heating is limited by the types and surface of agricultural products and the wavelength of the infrared radiation source.Therefore, it is unreliable for many agricultural products.Ohmic heating peeling is defined as a process wherein electric current is passed through materials with the primary purpose of heating them [16] .Ohmic heating usually works as assists for the traditional lye peeling, which was more excellent than traditional peeling in respect of enhancing product quality, peeling efficacy, product yield, and effluent quality [17][18][19][20][21] .The method is inadvisable for non-conductive and dry agricultural products resulted in the inability to carry out extensive promotion and application.
The main physical peeling method is Mechanical peeling.Mechanical peeling is to remove the undesirable parts directly from agriculture products by utilizing knives, blades, or abrasive devices.Mechanical peeling was mostly applied to peeling of agriculture products with regular shapes and smooth surface, such as the mango [22] , the potato [23] , the cassava [24] , the orange [25] , the watermelon, and the melon [26] .Although peeling efficiency of this method is more favorable than conventional peeling methods, peeling quality and rate still need to be enhanced.
Poria cocos is a large-scale raw material in traditional Chinese medicine and food with high research value.Peeling is one of the main post-harvest processes of Poria cocos, which affects yiled and quality of Poria cocos directly.However, none of the above methods are preferable for automatic peeling of Poria cocos and there is less research on it because of its large individual differences, irregular shapes, and uneven surface.Manual peeling brings about low peeling efficiency and the large loss of yield, which has a serious impact on the industrial development of Poria cocos [27,28] .Thus, it is a problem which is needed to be urgently solved for achieving automatic peeling of Poria cocos.The present study designed and fabricated a set of automatic peeling equipment for Poria cocos in the light of the image processing and the structure and function of the vertical milling machine, and this paper focus on describing the detection algorithm of Poria cocos epidermis position for the automatic peeling with the help of the image processing.With these conditions in mind, the objectives of this paper can be outlined as follows: 1) Develop a detection algorithm of Poria cocos epidermis position for automatic peeling based on image processing.
2) Take algorithm verification experiment in the field by using Poria cocos automatic peeling equipment.
3) Assess the performance of the detection algorithm through the experiment results.

Automatic peeling equipment of Poria cocos
This study designed and fabricated the automatic peeling equipment of Poria cocos, and its three-dimensional structure diagram is manifested in Figure 1 and its physical map is shown in Figure 2. In Figure 1, the blue starting mark (1) on the movable part of clamping parts, which was applied to mark the starting position of peeling operation.The camera (with built-in LED light source) (2) that was applied to acquire the image of Poria cocos.The blue ending mark (3) on the immovable part of the clamping parts, which was employed to mark the ending position of peeling operation.A drill (4) which was exploited for peeling operations.The center console (5), which controled the detection program and the movement of the drill, including feed, retraction, and the horizontal movement, to achieve the tracer control peeling operation of Poria cocos.The guide rail (6) which was utilized for the movement of the drill between the left and right (the side close to (5) is left), and its length was longer than the clamping parts and the initial position of the drill was at the left end of it.

Video acquisition
Sampling operations were conducted at Hebei Zhuozhou Ruifeng Machinery Co., Ltd. at 3:00 pm on October 8, 2019, and at 10:30 am on October 17, 2019.In Figure 1, the vertical height of the camera above the drill was 1 m, and the angle between its optical axis and the horizontal plane was 60°.The peeling position of Poria cocos epidermis was at the bottom half of the image.The blue ending mark was located in the right half of the image, and the blue starting mark in the opposite position.The drill self-acting moved from the left to the right on the guide rail at a constant and slow speed.The videos were saved as AVI format with a resolution of 640×480 pixels (horizontal×vertical) of every frame.
The specific image acquisition method is as follows.In the first place, the movable part of the clamping parts was manually controlled to clamp a Poria cocos and the drill ( 4) is located at the far left end of the guide rail (6).
Step 1: The equipment and the detection program were started through the central console (5).Then, the camera (2) started to acquire images, and the detection program commenced figuring out the position of the blue starting mark, blue ending mark and the initial window.
Step 2: The drill moved from the left to the right on the guide rail at a constant speed, and the drill image was taken in real-time which was employed to determine the position of the drill through the detection program.
Step 3: When the drill was at the blue starting mark (Figure 1(1)) position, the detection program embarked upon the calculation of Poria cocos epidermis positions.
Step 4: When the drill moved right to the blue ending mark (Figures 1(3)), the drill automatically retracted to the set position, and then quickly moved to left.When the drill was at the blue starting mark, the detection program went into step 3.During this process, clamping parts rotated at a fixed angle (10°) counterclockwise.

Detection algorithm
(1) Entire design As shown in Figure 3, the top left corner of the image is the origin of the coordinate system, and the orientations of arrows are the positive directions of the X-axis and the Y-axis.xsize and ysize represent the width and height of the image in pixels, respectively.The symbols of the image color component are R (red), G (green), and B (blue), and their values are represented by r, g, and b one-toone correspondence.The dashed rectangle is the initial window in Figure 3, and the top of the dashed frame, which is divided into two parts by the horizontal solid line, is the processing window.The flow of the detection algorithm is demonstrated in Figure 4.The left half of the image was regarded as the processing area because that the blue starting mark was located in it.Scanning pixel rows row-by-row from the top to the bottom in the processing area that the scanning direction of each pixel row was from the right to the left.If there was a pixel point on the i-th pixel row that there were n (n=10 in this study) consecutive pixels on the left of it satisfied both limitations (see Equation (1)), this pixel point was the top left corner point of the initial window.In the same way, the immovable part of the clamping parts was positioned in the right half of the image, so that the right half of the image was taken as the processing area.The method of determining the top right corner point of the initial window was the same as that of the top left corner point, except the scanning direction of each pixel row which was from the left to the right.The maximum value of the Y-axis coordinate between the top left corner point and the top right corner point was y m , and the area below the pixel segment y=y m is the initial window as it is demonstrated by the dashed rectangle in Figure 3. (1) (3) Grayscale processing of the initial window The epidermis of Poria cocos was reddish brown, and the relationship between R, G, B color components was r>g>b which was stable with the aid of the analysis on sample images.The color image in the initial window was converted into a grayscale image with the help of chromatic aberration |2r-g-b| depending on the above relationship, that is, emphasizing the R value and restraining the G and B values.The principle is as follows: Pixel(x, y) is the gray value of point (x, y) in the grayscale sample image, confined to [0, 255].
(4) Calculation of the processing window An array named p was defined with a size of ysize.Pixel rows was scanned row-by-row from the top to the bottom in the initial window, and the cumulative value of each pixel row was stored in p. Then p was smoothed with a step size of 10 with the help of Simple Blurring smoothing method, and the average a and the standard deviation d of p was calculated by Equation (3).The pixel The specific algorithm for calculating the position of the first trough is as follows.If s was less than e, finding out the first trough from the left to the right.Otherwise the first trough was calculated from the right to the left.The methods of the two cases were the same, so the first case was considered as the example for illustration.
1) Determination of the processing interval.The value of p[k] was b. m was the value of the trough with initial value of b.The calculation of b, m, s, and e is listed in Equation (4).
2) Finding out the trough.The data of p one by one from s to e was assessed.From the position of the trough implied by v p in Figure 5, it could be known that the shape of the trough went down and then went up.The following are the specific algorithm steps.
Step a: The data was at the left of the trough.Comparing p[i] and b, if p[i] was more than b, then going to the next data.Otherwise, comparing p[i] and m, if p[i] was less than m, then assigning the value of p[i] to m and continuing to the next data.When p[i] was more than m, it suggested that the data was at the right of the trough, so that the algorithm proceeded to step b.
Step b: If the difference between p[i] and m was more than or equal to t which was the threshold of the trough determination and generally set to be one n-th of d from Equation ( 5), the current value of i was the trough position v p .Otherwise, the algorithm went into step a to repeat to comparing p[i] and m to calculate the next data.All processing steps are shown in Figure 6, the red rectangle in Figure 6c is the processing window, and the red curve in Figure 6f shows the position of Poria cocos epidermis.

Results and discussion
Experiment was carried out in Hebei Zhuozhou Ruifeng

Experimental results and analysis
It is a false detection as an experiment error when the actual detection result has a large error from the visual inspection.There were five groups of Poria cocos, and each group contained ten Poria cocos.The position of each Poria cocos was detected epidermis for ten times with Poria cocos rotated randomly.The specific results are listed in Table 2.It can be seen from Table 1 that this detection accuracy of the first group and the third group are 100%, and they are 99% and 98% with once and twice false detections in the fourth group and the fifth group.The detection accuracy of the second group is 97%, slightly lower than the fourth and fifth groups, and there are three times false detections.The average detection accuracy is calculated to be 98.8%, the average detection speed is 0.024 s/once, thus the detection algorithm has a positive performance on detection accuracy and speed.
This algorithm can work out the Poria cocos epidermis position quickly and correctly, and its real-time, accuracy and stability meet the requirements of Poria cocos automatic peeling operations.This study lays the foundation for the automatic peeling operation of Poria cocos.

Algorithm correctness analysis
(1) Determination algorithm of the blue marks The RGB-line profiles of a random pixel row is described where the left and the right blue marks in Figure 7.It indicates that the relationship is b>g>r between the color components of pixels which belonged to blue marks, that is, from the 110-th pixel to the 145-th pixel column in Figure 7a, from the 515-th pixel column to the 550-th pixel column in Figure 7b.The trend of the RGB-line profile did not change much with the help of repeating the above observation and analysis in the experiment.The restriction situations of b-g>30 and b-r>30 could be used to calculate the initial window.(2) Grayscale processing of initial window Initial window images after the process of gray with |2r-g-b| is shown in Figure 8a.It can be seen that the algorithm of grayscale processing could make that the brightness of Poria cocos is significantly higher than the background.The position of the processing windows and the segmentation effect of binarization determined based on this grayscale method meets expectations shown in Figure 9a and 9b.Hence this grayscale method could be successfully employed to segment images and work out the processing window.
(3) Determination algorithm of the processing window The gray rectangle in Figure 8a is the initial window after process of gray, and Figure 8b  In Figure 8b, the troughs of distribution graphs are located between the 300-th pixel column and the 350-th pixel column.The method (in 2.2.2Detection algorithm-( 4)) was utilized to calculate the trough.The solid red rectangles in Figure 9a is the processing window determined.It signifies that the processing window is positioned correctly and the algorithm could be exploited to precisely work out the position of Poria cocos.The experiment images were employed for multiple verifications, and the results inferred that the algorithm can accurately work out the position of the processing window.
(4) Restoration processing After the automatic binarization processing, the outline of Poria cocos is clear and precise, and the background and Poria cocos could be better segmented shown in Figure 9b.There are black pixels, which conduce to false detection, within background in the bottom left corner of Figure 9b.
Processes of corrosion, denoising and dilation were taken in Figure 9b with black pixels object so as to remove the black pixels in the background, and the images after processing are shown in Figure 9c.It can be seen from Figure 9d that the restoration processing method was conductive making the Poria cocos epidermis position clear and accurate, and improve the detection accuracy.The final twice erosion process was mainly to reduce the edge of Poria cocos after the dilation processing, and to further improve the detection accuracy.

Analysis on the false detection
Figure 10 shows all the processing steps of the false detection.
It can be seen from the Figure 10b  initial window and processing window are accurate.It suggests that the determination algorithm of processing window has strong applicability.After binarization and restoration, the damaged area on the left side of the Poria cocos with severe damage forms a connected area with the background, which is the main reason for the misdetection shown in Figure 10f.
Figure 11b demonstrates the RGB-line profile of a random pixel row described as the horizontal solid line on the epidermis with severe damage in Figure 11a, and the pixel columns and the corresponding values of color component are the X-axis and the Yaxis, respectively.It indicates that relationships between the color component are unstable before the 170-th pixel column where the epidermis is with severe damage, sometimes g>r>b or g>b>r, and after the 170-th pixel column, the relationship always satisfied r>g>b.Thus, after the processing of the automatic binarization, the damaged epidermis were integrated with the background demonstrated in Figure 10d, and the pixel-connected component is more obvious after the restoration processing as shown in Figure 10e which lead to the false detection of Poria cocos manifested in Figure 10f.Consequently, the operators try to avoid damaging Poria cocos before peeling is paramount.

Conclusions
This study focused on the image detection algorithm of Poria cocos epidermis position with the aid of statistics and morphology for automatic peeling, and the following conclusions can be drawn: 1) A Poria cocos epidermis detection algorithm suitable for Poria cocos automatic peeling equipment was proposed.The algorithm mainly included determination of the initial window and processing window, binarization and restoration, and final extraction of the Poria cocos epidermis position.
2) An experiment of Poria cocos epidermis position detection was conducted.The results indicated that this algorithm can work out the Poria cocos epidermis position quickly and correctly with the average detection accuracy and speed are 98.8% and 0.024 s.This algorithm meets the requirements of Poria cocos automatic peeling operations in terms of real-time, accuracy and stability, and lays the foundation for the automatic peeling operation of Poria cocos.
3) The detection algorithm for the position of Poria cocos epidermis with severe damage needs further research.At the same time, this method can be applied to the peeling of agricultural products of the same quality as Poria cocos.

Figure 2
Figure 1 Three-dimensional structure diagram of the automatic peeling equipment of Poria cocos

Figure 3
Figure 3 Schematic diagram of Poria cocos epidermis position (2) Determination of the initial windowThe left half of the image was regarded as the processing area because that the blue starting mark was located in it.Scanning pixel rows row-by-row from the top to the bottom in the processing area that the scanning direction of each pixel row was from the right to the left.If there was a pixel point on the i-th pixel row that there were n (n=10 in this study) consecutive pixels on the left of it satisfied both limitations (see Equation (1)), this pixel point was the top left corner point of the initial window.In the same way, the immovable part of the clamping parts was positioned in the right half of the image, so that the right half of the image was taken as the processing area.The method of determining the top right corner point of the initial window was the same as that of the top left corner point, except the scanning direction of each pixel row which was from the left to the right.The maximum value of the Y-axis coordinate between the top left corner point and the top right corner

Figure 4 Figure 5
Figure 4 Flowchart of the detection algorithm

( 5 )
Image binarization and restorationThe image of the processing window was taken into the following processes of binarization and restoration, including automatic binarization based on Otsu, erosion twice with black pixels object, denoising with black connect pixel area of 5000, dilation twice with black pixels object, and erosion twice with black pixels object.Eight connected domain algorithm was used for all erosion and dilation operations.(6)Extraction position of Poria cocos epidermisThe dashed arc in the processing window in Figure3demonstrates the epidermis of Poria cocos.Pixel columns were scanned column-by-column from the left to the right in the processing window, and the scanning direction of each pixel column was from the bottom to the top.The coordinates of the first pixel with a value of 0 on each column were the position of Poria cocos epidermis.

Figure 6
Figure 6 Results of all processing steps Figure 7 RGB-line profile of a random pixel row where the blue marks

Figure 8
Figure 8 Initial window images after the grayscale processing and distribution graph of the grayscale accumulation in the initial window

Figure 9
Figure 9 Results of different processing steps

Figure 11
Figure 11 Analysis on false detection of Poria cocos epidermis position