# Classification Method Research of Fresh Agaricus Bisporus Based on Image Processing

Fengyun Wang, Jiye Zheng, Lei Wang, Wenjie Feng, Luyan Niu

► To cite this version:

Fengyun Wang, Jiye Zheng, Lei Wang, Wenjie Feng, Luyan Niu. Classification Method Research of Fresh Agaricus Bisporus Based on Image Processing. 11th International Conference on Computer and Computing Technologies in Agriculture (CCTA), Aug 2017, Jilin, China. pp.333-340, 10.1007/978-3-030-06137-1_30. hal-02124268

HAL Id: hal-02124268

https://inria.hal.science/hal-02124268

Submitted on 9 May 2019

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Classification Method Research of Fresh Agaricus
Bisporus Based on Image Processing

Fengyun Wang, Jiye Zheng, Lei Wang, Wenjie Feng, Luyan Niu (✉)

S&T Information Institute, Shandong Academy of Agricultural Sciences, Jinan 250100,
Shandong Province, P.R. China
wfylily@163.com, jiyezheng@163.com, nkywl@126.com, 34941269@qq.com, nly83412@126.com

**Abstract.** The article studies the classification method for the fresh agaricus bisporus based on image processing. When acquiring the image information, the shadow of image and mushroom stipe may affect the analysis of maximum diameter of agaricus bisporus which is the important factor. In this paper, the global threshold segmentation method and maximum entropy threshold segmentation method are combined to carry out the first watershed algorithm to remove the shadow of image. Then the Canny operator, opening and closing operation and corrosion expansion are used to carry out the second watershed algorithm for the removal of stipe interference. The method achieves a good result through the comparison between the actual measured results and experimental results.

**Keywords:** Agaricus bisporus, Image processing, Maximum entropy threshold segmentation, Watershed algorithm.

# 1 Introduction

The agaricus bisporus becomes the most widely cultivated edible mushrooms with the largest production in the world because of its pure white color, delicious taste and fruitful character. At present, the production of agaricus bisporus has been industrialized. The daily production for lager scaled factory is up to a hundred tons. However, the domestic classification for agaricus bisporus is mainly depended on the labor. Both the fatigue of eyes and emotional instability of workers can lead to error of classification. Also, the manual classification has many disadvantages such as large sum of labour, low productivity, different personal grading standard and unstable grading precision and so on. Therefore the article adopts the image processing method to intelligently grade the agaricus bisporus which achieve good effects.

Hutao[1] used the image morphological method to judge the position of stem and detect the edge for the apple which improve the measuring precision of maximum diameter of apple. Chen Jianjun[2] used the image segmentation and enhancement as the preprocessing and artificial neural network as classifier to realize the size grading, shape grading, sprouting detection and deformity detection for potato. Wen Youxian etc. [3] used the machine vision technology to make an automatic grading system according to the size and yolk color of duck egg which size error is ±3g and color accuracy is over 90%. Tan Bo etc. [4] used the background removal, graying, binaryzation and the method of detecting the width of outline by normal axis across barycenter to grade the mandarin orange which accuracy rate is up to 96.25%. Chandra Sekhar Nandi[5] etc. put forward a classification method based on fuzzy algorithm which was applied on mango and achieved a good effect. Chandra Sekhar Nandi etc. [6] extracted the region-of-interest of the acquired image, converted the color from RGB space to HSV space and extracted the character of ROI-HSV to grade the fruit which results showed that it was effective for the judgement of color and size.
The article combines the globe threshold segmentation method and maximum entropy threshold segmentation method to carry out the first watershed algorithm to remove the shadow of image. Then the Canny operator, opening and closing operation and corrosion expansion are used to carry out the second watershed algorithm for the removal of stipe interference. The method overcomes the shadow effect and stipe interference on the maximum diameter when acquiring the image.
## 2 Image acquiring system

The image acquiring system is mainly composed of computer control system and photoelectricity trigger device. The computer console receives the signals from the trigger, then acquires the image from the industry camera, processes and analyzes the image, judges the grade of agaricus bisporus and sends out the control signals to the relay of executing agency. The system flowchart is shown in Fig.1.

<figure><img src="image_2.png" /><figcaption>Fig. 1. System Flowchart</figcaption></figure>

