Herb powder granularity detection method based on industrial vision
Patent Information
- Application Number
- CN202611138496.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-29
- Publication Date
- 2026-10-16
AI Technical Summary
药草粉体存在深浅混杂、纤维纹理交错和软性团聚时,易产生边界偏移、过度切分或粘连保留,影响粒径统计准确性
1、本发明通过对出料口图像信号进行光照适配、亮度异常补偿、孤立噪点替换和背景灰度剔除,粉体区域在后续分析前形成稳定灰度基础,减弱阴影、反光、粉尘及传感器噪声干扰,提高颗粒边缘识别一致性和检测结果可靠性。
Smart Images

Figure CN122928816A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial vision inspection technology, and in particular to a method for detecting the particle size of powdered herbs based on industrial vision. Background Technology
[0002] The field of industrial vision inspection technology encompasses automatic inspection methods based on image acquisition and processing, involving the placement of optical imaging devices, image acquisition of continuously moving targets, particle morphology recognition, and statistical analysis. The core of this technology lies in continuously sampling target objects using industrial cameras, separating the targets from the background using image segmentation methods, obtaining size parameters based on geometric feature calculation rules, and simultaneously combining statistical distribution methods to analyze the particle size or morphology distribution of a large number of targets. This technology is widely applied in scenarios such as powder material inspection, particle grading, quality screening, and process monitoring, forming a complete inspection process system from image acquisition to result output.
[0003] Among them, the herbal powder particle size detection method based on industrial vision refers to the use of a linear industrial camera to acquire continuous images of herbal powder during the conveying process, perform grayscale conversion and threshold segmentation on the acquired images, separate the contacting or overlapping particle regions using a watershed segmentation method based on distance transformation, extract the equivalent diameter, roundness and aspect ratio of the separated individual particles, and calculate the particle size parameters by constructing a particle size distribution histogram to describe the size distribution of powder particles. This method covers specific technical matters such as image acquisition, image preprocessing, particle segmentation, feature calculation and statistical analysis.
[0004] Existing technologies rely on grayscale conversion, threshold segmentation, and distance transformation watershed processing to handle continuous images, which have high requirements for illumination stability, background contrast, and particle surface consistency. When herbal powders contain a mixture of light and dark shades, interwoven fiber textures, and soft agglomerations, they are prone to boundary shifts, over-segmentation, or adhesion retention, affecting the accuracy of particle size statistics. Summary of the Invention
[0005] To address the technical problems existing in the prior art, this invention provides a method for detecting the particle size of powdered herbs based on industrial vision. The technical solution is as follows: A method for detecting the particle size of powdered herbs based on industrial vision includes the following steps: S1: Collect image signals from the discharge port of the herbal powdering equipment, adjust exposure and gain, complete brightness anomaly compensation and isolated noise correction, remove background pixels, retain powder pixel coordinates and gray values, and generate herbal powder gray distribution map. S2: Based on the grayscale distribution map of powder, extract the pixel grayscale difference and determine the direction of grayscale change, identify the position of the grayscale change direction reversal and extract the continuous abnormal direction path, determine the extension angle and filter the continuous direction trajectory to obtain the particle contact interface distribution map. S3: Extract the extension angle based on the particle contact interface distribution map, construct the projection trajectory and count the coverage density, determine the search range of the adhesion boundary, mark the connected components of the powder pixels and distinguish between the adhesion and independent regions, filter the boundary pixels with gentle gray-scale changes, and form the particle separation boundary trajectory. S4: Extract the gray values of boundary pixels based on the particle separation boundary trajectory, match the gray values of pixels on both sides along the normal to form the gray value difference distribution on both sides of the boundary, record the gray value change amplitude in the normal direction, select continuous and stable boundary segments, and combine multi-directional boundary spacing measurement to correct the particle contour of the connected domain to obtain a multi-dimensional particle size set.
[0006] As a further aspect of the present invention, the method further includes S5, specifically: S5: Based on the multidimensional particle size set, determine the representative particle size, sort to generate the particle size distribution structure, divide the continuous particle size interval, form continuous particle size segments, identify particle morphology and distinguish between agglomeration and dispersion, and summarize to form the particle size detection results of herbal powder.
[0007] As a further aspect of the present invention, the step of obtaining S1 is as follows: S101: Acquire the image sensor output signal of the discharge port area of the herb pulverizing equipment, collect the current lighting environment status, adjust the exposure time parameter and gain parameter, scan the pixel brightness distribution, judge the pixel brightness status with the preset brightness consistency condition, select adjacent normal brightness pixels in the abnormal brightness area to complete the compensation correction, and obtain the brightness correction layer. S102: Based on the brightness correction layer, call the grayscale state of the current pixel and the grayscale state of the neighboring pixels in the compensated and corrected image, determine the grayscale change relationship between the current pixel and the neighboring pixels, locate isolated deviated pixels as noise pixels, select the grayscale state of the effective neighboring pixels to complete the replacement, and form a noise replacement layer. S103: Based on the noise replacement layer, collect the grayscale state of the powder area and the grayscale state of the background area, determine the grayscale difference relationship between the powder area and the background area, divide the background grayscale range, remove non-powder area pixels, extract the retained pixel coordinates and corresponding corrected pixel grayscale values, reconstruct the spatial grayscale distribution, and obtain the herbal powder grayscale distribution map.
[0008] As a further aspect of the present invention, the step of obtaining S2 is as follows: S201: Based on the grayscale distribution map of the herbal powder, extract the grayscale state of each powder pixel and the grayscale state of the neighboring pixels, determine the grayscale change relationship of the powder pixel relative to the neighboring pixels in the upper, lower, left and right directions, write the corresponding pixel position into the direction mark, and generate grayscale direction mark. S202: Call the grayscale direction mark, compare the direction marks of adjacent powder pixels, determine the reverse relationship between the previous powder pixel direction mark and the next powder pixel direction mark, record the pixel position where the grayscale change direction is reversed, and connect the path according to the adjacency and extension relationship of the reversed pixel position in spatial coordinates to obtain the abnormal direction path. S203: Based on the abnormal direction path, determine the extension angle according to the change of adjacent pixel coordinates within the path, classify the abnormal direction path according to the preset angle range, count the frequency of path occurrence within the same angle range, filter continuous direction trajectories by combining the concentration of extension angle distribution, match the herb category based on the color distribution features and texture direction of the compensated and corrected image, correct the trajectory coverage according to the matching category, and obtain the particle contact interface distribution map.
[0009] As a further aspect of the present invention, the step of obtaining S3 is as follows: S301: Based on the particle contact interface distribution map, extract the continuous direction trajectory extension angle, call the interface pixel coordinates and trajectory extension angle, arrange the interface pixels along the corresponding extension angle to form a projection trajectory, count the number of times each projection position is covered, write the number of times of coverage according to the projection position coordinates, form a projection coverage arrangement, and generate a projection spatial distribution. S302: Based on the projection space distribution, the projection coverage arrangement is divided according to the preset window, the number of projection coverages in each window is called, the adjacent state of the coverage position and the aggregation state of the coverage count in the window are determined, the window that meets the projection concentration judgment condition is marked as the concentration area, the coordinates of the concentration area are included in the boundary search range, and the adhesion boundary search range is obtained. S303: Call the adhesion boundary search range, the grayscale distribution map of the herbal powder, and the particle contact interface distribution map, mark the powder pixels as connected components, extract the adjacent state of the outer edge pixels of the connected components to form the connected component boundary relationship, extract the state of the interface pixels falling into the vicinity of the connected component boundary to form the interface distribution relationship, distinguish the adhesion area from the independent area based on the connected component boundary relationship and the interface distribution relationship, filter the boundary pixels with gentle grayscale changes within the search range and connect the candidate separation paths, retain the continuous and complete paths, and obtain the particle separation boundary trajectory.
[0010] As a further aspect of the present invention, the step of obtaining S4 is as follows: S401: Based on the particle separation boundary trajectory, extract the grayscale state of the boundary pixels, call the grayscale state of the inner pixels of the adjacent particles on both sides in the boundary normal direction, match the corresponding pixels on both sides of the boundary along the normal direction, compare the grayscale change relationship between the boundary pixels and the inner pixels on both sides, write the grayscale difference on both sides into the corresponding boundary position, and generate the boundary grayscale difference distribution. S402: Based on the boundary gray-scale difference distribution, record the normal gray-scale change amplitude point by point to form a gray-scale change trajectory, call the gray-scale change amplitude and change trend of adjacent boundary positions, determine the continuous state and stable state of gray-scale change, locate the corresponding boundary segment, record the pixel spacing information on both sides, and obtain the boundary spacing distribution. S403: Based on the boundary spacing distribution and particle separation boundary trajectory, compare the dispersion of boundary spacing in multiple directions, filter the size range with concentrated spacing distribution, correct the particle outline of the connected domain, and extract the area, boundary length, major axis direction and minor axis direction of the corrected particle outline to obtain a multidimensional particle size set.
[0011] As a further aspect of the present invention, the step of obtaining S5 is as follows: S501: Based on the multidimensional particle size set, call the boundary spacing, contour coverage area, boundary length, major axis dimension and minor axis dimension, determine the correspondence of each size item under the same particle mark, classify the boundary spacing and axial span into the corresponding particle contour, determine the representative size of each particle by combining the contour occupancy range, and sort them by size to generate a particle size distribution structure; S502: Based on the particle size distribution structure, compare the differences in representative size of adjacent particles, write the positions that meet the size change judgment conditions into change markers, divide the particle size intervals according to the intervals between adjacent size change markers, extract the representative size in each particle size interval, organize the boundary ranges of adjacent particle size intervals, and obtain continuous particle size segments. S503: Call the continuous particle size segmentation and multi-dimensional particle size set, combine the area of the contour coverage region, the boundary length and the ratio of the major axis to the minor axis to identify the particle morphology, divide the round particles and slender particles and count their number, determine the boundary adjacency relationship and spacing distribution between particles based on the corrected particle contour, distinguish between aggregated particles and dispersed particles and count their number, summarize the particle size interval, the representative size of the interval, the number of particle morphologies and the number of aggregate states, and obtain the particle size detection results of the herbal powder.
[0012] As a further aspect of the present invention, the specific operation of extracting the contour coverage area, boundary length, and major and minor axis directions of the corrected particle contour is as follows: Read the closed boundary pixel coordinates in the corrected particle contour, mark the powder pixel coordinates within the closed boundary as the contour coverage area, count the pixel occupancy within the contour coverage area to form the contour coverage area area, connect adjacent boundary pixels according to the adjacent order of boundary pixel coordinates and accumulate the boundary coordinate step size to form the boundary length, read the pixel coordinate span of the contour coverage area along multiple candidate directions, determine the direction with the largest coordinate span as the major axis direction, and determine the direction that is perpendicular to the major axis direction and corresponds to the horizontal span of the coverage area as the minor axis direction.
[0013] The beneficial effects of the technical solutions provided in the embodiments of the present invention include at least the following: 1. This invention adapts the image signal from the discharge port to lighting, compensates for abnormal brightness, replaces isolated noise points, and removes background grayscale. This results in a stable grayscale base for the powder area before subsequent analysis, reducing interference from shadows, reflections, dust, and sensor noise, and improving the consistency of particle edge recognition and the reliability of detection results.
[0014] 2. This invention extracts the direction of grayscale change, reversal position, continuous abnormal direction path and projection concentration area. The contact interface can be derived from the pixel change trajectory. Combined with normal grayscale difference, boundary spacing, contour area, boundary length and major and minor axis dimensions, the particle contour is corrected, thereby improving the separation accuracy of adhering particles and the integrity of particle size characterization. Attached Figure Description
[0015] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a flowchart illustrating the acquisition process of S1 in this invention; Figure 3 This is a flowchart illustrating the acquisition process of S2 in this invention; Figure 4 This is a flowchart illustrating the acquisition process of S3 in this invention; Figure 5 This is a flowchart illustrating the acquisition process of S4 in this invention; Figure 6 This is a flowchart of the acquisition process for S5 of the present invention. Detailed Implementation
[0016] The technical solution of the present invention will now be described with reference to the accompanying drawings.
[0017] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.
[0018] In the embodiments of this invention, the terms "image" and "picture" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning. Similarly, the terms "of," "corresponding (relevant)," and "corresponding" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning.
[0019] In this embodiment of the invention, sometimes a subscript such as W1 may be written in a non-subscript form such as W1. When the difference is not emphasized, the meaning they express is the same.
[0020] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.
[0021] Example 1, please refer to Figure 1 This invention provides a technical solution: a method for detecting the particle size of powdered herbs based on industrial vision, comprising the following steps: S1: Acquire the image sensor output signal of the discharge port area of the herb pulverizing equipment, adjust the exposure time and gain parameters according to the current lighting environment, scan the pixel brightness distribution, identify the brightness abnormal area according to the brightness consistency condition and complete the compensation correction, compare the gray level difference between the current pixel and the neighboring pixels, locate isolated noise points according to the noise judgment condition, and replace them with the gray level of the neighboring effective pixels, define the background gray level range according to the gray level difference between the powder area and the background area, remove non-powder area pixels, retain the powder pixel coordinates and corrected gray level values, reconstruct the spatial gray level distribution, and obtain the herb powder gray level distribution map; S2: Based on the grayscale distribution map of herb powder, extract the grayscale difference between powder pixels and neighboring pixels, determine the direction of grayscale change at each pixel position and generate direction markers, compare the direction markers of adjacent powder pixels, record the reverse position of grayscale change direction, extract continuous abnormal direction paths based on the spatial adjacency and extension relationship of the reverse position, determine the extension angle based on the coordinate change of adjacent pixels in the path, classify abnormal direction paths according to the angle range, count the frequency of abnormal direction paths within the same angle range, and filter continuous direction trajectories based on the concentration of extension angle distribution. Match herb categories based on the color distribution features and texture direction of the compensated and corrected image, correct the trajectory coverage, and obtain the particle contact interface distribution map. S3: Based on the particle contact interface distribution map, extract the extension angle of the continuous direction trajectory, construct the projection trajectory of the interface pixels along the corresponding extension angle, count the number of projection coverages and form the projection spatial distribution, divide the projection spatial distribution according to the preset window, select the concentrated projection area based on the density of the number of projection coverages within the window and use it as the search range for the adhesion boundary, combine the grayscale distribution map of the herbal powder and the particle contact interface distribution map, mark the powder pixels with connected components, distinguish the adhesion area from the independent area based on the boundary relationship of the connected components and the interface distribution relationship, for the boundary of the adhesion area, select the boundary pixels within the search range with a smooth grayscale change and connect them as candidate separation paths, check the integrity of the candidate separation paths, and obtain the particle separation boundary trajectory; S4: Based on the particle separation boundary trajectory, extract the gray values of the boundary pixels, match the gray values of the inner pixels of adjacent particles on both sides of the boundary along the normal direction of the boundary to form the gray value difference distribution on both sides of the boundary, record the gray value change amplitude of the normal direction point by point, generate the gray value change trajectory, compare the gray value change amplitude and trend of adjacent boundary positions, locate the boundary segment with continuous and stable gray value change amplitude, record the pixel spacing on both sides, compare the dispersion of the boundary spacing obtained by multi-direction measurement, filter the size range with concentrated spacing distribution, correct the particle contour of the connected domain based on the particle separation boundary trajectory, extract the area of the contour coverage region, boundary length, and major axis and minor axis directions of the corrected particle contour to obtain a multi-dimensional particle size set; S5: Based on the multidimensional particle size set, the representative size of each particle is determined by combining the boundary spacing, contour coverage area, boundary length, and major and minor axis dimensions. The particle size distribution structure is formed by sorting the values. The differences in the representative sizes of adjacent particles are compared, and the positions of size changes are marked. The particle size intervals are divided according to the interval between adjacent size change positions. The representative size of the interval is extracted and the boundary range of the interval is sorted to form a continuous particle size segment. The particle morphology is identified by combining the contour coverage area, boundary length, and major and minor axis ratio. The number of round and slender particles is counted. The boundary adjacency relationship and spacing distribution between particles are determined based on the corrected particle contour. Aggregated particles and dispersed particles are distinguished and their numbers are counted. The particle size intervals, the representative size of the intervals, the number of particle morphologies, and the number of aggregate states are summarized to obtain the particle size detection results of the herbal powder.
[0022] Example 2 further specifies the process for obtaining the grayscale distribution map of the herbal powder. Please refer to [link / reference]. Figure 2 The steps to obtain S1 are as follows: S101: Acquire the image sensor output signal of the discharge port area of the herb pulverizing equipment, collect the current lighting environment status, adjust the exposure time parameter and gain parameter, scan the pixel brightness distribution, judge the pixel brightness status with the preset brightness consistency condition, select adjacent normal brightness pixels in the abnormal brightness area to complete the compensation correction, and obtain the brightness correction layer. The image sensor output signal from the discharge port area of the herbal pulverizing equipment is acquired. Specifically, an industrial-grade RGB color CCD or CMOS industrial camera with a low-distortion industrial lens, installed 300 mm vertically above the discharge conveyor belt, acquires the image signal. A diffuse dome LED light source providing uniform, shadow-free illumination is configured. The raw charge quantity output pixel by pixel from the image sensor is read and converted into grayscale integer values from 0 to 255. Simultaneously, the raw red, green, and blue three-channel color layer data are cached in system memory for subsequent comparison. When acquiring the current lighting environment, the ambient illuminance reading E returned by the silicon photodiode photodetector point directly above the discharge port, protected by a dustproof and light-transmitting cover, is retrieved. When the ambient illuminance E falls within the range of 800 to 1200 lux, it is considered a standard lighting state; when E is less than 800 lux, it is considered a dim state; and when E is greater than 1200 lux, it is considered a bright state. Then, the exposure time parameter T and the gain parameter G are adjusted, where the exposure time T is adjusted according to... The calculation is performed, where T is the exposure time in milliseconds, k is the illuminance compensation reference coefficient, and E is the measured ambient illuminance reading. The value of k is determined by referring to the sensor's full-well capacity and the powder reflectance at the outlet. The powder reflectance is pre-measured using an offline spectrophotometer for the batch of samples to be tested, and the corresponding coefficient k is entered into the system control parameter library. For light-colored powders such as Angelica sinensis and Astragalus membranaceus with a reflectance between 0.3 and 0.5, k is set to 8; for dark-colored powders such as Rehmannia glutinosa and Salvia miltiorrhiza with a reflectance between 0.1 and 0.3, k is set to 12. The measured E is 600 lux under a slightly dark condition. Taking a light-colored Angelica sinensis powder as an example, the exposure time T is approximately 13.3 milliseconds (T = 8 x 1000 / 600). The gain parameter G is gradually increased by 2 dB per level if the exposure time is insufficient even at the 20-millisecond upper limit, but not exceeding the 18-dB upper limit. In this example, T is 13.3 milliseconds, which is below the upper limit, so G remains at 0 dB. Next, the pixel brightness distribution is scanned, and all pixel grayscale values are read line by line and grouped into a statistical column for every 16 grayscale levels, forming a 16-column brightness histogram. The consistency between the brightness state of each pixel and the preset brightness condition is then judged. When scanning reaches the physical edge of the image or the neighborhood exceeds the image range, the window is filled using a nearest-neighbor edge pixel grayscale mirroring strategy. The average grayscale value M of all 25 pixels within a 5x5 window surrounding the pixel is taken as the local reference. If the absolute value of the difference between a pixel's grayscale value and M exceeds 40 grayscale levels, the pixel is judged as having abnormal brightness. If the absolute value of the difference between a pixel's grayscale value and M does not exceed 40 grayscale levels, it is judged as normal and its original value remains unchanged. For example, if a pixel's grayscale value is 210 and its 5x5 window average value M is 150, the difference is 60. If the value exceeds 40, it is determined to be a brightness abnormality area. For the brightness abnormality area, adjacent normal brightness pixels are selected to complete the compensation correction. One normal pixel is selected above, below, to the left, and to the right of the abnormal pixel, and the difference between the value and M is no more than 40. The arithmetic mean of the gray values of these four normal pixels is calculated and assigned back to the position of the abnormal pixel. In the example above, the gray values of the four normal pixels are 148, 152, 149, and 151. The average value of 150 replaces the original 210. The process of selecting neighbors, calculating the average, and assigning values is repeated for each abnormal pixel until there are no pixels in the entire image with a gray value difference exceeding 40, and the brightness correction layer is obtained.
[0023] S102: Based on the brightness correction layer, call the grayscale state of the current pixel and the grayscale state of the neighboring pixels in the compensated and corrected image, determine the grayscale change relationship between the current pixel and the neighboring pixels, locate isolated off-center pixels as noise pixels, select the grayscale state of the effective neighboring pixels to complete the replacement, and form a noise replacement layer. Based on the brightness correction layer, the grayscale state of the current pixel and the grayscale state of neighboring pixels in the compensated and corrected image are called. For each pixel to be inspected, the grayscale values of its 8 neighboring pixels (excluding itself) within a 3x3 window are taken. For boundary pixels to be inspected that are in the first row, last row, first column, or last column of the image and have fewer than 8 neighboring pixels, the grayscale value of the missing position is set to the grayscale value of the pixel to be inspected according to the extrapolation zero-padding rule and used in the calculation. The grayscale change relationship between the current pixel and its neighboring pixels is judged. The absolute value of the difference between the grayscale value C of the current pixel and the grayscale values of the 8 neighboring pixels is calculated. The number N of neighboring pixels whose absolute difference exceeds the noise judgment threshold D is counted. The noise judgment threshold D is set with reference to the grayscale fluctuation range between normal particles of powder. The measured grayscale fluctuation of adjacent normal pixels of Angelica sinensis powder is mostly between 10 and 25 grayscale levels, so D is set to 30 to avoid normal fluctuations. When the absolute value of the difference among the 8 neighbors exceeds D When the number N reaches 7 or more, the pixel is determined to be an isolated off-target pixel and positioned as a noise pixel. When the number N is less than 7, it is determined to be a normal pixel and its original value is retained. For example, if a pixel has a gray level C of 235, and its eight neighboring pixels have gray levels of 120, 118, 122, 119, 121, 117, 123, and 120 respectively, the absolute value of all eight differences exceeds 110, that is, all exceed the threshold of 30. Therefore, N equals 8, which meets the condition of 7 or more, and it is determined to be a noise pixel. The gray level of the effective neighboring pixels is selected to complete the replacement. The gray levels of the eight neighboring pixels are sorted by value and the average of the two middle values is taken as the median replacement amount. In the example above, after sorting the eight neighbors, the middle two are 120 and 120. The average of 120 is 120, which is assigned back to the original position of 235. The process of taking a window, subtracting each pixel, counting N, comparing thresholds, sorting and taking the median value, and assigning values is repeated for each pixel in the entire image to form a noise replacement layer.
[0024] S103: Based on the noise replacement layer, collect the grayscale status of the powder area and the grayscale status of the background area, determine the grayscale difference relationship between the powder area and the background area, divide the background grayscale range, remove non-powder area pixels, extract the retained pixel coordinates and corresponding corrected pixel grayscale values, reconstruct the spatial grayscale distribution, and obtain the herbal powder grayscale distribution map. Based on the noise replacement layer, the grayscale states of the powder area and the background area are collected. Several pixels at the center of the powder accumulation area and several pixels at the four corner discharge port baffles are read to determine the grayscale difference between the powder area and the background area. The grayscale histogram of the entire image is statistically analyzed, and its bimodal shape is observed. Dark background pixels near the baffles tend to cluster between 30 and 70, forming low grayscale peaks, while light-colored angelica powder pixels tend to cluster between 130 and 200, forming high grayscale peaks. When dividing the background grayscale range, the valley grayscale value between the two peaks is taken as the background segmentation benchmark B. The benchmark B is set according to the location of the valley bottom of the bimodal peaks. In this example, the low grayscale peak is at grayscale 50, and the high grayscale peak is at grayscale 160. The valley with the fewest grayscale histogram counts between the two peaks appears at grayscale 95. Therefore, the background segmentation benchmark B is taken as 95. Pixels with a grayscale value less than or equal to 95 are classified as background and removed; that is, these pixel coordinates are marked as invalid and no longer participate in subsequent calculations. For example, if a pixel has a grayscale value of... Removed, a certain pixel has a grayscale value of The pixels are retained, and the coordinates of the retained pixels and the corresponding gray values of the corrected pixels are extracted. The row and column coordinates (x, y) of each retained pixel and its gray value after correction by S101 and S102 are recorded to form a triplet data. At the same time, the pixel pointer of the color layer cached in S101 is retained. For example, the retained pixel is recorded as (128, 96, 150), which means that the gray value of the 128th column and the 96th row is 150. The spatial gray distribution is reconstructed, and all retained triplets are written back to the corresponding positions of the blank layer of the same size according to their row and column coordinates. The positions that were removed are set to 0. The process is repeated pixel by pixel until all retained pixels are in place, and the gray distribution map of the herbal powder is obtained.
[0025] Example 3 further illustrates the process of obtaining the particle contact interface distribution map. Please refer to [link to example]. Figure 3 The steps to obtain S2 are as follows: S201: Based on the grayscale distribution map of herbal powder, extract the grayscale state of each powder pixel and the grayscale state of neighboring pixels, determine the grayscale change relationship of the powder pixel relative to the neighboring pixels in the upper, lower, left and right directions, write the corresponding pixel position into the direction mark, and generate grayscale direction mark. Based on the grayscale distribution map of herbal powder, the grayscale state of each powder pixel and the grayscale state of its neighboring pixels are extracted. Using the retained triplet data obtained in S103, the corrected grayscale value of each retained powder pixel and the corrected grayscale values of its four adjacent positions (above, below, left, and right) are read. If the coordinates of an adjacent position point to a background position where the grayscale value is set to 0 or outside the image, its grayscale value is recorded as the current retained pixel's own grayscale value to ensure the grayscale difference is zero. The grayscale change relationship between the powder pixel and its neighboring pixels in the above, below, left, and right directions is determined. The current pixel's grayscale value is subtracted from the grayscale values of its upper, lower, left, and right neighbors, respectively. When the difference in a certain direction is greater than the direction determination threshold P, that direction is recorded as a positive change and incremented by one. When the difference is less than the negative direction determination threshold P, the change is recorded as a positive change. When the threshold P is reached, a negative change is recorded as a sign minus one. When the absolute value of the difference falls within the threshold P, it is recorded as a stable write of zero. The setting of the direction determination threshold P is determined with reference to the grayscale fluctuation amplitude between normal particles after noise removal in S102. The fluctuation of adjacent normal pixels of the aforementioned Angelica sinensis powder is mostly between 10 and 25 grayscale levels, so P is set to 15 to distinguish the real particle edges from the internal stable fluctuations. Taking the reserved pixel with grayscale 150 in column 128, row 96 as an example, its upper neighbor grayscale is 152, lower neighbor grayscale is 148, left neighbor grayscale is 176, and right neighbor grayscale is 128. The difference between this pixel and the upper neighbor is -2, which falls within ±15 and is recorded as zero. The difference with the lower neighbor is +2 and is recorded as zero. The difference with the left neighbor is -26, which is less than -15 and is recorded as -1. The difference with the right neighbor is +22, which is greater than 15 and is recorded as +1. Therefore, the left and right directions of this pixel are marked as follows: The up and down directions are marked as The +1, -1, or 0 values in the four directions are combined in a fixed order (up, down, left, right) to form the direction marker code for that pixel, and then written back to its coordinate position. For example, in the above example, it is recorded as code. The process involves repeatedly taking the grayscale value of each pixel, taking the grayscale values of its four neighboring pixels, subtracting each pixel in each direction, comparing positive and negative P values, and writing a sign. The direction mark code is then filled pixel by pixel to obtain the grayscale direction mark.
[0026] S202: Call the grayscale direction marker, compare the direction markers of adjacent powder pixels, determine the reverse relationship between the previous powder pixel direction marker and the next powder pixel direction marker, record the pixel position where the grayscale change direction is reversed, and connect the path according to the adjacency and extension relationship of the reversed pixel position in spatial coordinates to obtain the abnormal direction path. The grayscale orientation marker is invoked, and the orientation markers of adjacent powder pixels are compared. The orientation marker codes of the preceding and following powder pixels are read pairwise along the row and column directions of the image. The inversion relationship between the preceding and following powder pixel orientation markers is determined. The signs of the two pixels in the same direction component are multiplied. If the product of the left-right or up-down components is negative, a direction reversal is determined; if the product is positive or zero, no reversal is determined. Coordinates of points determined not to be reversed are not added to the reversal position set and are considered as smooth transitions. The region is directly skipped in the subsequent extended path construction. Taking the pixel in the 128th column and 96th row of (0,0,-1,+1) in S201 as an example, the direction marker code of the pixel in the 129th column and 96th row to its right is calculated in the same way as (0,0,+1,-1). The left and right components of the two pixels are negative one and positive one respectively. The product of these components is negative one. It is determined that the left and right directions are reversed at this point. The pixel position where the grayscale change direction is reversed is recorded as the intersection of the 128th and 129th columns. After comparing all rows and columns, the intersection coordinates of all products that result in negative one are recorded in the reversed position. Set a set of inverted pixel positions and connect paths based on their adjacency and extension relationships in spatial coordinates. Starting from any coordinate in the set of inverted positions, search its eight-neighbor area for adjacent coordinates belonging to the same set. If they exist, connect the two coordinates with a line segment and record the connection direction. Continue searching outwards from the newly included coordinate as the endpoint until no adjacent inverted coordinates can be included. When the cumulative number of inverted coordinates included in a connection reaches or exceeds the connection length benchmark L, it is retained as a valid path; otherwise, it is discarded. The connection length benchmark L... The minimum recognizable diameter of a single powder particle at the reference outlet is determined by the corresponding pixel span. The minimum diameter of a single Angelica sinensis powder particle at the current imaging magnification is approximately 6 pixels. Therefore, L is set to 6 to filter out isolated reversal points. For example, starting from the intersection of columns 128 and 129, the six reversal coordinates in rows 96, 97, 98, 99, 100, and 101 are sequentially included and connected to satisfy L equal to 6 and retained. The starting point selection, eight-neighbor search, inclusion extension, and length comparison are repeated for all coordinates in the reversal position set to obtain the abnormal direction path.
[0027] S203: Based on the abnormal direction path, determine the extension angle according to the change of adjacent pixel coordinates within the path, classify the abnormal direction path according to the preset angle range, count the frequency of path occurrence within the same angle range, filter continuous direction trajectories by combining the concentration of extension angle distribution, match the herb category based on the color distribution features and texture direction of the compensated and corrected image, correct the trajectory coverage according to the matching category, and obtain the particle contact interface distribution map. Based on the abnormal direction path, the extension angle is determined according to the changes in the coordinates of adjacent pixels within the path. The coordinates of the first and last ends of each path are taken. The column span is obtained by subtracting the column coordinates of the first end from the column coordinates of the last end, and the row span is obtained by subtracting the row coordinates of the first end from the row coordinates of the last end. The ratio of the row span to the column span is then inverted and converted to the extension angle θ of the path relative to the horizontal direction. Taking the path in S202 extending from column 96 of column 128 to row 101 of column 128 as an example, its column span is 0, and its row span is... With a span of 5, the ratio approaches infinity, corresponding to θ of 90 degrees (vertical direction). Abnormal directional paths are categorized according to a preset angle range. The 0 to 180 degree range is divided into six 30-degree intervals: 0 to 30 degrees, 30 to 60 degrees, 60 to 90 degrees, 90 to 120 degrees, 120 to 150 degrees, and 150 to 180 degrees. Each path's θ is then assigned to its corresponding interval. In the example above, 90 degrees is assigned to the boundary between 60 to 90 and 90 to 120 degrees, following a left-closed, right-open rule. The path is then categorized into the 90-120 degree range. The frequency of paths within the same angle range is counted, and the number of paths falling into each angle range is accumulated to obtain the frequency count for that range. For example, if the 90-120 degree range has a total of 42 paths, and the other ranges each have less than 10, the continuous directional trajectories are selected based on the concentration of the extended angle distribution. The ratio of the maximum frequency count in each range to the sum of the frequency counts of all ranges is taken as the concentration degree. When the frequency proportion of a certain range is greater than the concentration degree benchmark of 0.5, that range is determined as the dominant direction, and the paths within it are retained as continuous directional trajectories. The concentration degree benchmark of 0.5 is set with reference to the empirical proportion of particle contact edges in the same batch of powder where the directions tend to be similar. In the example above, the ratio of the 42 dominant ranges to the total of approximately 90 is about 0.47, which is less than 0.5. Therefore, the particle size of the partition is reduced, and the division is recalculated in 15-degree increments until the proportion of a certain range exceeds 0.5. If, after re-division, no range still meets the requirement of a proportion greater than 0.If condition 5 is met, the recalculation is terminated and the interval with the largest current proportion is directly selected as the dominant direction. Based on the color distribution characteristics and texture direction of the compensated and corrected image, the herb category is matched. According to the color layer cache associated with S103, the mean values of the red, green, and blue channels of the retained pixels at the corresponding positions in the original compensated and corrected image are read. When the mean value of the red channel is in the range of 150 to 190, the green channel is in the range of 120 to 160, and the blue channel is in the range of 80 to 120, and the dominant extension direction tends to be singular, it should be classified as a medicinal powder category. Based on this, the pre-stored contact ridge direction range of the category is retrieved. The pre-stored contact ridge direction range of the category and the color interval The database is generated by pre-collecting images of no fewer than 500 sets of known standard herbal powder slices, extracting the upper and lower limits of the dominant texture angles and the distribution range of the three-channel color mean values through statistical cluster analysis, and storing these data in the system memory. Based on the matching category, the trajectory coverage is corrected. Path segments in continuous directional trajectories whose extension angle deviates from the pre-stored directional range of the Angelica sinensis category by more than 15 degrees are removed; the remaining segments are retained, and the breakpoints are filled by extending one pixel on each side of the trajectory. The processes of angle conversion, interval subtraction, frequency accumulation, proportion comparison, color interval comparison, and deviation removal are repeated for each path to obtain the particle contact interface distribution map.
[0028] Example 4: Based on the particle contact interface distribution map, this example further defines the process for obtaining the particle separation boundary trajectory. Please refer to [link to example]. Figure 4 The steps to obtain S3 are as follows: S301: Based on the particle contact interface distribution map, extract the continuous direction trajectory extension angle, call the interface pixel coordinates and trajectory extension angle, arrange the interface pixels along the corresponding extension angle to form a projection trajectory, count the number of times each projection position is covered, write the number of times of coverage according to the projection position coordinates, form a projection coverage arrangement, and generate a projection spatial distribution. Based on the particle contact interface distribution map, the extension angles of continuous directional trajectories are extracted. Each continuous directional trajectory and its extension angle θ, which are retained after being classified into the dominant angle interval and corrected by the angelica category in S203, are retrieved. The arithmetic mean of the extension angles of all retained trajectories within the dominant angle interval is calculated as the unified reference projection angle. Simultaneously, the row and column coordinates of all interface pixels on this trajectory are retrieved. The interface pixels are arranged into projection trajectories along the corresponding extension angles. The coordinates (x, y) of each interface pixel and the aforementioned unified reference projection angle are substituted into θ in the following formula. The pixel is mapped perpendicularly to a reference projection line along a direction perpendicular to θ. Its projection position index j is determined according to... The calculation is performed, where j is the integer index of the projection position, x is the pixel column coordinate, y is the pixel row coordinate, θ is the unified reference projection angle corresponding to the pixel, and round indicates rounding to the nearest integer. Taking the vertical trajectory from S202 to S203 with a unified reference projection angle θ of 90 degrees as an example, its cosθ is 0 and sinθ is 1. Then the pixel projection index of the 128th column and 96th row is: ; The pixel projection index j in column 128, row 101 is equal to 101. The number of times each projection position is covered is counted. A one-dimensional counting sequence with a length covering the entire range of j values is set to zero. For each interface pixel mapped to a certain index j, the count of that index position is incremented by one. The coverage count is written according to the projection position coordinates. The process of taking the coordinates, substituting θ, calculating j, and incrementing the corresponding count is repeated for each interface pixel. For example, if there are a total of 5 interface pixels on the vertical trajectory that fall at j equal to 96, then 5 is written for that position; if there are a total of 4 pixels that fall at j equal to 97, then 4 is written. The perpendicular mapping and count accumulation are repeated for all interface pixels on all retained trajectories to form a projection coverage arrangement and generate a projection spatial distribution.
[0029] S302: Based on the spatial distribution of projection, the projection coverage is arranged according to the preset window division, the number of projection coverages in each window is called, the adjacent status of the coverage positions and the aggregation status of the coverage counts in the window are judged, the windows that meet the projection concentration judgment conditions are marked as concentrated areas, and the coordinates of the concentrated areas are included in the boundary search range to obtain the adhesion boundary search range. Based on the spatial distribution of projection, the projection coverage is arranged according to a preset window. A sliding window of fixed width is set along the projection position index j. The window width W is set with reference to the minimum diameter pixel span of the Angelica sinensis single particle corresponding to the connection length reference L in S202. The minimum diameter of a single particle occupies about 6 pixels, so the window width W is set to 6 index units so that a window can just cover the projection accumulation within the single particle scale. The first window is set with j equal to 93 to 98, and the second window is set with j equal to 99 to 104, and the two windows are divided in sequence without overlap. When the number of remaining indexes at the end is less than 6 units, the corresponding number of zero-value indexes are automatically added to make up a complete window for statistics. The number of projection coverages in each window is called, and the indexes falling in the same window are counted. The counts of each position are added together to obtain the cumulative coverage count S of the window. In the first window, the counts of positions j from 93 to 98 are 1, 2, 3, 5, 4, 3 respectively, and S equals 18. In the second window, the counts of each position are 3, 4, 2, 1, 0, 0 respectively, and S equals 10. The adjacent state of the covered positions and the aggregation state of the coverage counts within the window are determined. It is checked whether the index positions with non-zero counts within the window are arranged consecutively. The cumulative coverage count S of the window is compared with the centralized judgment criterion S0. The centralized judgment criterion S0 is set with reference to the average value of the cumulative coverage counts of all windows. The sum of the S values of each window is divided by the number of windows to obtain the average value, and then multiplied by the magnification factor of 1.5 to obtain S0. Let the average value of S of all windows be 12. Windows that meet the criteria for projection concentration are marked as concentrated regions. When non-zero indices are consecutively arranged within a window and their... When a window is determined to be clustered, it is considered clustered if the window does not meet the condition of continuous arrangement or If the first window S is 18, reaching S0, and the counts from 93 to 98 are all non-zero and continuous, it is marked as a concentrated region. The second window S is... If no marking is made, the coordinates of the concentrated area are included in the boundary search range. The index interval covered by the marked window is reverse-mapped back to the corresponding row and column coordinate bands in the original grayscale distribution map and registered. The actions of counting and adding, continuous retrieval, comparison with S0, and coordinate inversion are repeated window by window to obtain the adhesion boundary search range.
[0030] S303: Call the adhesion boundary search range, the grayscale distribution map of herbal powder and the particle contact interface distribution map, mark the powder pixels with connected components, extract the adjacent state of the outer edge pixels of the connected components to form the connected component boundary relationship, extract the state of the interface pixels falling into the vicinity of the connected component boundary to form the interface distribution relationship, distinguish the adhesion area from the independent area based on the connected component boundary relationship and the interface distribution relationship, filter the boundary pixels with gentle grayscale changes within the search range and connect the candidate separation paths, retain the continuous and complete path, and obtain the particle separation boundary trajectory; The system uses the adhesion boundary search range, herbal powder grayscale distribution map, and particle contact interface distribution map to mark connected components for powder pixels. It retrieves all powder pixels retained in S103 and, during line-by-line scanning, checks whether the pixels to its left and above have been assigned connected component numbers. If an already numbered adjacent pixel exists, its number is retained; otherwise, a new, incrementally increasing number is created and assigned to the current pixel. After scanning, equivalent numbers are merged into the same connected component. For example, at the outlet, two angelica powder particles adhere together and are assigned connected component number 7, covering approximately 1200 pixels. The system extracts the adjacency status of the outer edge pixel coordinates of the connected component to form the connected component boundary relationship. For each connected component, it retrieves the pixel whose number is directly adjacent to the background zero value and registers it as the outer edge coordinate of that component. The outer edge coordinates of connected component number 7 form a closed boundary by connecting the beginning and end of its contour. Interface pixels are then extracted. The state of falling near the boundary of the connected domain forms the interface distribution relationship. Take the interface pixels in the S203 particle contact interface distribution map and check whether their coordinates fall inside a certain connected domain and are more than one pixel away from the outer edge. The interface pixel falling in the center of the domain number 7 is registered as the contact interface inside the domain. Based on the boundary relationship of the connected domain and the interface distribution relationship, the adhesive region and the independent region are distinguished. When there are registered contact interface pixels inside a connected domain and the total number of pixels is greater than 1.5 times the average number of pixels per particle, it is determined to be an adhesive region. When there is no contact interface inside and the total number of pixels falls within the range of ±30% of the average number of pixels per particle, it is determined to be an independent region. The average number of pixels per particle is taken as the median of the number of pixels in the independent regions without internal contact interfaces in the same batch of pre-scan data, which is about 620. The 1200 pixels in the connected domain number 7 exceed 620 times 1.5, i.e., 930, and containing a contact interface, is determined to be an adhesion region. Pixels with smooth grayscale changes within the search range are selected and candidate separation paths are connected. Within the coordinate band of the adhesion boundary search range obtained in S302, the grayscale values of one pixel on each side of the contact interface along the normal direction are read for each candidate pixel, and the absolute value of the difference is taken. If the absolute value is less than the grayscale smoothness benchmark 15, it is determined to be a smooth boundary pixel; if the absolute value is greater than or equal to 15, it is determined to be a non-smooth boundary, and the current candidate path is interrupted. The process then continues to the next candidate pixel within the search range as the starting point to attempt path connection again. The grayscale smoothness benchmark 15 is determined using the value of the threshold P in the direction of S201 to maintain particle size distribution. The consistency between internal undulations and the true boundary is determined by sequentially connecting adjacent smooth boundary pixels according to their coordinates to form candidate separation paths. Continuous and complete paths are retained. The process checks whether both ends of a candidate path reach the outer edge of the connected domain and whether there are any breaks along the way. If both ends reach the outer edge and there are no breaks, the path is retained; otherwise, a smooth pixel is added along the normal direction to continue the connection. In connected domain number 7, starting from the smooth pixel at the upper edge j96, approximately 22 smooth pixels are sequentially connected vertically to the lower edge, with both ends reaching the outer edge, and these are retained. This process of assigning numbers, registering outer edges, searching for interface affiliation, comparing pixel counts, subtracting normals, smooth connection, and checking endpoints is repeated for each connected domain to obtain the particle separation boundary trajectory.
[0031] Example 5 further illustrates the process of obtaining the multidimensional particle size set. Please refer to [link to example]. Figure 5 The steps to obtain S4 are as follows: S401: Based on the particle separation boundary trajectory, extract the grayscale state of the boundary pixels, call the grayscale state of the inner pixels of the adjacent particles on both sides in the boundary normal direction, match the corresponding pixels on both sides of the boundary along the normal direction, compare the grayscale change relationship between the boundary pixels and the inner pixels on both sides, write the grayscale difference on both sides into the corresponding boundary position, and generate the boundary grayscale difference distribution. Based on the particle separation boundary trajectory, the grayscale state of the boundary pixels is extracted. The coordinates of approximately 22 separation boundary pixels in the adhesion region numbered 7 in S303, sequentially connected from the upper edge j96 to the lower edge, are called. The corrected grayscale value of each pixel in the herbal powder grayscale distribution map is read one by one. The boundary normal direction and the grayscale state of the inner pixels of adjacent particles on both sides are called. For each boundary pixel, the normal direction is obtained by rotating it 90 degrees along the tangent direction of its separation path at that point. The normal direction corresponding to the vertical separation interface with θ of 90 degrees in S203 is the horizontal direction. Along this normal direction, the inner pixel is advanced 3 pixels to the left of the particle and 3 pixels to the right. If the advancement touches the outer shell of the connected domain boundary, the advancement stops, and the deepest inner effective pixel that can be reached is directly taken as the pixel to be compared. The inner advancement step size of 3 is set to half of the minimum diameter of a single Angelica sinensis particle (6 pixels) to ensure it falls inside the particle entity without exceeding the boundary. The corresponding pixels on both sides of the boundary are matched along the normal direction. The inner pixels on the left side of the same boundary pixel are then compared. The side pixel is paired with the right inner pixel and bound to the coordinates of the boundary pixel. The grayscale changes of the boundary pixel and the inner pixels on both sides are compared. Taking the boundary pixel in column 128, row 96 as an example, its self-corrected grayscale is 150. Pushing 3 pixels to the left along the horizontal direction, the grayscale of the left inner pixel is 172. Pushing 3 pixels to the right, the grayscale of the right inner pixel is 118. Subtracting the boundary grayscale from the left inner pixel gives 22. Subtracting the boundary grayscale from the right inner pixel gives -32. Subtracting the grayscale of the inner pixels on both sides gives 172 minus 118, which is 54. To determine the grayscale difference on both sides of the boundary position, the grayscale difference on both sides is written to the corresponding boundary position. For each boundary pixel, the following actions are repeated: take its own grayscale, determine the normal, advance 3 pixels in both directions to take the inner grayscale, subtract the difference between the two sides, and bind and write back. For example, the inner grayscale of the boundary pixel in the 97th row of the 128th column is 170 and 120 with a difference of 50, and the grayscale of the boundary pixel in the 98th row of the 128th column is 174 and 116 with a difference of 58. The difference values corresponding to each boundary pixel are registered in a difference sequence according to their coordinates to generate the boundary grayscale difference distribution.
[0032] S402: Based on the boundary gray-level difference distribution, record the normal gray-level change amplitude point by point to form a gray-level change trajectory, call the gray-level change amplitude and trend of adjacent boundary positions, determine the continuous state and stable state of gray-level change, locate the corresponding boundary segment, record the corresponding pixel spacing information on both sides, and obtain the boundary spacing distribution. Based on the boundary gray-level difference distribution, the normal gray-level change amplitude is recorded point by point. The absolute value of the gray-level difference on both sides of each boundary pixel is taken as the normal gray-level change amplitude at that point, and arranged in order of boundary coordinates. The amplitudes of the three boundary pixels in rows 96, 97, and 98 are 54, 50, and 58 respectively, forming a gray-level change trajectory. The amplitudes of each point are connected according to their positions along the separation path to form an amplitude sequence extending along the boundary position. The gray-level change amplitude and trend of adjacent boundary positions are retrieved. The amplitudes of adjacent boundary points are read in pairs and subtracted to obtain the amplitude increment, while recording the positive or negative sign of the increment as the trend. The increment in rows 96 to 97 is... The increment from line 97 to line 98 is The algorithm determines the continuity and stability of grayscale changes. For adjacent boundary points, it checks if their coordinates are contiguous within eight neighboring regions to determine continuity. It then compares the absolute values of adjacent amplitude increments with an amplitude stability benchmark. The benchmark is determined by multiplying the average amplitude of all amplitudes in the difference sequence by the allowable fluctuation ratio. The average amplitude of three points (approximately 54) multiplied by 0.2 (approximately 10.8) is used as the stability benchmark. If the absolute value of an adjacent increment is less than this benchmark, the amplitude of that segment is considered stable. If the absolute value of an adjacent increment is greater than or equal to this benchmark, a sudden amplitude change is considered, the segment is interrupted, and a new segment is recorded starting from the next point that meets the conditions. The absolute values of both negative 4 and positive 8 are less than 10.8, and the coordinates... Since the three points are connected in sequence, they belong to the same stable continuous segment. The corresponding boundary segment is located. The set of continuously connected boundary points whose absolute values of each pair of increments are all less than the stable reference is defined as a boundary segment and its first and last coordinates are recorded. The pixel spacing information on both sides is recorded. For each boundary point in the segment, the coordinate distance along the normal direction between its left inner pixel and its right inner pixel is measured. At row 96, the left inner pixel is in column 125 and the right inner pixel is in column 131, with a spacing of 6 pixels. The spacing of each point in the segment is measured point by point, and the spacing is 6, 6, and 5 pixels. The actions of taking absolute values, subtracting adjacent pixels, recording positive and negative values, searching for adjacency, comparing with the stable reference, and measuring spacing are repeated for all boundary segments to obtain the boundary spacing distribution.
[0033] S403: Based on the boundary spacing distribution and particle separation boundary trajectory, compare the dispersion of boundary spacing in multiple directions, filter the size range with concentrated spacing distribution, correct the particle outline of the connected domain, and extract the area, boundary length, major axis direction and minor axis direction of the corrected particle outline to obtain a multidimensional particle size set. The process of extracting the area of the contour coverage region, the boundary length, and the major and minor axis directions of the corrected particle contour is as follows: Read the closed boundary pixel coordinates in the corrected particle contour, mark the powder pixel coordinates within the closed boundary as the contour coverage region, count the pixel occupancy within the contour coverage region to form the area of the contour coverage region, connect adjacent boundary pixels according to the adjacent order of boundary pixel coordinates and accumulate the boundary coordinate step size to form the boundary length, read the pixel coordinate span of the contour coverage region along multiple candidate directions, determine the direction with the largest coordinate span as the major axis direction, and determine the direction that is perpendicular to the major axis direction and corresponds to the horizontal span of the coverage region as the minor axis direction; Based on the boundary spacing distribution and particle separation boundary trajectory, the dispersion of boundary spacing measured in multiple directions was compared. For the same particle, boundary spacing sequences were measured along four directions: vertical normal, horizontal normal, and ±45° oblique angles. The vertical spacing sets were 6, 6, and 5 pixels; the horizontal spacing sets were 7, 6, and 6 pixels; and the oblique spacing sets were approximately 8 and 7 pixels each. The dispersion was calculated by averaging the spacing sequences in each direction and then summing the absolute values of the deviations of each direction's spacing from its mean, divided by the number of points. The vertical mean was approximately 5.7, with a dispersion of approximately 0.44, indicating low dispersion. The oblique mean was approximately 7.5, with a dispersion of approximately 0.5. The size ranges with concentrated spacing distributions were selected, and directions with a dispersion less than the dispersion benchmark of 0.6 were chosen. The effective size and discrete reference of 0.6 are set based on one-tenth of the diameter of a single 6-pixel particle, which is used as the allowable fluctuation. If the dispersion in multiple measurement directions all meet the condition of being less than 0.6, they are all included and the comprehensive average value of all directions that meet the spacing is calculated to ensure the uniqueness of the size. In this example, the vertical, horizontal, and diagonal dispersions are all less than 0.6 and are fully included. Based on the average spacing in each direction, 5 to 7 pixels are calculated as the effective size range of the particle. The particle outline of the connected domain is corrected. The connected domain numbered 7 is divided into two parts along the separation boundary trajectory of S303 to obtain two sub-particle outlines. The pixels on both sides of the separation boundary are reclassified as belonging to their respective sub-particles. The closed boundary pixels are read from the corrected particle outline. The coordinates of the powder pixels within the closed boundary are marked as the contour coverage area. The number of powder pixels falling within the closed boundary is counted row by row for the left sub-particle. The pixel occupancy within the contour coverage area is calculated to form the area of the contour coverage area. The left sub-particle covers approximately 560 pixels, or 560 square pixels. Adjacent boundary pixels are connected in the order of their adjacent boundary pixel coordinates, and the boundary coordinate step size is accumulated to form the boundary length. Along the closed boundary, the step size is calculated as √2 (1.414) when the difference between the row and column coordinates of two adjacent coordinates is 1, and as 1 when only one coordinate differs. These steps are accumulated. The accumulated step size for the left sub-particle yields a boundary length of approximately 92 pixels. The span of the pixel coordinates of the contour coverage area is read along multiple candidate directions. The four candidate directions of 0 degrees, 45 degrees, 90 degrees, and 135 degrees are respectively determined by the difference between the maximum and minimum projected coordinates of the covered area in that direction, resulting in spans of 28, 31, 22, and 26 pixels, respectively. The direction with the largest coordinate span is determined as the major axis direction, and the 45-degree direction with a maximum span of 31 is determined as the major axis direction with a major axis size of 31 pixels. The direction perpendicular to the major axis direction and corresponding to the lateral span of the covered area is determined as the minor axis direction, and the 135-degree direction with a span of 26, perpendicular to the 45-degree direction, is determined as the minor axis direction with a minor axis size of 26 pixels. For each corrected sub-particle, the actions of measuring the direction distance, discretizing, comparing with the discrete benchmark, boundary enclosure, pixel counting, step size accumulation, and multi-directional span comparison are repeated to obtain a multi-dimensional particle size set.
[0034] Example 6 supplements the process of generating the particle size detection results for herbal powders. Please refer to [link / reference]. Figure 6 The steps to obtain S5 are as follows: S501: Based on the multidimensional particle size set, call the boundary spacing, contour coverage area, boundary length, major axis dimension and minor axis dimension, determine the correspondence of each size item under the same particle mark, classify the boundary spacing and axial span into the corresponding particle contour, determine the representative size of each particle by combining the contour occupancy range, and sort by size to generate the particle size distribution structure; Based on the multidimensional particle size set, the boundary spacing, contour coverage area, boundary length, major axis dimension, and minor axis dimension are retrieved. Data for the left sub-particle differentiated from region S403 (number 7) is extracted, including an area of 560 square pixels, a length of 92 pixels, a major axis of 31 pixels, a minor axis of 26 pixels, and an average effective boundary spacing of 5.7 pixels. The correspondence of each size item under the same particle marker is determined. Parameters under the same closed boundary coordinate index are logically bound using the particle's unique ID. Boundary spacing and axial span are assigned to the corresponding particle contour. The average spacing of each point in the boundary spacing distribution is extracted as a width constraint. Combined with the contour occupancy range, the representative size of each particle is determined. The weighted sum of the particle's major axis dimension L, minor axis dimension W, and equivalent area diameter D is taken as the representative size value R. The equivalent area diameter D is determined according to: ; Calculate, where Area is the area of the outline-covered region. Taking 3.14 as an example, with the area of the left sub-particle being 560, the calculated D is approximately 26.7 pixels. The representative size weighting coefficients are set as follows: major axis weight 0.2, minor axis weight 0.3, and equivalent diameter weight 0.5. The weighting coefficients are determined based on the symmetry and stability of the morphology of Angelica sinensis powder projected in three-dimensional space. Since the area index is least affected by the projection angle, it is assigned the highest weight of 0.5. These values are then substituted into the calculation of the representative size. The R values of all particles in the entire image are sorted by size and arranged in ascending order. For example, the R values of three particles are measured to be 15.2, 27.35 and 45.8, respectively, to generate the particle size distribution structure.
[0035] S502: Based on the particle size distribution structure, compare the differences in representative size of adjacent particles, write the positions that meet the size change judgment conditions into change markers, divide the particle size intervals according to the intervals between adjacent size change markers, extract the representative size in each particle size interval, organize the boundary ranges of adjacent particle size intervals, and obtain continuous particle size segments. Based on the particle size distribution structure, the representative size differences between adjacent particles are compared. Two adjacent representative sizes R(i) and R(i+1) are retrieved from the sorted sequence, and the absolute value of the difference between the two sizes is calculated. Positions meeting the size change judgment criteria are marked with a change flag. The absolute value of the difference is compared with the size change threshold K. The size change threshold K is determined by referring to the physical resolution fluctuation range corresponding to the current imaging magnification of the image sensor. The physical resolution is precisely determined by fixing the system focal length and placing a standard micrometer line at the horizontal height of the discharge port to measure the actual spatial physical length corresponding to each pixel using a ruler. It is set to 5 micrometers per pixel. The normal grading step size is 50 micrometers, or 10 pixels. Therefore, K is set to 10 to identify the transition points between different particle size grades. If the difference between adjacent sizes is greater than 10, a flag of 1 is stored at that position; if the difference between adjacent sizes is less than or equal to 10, 0 is stored and no interval truncation is performed. For example, the difference between R values of 27.35 and 45.8 is... Therefore, a change marker 1 is written, and particle size intervals are divided according to the interval between adjacent size change marker positions. The sorting sequence is truncated at the position where marker 1 appears. All particles between two adjacent markers 1 are grouped into one particle size interval. The representative size within each particle size interval is extracted, and the arithmetic mean of all representative sizes R falling into the same interval is taken as the nominal particle size of that interval. For example, if an interval contains three particles with R values of 25.4, 27.35, and 28.2, the average value of 26.98 is taken as the representative size of that interval. The boundary range of adjacent particle size intervals is sorted out, and the average value of the maximum value of the previous interval and the minimum value of the next interval at the junction of two adjacent intervals is taken as the segment boundary to obtain continuous particle size segments.
[0036] S503: Call the continuous particle size segment and multi-dimensional particle size set, combine the area of the contour coverage area, the boundary length and the ratio of the major axis to the minor axis to identify the particle shape, divide the round particles and the slender particles and count the number, determine the boundary adjacency relationship and spacing distribution between particles based on the corrected particle contour, distinguish between aggregated particles and dispersed particles and count the number, summarize the particle size interval, the representative size of the interval, the number of particle shapes and the number of aggregate states, and obtain the particle size detection results of the herbal powder; The system calls upon continuous particle size segments and a multidimensional particle size set, and combines the area of the contour coverage region, boundary length, and the ratio of the major axis to the minor axis to identify particle morphology. The ratio of the major axis dimension to the minor axis dimension is read as the elongation rate E. Dividing the major axis (31) by the minor axis (26) yields E approximately 1.19. Simultaneously, the roundness factor C is calculated according to: ; The operational logic involves multiplying a constant 4 by pi (3.14), then multiplying by the outline coverage area (Area), and dividing the result by the square of the boundary length (Length). In this example, Area is 560, and Length is the boundary length (92). The calculated roundness factor C is approximately 0.83. This process distinguishes between round and elongated particles and counts their quantities. and The particles were determined to be round particles. The particle is determined to be slender. If the sub-particle meets the condition, it is determined to be round and the roundness counter is incremented. The boundary adjacency relationship and spacing distribution between particles are determined based on the corrected particle outline. A 3x3 square morphological structural element is used to perform dilation processing on the corrected particle outline of the whole image. The coordinates of different particle outlines within the dilation range of 3 pixels are checked. If there is overlap and the boundary spacing in S402 is less than 3 pixels, they are determined to be adjacent to each other. Agglomerated particles and dispersed particles are distinguished and their numbers are counted. When a particle has an adjacency relationship with 2 or more particles, it is determined to be in an agglomerated state and recorded in the agglomeration counter; otherwise, it is recorded in the dispersion counter. The particle size interval, the representative size of the interval, the number of particle shapes, and the number of aggregated states are summarized. The nominal particle size of each interval, the total number of round particles, the total number of slender particles, and the total number of agglomerated and dispersed particles are packaged in a report format to obtain the particle size detection results of the herbal powder.
[0037] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for detecting the particle size of powdered herbs based on industrial vision, characterized in that, Includes the following steps: S1: Collect image signals from the discharge port of the herbal powdering equipment, adjust exposure and gain, complete brightness anomaly compensation and isolated noise correction, remove background pixels, retain powder pixel coordinates and gray values, and generate herbal powder gray distribution map. S2: Based on the grayscale distribution map of powder, extract the pixel grayscale difference and determine the direction of grayscale change, identify the position of the grayscale change direction reversal and extract the continuous abnormal direction path, determine the extension angle and filter the continuous direction trajectory to obtain the particle contact interface distribution map. S3: Extract the extension angle based on the particle contact interface distribution map, construct the projection trajectory and count the coverage density, determine the search range of the adhesion boundary, mark the connected components of the powder pixels and distinguish between the adhesion and independent regions, filter the boundary pixels with gentle gray-scale changes, and form the particle separation boundary trajectory. S4: Extract the gray values of boundary pixels based on the particle separation boundary trajectory, match the gray values of pixels on both sides along the normal to form the gray value difference distribution on both sides of the boundary, record the gray value change amplitude in the normal direction, select continuous and stable boundary segments, and combine multi-directional boundary spacing measurement to correct the particle contour of the connected domain to obtain a multi-dimensional particle size set.
2. The method for detecting particle size of powdered herbs based on industrial vision according to claim 1, characterized in that: The method also includes S5, which is as follows: S5: Based on the multidimensional particle size set, determine the representative particle size, sort to generate the particle size distribution structure, divide the continuous particle size interval, form continuous particle size segments, identify particle morphology and distinguish between agglomeration and dispersion, and summarize to form the particle size detection results of herbal powder.
3. The method for detecting particle size of powdered herbs based on industrial vision according to claim 1, characterized in that, The steps for obtaining S1 are as follows: S101: Acquire the image sensor output signal of the discharge port area of the herb pulverizing equipment, collect the current lighting environment status, adjust the exposure time parameter and gain parameter, scan the pixel brightness distribution, judge the pixel brightness status with the preset brightness consistency condition, select adjacent normal brightness pixels in the abnormal brightness area to complete the compensation correction, and obtain the brightness correction layer. S102: Based on the brightness correction layer, call the grayscale state of the current pixel and the grayscale state of the neighboring pixels in the compensated and corrected image, determine the grayscale change relationship between the current pixel and the neighboring pixels, locate isolated deviated pixels as noise pixels, select the grayscale state of the effective neighboring pixels to complete the replacement, and form a noise replacement layer. S103: Based on the noise replacement layer, collect the grayscale state of the powder area and the grayscale state of the background area, determine the grayscale difference relationship between the powder area and the background area, divide the background grayscale range, remove non-powder area pixels, extract the retained pixel coordinates and corresponding corrected pixel grayscale values, reconstruct the spatial grayscale distribution, and obtain the herbal powder grayscale distribution map.
4. The method for detecting particle size of powdered herbs based on industrial vision according to claim 1, characterized in that, The steps for obtaining S2 are as follows: S201: Based on the grayscale distribution map of the herbal powder, extract the grayscale state of each powder pixel and the grayscale state of the neighboring pixels, determine the grayscale change relationship of the powder pixel relative to the neighboring pixels in the upper, lower, left and right directions, write the corresponding pixel position into the direction mark, and generate grayscale direction mark. S202: Call the grayscale direction mark, compare the direction marks of adjacent powder pixels, determine the reverse relationship between the previous powder pixel direction mark and the next powder pixel direction mark, record the pixel position where the grayscale change direction is reversed, and connect the path according to the adjacency and extension relationship of the reversed pixel position in spatial coordinates to obtain the abnormal direction path. S203: Based on the abnormal direction path, determine the extension angle according to the change of adjacent pixel coordinates within the path, classify the abnormal direction path according to the preset angle range, count the frequency of path occurrence within the same angle range, filter continuous direction trajectories by combining the concentration of extension angle distribution, match the herb category based on the color distribution features and texture direction of the compensated and corrected image, correct the trajectory coverage according to the matching category, and obtain the particle contact interface distribution map.
5. The method for detecting particle size of powdered herbs based on industrial vision according to claim 1, characterized in that, The steps for obtaining S3 are as follows: S301: Based on the particle contact interface distribution map, extract the continuous direction trajectory extension angle, call the interface pixel coordinates and trajectory extension angle, arrange the interface pixels along the corresponding extension angle to form a projection trajectory, count the number of times each projection position is covered, write the number of times of coverage according to the projection position coordinates, form a projection coverage arrangement, and generate a projection spatial distribution. S302: Based on the projection space distribution, the projection coverage arrangement is divided according to the preset window, the number of projection coverages in each window is called, the adjacent state of the coverage position and the aggregation state of the coverage count in the window are determined, the window that meets the projection concentration judgment condition is marked as the concentration area, the coordinates of the concentration area are included in the boundary search range, and the adhesion boundary search range is obtained. S303: Call the adhesion boundary search range, the grayscale distribution map of the herbal powder, and the particle contact interface distribution map, mark the powder pixels as connected components, extract the adjacent state of the outer edge pixels of the connected components to form the connected component boundary relationship, extract the state of the interface pixels falling into the vicinity of the connected component boundary to form the interface distribution relationship, distinguish the adhesion area from the independent area based on the connected component boundary relationship and the interface distribution relationship, filter the boundary pixels with gentle grayscale changes within the search range and connect the candidate separation paths, retain the continuous and complete paths, and obtain the particle separation boundary trajectory.
6. The method for detecting particle size of powdered herbs based on industrial vision according to claim 1, characterized in that, The steps for obtaining S4 are as follows: S401: Based on the particle separation boundary trajectory, extract the grayscale state of the boundary pixels, call the grayscale state of the inner pixels of the adjacent particles on both sides in the boundary normal direction, match the corresponding pixels on both sides of the boundary along the normal direction, compare the grayscale change relationship between the boundary pixels and the inner pixels on both sides, write the grayscale difference on both sides into the corresponding boundary position, and generate the boundary grayscale difference distribution. S402: Based on the boundary gray-scale difference distribution, record the normal gray-scale change amplitude point by point to form a gray-scale change trajectory, call the gray-scale change amplitude and change trend of adjacent boundary positions, determine the continuous state and stable state of gray-scale change, locate the corresponding boundary segment, record the pixel spacing information on both sides, and obtain the boundary spacing distribution. S403: Based on the boundary spacing distribution and particle separation boundary trajectory, compare the dispersion of boundary spacing in multiple directions, filter the size range with concentrated spacing distribution, correct the particle outline of the connected domain, and extract the area, boundary length, major axis direction and minor axis direction of the corrected particle outline to obtain a multidimensional particle size set.
7. The method for detecting particle size of powdered herbs based on industrial vision according to claim 2, characterized in that, The steps for obtaining S5 are as follows: S501: Based on the multidimensional particle size set, call the boundary spacing, contour coverage area, boundary length, major axis dimension and minor axis dimension, determine the correspondence of each size item under the same particle mark, classify the boundary spacing and axial span into the corresponding particle contour, determine the representative size of each particle by combining the contour occupancy range, and sort them by size to generate a particle size distribution structure; S502: Based on the particle size distribution structure, compare the differences in representative size of adjacent particles, write the positions that meet the size change judgment conditions into change markers, divide the particle size intervals according to the intervals between adjacent size change markers, extract the representative size in each particle size interval, organize the boundary ranges of adjacent particle size intervals, and obtain continuous particle size segments. S503: Call the continuous particle size segmentation and multi-dimensional particle size set, combine the area of the contour coverage region, the boundary length and the ratio of the major axis to the minor axis to identify the particle morphology, divide the round particles and slender particles and count their number, determine the boundary adjacency relationship and spacing distribution between particles based on the corrected particle contour, distinguish between aggregated particles and dispersed particles and count their number, summarize the particle size interval, the representative size of the interval, the number of particle morphologies and the number of aggregate states, and obtain the particle size detection results of the herbal powder.
8. The method for detecting particle size of powdered herbs based on industrial vision according to claim 6, characterized in that, The specific operations for extracting the area of the contour coverage region, boundary length, and major and minor axis directions of the corrected particle contour are as follows: Read the closed boundary pixel coordinates in the corrected particle contour, mark the powder pixel coordinates within the closed boundary as the contour coverage area, count the pixel occupancy within the contour coverage area to form the contour coverage area area, connect adjacent boundary pixels according to the adjacent order of boundary pixel coordinates and accumulate the boundary coordinate step size to form the boundary length, read the pixel coordinate span of the contour coverage area along multiple candidate directions, determine the direction with the largest coordinate span as the major axis direction, and determine the direction that is perpendicular to the major axis direction and corresponds to the horizontal span of the coverage area as the minor axis direction.