A ganoderma lucidum image analysis method, device and system
Patent Information
- Application Number
- CN202511381847.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-25
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2045-09-25
AI Technical Summary
[0003]目前对于灵芝外观品质鉴别仍然依赖于人工,但不同的鉴别者的经验水平不同,无法精确量化灵芝的大小,灵芝颜色受光线影响人工判断可能不一致,从而导致同一批灵芝被划分为不同等级
[0019]本发明灵芝图像分析方法,以灵芝特有的结构为基础,通过特定的视觉算法,将灵芝的菌盖和菌柄准确分割,再结合特定的物体检测算法,可获得准确的灵芝外观和形态特征,快速识别出符合标准的灵芝个体,从而避免了人工初筛导致的主观误差、效率低下、市场混乱,为灵芝后续加工和处理提供保障,提高生产效率,具备实际推广应用价值。
Smart Images

Figure CN121600008B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of machine learning technology, specifically relating to a method, apparatus, and system for analyzing Ganoderma lucidum images. Background Technology
[0002] Reishi mushroom is a precious medicinal fungus belonging to the Polyporaceae family, mainly divided into red reishi and purple reishi. Its dried fruiting body is an important component of traditional Chinese medicine, with a long history and extensive medicinal value. Modern pharmacological studies show that reishi possesses various pharmacological activities: anti-tumor, antioxidant, immunomodulatory, cardiovascular protective, and nervous system protective effects. To ensure the medicinal value of reishi, the Chinese Pharmacopoeia has clear standards for quality control, among which the identification of reishi's appearance quality is an important aspect. As a precious traditional Chinese medicine, the appearance quality of reishi directly affects its market value.
[0003] Currently, the identification of Ganoderma lucidum's appearance quality still relies on manual methods. However, different assessors have varying levels of experience, making it impossible to accurately quantify the size of the Ganoderma lucidum. Furthermore, the color of Ganoderma lucidum is affected by light, leading to inconsistent manual judgments and resulting in the same batch of Ganoderma lucidum being classified into different grades. Image detection technology can objectively assess the appearance quality of Ganoderma lucidum, providing a scientific basis for the standardized production of Ganoderma lucidum. Summary of the Invention
[0004] To achieve the above objectives, the present invention provides a method for analyzing Ganoderma lucidum images, comprising the following steps: Images of Ganoderma lucidum are acquired, and the main body of Ganoderma lucidum is separated and extracted from its background. Then, the concave points and / or mutation points of the contour in the main body image of Ganoderma lucidum are used to segment the cap and stipe of Ganoderma lucidum. Finally, the length and width of the cap of Ganoderma lucidum are calculated, and the color and shape are identified. The length of the stipe is also calculated. The indentation is a point that is recessed inward on the smooth outline of the connection between the cap and the stem in the main image of Ganoderma lucidum. The mutation point is the point where two adjacent points on the outline of the main image of Ganoderma lucidum undergo a visible inflection.
[0005] Further, the concave point is determined as follows: for the outline of the connection between the cap and the stem in the main image of Ganoderma lucidum, within the scale parameter range, multi-scale curvature calculation is performed using formula (12); points with curvature values greater than the threshold A are selected, and pairing quality scores are performed using formulas (13) to (16), and the two points with the highest scores are the concave points; The scale parameter range is scale = [0.02L, 0.04L, 0.06L, 0.08L, 0.10L], where L is the perimeter of the contour; The threshold A is determined as follows: multi-scale curvature is calculated using formula (12), and the obtained curvature values are sorted from smallest to largest. The 95th percentile curvature value is taken as the threshold. Formula (12) Where x′ and y′ are the first derivatives of the horizontal and vertical coordinates of the profile curve at the arc length parameter s; x′′ and y′′ are the second derivatives of the horizontal and vertical coordinates of the profile curve at the arc length parameter s; and k(s) is the profile curvature value. Formula (13) Formula (14) Formula (15) Formula (16) Where d is the maximum depth of the inward concavity of the contour between the two concave points, W is the maximum width of the Ganoderma lucidum cap contour, and D is the depth score of the concave point. , , respectively, are the perpendicular distances from the two concave points to the center line of symmetry of the cap. The center line of symmetry is a straight line that passes through the centroid of the cap outline and is perpendicular to the direction of the line connecting the two concave points. The centroid is the geometric center of the Ganoderma lucidum cap outline image; S is the symmetry score. x Let exp() be the average position of the two concave points within the range of cap width normalized to the interval [0,1], where exp() is the exponential function and P is the relative position score. It is 0.4. , Both are 0.3, and F represents the structural feature of concave point pairing; The mutation points are determined as follows: the Ganoderma lucidum main image is extracted using an edge detection algorithm, and then the slope change rate of each contour point is calculated from top to bottom using formulas (27) to (30). Points with an absolute value of slope change rate greater than the threshold B are selected and set using formula (31). The two points at the beginning and end of the middle section are referred to as the mutation points; The threshold B is determined by a statistical method. The specific statistical method is as follows: first, sort the calculated slope change rate from smallest to largest, and then select one of them as the threshold B. If the detected mutation point contains noise points, then select the value with a larger slope change rate as the threshold B. If the detected mutation point misses the visually visible inflection point, then select the value with a smaller slope change rate as the threshold B. Repeat the selection until the detected mutation point contains the visually visible inflection point and there is no background noise. Formula (27) Formula (28) Formula (29) Formula (30) Formula (31); in, x i It is the first i The x-coordinates of the contour points y i It is the first i The ordinates of the contour points, m i m is the slope of the tangent line at contour point i from 1 to n-2; m0 is the slope of the tangent line at contour endpoint i=0, m n-1 It is the slope of the tangent line at the endpoint i=n-1 of the profile; dm / dy i It is the rate of change of the slope of the contour point i from 0 to n-1, when y i+1 =y i When the slope changes infinitely, smoothing or using the average slope of nearby points should be employed. The threshold B is set.
[0006] Furthermore, the steps for calculating the concave point segmentation of the contour in the main image of Ganoderma lucidum are as follows: 1) Separate the stem and cap of Ganoderma lucidum The cap and stipe of Ganoderma lucidum are segmented by a straight line connecting two concave points to obtain images of the cap and stipe of Ganoderma lucidum. 2) Calculation of cap length and width Take an image of the Ganoderma lucidum cap, use the findContours function to extract the contour, and then use the area filter condition: area>0.05. image_area and Douglas-Peucker algorithm parameters: epsilon = 0.005 Perimeter optimizes the cap outline. Formulas (17) and (18) are used to find the cap centroid of the optimized cap outline. Formula (54) is used to find the two points on the cap outline that are farthest apart and whose connecting lines pass through the centroid. Formula (55) is used to obtain the axis of symmetry. The cap length is the distance between the two intersection points of the axis of symmetry and the outline. The cap width is the distance between the two intersection points of the straight line perpendicular to the axis of symmetry and passing through the centroid and the outline. Formula (17) Formula (18); in, x, y These represent the column and row coordinates of a pixel in the image, respectively. M represents the grayscale value at a pixel location in the image. 00M is the zeroth moment, corresponding to the sum of all foreground pixels in the image; 10 and M 01 , , and , respectively, represent the first moments of the image, and , representing the weighted sum of positions along the horizontal and vertical directions; Formula (54) Where d1 represents the distance between two points on the cap outline, and (x1,y1) and (x2,y2) are the x and y coordinates of the two points, respectively; Formula (55) Where dx represents the difference in the x-coordinates of the two points on the contour whose line passes through the centroid and are farthest apart, and dy represents the difference in the y-coordinates of the two points on the contour whose line passes through the centroid and are farthest apart. The direction vector of the axis of symmetry; 3) Reishi mushroom cap color identification Take an image of Ganoderma lucidum cap, use formulas (19) to (21) to convert the RGB format to HSV format, then use formula (22) to perform illumination normalization, use formula (23) to perform feature statistics on each channel of the HSV space, and finally use formula (24) to perform cluster analysis, use formula (25) to perform color classification, and use formula (26) to perform color proportion quantification. Formula (19) Formula (20) Formula (21) Where V is lightness, S is saturation, and H is hue. The value for the red channel. This is the value for the green channel. For the blue channel values, max() is the maximum value function, and min() is the minimum value function; Formula (22) in, x, y R represents the column coordinates and row coordinates of a pixel in the image, respectively. (x,y) Indicates the pixel position (x,y) Image reflection component at location; I (x,y) Indicates the pixel position of the original image. (x,y) The brightness value at that location; F represents the smooth convolution kernel used to simulate ambient lighting.
[0007] Formula (23) Where μ represents the mean of the color distribution, σ represents the standard deviation, and s represents the skewness of the color distribution. p ( i) represents the pixel value of the i-th color channel (i.e., the H, S, or V channel in HSV), and N is the total number of pixels.
[0008] Formula (24) in, t For the number of iterations, x ( t Let represent the current solution vector at time t, and M(x(t)) represent the search direction or update increment calculated for the current solution x(t). x ( t +1) is the final solution vector.
[0009] Formula (25) Formula (26) in, x It is the feature vector (i.e., hue, saturation, and brightness value) of a pixel in the image in the HSV color space. c It is a color classification center, namely, predefined color classes such as "red", "yellow", and "brown"; d ( x, c ) express x Go to the color sorting center c Mahalanobis distance, d ( x,c′ ) express x To the color classification center c The Mahalanobis distances to the color classification centers c′ other than σ, where σ is the standardized coefficient of the Mahalanobis distance, exp() is the exponential function, and p(c|x) represents x Belongs to color category c The posterior probability; total pixels is the total number of pixels; ratio(c) represents the color category in the image. c The percentage of pixels.
[0010] Furthermore, the steps for segmenting and recognizing the abrupt changes in the contour of the Ganoderma lucidum main image are as follows: ①Splitting the Ganoderma lucidum stem cap The cap and stipe of Ganoderma lucidum were segmented by a straight line connecting two mutation points to obtain images of the cap and stipe of Ganoderma lucidum. ② Image symmetry axis correction The segmented images of the Ganoderma lucidum cap and stipe are obtained separately. The geometric symmetry axes of the Ganoderma lucidum cap and stipe are determined by contour principal component analysis and symmetry matching. Then, the images are rotated by affine transformation to align the symmetry axes with the principal axes, thus obtaining the corrected images of the Ganoderma lucidum cap and stipe. ③ Calculation of Ganoderma lucidum cap length Take the corrected image of the Ganoderma lucidum cap, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom. Points with a slope change rate of zero are represented as the set of extreme points. , with the vertical axis y i The largest point is the vertex, with the y-coordinate as the vertex. i The point with the smallest value is the lowest point, calculated based on the y-coordinates of the highest and lowest points. length; ④ Calculation of Ganoderma lucidum cap width Take the corrected image of the Ganoderma lucidum cap, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom; calculate based on two points with infinite slopes. width; ⑤ Reishi mushroom cap shape identification Take the corrected image of the Ganoderma lucidum cap, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom along the contour. Take the point with a slope of positive infinity, use formula (39) to locate it, and extract all the lower half contour points between the points to form the lower half contour C of the cap. lower ={p a ,p a+1 ,...,p b}; When C lower The slope change rate sequence {k a ,k a+1 ,...,k b The cap is kidney-shaped and satisfies at least two sign alternations, and the overall trend conforms to the pattern of "negative → positive → negative → positive". When C lower The overall trend of the slope change rate sequence is "negative → positive", and there is at least one k i Satisfy |k i |≥T, the cap is nearly round; When C lower The overall trend of the slope change rate sequence is "negative → positive", and all k i Satisfy |k i |≥T, the cap is semi-circular; Formula (39); in, k i For contour points i The slope of the tangent at p a The first condition that satisfies k during a top-down search. i =+∞ contour point index; k j For contour points j The slope of the tangent at p b For in pa The search then continues to find the second one that satisfies k. j =+∞ contour point index; T The threshold for judging the steepness of the contour is 0.2.
[0011] ⑥ Calculation of Ganoderma lucidum stipe length Take the corrected image of Ganoderma lucidum stipe, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom. Take the points whose absolute value of the slope change rate is greater than the threshold D, and use formula (31) to set them together, with the vertical axis y i The largest point is the vertex, with the y-coordinate as the vertex. i The minimum point is the lowest point. The stipe length is calculated based on the y-coordinates of the highest and lowest points. The threshold D is determined using statistical methods, specifically: first, the calculated slope change rate dm / dy is... i Sort the data from smallest to largest, and then select one of them as the threshold D. If the detected mutation point contains noise points, select the value with the larger slope change rate as the threshold D. If the detected mutation point misses the visually visible inflection point, select the value with the smaller slope change rate as the threshold D. Repeat the selection until the detected mutation point contains the visually visible inflection point and there is no background noise. ⑦ Reishi mushroom cap color identification The segmented Ganoderma lucidum cap image is preprocessed using Gaussian and median filters, and then converted from RGB to HSV format. The frequency of each hue value in the HSV format image is counted using formula (46) for histogram analysis. The histogram is normalized using formula (47) to make its sum equal to 1. Finally, formulas (48) and (49) are used to calculate the proportion of frontal and back energy in the histogram. Larger than the back The image shows the front of the Ganoderma lucidum cap. Smaller than the back The image shows the back of the Ganoderma lucidum cap; Formula (46) Formula (47) Formula (48) Formula (49); The count() function is used to count the tonal values of the front area, which range from 0° to 30° or 330° to 360°, and the back area tonal values, which range from 30° to 90°.
[0012] Furthermore, the steps of contour principal component analysis and symmetry matching in step ② are as follows: Represent the coordinates of the Ganoderma lucidum cap or stipe outline as a two-dimensional dataset. Then, the covariance matrix C of the two-dimensional dataset is calculated using formula (32), and the eigenvalues and eigenvectors of the covariance matrix C are calculated using formula (33). The eigenvector corresponding to the largest eigenvalue is selected as the principal component direction, and multiple candidate symmetry axes are generated through the principal component direction. The symmetry score of each candidate symmetry axis is calculated using formula (34), and the symmetry axis with the highest score is taken as the final symmetry axis. Formula (32) Formula (33) Formula (34) in, x i It is the x-coordinate of the i-th contour point. y i Let be the ordinate of the i-th contour point, n be the total number of contour points, x̄ be the average x-coordinate of all contour points, and ȳ be the average ordinate of all contour points. These are the eigenvalues of the covariance matrix. Let C be the eigenvector of the covariance matrix. Let be the angle between the candidate axis of symmetry and the x-axis, and b be the intercept of the candidate axis of symmetry.
[0013] The steps of the affine transformation are as follows: Based on the direction of the final axis of symmetry, the rotation angle of the affine transformation is calculated using formula (35), and then the rotation matrix is calculated using formula (36); the translation vector is calculated using formula (37); and the affine transformation is performed using formula (38) to obtain the rotated image, which is the corrected image of the Ganoderma lucidum cap or stipe. Formula (35) Formula (36) Formula (37) Formula (38) in, It is relative to x The angle along the positive direction of the axis. For rotation angle, for Rotation matrix, t x Let x be the x-coordinate of the rotation center. t yx is the ordinate of the rotation center, x is the x-coordinate of the original image pixel, y is the ordinate of the original image pixel, x' is the x-coordinate of the transformed image pixel, and y' is the ordinate of the transformed image pixel.
[0014] Furthermore, the steps for extracting the main body of Ganoderma lucidum are as follows: a. Image preprocessing The original Ganoderma lucidum image in RGB format was divided into 8×8 grid regions. Adaptive histogram equalization (AHE) was performed independently on each grid region. Then, the contrast magnification factor was limited by formula (1). Bilinear interpolation was used to smooth the grid boundaries. The grayscale channel Y was processed by formula (2). Formula (1) Where (i,j) is the row and column coordinates of a pixel in the image, f(i,j) is the gray value of the original image at pixel position (i,j), and g(i,j) is the gray value of the enhanced image at pixel position (i,j). = 2.0 is the magnification factor. = 0.8 is the limiting factor. `min()` is the maximum pixel value; `min()` is the minimum value function, used to select the minimum pixel value among multiple channels or multiple values. Formula (2) in The value for the red channel. This is the value for the green channel. The value is for the blue channel. b. Multi-feature fusion For the preprocessed image, the gray-level gradient is calculated using formulas (3) to (5), and then the local variance features are calculated in a window with a radius of r=5 using formulas (6) to (7). The morphological gradient is calculated using formula (8), and finally the weighted combination is performed using formula (9) to achieve feature fusion. Formula (3) Formula (4) Formula (5) in, It is the grayscale matrix of the input image; and It is the gradient image of the image in the x and y directions. It is a convolution operation, G is the edge intensity of each pixel, θ is the direction angle of the edge, and arctan() is the inverse trigonometric function; Formula (6) Formula (7) in, For falling on the current center pixel Let r be the coordinates of the pixel within a local window centered at a radius of r. The row and column coordinates of a pixel in the image; Indicates the pixel position of the image grayscale value, This represents the average gray level within a local area. denoted as ρ, where ρ is the gray-level variance within the local region; r is the neighborhood radius. Formula (8) Formula (9) in, It is the grayscale matrix of the input image, dilate( I ) and erode( I The first two characters represent dilation and erosion operations on the image, respectively; morphGrad represents the morphological gradient image; norm() is a normalization function used to uniformly scale each feature channel to [0,1]. , , represents the weighting coefficients for the features of each channel; F represents the final fused image; c. Extract the main image of Ganoderma lucidum. For the image after multi-feature fusion, the optimal threshold E is calculated using the Otsu method, and then the image is binarized using formula (10). Finally, the morphological closing operation is applied using formula (11) to obtain the main image of Ganoderma lucidum. Formula (10) Formula (11) in t The optimal threshold E is calculated using the Otsu method. It is the variance between classes. Here, is the total variance; arg max() represents finding the threshold F that maximizes the inter-class variance; threshold is the process of binarizing the image based on the optimal threshold Et; SE is a disk structuring element with a radius of 3; binary is the binary image after thresholding; erode() is the erosion operation; dilate() is the dilation operation; and closing is the final image of the Ganoderma lucidum.
[0015] Furthermore, the length, width, and color of the Ganoderma lucidum cap are averaged by averaging the length, width, and color calculated by segmenting the main body of the Ganoderma lucidum using concave points, and the length, width, and color calculated by segmenting the main body of the Ganoderma lucidum using mutation points.
[0016] The present invention also provides an apparatus for the appearance analysis of Ganoderma lucidum, the apparatus being proposed based on the same principle as the aforementioned method, and comprising seven units, namely: Image acquisition unit, used to receive images of Ganoderma lucidum; The image extraction unit is used to extract the main image of Ganoderma lucidum from the images collected from Ganoderma lucidum. Image segmentation unit one and image segmentation unit two are two functionally parallel units used to segment the main image of Ganoderma lucidum to obtain the segmented image of Ganoderma lucidum stem and cap. Image measurement unit one and image measurement unit two are two functionally parallel units used to measure the segmented images of Ganoderma lucidum cap and stem. Image measurement unit one obtains the length, width and color of the Ganoderma lucidum cap, while image measurement unit two obtains the length, width, shape and color of the Ganoderma lucidum cap and the height of the stem. The image measurement unit is used to average the length, width, and color of the Ganoderma lucidum cap to obtain the final length, width, and color of the Ganoderma lucidum cap.
[0017] The present invention also provides a computer-readable storage medium having a computer program stored thereon, the computer program being used to cause a computer to perform the image analysis method as described above.
[0018] The present invention also provides a system for analyzing the appearance of Ganoderma lucidum, including the aforementioned device connected via a data cable and / or a data interface.
[0019] This invention relates to a Ganoderma lucidum image analysis method. Based on the unique structure of Ganoderma lucidum, it uses a specific visual algorithm to accurately segment the cap and stipe of Ganoderma lucidum. Combined with a specific object detection algorithm, it can obtain accurate appearance and morphological characteristics of Ganoderma lucidum, quickly identify Ganoderma lucidum individuals that meet the standards, thereby avoiding subjective errors, low efficiency, and market chaos caused by manual initial screening. This provides a guarantee for subsequent processing and handling of Ganoderma lucidum, improves production efficiency, and has practical application value.
[0020] Obviously, based on the above description of the present invention, and according to common technical knowledge and conventional methods in the field, various other modifications, substitutions or alterations can be made without departing from the basic technical concept of the present invention.
[0021] The following detailed embodiments further illustrate the above-described content of the present invention. However, this should not be construed as limiting the scope of the present invention to the following examples. All technologies implemented based on the above-described content of the present invention fall within the scope of the present invention. Attached Figure Description
[0022] Figure 1 Image showing the effect of segmenting the head and stem of Ganoderma lucidum; Figure 2 Size inspection result diagram; Figure 3 Ganoderma lucidum image analysis flowchart; Figure 4 Architecture diagram of Ganoderma lucidum image analysis device. Detailed Implementation
[0023] It should be noted that the algorithms for data acquisition, transmission, storage and processing steps not specifically described in the embodiments, as well as the hardware structures and circuit connections not specifically described, can all be implemented using content already disclosed in the prior art.
[0024] Example 1: Ganoderma lucidum image analysis method Images of Ganoderma lucidum were acquired, and the main body of the Ganoderma lucidum was separated and extracted from its background. Then, the concave points in the outline of the Ganoderma lucidum were used to segment the stalk and cap. Figure 1 Finally, the length, width, and color of the Ganoderma lucidum cap were calculated separately. The specific steps are as follows: (a) Extraction of Ganoderma lucidum body 1) Image preprocessing The original Ganoderma lucidum image in RGB format was divided into 8×8 grid regions. Adaptive histogram equalization (AHE) was performed independently on each grid region. Then, the contrast magnification factor was limited by formula (1). Bilinear interpolation was used to smooth the grid boundaries. The grayscale channel Y was processed by formula (2). Formula (1) Where (i,j) is the row and column coordinates of a pixel in the image, f(i,j) is the gray value of the original image at pixel position (i,j), and g(i,j) is the gray value of the enhanced image at pixel position (i,j). = 2.0 is the magnification factor. = 0.8 is the limiting factor. `min()` is the maximum pixel value; `min()` is the minimum value function, used to select the minimum pixel value among multiple channels or multiple values. Formula (2) in The value for the red channel. This is the value for the green channel. The value is for the blue channel. 2) Multi-feature fusion For the preprocessed image, the Sobel operator is used to calculate the gray gradient using formulas (3) to (5). Then, formulas (6) to (7) are used to calculate the local variance features within a window with a radius of r=5. Formula (8) is used to calculate the morphological gradient. Finally, formula (9) is used to perform weighted combination to achieve feature fusion.
[0025] Formula (3) Formula (4) Formula (5) in, It is the grayscale matrix of the input image; and It is the gradient image of the image in the x and y directions. This is a convolution operation, where G is the edge intensity of each pixel, θ is the edge orientation angle, and arctan() is the inverse trigonometric function. Formula (6) Formula (7) in, For falling on the current center pixel Let r be the coordinates of the pixel within a local window centered at a radius of r. The row and column coordinates of a pixel in the image; Indicates the pixel position of the image grayscale value, This represents the average gray level within a local area. denoted as ρ, where ρ is the gray-level variance within the local region; r is the neighborhood radius.
[0026] Formula (8) Formula (9) in, It is the grayscale matrix of the input image, dilate( I ) and erode( I The first two characters represent dilation and erosion operations on the image, respectively; morphGrad represents the morphological gradient image; norm() is a normalization function used to uniformly scale each feature channel to [0,1]. , , represents the weighting coefficients for the features of each channel; F represents the final fused image.
[0027] 3) Extract the main image of Ganoderma lucidum. For the image after multi-feature fusion, the Otsu method is used to calculate the optimal threshold. t Then, the image is binarized using formula (10), and finally, morphological closing operation is performed using formula (11) to obtain the main image of Ganoderma lucidum. Formula (10) Formula (11) in t The optimal threshold is calculated using the Otsu method. It is the variance between classes. t is the total variance, arg max() means finding the threshold that maximizes the inter-class variance, threshold is the process of binarizing the image based on the optimal threshold t; SE is a disk structuring element with a radius of 3, binary is the binary image after thresholding, erode() is the erosion operation, dilate() is the dilation operation, and closing is the final image of the Ganoderma lucidum. (II) Segmentation of Ganoderma lucidum stem and cap For the contour of the stem-cap connection in the main image of Ganoderma lucidum, the curvature is calculated using formula (12) within the scale parameter range of scale = [0.02L, 0.04L, 0.06L, 0.08L, 0.10L] (Note: L is the perimeter of the contour). The obtained curvature values k(s) are sorted from smallest to largest to form a curvature sequence. The 95th percentile (i.e., the 95th percentile) in the curvature sequence is taken as the threshold κ. th The curvature value in the curvature sequence is greater than κ. th The point is the concave point at the connection between the cap and stem of Ganoderma lucidum. The concave points are used to calculate the pairing quality score using formulas (13) to (16). The line connecting the two concave points with the highest scores is used to divide the cap and stem of Ganoderma lucidum.
[0028] Formula (12) Where x′ and y′ are the first derivatives of the horizontal and vertical coordinates of the contour curve at the arc length parameter s; x′′ and y′′ are the second derivatives of the horizontal and vertical coordinates of the contour curve at the arc length parameter s; and k(s) is the contour curvature value.
[0029] Formula (13) Formula (14) Formula (15) Formula (16) Where d is the maximum depth of the inward concavity of the contour between the two concave points, W is the maximum width of the Ganoderma lucidum cap contour, and D is the depth score of the concave point. , , respectively, are the perpendicular distances from the two concave points to the center line of symmetry of the cap. The center line is a straight line that passes through the centroid of the cap outline and is perpendicular to the direction of the line connecting the two concave points. The centroid is the geometric center of the Ganoderma lucidum cap outline image, and its coordinates are calculated through the geometric moments of the cap image; S is the symmetry score. x Let exp() be the average position of the two concave points within the range of cap width normalized to the interval [0,1], where exp() is the exponential function and P is the relative position score. It is 0.4. , Both are 0.3, and F is the structural feature of concave point pairing.
[0030] (III) Detection of the length and width of Ganoderma lucidum cap For the segmented Ganoderma lucidum cap image, the findContours function was used to extract the contour, and then the area was used as the filtering condition: area>0.05. image_area (where image_area is the total number of pixels in the image) and Douglas-Peucker algorithm parameters: epsilon = 0.005 The perimeter (epsilon is the fitting accuracy threshold, perimeter is the perimeter of the contour) is used to optimize the cap contour; the centroid of the cap is found using formulas (17) and (18) after optimization; the two points on the cap contour that are farthest apart and whose connecting lines pass through the centroid are found using formula (54); the axis of symmetry is obtained using formula (55); the length of the cap is the distance between the two intersection points of the axis of symmetry and the contour; the width of the cap is the distance between the two intersection points of the straight line perpendicular to the axis of symmetry and passing through the centroid and the contour. Figure 2 ); Formula (17) Formula (18) in, x, y These represent the column and row coordinates of a pixel in the image, respectively. M represents the grayscale value at a pixel location in the image. 00 M is the zeroth moment, corresponding to the sum of all foreground pixels in the image; 10 and M 01 , and represent the first moments of the image, respectively, and represent the weighted sum of positions along the horizontal and vertical directions; Formula (54) Where d1 represents the distance between two points on the cap outline, and (x1,y1) and (x2,y2) are the x and y coordinates of the two points, respectively; (55) Where dx represents the difference in the x-coordinates of the two points on the contour whose line passes through the centroid and are farthest apart, and dy represents the difference in the y-coordinates of the two points on the contour whose line passes through the centroid and are farthest apart. The direction vector of the axis of symmetry; (iv) Classification by color of Ganoderma lucidum cap For the segmented Ganoderma lucidum cap image, the RGB format is converted to HSV format using formulas (19) to (21), and then the illumination is normalized using the Retinex algorithm, i.e., formula (22). The feature statistics of each channel in the HSV space are performed using formula (23), and finally the cluster analysis is performed using the mean shift algorithm, i.e., formula (24). The color classification is performed using formula (25), and the color proportion is quantized using formula (26). Formula (19) Formula (20) Formula (21) Where V is lightness, S is saturation, and H is hue. The value for the red channel. This is the value for the green channel. For the blue channel values, max() is the maximum value function, and min() is the minimum value function; Formula (22) in, x, y R represents the column coordinates and row coordinates of a pixel in the image, respectively. (x,y) Indicates the pixel position (x,y) Image reflection component at location; I (x,y) Indicates the pixel position of the original image. (x,y) The brightness value at the location; F represents the smooth convolution kernel used to simulate ambient lighting.
[0031] Formula (23) Where μ represents the mean of the color distribution, σ represents the standard deviation, and s represents the skewness of the color distribution. p ( i ) represents the pixel value of the i-th color channel (i.e., the H, S, or V channel in HSV), and N is the total number of pixels.
[0032] Formula (24) in, tFor the number of iterations, x ( t Let represent the current solution vector at time t, and M(x(t)) represent the search direction or update increment calculated for the current solution x(t). x ( t +1) is the final solution vector.
[0033] Formula (25) Formula (26) in, x It is the feature vector (i.e., hue, saturation, and brightness value) of a pixel in the image in the HSV color space. c It is a color classification center, namely, predefined color classes such as "red", "yellow", and "brown"; d ( x, c ) express x Go to the color sorting center c Mahalanobis distance, d ( x,c′ ) express x To the color classification center c The Mahalanobis distances to the color classification centers c′ other than σ, where σ is the standardized coefficient of the Mahalanobis distance, exp() is the exponential function, and p(c|x) represents x Belongs to color category c The posterior probability; total pixels is the total number of pixels; ratio(c) represents the color category in the image. c The percentage of pixels.
[0034] Example 2: Ganoderma lucidum image analysis method Images of Ganoderma lucidum were acquired, the main body of Ganoderma lucidum was separated and extracted from its background, and the Ganoderma lucidum stipe and cap were segmented using mutation points in the Ganoderma lucidum outline. Finally, the length, width, color and shape of the Ganoderma lucidum cap and the length of the stipe were calculated respectively. (a) Extraction of Ganoderma lucidum body 1) Image preprocessing The original Ganoderma lucidum image in RGB format was divided into 8×8 grid regions. Adaptive histogram equalization (AHE) was performed independently on each grid region. Then, the contrast magnification factor was limited by formula (1). Bilinear interpolation was used to smooth the grid boundaries. The grayscale channel Y was processed by formula (2). Formula (1) Where (i,j) is the row and column coordinates of a pixel in the image, f(i,j) is the gray value of the original image at pixel position (i,j), and g(i,j) is the gray value of the enhanced image at pixel position (i,j). = 2.0 is the magnification factor. = 0.8 is the limiting factor. `min()` is the maximum pixel value; `min()` is the minimum value function, used to select the minimum pixel value among multiple channels or multiple values. Formula (2) in The value for the red channel. This is the value for the green channel. This represents the value for the blue channel.
[0035] 2) Multi-feature fusion For the preprocessed image, the Sobel operator is used to calculate the gray-level gradient using formulas (3) to (5), and then formulas (6) to (7) are used to calculate the local variance features within a window with a radius of r=5. The morphological gradient is calculated using formula (8), and finally, formula (9) is used for weighted combination to achieve feature fusion.
[0036] Formula (3) Formula (4) Formula (5) in, It is the grayscale matrix of the input image; and It is the gradient image of the image in the x and y directions. This is a convolution operation, where G is the edge intensity of each pixel, θ is the edge orientation angle, and arctan() is the inverse trigonometric function. Formula (6) Formula (7) in, For falling on the current center pixel Let r be the coordinates of the pixel within a local window centered at a radius of r. The row and column coordinates of a pixel in the image; Indicates the pixel position of the image grayscale value, This represents the average gray level within a local area. denoted as ρ, where ρ is the gray-level variance within the local region; r is the neighborhood radius.
[0037] Formula (8) Formula (9) in, It is the grayscale matrix of the input image, dilate( I ) and erode( I The first two characters represent dilation and erosion operations on the image, respectively; morphGrad represents the morphological gradient image; norm() is a normalization function used to uniformly scale each feature channel to [0,1]. , , represents the weighting coefficients for the features of each channel; F represents the final fused image.
[0038] 3) Extract the main image of Ganoderma lucidum. For the image after multi-feature fusion, the Otsu method is used to calculate the optimal threshold. t Then, the image is binarized using formula (10), and finally, morphological closing operation is performed using formula (11) to obtain the main image of Ganoderma lucidum. Formula (10) Formula (11) in t The optimal threshold is calculated using the Otsu method. It is the variance between classes. This is the total variance. `arg max()` represents finding the threshold that maximizes the inter-class variance. `threshold` is the process of binarizing the image based on the optimal threshold `t`. `SE` is a disk structuring element with a radius of 3. `binary` is the binary image after thresholding. `erode()` is the erosion operation. `dilate()` is the dilation operation. `closing` is the final image of the Ganoderma lucidum.
[0039] (II) Segmentation of Ganoderma lucidum stem and cap The contour of the main image of Ganoderma lucidum is extracted using the edge detection algorithm (Canny edge detection). Then, the slope change rate of each contour point is calculated from top to bottom using formulas (27) to (30). Points with an absolute value of slope change rate greater than a threshold are identified as abrupt change points. The abrupt change points are then set up using formula (31) and selected. The first and last mutation points are connected by a straight line as the dividing baseline, dividing the main image of Ganoderma lucidum into the stipe and cap. Formula (27) Formula (28) Formula (29) Formula (30) Formula (31) in, x i It is the first i The x-coordinates of the contour points y i It is the first i The ordinates of the contour points, m i m is the slope of the tangent line at contour point i from 1 to n-2; m0 is the slope of the tangent line at contour endpoint i=0, m n-1 It is the slope of the tangent line at the endpoint i=n-1 of the profile; dm / dy i It is the rate of change of the slope of the contour point i from 0 to n-1, when y i+1 =y i When the slope changes infinitely, smoothing or other numerical methods should be used, such as using the average slope of nearby points. The threshold value is determined through statistical methods, specifically: first, the calculated slope change rate dm / dy is... i Sort the data from smallest to largest, and then select one of them as the threshold. If the detected mutation point contains noise points, select the value with the larger slope change rate as the threshold. If the detected mutation point misses the visually visible inflection point, select the value with the smaller slope change rate as the threshold. Repeat this selection until the detected mutation point contains the visually visible inflection point and has no background noise.
[0040] (III) Detection of the length, width, shape, and stipe length of Ganoderma lucidum cap 1) Symmetry axis correction The segmented images of the Ganoderma lucidum cap and stipe are obtained separately. The geometric symmetry axes of the cap and stipe are determined through principal component analysis and symmetry matching. Then, affine transformation is used to rotate the images so that the symmetry axes are perfectly aligned with the principal axes (i.e., the vertical axis: the direction perpendicular to the image coordinate system). The corrected images of the Ganoderma lucidum cap and stipe are obtained. The methods for contour principal component analysis and symmetry matching are as follows: Represent the coordinates of the Ganoderma lucidum cap or stipe outline as a two-dimensional dataset. Then, the covariance matrix C of the two-dimensional dataset is calculated using formula (32); the eigenvalues and eigenvectors of the covariance matrix C are calculated using formula (33), and the eigenvector corresponding to the largest eigenvalue is selected as the principal component direction. Multiple candidate symmetry axes are generated through the principal component direction; the symmetry score of each candidate symmetry axis is calculated using formula (34), and the symmetry axis with the highest score is taken as the final symmetry axis. Formula (32) Formula (33) Formula (34) in,x i It is the x-coordinate of the i-th contour point. y i Let be the ordinate of the i-th contour point, n be the total number of contour points, x̄ be the average x-coordinate of all contour points, and ȳ be the average ordinate of all contour points. These are the eigenvalues of the covariance matrix. Let C be the eigenvector of the covariance matrix. Let be the angle between the candidate axis of symmetry and the x-axis, and b be the intercept of the candidate axis of symmetry.
[0041] The method of affine transformation is as follows: Based on the direction of the final axis of symmetry, the rotation angle of the affine transformation is calculated using formula (35), and then the rotation matrix is calculated using formula (36); the translation vector is calculated using formula (37); and the affine transformation is performed using formula (38) to obtain the rotated image, which is the corrected image of the Ganoderma lucidum cap or stipe. Formula (35) Formula (36) Formula (37) Formula (38) in, It is relative to x The angle between the positive axis and the horizontal to the right. For rotation angle, for Rotation matrix, t x Let x be the x-coordinate of the rotation center. t y x is the ordinate of the rotation center, x is the x-coordinate of the original image pixel, y is the ordinate of the original image pixel, x' is the x-coordinate of the transformed image pixel, and y' is the ordinate of the transformed image pixel.
[0042] 2) Calculation of Ganoderma lucidum cap length For the corrected Ganoderma lucidum cap image, the slope change rate of each contour point is calculated from top to bottom using formulas (27) to (30), and the points with a slope change rate of zero are represented as the set of extreme points. Based on the shape of the Ganoderma lucidum, there are a total of 3 extreme points in the extreme point set, where the ordinate y is the extreme point. i The largest point is the highest point at the top. The other two ordinates y i The smaller points are the two valley bottom points. and Take the y-coordinate of the valley bottom point. iThe smaller point represents the lowest point of the cap, and the highest point of the cap is the highest point of the apex. ,Right now ; Calculate based on the y-coordinates of the highest and lowest points. length: ; 3) Calculation of Ganoderma lucidum cap width For the corrected image of the Ganoderma lucidum cap, the slope change rate of each contour point is calculated from top to bottom using formulas (27) to (30). According to the shape of Ganoderma lucidum, there are two points with infinite slope, namely and ; Calculate based on two points with infinite slopes width, 4) Determination of Ganoderma lucidum cap shape For the corrected image of the Ganoderma lucidum cap, the slope change rate of each contour point is calculated from top to bottom using formulas (27) to (30). According to the shape of Ganoderma lucidum, there are two points with a slope of positive infinity. Formula (39) is used to locate these two points, and all the lower half contour points between these two points are extracted to form the lower half contour C of the cap. lower ={p a ,p a+1 ,...,p b}; When C lower The slope change rate sequence {k a ,k a+1 ,...,k b} satisfies at least two sign alternations, that is: Make k i <0, k j >0, k m <0, k n >0 (a≤i<j<m<n≤b), and the overall trend conforms to the pattern of "negative→positive→negative→positive", with a kidney-shaped cap; where a is the starting point in the slope change rate sequence, that is, the x-coordinate of the first point where the slope change rate is infinite, and b is the ending point in the slope change rate sequence, that is, the x-coordinate of the second point where the slope change rate is infinite. i, j, m, n Let a be the x-coordinate of some of these contour points, and let a ≤ i < j < m < n ≤ b. That is, first find points with negative slopes, then find points with positive slopes, then find points with negative slopes again, and then find points with positive slopes again. If such a relationship is satisfied, it can be proved that the cap is kidney-shaped.
[0043] When C lower The overall trend of the slope sequence is "negative → positive" (i.e., monotonically increasing), and there is at least one k. iSatisfy |k i |≥T, the cap is nearly round; When C lower The overall trend of the slope sequence is "negative → positive" (i.e., monotonically increasing), and all k i Satisfy |k i | < T, the cap is semi-circular; Formula (39) in, k i For contour points i The slope of the tangent at p a The first condition that satisfies k during a top-down search. i =+∞ contour point index; k j For contour points j The slope of the tangent at p b For in p a The search then continues to find the second one that satisfies k. j =+∞ contour point index; T The threshold for judging the steepness of the contour is 0.2.
[0044] 5) Calculation of Ganoderma lucidum stipe length For the corrected Ganoderma lucidum stipe image, the slope change rate of each contour point is calculated from top to bottom using formulas (27) to (30). Points with an absolute value of the slope change rate greater than a threshold are taken as mutation points. The mutation points were aggregated using formula (31). Based on the morphological characteristics of the Ganoderma lucidum stipe, the aggregate contained four mutation points, namely the two largest ordinate mutation points in the top region, i.e. = And the two smallest vertical coordinate abrupt change points in the bottom region, namely = Take the highest position of the top two mutation points and the lowest position of the bottom two mutation points. That is... , Calculate the stipe length, i.e. ; The threshold is determined by a statistical method, which is as follows: First, the calculated slope change rate dm / dyi is sorted from smallest to largest, and then one of them is selected as the threshold. If the detected mutation point contains noise points, the value with the larger slope change rate is selected as the threshold; if the detected mutation point misses the visually visible inflection point, the value with the smaller slope change rate is selected as the threshold. This process is repeated until the detected mutation point contains the visually visible inflection point and there is no background noise.
[0045] (iv) Color of Ganoderma lucidum cap 1) Image preprocessing The segmented Ganoderma lucidum cap image is processed by convolution using a Gaussian filter, i.e., formula (40), and then by median filtering, i.e., formula (41), the median gray value of each pixel in the image is calculated for the surrounding pixels to suppress noise interference while preserving color details. Formula (40) Formula (41) in x, y These represent the column and row coordinates of a pixel in the image, respectively. Let be the standard deviation of the Gaussian distribution. It is the kernel function of a two-dimensional Gaussian filter; is the grayscale value of the original image, and Median is the median function. It is the grayscale value after median filtering.
[0046] 2) Color space conversion Convert RGB format images to HSV format images.
[0047] 3) Identifying the front and back of the Ganoderma lucidum cap For the frequency of each hue value in the HSV format image, histogram statistics are performed using formula (46), and then the histogram is normalized using formula (47) to make its sum equal to 1. Finally, the proportions of positive and negative energy in the histogram are calculated using formulas (48) and (49). Larger than the back The image shows the front of the Ganoderma lucidum cap. Smaller than the back The image shows the back of the Ganoderma lucidum cap; Formula (46) Formula (47) Formula (48) Formula (49) The count() function is used to count the tonal values of the front area, which range from 0° to 30° or 330° to 360°, and the back area tonal values, which range from 30° to 90°.
[0048] 4) Refine color classification In the HSV format image, the front of the Ganoderma lucidum cap is reddish and the back is yellowish. After determining the front and back of the Ganoderma lucidum cap, the color classification is further refined by the screening conditions in formulas (50) to (53). The front of the cap is dark red if it meets formula (50) and standard red if it meets formula (51); the back of the cap is light yellow if it meets formula (52) and orange-yellow if it meets formula (53).
[0049] Formula (50) The H value covers the extreme area of the red main color (darker red), and needs to meet the requirement of high saturation (S). red_min =0.6) and low brightness (V red_max =0.7), to distinguish it from the light red in bright environments; Formula (51) The H value is located in the central area of the red primary color, maintaining the same S and V thresholds, but allowing a slightly higher brightness (V). red_max (Can be relaxed to 0.8). Formula (52) The H value is located in the light region of the yellow spectrum, requiring a lower saturation (such as S). yellow_min =0.4) and higher brightness (such as V) yellow_min =0.6), to match the pale yellow characteristic under natural light; Formula (53) For the H value to transition to the orange region, a higher saturation (such as S) is required. orange_min =0.5) and medium brightness (such as V) orange_min =0.5), to distinguish it from brown tones.
[0050] Example 3: Ganoderma lucidum image analysis method Figure 3 This is a flowchart of the Ganoderma lucidum image analysis method in this embodiment; specifically, the length, width, shape, and color of the Ganoderma lucidum cap, as well as the length of the stipe, are obtained according to the methods in Examples 1 and 2 respectively; The average length of the cap obtained in Example 1 and the cap obtained in Example 2 is used to obtain the length of the Ganoderma lucidum cap. The width of the cap obtained in Example 1 is averaged with the width of the cap obtained in Example 2 to obtain the width of the Ganoderma lucidum cap. The shape obtained in Example 2 is the shape of the Ganoderma lucidum cap; When the color ratio (i.e., ratio(c)) obtained in Example 1 is displayed as yellow, the color ratio value is averaged with the reverse energy ratio output in Example 2 to obtain the color of the reverse side of the Ganoderma lucidum cap; when the output color ratio (i.e., ratio(c)) is displayed as red, the color ratio value is averaged with the positive energy ratio output in Example 2 to obtain the color of the front side of the Ganoderma lucidum cap.
[0051] The length of the Ganoderma lucidum stipe obtained in Example 2 is the same as the length of the Ganoderma lucidum stipe.
[0052] The analysis method of this embodiment was used to analyze and detect 30 images of Ganoderma lucidum and Ganoderma sinense. The detection results were consistent with those of professionals in traditional Chinese medicine.
[0053] Example 4: An apparatus for the appearance analysis of Ganoderma lucidum. This device is proposed based on the same principle as the method in Example 3, see [link]. Figure 4 The device includes: Image acquisition unit, used to receive images of Ganoderma lucidum; The image extraction unit is used to extract the main image of Ganoderma lucidum from the images collected from Ganoderma lucidum. Image segmentation unit one and image segmentation unit two are two functionally parallel units used to segment the main image of Ganoderma lucidum to obtain the segmented image of Ganoderma lucidum stem and cap. Image measurement unit one and image measurement unit two are two functionally parallel units used to measure the segmented image of Ganoderma lucidum cap and stem. Image measurement unit one obtains the length, width and color of the Ganoderma lucidum cap, while image measurement unit two obtains the length, width, shape and color of the Ganoderma lucidum cap and the length of the stem. The image measurement unit is used to average the length, width, and color of the Ganoderma lucidum cap to obtain the final length, width, and color of the Ganoderma lucidum cap.
[0054] In summary, this invention uses a specific visual algorithm to accurately segment the cap and stem of Ganoderma lucidum. Combined with a specific object detection algorithm, it can obtain accurate appearance and morphological characteristics of Ganoderma lucidum, quickly identify Ganoderma lucidum individuals that meet the standards, thereby avoiding subjective errors, low efficiency, and market chaos caused by manual screening. This provides a guarantee for subsequent processing and handling of Ganoderma lucidum, improves production efficiency, and has practical application value.
Claims
1. A method for analyzing Ganoderma lucidum images, characterized in that: Includes the following steps: Images of Ganoderma lucidum are acquired, and the main body of Ganoderma lucidum is separated and extracted from its background. The cap and stipe of Ganoderma lucidum are segmented using the concave points of the outline in the main body image. The length and width of the cap of Ganoderma lucidum are calculated, and the color of the cap of Ganoderma lucidum is identified. The cap and stipe of Ganoderma lucidum are segmented using the abrupt change points of the outline in the main image of Ganoderma lucidum. The length and width of the cap are calculated, the color and shape of the cap are identified, and the length of the stipe is calculated. The average of the cap length calculated based on concave point segmentation and the cap length calculated based on mutation point segmentation is taken as the cap length of Ganoderma lucidum. The average of the cap width calculated based on concave point segmentation and the cap width calculated based on mutation point segmentation is taken as the cap width of Ganoderma lucidum. The cap shape and stipe length calculated based on mutation point segmentation are taken as the cap shape and stipe length of Ganoderma lucidum. The concave points are determined as follows: for the outline of the connection between the cap and the stem in the main image of Ganoderma lucidum, within the scale parameter range, multi-scale curvature calculation is performed using formula (12); points with curvature values greater than the threshold A are selected, and pairing quality scores are performed using formulas (13) to (16), and the two points with the highest scores are the concave points; The scale parameter range is scale = [0.02L, 0.04L, 0.06L, 0.08L, 0.10L], where L is the perimeter of the contour; The threshold A is determined as follows: multi-scale curvature is calculated using formula (12), and the obtained curvature values are sorted from smallest to largest. The 95th percentile curvature value is taken as the threshold. Official (12) Where x′ and y′ are the first derivatives of the horizontal and vertical coordinates of the profile curve at the arc length parameter s; x′′ and y′′ are the second derivatives of the horizontal and vertical coordinates of the profile curve at the arc length parameter s; and k(s) is the profile curvature value. Official (13) Official (14) Official (15) Official (16) Where d is the maximum depth of the inward concavity of the contour between the two concave points, W is the maximum width of the Ganoderma lucidum cap contour, and D is the depth score of the concave point. , , respectively, are the perpendicular distances from the two concave points to the center line of symmetry of the cap. The center line of symmetry is a straight line that passes through the centroid of the cap outline and is perpendicular to the direction of the line connecting the two concave points. The centroid is the geometric center of the Ganoderma lucidum cap outline image; S is the symmetry score. x Let exp() be the average position of the two concave points within the range of cap width normalized to the interval [0,1], where exp() is the exponential function and P is the relative position score. It is 0.
4. , Both are 0.3, and F represents the structural feature of concave point pairing; The mutation points are determined as follows: the Ganoderma lucidum main image is extracted using an edge detection algorithm, and then the slope change rate of each contour point is calculated from top to bottom using formulas (27) to (30). Points with an absolute value of slope change rate greater than the threshold B are selected and set using formula (31). The two points at the beginning and end of the middle section are referred to as the mutation points; The threshold B is a value predetermined by statistical methods; Official (27) Official (28) Official (29) Official (30) Official (31); in, x i It is the first i The x-coordinates of the contour points y i It is the first i The ordinates of the contour points, m i m is the slope of the tangent line at contour point i from 1 to n-2; m0 is the slope of the tangent line at contour endpoint i=0, m n-1 It is the slope of the tangent line at the endpoint i=n-1 of the profile; dm / dy i It is the rate of change of the slope of the contour point i from 0 to n-1, when y i+1 =y i When the slope changes infinitely, smoothing or using the average slope of nearby points should be used. The threshold B is set.
2. The Ganoderma lucidum image analysis method according to claim 1, characterized in that: The steps for calculating and recognizing the Ganoderma lucidum using concave point segmentation of the contour in the main image are as follows: 1) Separate the stem and cap of Ganoderma lucidum The cap and stipe of Ganoderma lucidum are segmented by a straight line connecting two concave points to obtain images of the cap and stipe of Ganoderma lucidum. 2) Calculation of cap length and width Take an image of the Ganoderma lucidum cap, use the findContours function to extract the contour, and then use the area filter condition: area > 0.
05. image_area and Douglas-Peucker algorithm parameters: epsilon = 0.005 Perimeter optimizes the cap outline. Formulas (17) and (18) are used to find the cap centroid of the optimized cap outline. Formula (54) is used to find the two points on the cap outline that are farthest apart and whose connecting lines pass through the centroid. Formula (55) is used to obtain the axis of symmetry. The cap length is the distance between the two intersection points of the axis of symmetry and the outline. The cap width is the distance between the two intersection points of the straight line perpendicular to the axis of symmetry and passing through the centroid and the outline. Official (17) Official (18); in, x, y These represent the column and row coordinates of a pixel in the image, respectively. M represents the grayscale value at a pixel location in the image. 00 M is the zeroth moment, corresponding to the sum of all foreground pixels in the image; 10 and M 01 , , and , respectively, represent the first moments of the image, and , representing the weighted sum of positions along the horizontal and vertical directions; Official (54) Where d1 represents the distance between two points on the cap outline, and (x1,y1) and (x2,y2) are the x and y coordinates of the two points, respectively; Official (55) Where dx represents the difference in the x-coordinates of the two points on the contour whose line passes through the centroid and are farthest apart, and dy represents the difference in the y-coordinates of the two points on the contour whose line passes through the centroid and are farthest apart. The direction vector of the axis of symmetry; 3) Reishi mushroom cap color identification Take the image of Ganoderma lucidum cap, use formula (19)~(21) to convert the RGB format to HSV format, then use formula (22) to normalize the illumination, use formula (23) to perform feature statistics on each channel of the HSV space, and finally use formula (24) to perform cluster analysis, use formula (25) to perform color classification, and use formula (26) to quantify the color proportion. Official (19) Official (20) Official (21) Where V is lightness, S is saturation, and H is hue. The value for the red channel. This is the value for the green channel. For the blue channel values, max() is the maximum value function, and min() is the minimum value function; Official (22) in, x, y R represents the column coordinates and row coordinates of a pixel in the image, respectively. (x,y) Indicates the pixel position (x,y) Image reflection component at location; I (x,y) Indicates the pixel position of the original image. (x,y) The brightness value at that location; F represents the smooth convolution kernel used to simulate ambient lighting; Official (23) Where μ represents the mean of the color distribution, σ represents the standard deviation, and s represents the skewness of the color distribution. p ( i ) represents the pixel value of the i-th color channel, and N is the total number of pixels; Official (24) in, t For the number of iterations, x ( t Let represent the current solution vector at time t, and M(x(t)) represent the search direction or update increment calculated for the current solution x(t). x ( t +1) is the final solution vector; Official (25) Official (26) in, x It is the feature vector of a pixel in the image in the HSV color space. c It is a color classification center; d ( x, c ) express x Go to the color sorting center c Mahalanobis distance, d ( x,c′ ) express x To the color classification center c The Mahalanobis distances to the color classification centers c′ other than σ, where σ is the standardized coefficient of the Mahalanobis distance, exp() is the exponential function, and p(c|x) represents x Belongs to color category c The posterior probability; total pixels is the total number of pixels; ratio(c) represents the color category in the image. c The percentage of pixels.
3. The Ganoderma lucidum image analysis method according to claim 1, characterized in that: The steps for segmenting and recognizing Ganoderma lucidum using abrupt change points in the contour of the main image are as follows: ①Splitting the Ganoderma lucidum stem cap The cap and stipe of Ganoderma lucidum were segmented by a straight line connecting two mutation points to obtain images of the cap and stipe of Ganoderma lucidum. ② Image symmetry axis correction The segmented images of Ganoderma lucidum cap and stipe are obtained separately. The geometric symmetry axes of Ganoderma lucidum cap and stipe are determined by contour principal component analysis and symmetry matching. Then, the images are rotated by affine transformation to align the symmetry axes with the principal axes, thus obtaining the corrected images of Ganoderma lucidum cap and stipe. ③ Calculation of Ganoderma lucidum cap length Take the corrected image of the Ganoderma lucidum cap, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom. Points with a slope change rate of zero are represented as the set of extreme points. , with the vertical axis y i The largest point is the vertex, with the y-coordinate as the vertex. i The point with the smallest value is the lowest point, calculated based on the y-coordinates of the highest and lowest points. length; ④ Calculation of Ganoderma lucidum cap width Take the corrected image of the Ganoderma lucidum cap, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom; calculate based on two points with infinite slopes. width; ⑤ Reishi mushroom cap shape identification Take the corrected image of the Ganoderma lucidum cap, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom along the contour. Take the point with a slope of positive infinity, use formula (39) to locate it, and extract all the lower half contour points between the points to form the lower half contour C of the cap. lower ={p a ,p a+1 ,...,p b }; When C lower The slope change rate sequence {k a ,k a+1 ,...,k b The cap is kidney-shaped and satisfies at least two sign alternations, and the overall trend conforms to the pattern of "negative → positive → negative → positive". When C lower The overall trend of the slope change rate sequence is "negative → positive", and there is at least one k i Satisfy |k i |≥T, the cap is nearly round; When C lower The overall trend of the slope change rate sequence is "negative → positive", and all k i Satisfy |k i |≥T, the cap is semi-circular; Official (39); in, k i For contour points i The slope of the tangent at point p a The first condition that satisfies k during a top-down search. i =+∞ contour point index; k j For contour points j The slope of the tangent at p b For in p a The search then continues to find the second one that satisfies k. j =+∞ contour point index; T It is 0.2; ⑥ Calculation of Ganoderma lucidum stipe length Take the corrected image of Ganoderma lucidum stipe, and use formulas (27) to (30) to calculate the slope change rate of each contour point from top to bottom. Take the points whose absolute value of the slope change rate is greater than the threshold D, and use formula (31) to set them together, with the vertical axis y i The largest point is the vertex, with the y-coordinate as the vertex. i The minimum point is the lowest point. The stipe length is calculated based on the y-coordinates of the highest and lowest points. The threshold D is a value predetermined by statistical methods; ⑦ Reishi mushroom cap color identification The segmented Ganoderma lucidum cap image is preprocessed using Gaussian and median filters, and then converted from RGB to HSV format. The frequency of each hue value in the HSV format image is statistically analyzed using formula (46). The histogram is normalized using formula (47) to make its sum equal to 1. Finally, formulas (48) and (49) are used to calculate the proportion of frontal and back energy in the histogram. Larger than the back The image shows the front of the Ganoderma lucidum cap. Smaller than the back The image shows the back of the Ganoderma lucidum cap; Official (46) Official (47) Official (48) Official (49); The count() function is used to count the tonal values of the front area, which range from 0° to 30° or 330° to 360°, and the back area tonal values, which range from 30° to 90°.
4. The image analysis method according to claim 3, characterized in that: Step ② involves the following steps: principal component analysis of the contour and symmetry matching. Represent the coordinates of the Ganoderma lucidum cap or stipe outline as a two-dimensional dataset. Then, the covariance matrix C of the two-dimensional dataset is calculated using formula (32), and the eigenvalues and eigenvectors of the covariance matrix C are calculated using formula (33). The eigenvector corresponding to the largest eigenvalue is selected as the principal component direction, and multiple candidate symmetry axes are generated through the principal component direction. The symmetry score of each candidate symmetry axis is calculated using formula (34), and the symmetry axis with the highest score is taken as the final symmetry axis. Official (32) Official (33) Official (34) in, x i It is the x-coordinate of the i-th contour point. y i Let be the ordinate of the i-th contour point, n be the total number of contour points, x̄ be the average x-coordinate of all contour points, and ȳ be the average ordinate of all contour points. These are the eigenvalues of the covariance matrix. Let C be the eigenvector of the covariance matrix. Let be the angle between the candidate axis of symmetry and the x-axis, and b be the intercept of the candidate axis of symmetry. The steps of the affine transformation are as follows: Based on the direction of the final axis of symmetry, the rotation angle of the affine transformation is calculated using formula (35), and then the rotation matrix is calculated using formula (36); the translation vector is calculated using formula (37); and the affine transformation is performed using formula (38) to obtain the rotated image, which is the corrected image of the Ganoderma lucidum cap or stipe. Official (35) Official (36) Official (37) Official (38) in, It is relative to x The angle along the positive direction of the axis. For rotation angle, for Rotation matrix, t x Let x be the x-coordinate of the rotation center. t y x is the ordinate of the rotation center, x is the x-coordinate of the original image pixel, y is the ordinate of the original image pixel, x' is the x-coordinate of the transformed image pixel, and y' is the ordinate of the transformed image pixel.
5. The image analysis method according to claim 1, characterized in that: The steps for extracting the main body of Ganoderma lucidum are as follows: a. Image preprocessing The original Ganoderma lucidum image in RGB format was divided into 8×8 grid regions. Each grid region was independently subjected to adaptive histogram equalization. Then, the contrast magnification factor was limited by formula (1). Bilinear interpolation was used to smooth the grid boundaries. The grayscale channel Y was processed by formula (2). Official (1) Where (i,j) is the row and column coordinates of a pixel in the image, f(i,j) is the gray value of the original image at pixel position (i,j), and g(i,j) is the gray value of the enhanced image at pixel position (i,j). = 2.0 is the magnification factor. =0.8 is the limiting factor. `min()` is the maximum pixel value; `min()` is the minimum value function. Official (2) in The value for the red channel. This is the value for the green channel. The value is for the blue channel. b. Multi-feature fusion For the preprocessed image, the gray-level gradient is calculated using formulas (3) to (5), and then the local variance features are calculated in a window with a radius of r=5 using formulas (6) to (7). The morphological gradient is calculated using formula (8), and finally the weighted combination is performed using formula (9) to achieve feature fusion. Official (3) Official (4) Official (5) in, It is the grayscale matrix of the input image; and It is the gradient image of the image in the x and y directions. It is a convolution operation, where G is the edge intensity of each pixel, θ is the direction angle of the edge, and arctan() is the inverse trigonometric function; Official (6) Official (7) in, For falling on the current center pixel Let r be the coordinates of the pixel within a local window centered at a radius of r. The row and column coordinates of a pixel in the image; Indicates the pixel position of the image grayscale value, This represents the average gray level within a local area. denoted as ρ, where ρ is the gray-level variance within the local region; r is the neighborhood radius. Official (8) Official (9) in, It is the grayscale matrix of the input image, dilate( I ) and erode( I The symbols ) represent dilation and erosion operations on the image, respectively; morphGrad represents the morphological gradient image; norm() is the normalization function. , , represents the weighting coefficients for the features of each channel; F represents the final fused image; c. Extract the main image of Ganoderma lucidum. For the image after multi-feature fusion, the optimal threshold E is calculated using the Otsu method, and then the image is binarized using formula (10). Finally, the morphological closing operation is applied using formula (11) to obtain the main image of Ganoderma lucidum. Official (10) Official (11) in t The optimal threshold E is calculated using the Otsu method. It is the variance between classes. is the total variance, arg max() means finding the threshold F that maximizes the inter-class variance, threshold is the process of binarizing the image based on t; SE is a disk structuring element with a radius of 3, binary is the binary image after thresholding, erode() is the erosion operation, dilate() is the dilation operation, and closing is the final image of the Ganoderma lucidum.
6. An apparatus for analyzing the appearance of Ganoderma lucidum, characterized in that: The apparatus performs the method as described in any one of claims 1-5.
7. A computer-readable storage medium, characterized in that: It stores a computer program that enables the computer to perform the image analysis method as described in any one of claims 1-5.
8. A system for analyzing the appearance of Ganoderma lucidum, characterized in that, Includes the apparatus of claim 6, which is connected via a data cable and a data interface.
Citation Information
Patent Citations
Mushroom form data acquisition method and system, storage medium and equipment
CN118397028A