## 3 Image acquiring and processing

### 3.1 Image acquiring

The acquiring of image is the foundation for intelligently classification of agaricus bisporus. The image acquiring devices mainly comprises linear array industrial camera, image acquiring card, light source, photoelectricity sensor and conveyor belt etc. The light must be uniform to avoid highlight and dimming areas. The set background also must be uniform and meets the requirements for later processing. The image acquiring system must be realtime and quickly to make sure the stability of on-line detection.

### 3.2 Contact Author Information

#### 3.2.1 Extracting of region of interest

During the image acquiring, the edge of belt maybe shot. It need extract the region of interest for the acquired image in order to process conveniently and improve the speed of image processing later. The area of agaricus bisporus is separated from the whole image. The subsequent processing is only for the separated part[7]. The extracting procedure is as following:

(1) Load the image and gray processing. Use the larger threshold value to binarize and get the binarization image.

(2) Extract the outline of binarized image. Eliminate the interference of other objects (mainly the fragment from the agaricus bisporus and belt) through setting the maximum and minimum perimeter of outline to get the rough outline of agaricus bisporus preliminarily.

(3) Make the smallest rectangle along the vertical edge of rough outline. The rectangle is parallel to the top and bottom border. The area within the rectangle is the region of interest which is saved.

#### 3.2.2 Edge detection and outline extraction

In order to extract the edge outline quickly and accurately for various agaricus bisporuss under different light and remove the shadow and stipe of image, the single threshold segmentation can't achieve a good effect. The segmentation results for seven threshold segmentation methods are shown in Fig.2.
<figure><img src="image_3.png" /><figcaption>Fig. 2. Seven Threshold Segmentation Effect Image</figcaption></figure>

(a) Original image. (b) Basic global threshold segmentation effect image. (c) Iteration method threshold segmentation effect image. (d) Otsu segmentation effect image. (e) Self-adaption threshold segmentation effect image. (f) Top and bottom threshold segmentation effect image. (g) Manual threshold=71 segmentation effect image. (h) Maximum entropy threshold segmentation effect image.

The article uses the watershed algorithm [8] to realize the segmentation of agaricus bisporus based on the above analysis. The watershed algorithm is an image segmentation algorithm based on the region. It takes the image as the topographic feature of mapping. The gray value of every pixel signifies the altitude of the point. Every local minimum value and its affected area is called as catchment basin and the border of catchment basin forms the watershed. The watershed algorithm is usually used to quickly separate the image into several areas with the same character. The same area amounts to the relative flat basin within the cliffy border. However the traditional watershed algorithm may produce many small catchment basins due to too many smallest areas of input image which will lead to over-separate of image to make much difference between separated image and expected image. Therefore the article adopts the improved version of openCV. It firstly marks part of pixels of the image, confirmed foreground pixel and background pixel. Then the watershed algorithm identifies the region of other pixels in according to the marked pixels.

The whole design of outline detection and extraction part is shown in Fig.3.

<figure><img src="image_4.png" /><figcaption>Fig. 3. Whole Design Thought of Outline Extraction</figcaption></figure>
From the seven threshold segmentations for several agaricus bisporus, we can find that a part of foreground image can be basically separated by the basic global threshold segmentation method and a part of background can be basically separated by seeking the maximum entropy threshold value to get a part of confirmed foreground pixel and background pixel. The watershed algorithm is used for the marked image to get the image of first watershed algorithm as shown in Fig.3. From the images, it shows that the results are better than that of single threshold segmentation which not only separates the image of agaricus bisporus wholly but also removes the shadow by uneven light.

The existence of stipe makes it difficult to detect the maximum diameter. The article uses the second watershed algorithm to remove the image of stipe. The background after the first watershed algorithm is marked as the background of the second background. The outline is extracted by Canny operator. The top and bottom thresholds of Canny are separately the basic global threshold and the maximum entropy value. The result is AND with the foreground of the first watershed and carries out several CLOSE operation which result is marked as the foreground of the second watershed algorithm. Then carry out the second watershed operation to get the image of removing the stipe of agaricus bisporus as shown in Fig.4.

<figure><img src="image_5.png" /><figcaption>Fig. 4. Effect Image for Twice Watershed Processing</figcaption></figure>

((a) Original image acquired by linear array camera. (b) Marked image before the first watershed, white for foreground, gray for background and black for unconfirmed part. (c) Effect image after the first watershed. (d) Marked image before the second watershed. (e) Effect image after the second watershed. (f) Final image which maximum diameter range can be confirmed by computing the longer edge of rectangle.)

Under strong light, the brightness of some parts within the agaricus bisporus is larger caused by reflection etc. factors. The watershed algorithm may produce several outlines. Several expansion corrosion methods can be used to get a final segmentation of outline as shown in Fig.5. It can be obviously shown that the second watershed isn't applicable for the strong reflection.

<figure><img src="image_6.png" /></figure>
<figure><img src="image_7.png" /></figure>

<figure><img src="image_8.png" /></figure>

(f)

<caption>**Fig. 5.** Effect Comparison Image between Expansion Corrosion after First Watershed and Second Watershed</caption>

(d)

(e)

### 3.2.3 Maximum diameter detection

The article uses the minimum bounding rectangle (MBR) method to detect the maximum diameter after outline extracting.

MBR method needs find the rectangle with the minimum area of aimed image. It usually uses Graham method to solve the convex hull of aimed image firstly, then uses the method of rotation or projection to get the rectangle with the minimum area. The results are shown in Fig. 4(f) and Fig.5(a). The length of longer edge in the minimum enclosing rectangle is the required diameter.

$$ \alpha = \frac{x_1 - x_2}{L} \qquad (1) $$

Where $x_1$ signifies the pixel coordinate of the left marking point, $x_2$ signifies the pixel coordinate of the right marking point, $L$ signifies the actual distance between two marked points on the ruler, $\alpha$ signifies the amount of pixels per unit length. Divide the pixel difference between two points by $\alpha$ to get the actual distance which is the actual diameter of agaricus bisporus.

## 4 Experiments and Discussion

The article uses the pixel value as the unit of measured value (MV) to experiment due to the calibrated result affected by the change of various parameters and erection height of camera and so on. The actual value (AV) is got by the vernier caliper which is converted into pixel. The experimental results for random 20 agaricus bisporus images are shown in Table 1 where the maximum and minimum error values are marked by bold font.

The error is computed by formula (2):

$$ Error = \frac{|Actual\ value-measured\ value|}{Actual\ value} \qquad (2) $$

<table><caption>**Table 1.** Comparison of results between actual value and measured value for maximum diameter</caption><thead><tr><th>No.</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th></tr></thead><tbody><tr><td>MV</td><td>91.00</td><td>110.63</td><td>108.24</td><td>116.84</td><td>110.17</td><td>77.49</td><td>82.22</td><td>102.42</td><td>110.31</td><td>121.84</td></tr><tr><td>AV</td><td>90.10</td><td>112.31</td><td>110.08</td><td>115.95</td><td>107.32</td><td>79.60</td><td>82.00</td><td>98.00</td><td>109.00</td><td>123.93</td></tr><tr><td>Error</td><td>0.0099</td><td>0.0152</td><td>0.0237</td><td>0.0079</td><td>0.0259</td><td>0.0272</td><td>0.0027</td><td>0.0432</td><td>0.0119</td><td>0.0172</td></tr><tr><td>No.</td><td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td></tr><tr><td>MV</td><td>107.02</td><td>92.65</td><td>101.40</td><td>102.18</td><td>97.02</td><td>98.05</td><td>101.04</td><td>90.91</td><td>89.59</td><td>96.77</td></tr><tr><td>AV</td><td>104.65</td><td>91.43</td><td>103.30</td><td>102.33</td><td>95.38</td><td>98.00</td><td>103.04</td><td>90.00</td><td>90.95</td><td>93.99</td></tr><tr><td>Error</td><td>0.0221</td><td>0.0132</td><td>0.0187</td><td>0.0015</td><td>0.0169</td><td>0.0005</td><td>0.0198</td><td>0.0100</td><td>0.0152</td><td>0.0287</td></tr><tr><td colspan="10">Average error: 0.01657</td></tr></tbody></table>

From the table it shows that better effect can be achieved by the method in this article for the measurement of maximum diameter of agaricus bisporus. Among the random 20 samples, the maximum error is 4.32% and the minimum error is 0.05%. The degree of accuracy will directly determine the accuracy of grading results of agaricus bisporus.

The classification of agaricus bisporus is in according to the maximum diameter by image analysis and industrial standard. The industrial standard uses NY/T 1790-2009 in China which classifies the fresh agaricus bisporus into three specifications
according to the diameter of pileus as shown in Table 2. The application effect by the method put forward in this article is good in the realtime automatically classification system of agaricus bisporus.

<table><caption>**Table 2. Specification of fresh agaricus bisporus (unit: cm)**</caption><thead><tr><th>Specification</th><th>Small</th><th>Medium</th><th>Large</th></tr></thead><tbody><tr><td>Pileus diameter</td><td>&lt;2.5</td><td>2.5~4.5</td><td>&gt;4.5</td></tr><tr><td>Difference between maximum and minimum diameter in one same package</td><td>&lt;=0.7</td><td>&lt;=0.8</td><td>&lt;=0.8</td></tr></tbody></table>

## 5 Conclusions

During the realtime image processing of agaricus bisporus, twice watershed algorithm computing removes the interference of shadow and stipe in the image very well. But it isn't thorough for part images of agaricus bisporus with little difference between color and pileus which is one of the main factors for experimental error. The further study is how to remove the stipe of agaricus bisporus better and completely extract the image of pileus.

## Acknowledgment

Funds for this research was provided by the Key Research and Development Plan of Shandong Province (2016GNC110008, 2016CYJS03A01-1), Agricultural Science and Technology Innovation Project of Shandong Academy of Agricultural Sciences (CXGC2017B04), Shandong Academy of Agricultural Sciences (SAAS) Youth Scientific Research Funds Project (2015YQN58), Key Applied Technological Innovation Project in Agriculture of Shandong: Key Technology Research and Development of Intelligent Control for Healthy Broiler Production in Greenhouse.

## References

1. HU Tao. Application of Morphological Image Processing in Stem Location and Edge Detection of Apple Automatic Grading [J]. Journal of Anhui Agri. Sci.2007, 35(6):1866-1867.

2. Jianjun Ma. Design of Automatic Grading Mechanization System for Potato [J]. Agricultural Technology and Equipment. 2011(12):4-5

3. Wen Youxian, Wang Qiaohua, Chen Xiaowei, et al. Development on the Automatic Grading Software of Duck Egg Bulk and Yolk Color [J]. Journal of Huazhong Agricultural University, 2001, 20(4): 395-399.

4. TAN Bo, TANG Shan-Xian. Mandarin size of the automatic classification method based on image processing [J]. HUNAN AGRICULTURAL MACHINERY. 2012, 39(5): 207-209.

5. Chandra Sekhar Nandi, Bipan Tudu and Chiranjib Koley. Machine Vision Based Automatic Fruit Grading System using Fuzzy Algorithm. 2014 International Conference on Control, Instrumentation, Energy & Communication(CIEC), 2014, 26-30.

6. Hadha Afrisal, Muhammad Faris and Guntur Utomo P, et al. Portable Smart Sorting and Grading Machine for Fruits Using Computer Vision. 2013 International Conference on Computer, Control, Informatics and Its Applications, 2013, 71-75.

7. Takeshi Hagisawa, Masashi Todat and Teruyasu Sakoil, et al. Image Analysis Method for Grading Raw Shiitake Mushrooms. The 19th Korea -Japan Joint Workshop on Frontiers of Computer Vision, 2013, 46-52.

8. MA Li-hong, ZHANG Yu, DENG Jian-ping. A Target Segmentation Algorithm Based on Opening-Closing Binary Marker on Watersheds and Texture Merging [J]. Journal of Image and Graphics. 2003, 8 (1): 80-86

9. ZHANG Fajun, LEI Yi, ZHU Xing, et al. Research on sorting device technology of navel orange based on image [J]. Modern Machinery.2014, (1): 57-60.

10. HU Jing, GUO Xin, HE Haojia, et al. Automatic Classification of Fruit Using Multi-Classifier Fusing [J]. JOURNAL OF SHANGHAI DIANJI UNIVERSITY. 2012, 15(3):