Medicinal raw material screening method based on machine vision
By adaptively setting gamma values, the image of medicinal material raw materials is blocked and texture analysis is performed based on machine vision, which solves the problems of low efficiency and poor accuracy in screening of traditional medicinal material raw materials, and improves image quality and screening accuracy.
Patent Information
- Application Number
- CN202510715908.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2045-05-30
AI Technical Summary
The screening of traditional medicinal materials relies on manual observation, which is inefficient and subjective. The machine vision system is disturbed by uneven light and background noise, resulting in low image quality and poor inadaptation of gamma value settings, which affects the accuracy of screening.
By adaptively setting the gamma value, the raw materials images of the medicinal material are blocked based on machine vision, the degree of stretching and the necessity of texture enhancement are calculated, and the gamma value is judged using texture distinction and highlighting to achieve adaptive enhancement of image blocks.
It improves image quality and screening accuracy, ensures the adaptability and enhancement effect of gamma values, and improves the efficiency and accuracy of screening raw materials of medicinal materials.
Smart Images

Figure CN120235798A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing. More specifically, the present invention relates to a method for screening medicinal material raw materials based on machine vision. Background Art
[0002] The quality of medicinal material raw materials is directly related to the efficacy and safety of drugs. Therefore, in order to make the drugs achieve better effects, it is necessary to screen the medicinal material raw materials according to their quality.
[0003] Traditional screening of medicinal material raw materials mainly relies on manual operation, and the appearance characteristics of medicinal materials are distinguished by the experience of workers and naked-eye observation. However, this manual screening method has many disadvantages. For example, the screening efficiency is low and the subjectivity is strong. The machine vision system can quickly obtain the image information of medicinal material raw materials and evaluate the quality of medicinal materials through image processing and analysis algorithms. Compared with manual screening, machine vision technology has the advantages of high efficiency, objectivity, accuracy, etc. However, in practical applications, the images of medicinal material raw materials obtained by the machine vision system are often interfered by various factors, such as uneven illumination, background noise, complex surface texture of medicinal materials, etc., resulting in low image quality and unclear feature information, thus affecting the subsequent screening accuracy. Image enhancement processing, as a key technology for improving image quality, plays a crucial role in the machine vision system. As a commonly used image enhancement algorithm, the gamma transform algorithm has a good enhancement effect, but it is highly dependent on the gamma value. Setting the gamma value too large or too small will result in poor image enhancement effects. Traditionally, the appropriate gamma value is set according to experience or multiple attempts. This way of setting the gamma value not only has poor adaptability but also affects the image enhancement efficiency. Therefore, how to adaptively set the appropriate gamma value has become the research focus of the present invention. Summary of the Invention
[0004] To solve the problem of how to adaptively set the appropriate gamma value, the present invention proposes a method for screening medicinal material raw materials based on machine vision, which includes the following steps: Obtain the image of the medicinal material raw material and the gamma transform baseline of each gamma value; Perform block processing on the image of the medicinal material raw material to obtain a number of image blocks, obtain the analysis segment of any pixel point in the image block on the gamma transform baseline, and calculate the stretching degree according to the value width of the input value and the value width of the output value in the analysis segment. The stretching degree is positively correlated with the value width of the output value and negatively correlated with the value width of the input value; Calculate the texture enhancement necessity of this pixel point, where the texture enhancement necessity is equal to the ratio of texture distinctiveness to saliency, where saliency reflects the difficulty of extracting the texture; texture distinctiveness reflects the difference between this texture and the corresponding textures of other individual medicinal material raw materials; Take the product of the stretching degree and the necessity of texture enhancement as the enhancement degree of this pixel, and take the sum of the enhancement degrees of all pixels in the image block as the overall enhancement degree; take the gamma value corresponding to the maximum value of the overall enhancement degree as the target gamma value, and perform enhancement processing on the image block based on the target gamma value to achieve the screening of raw medicinal materials.
[0005] The present invention realizes effective image enhancement by adaptively setting appropriate gamma values for each image block, thereby improving the image quality; further, when adaptively setting appropriate gamma values, by analyzing the stretching of different gamma values for different pixel values, it can accurately judge whether this gamma value can effectively enhance the image to be enhanced, thus providing a basis for accurately screening gamma values; further, when adaptively setting appropriate gamma values, by introducing the necessity of enhancement to judge the necessary situation of each pixel to be enhanced, thus providing a basis for subsequent judgment of the enhancement situation of each gamma value; further, when analyzing the necessity of enhancement, by introducing the saliency to reflect the texture saliency at the position of each pixel, thus providing a basis for accurately determining the texture enhancement situation of each pixel; further, when analyzing the necessity of enhancement, by introducing the texture distinctiveness to reflect the situation that the texture at the position of each pixel is a distinctive texture for medicinal material screening, thus providing a basis for effectively enhancing the distinctive texture of medicinal material screening.
[0006] Preferably, the splitting the raw medicinal material image into blocks to obtain several image blocks includes: Uniformly dividing the raw medicinal material image into several preset-size image blocks.
[0007] Preferably, the obtaining the analysis segment of any pixel point in the image block on the gamma transformation baseline includes: Obtain the neighborhood pixels of this pixel point, calculate the absolute value of the difference in gray value between this pixel point and the neighborhood pixels and record it as the contrast value between this pixel and the neighborhood pixels, and divide the average value of the contrast values between this pixel and all neighborhood pixels by 255 to obtain the analysis length of this pixel; Intercept a curve segment with a horizontal axis length of the analysis length on the gamma transformation baseline with the normalized value of the gray value of this pixel as the center, and record it as the analysis segment of this pixel point on the gamma transformation baseline.
[0008] The present invention stages the analysis segment on the gamma transformation baseline according to the contrast values of the local regions of each pixel, so that the information in the analysis segment can reflect the pixel value mapping stretching situation of the local regions of each pixel, thus providing a basis for accurately analyzing the enhancement stretching situation of each pixel under different gamma values.
[0009] Preferably, the calculating the stretching degree according to the value width of the input value and the value width of the output value in the analysis segment includes: Obtain the value width of the analysis segment on the horizontal axis and the value width on the vertical axis, and use the ratio of the value width on the horizontal axis to the value width on the vertical axis as the stretching degree.
[0010] The present invention calculates the stretching degree through the ratio of the value widths, and this calculation method is relatively simple and has higher implementation efficiency.
[0011] Preferably, the saliency satisfies the relational expression: ; Among them, based on different thresholds, edge detection is performed on the medicinal material raw material image, and real edge pixel points are obtained in the edge images obtained under each threshold. Indicates the absence of a symbol. Indicates that the pixel point is a pixel point in the edge image obtained under i thresholds. Indicates a real edge pixel point. Indicates the presence of a symbol. Indicates the number of times that the real edge pixel point appears in the edge images obtained under all thresholds for this pixel point. Indicates the average value of the number of times that all pixel points in the image block appear as real edge pixel points in the edge images obtained under all thresholds, and norm() represents the normalization function. Indicates the saliency of this pixel point.
[0012] The present invention accurately reflects the difficulty of extracting the texture at each pixel position by analyzing the proportion of the number of times that the real edge pixel points at each pixel position are extracted under different thresholds, and thus more accurately quantifies the texture saliency of each pixel.
[0013] Preferably, the method for obtaining the real edge pixel points includes: Obtain edge pixel points in the edge images obtained under each threshold, and take any edge pixel point as the center to obtain the edge pixel points existing in the neighborhood and record them as the connected pixel points of this edge pixel point; take any connected pixel point of this edge pixel point as the center to obtain the connected pixel points of this connected pixel point, and so on, until there are no connected pixel points in the neighborhood of the connected pixel points, and obtain a connected chain of this edge pixel point; obtain other connected chains according to other connected pixel points of this edge pixel point; obtain the longest connected chain of this edge pixel point. Record the number of connected pixel points of each pixel on the longest connected chain of this edge pixel point as the connected head number of each pixel point, and use the normalized value of the ratio of the number of pixel points on the longest connected chain of this edge pixel point to the average value of the connected head numbers of all pixel points on the longest connected chain as the realness degree of this edge pixel point. Take the edge pixel points with a realness degree greater than the preset degree threshold as real edge pixel points.
[0014] The present invention accurately reflects the situation of each edge pixel point being a real edge by introducing the degree of authenticity, effectively eliminates false edge points, and obtains accurate edge pixel points.
[0015] Preferably, the method for obtaining the texture distinctiveness includes: Segmenting a plurality of individual regions of medicinal material raw materials in the medicinal material raw material image; In the edge images at all thresholds of the medicinal material raw material image, obtaining the edge image with the largest number of real edge pixel points as the reference edge image; obtaining each edge line in the individual regions of the medicinal material raw materials in the reference edge image as the texture line of the individual regions of the medicinal material raw materials; Calculating the similarity between each texture line of each individual region of the medicinal material raw materials and the corresponding matching texture lines of other individual regions of the medicinal material raw materials, and taking the reciprocal of the average similarity of each texture line of each individual region of the medicinal material raw materials and the corresponding matching texture lines of all other individual regions of the medicinal material raw materials as the texture distinctiveness of this texture line; Taking the texture distinctiveness of the texture line to which the pixel belongs as the texture distinctiveness of this pixel.
[0016] Preferably, segmenting a plurality of individual regions of medicinal material raw materials in the medicinal material raw material image includes: Performing segmentation processing on the medicinal material raw material image by using the Otsu threshold segmentation algorithm to obtain a plurality of connected regions, and obtaining a preset number of connected regions with the smallest area in the plurality of connected regions as the alternative connected regions; Taking the alternative connected region with the median area as the reference connected region; Performing matching processing on the reference connected region and each other connected region, and segmenting each other connected region into a plurality of sub-connected regions based on the matching result; Taking each sub-connected region as an individual region of the medicinal material raw materials.
[0017] Preferably, after performing enhancement processing on the image block, it further includes: Stitching all the enhanced image blocks together, and performing smoothing processing on the connection regions between the enhanced image blocks to obtain the enhanced medicinal material raw material image.
[0018] Preferably, the realization of screening of medicinal material raw materials includes: Inputting the enhanced medicinal material raw material image into the trained medicinal material raw material screening network to obtain the quality grades of each individual of the medicinal material raw materials; Selecting the individuals of the medicinal material raw materials whose quality grades meet the grade requirements.
[0019] The present invention has the following beneficial effects: The present invention realizes effective enhancement of the image by adaptively setting appropriate gamma values for each image block, thereby improving the image quality; Further, when adaptively setting an appropriate gamma value, by analyzing the stretching of different gamma values for different pixel values, it is possible to accurately determine whether the gamma value can effectively enhance the image to be enhanced, thereby providing a basis for accurately screening the gamma value; Further, when adaptively setting an appropriate gamma value, by introducing the necessity for enhancement to judge the necessary situation of each pixel to be enhanced, it provides a basis for subsequent judgment of the enhancement situation of each gamma value; Further, when analyzing the necessity for enhancement, by introducing saliency to reflect the texture saliency at the position of each pixel, it provides a basis for accurately determining the situation where the texture of each pixel needs to be enhanced; Further, when analyzing the necessity for enhancement, by introducing texture distinctiveness to reflect the situation of the distinctiveness texture for medicinal material screening at the position of each pixel, it provides a basis for effectively enhancing the distinctiveness texture for medicinal material screening. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 is a flowchart of the steps of the method for screening medicinal material raw materials based on machine vision according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0021] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0022] The following will describe in detail the specific implementation manners of the present invention with reference to the accompanying drawings.
[0023] Please refer to Figure 1 , which shows a flowchart of the steps of the method for screening medicinal material raw materials based on machine vision provided by an embodiment of the present invention. The method includes the following steps: S1: Obtain a medicinal material raw material image and a gamma transformation baseline for each gamma value.
[0024] Specifically, after laying the medicinal material raw materials flat, collect the medicinal material raw material image; and the gamma transformation baseline for each gamma value. Gray-scale the medicinal material raw material image to obtain the gray-scale image of the medicinal material raw material image. For the convenience of description, the gray-scale image of the medicinal material raw material image will still be referred to as the medicinal material raw material image hereinafter.
[0025] It should be noted that the gamma transformation baseline is an existing mathematical curve and will not be elaborated here.
[0026] S2: Divide the medicinal material raw material image into blocks to obtain a number of image blocks, obtain the analysis segment of any pixel point in the image block on the gamma transformation baseline, and calculate the stretching degree according to the value width of the input value and the value width of the output value within the analysis segment. The stretching degree is positively correlated with the value width of the output value and negatively correlated with the value width of the input value.
[0027] S20: Divide the medicinal material raw material image into blocks to obtain a number of image blocks.
[0028] It should be noted that there are differences in the illumination of each area in the medicinal material raw material image. If the same enhancement method is used for the entire image of the medicinal material raw material image, it is easy to have some areas that are too bright and some areas that are too dark. Therefore, in order to achieve a better enhancement effect, the medicinal material raw material image needs to be divided into small pieces, and the corresponding gamma value is set according to the needs of each small piece, so as to achieve a better enhancement effect.
[0029] Preferably, as an example, dividing the medicinal material raw material image into blocks to obtain a number of image blocks includes: Uniformly divide the medicinal material raw material image into a number of preset-size image blocks. In this embodiment, the preset size is taken as an example for description. Other embodiments can adopt other methods, and this embodiment does not make specific limitations.
[0030] S21: Obtain the analysis segment of any pixel point in the image block on the gamma transformation baseline, and calculate the stretching degree according to the value width of the input value and the value width of the output value within the analysis segment.
[0031] It should be noted that the gamma transformation baseline compresses some data to a smaller value range and enlarges some data to a larger value range through a non-linear mapping transformation, so as to amplify the differences between the data to achieve image enhancement. In other words, if the gamma transformation with a certain gamma value can compress the smaller gray values in the texture area to be enhanced to a smaller value and enlarge the larger gray values in the texture area to a larger value, the texture to be enhanced can achieve a better enhancement effect. Therefore, to set an appropriate gamma value, it is necessary to analyze the stretching situation of the gray value value width of each pixel in the texture area corresponding to each gamma value's gamma transformation baseline.
[0032] S210: Obtain the analysis segment of any pixel point in the image block on the gamma transformation baseline.
[0033] It should be noted that since the texture area cannot be accurately extracted at present, the stretching situation of the gray value value width of the local area of each pixel is analyzed here. Since there are many diversities in the gray value values of the local areas where each pixel is located, in order to reduce the number of analyses, it is only necessary to analyze the stretching situation of the gray value value width that can represent most of the gray values in the local area where the pixel is located.
[0034] It should be further noted that the average contrast within the local area where each pixel is located can reflect the value width of the local area of the pixel. The value width of most gray values can be characterized by the average contrast. Therefore, the corresponding transformation segment is obtained on the gamma transformation baseline through the average contrast to analyze the stretching situation of the gamma transformation on the value width of the gray value of the pixel.
[0035] Preferably, as an example, obtaining the analysis segment of any pixel point on the gamma transformation baseline in the image block includes: Obtaining the neighboring pixels of the pixel point, calculating the absolute value of the difference in gray values between the pixel point and the neighboring pixels, recording it as the contrast value between the pixel and the neighboring pixels, and dividing the average value of the contrast values between the pixel and all neighboring pixels by 255 to obtain the analysis length of the pixel; Taking the normalized value of the gray value of the pixel as the center, intercepting a curve segment with a horizontal axis length of the analysis length on the gamma transformation baseline, which is recorded as the analysis segment of the pixel point on the gamma transformation baseline.
[0036] It should be noted that the analysis length can be the normalized value of the value width of the local area of the pixel. The interval with a horizontal axis length of the analysis length centered on the normalized value of the pixel can reflect the value interval of the local area of the pixel. Therefore, the analysis segment intercepted in this way can reflect the change situation of the values in the local area of the pixel before and after mapping.
[0037] S211: Calculate the stretching degree according to the value width of the input value and the value width of the output value within the analysis segment.
[0038] It should be noted that the horizontal axis value of the gamma transformation baseline is the normalized value of the gray value before pixel mapping, and the vertical axis value of the analysis segment is the normalized value of the gray value after pixel mapping. Therefore, by calculating the difference between the horizontal axis value width and the vertical axis value width of the analysis segment, the stretching situation of the values in the local area of the local area texture of the pixel can be reflected.
[0039] Preferably, as an example, calculating the stretching degree according to the value width of the input value and the value width of the output value within the analysis segment includes: Obtaining the value width of the analysis segment on the horizontal axis and the value width on the vertical axis, and taking the ratio of the value width on the horizontal axis to the value width on the vertical axis as the stretching degree.
[0040] It can be understood that the greater the stretching degree, the greater the proportion by which the value width of the local area of the pixel after enhancement is enlarged. Therefore, the better the enhancement effect of the texture in the local area of the pixel.
[0041] S3: Calculate the necessity of texture enhancement for this pixel. The necessity of texture enhancement is equal to the ratio of texture distinctiveness to saliency, where saliency reflects the difficulty of texture extraction; texture distinctiveness reflects the difference between this texture and the corresponding textures of other medicinal material raw material individuals.
[0042] It should be noted that to set an appropriate gamma value, it is also necessary to ensure that the pixels to be enhanced can be better enhanced under this gamma value for mapping. Therefore, it is necessary to analyze the enhancement requirements of each pixel in the medicinal material raw material image.
[0043] For example, some faint textures. It is difficult to identify their texture information without enhancement, which affects the screening accuracy of medicinal material raw materials. There are also some distinctiveness texture information used for medicinal material screening. If the saliency of these textures is poor, the texture information cannot be recognized during the screening of medicinal material raw materials, resulting in a reduction in the screening accuracy of medicinal material raw materials. Some areas require weaker enhancement, such as textureless areas or areas with relatively prominent textures. Therefore, it is necessary to analyze the necessity of enhancement for each pixel.
[0044] S30: Obtain the saliency.
[0045] It should be noted that some textures in the texture are more obvious, and some textures are less obvious. Among them, the obvious textures can identify the texture information without enhancement, and the less obvious textures need to be enhanced to identify the texture information. The necessity of enhancement for each texture can be reflected by the saliency of the texture.
[0046] It should be further noted that the textures extracted by the texture extraction algorithm are different under different parameters. Among them, the textures with higher saliency can be extracted under most parameters of the texture extraction algorithm, and the textures with lower saliency can be recognized under fewer parameters of the texture extraction algorithm. Therefore, the saliency can be analyzed according to the extraction situation of the texture under different parameters of the texture extraction algorithm.
[0047] Preferably, the method for obtaining the saliency includes: Edge detection is performed on the medicinal material raw material image based on different thresholds. Edge pixel points are obtained from the edge images obtained under each threshold. The edge pixel points existing in the neighborhood are obtained with any edge pixel point as the center and are recorded as the connected pixel points of this edge pixel point; with any connected pixel point of this edge pixel point as the center, the connected pixel points of this connected pixel point are obtained, and so on, until there are no connected pixel points in the neighborhood of the connected pixel points, and a connected chain of this edge pixel point is obtained; other connected chains are obtained according to other connected pixel points of this edge pixel point; the longest connected chain of this edge pixel point is obtained; the number of connected pixel points of each pixel on the longest connected chain of this edge pixel point is recorded as the connected head number of each pixel point, and the normalized value of the ratio of the number of pixel points on the longest connected chain of this edge pixel point to the average value of the connected head numbers of all pixel points on the longest connected chain is used as the authenticity degree of this edge pixel point; the edge pixel points with an authenticity degree greater than the preset degree threshold are used as real edge pixel points.
[0048] It can be understood that since when the threshold is set relatively low, some non-edge pixels are extracted, and non-edge pixels generally exist concentratedly and do not have the characteristic of one-way extension, so the pseudo-edge pixels are excluded through this feature to obtain real edge pixels.
[0049] The saliency satisfies the relational expression: ; Among them, represents the non-existence symbol, represents the pixel point in the edge image obtained by this pixel point under i thresholds, represents the real edge pixel point, represents the existence symbol, represents the number of times the real edge pixel point appears in the edge images obtained by this pixel point under all thresholds, represents the average value of the number of times the real edge pixel point appears in the edge images obtained by all pixel points in the image block under all thresholds, norm() represents the normalization function, represents the saliency of this pixel point.
[0050] It can be understood that if the edge pixel cannot be recognized under different thresholds, it means that this pixel itself is not a texture pixel, so this pixel has clearly highlighted its non-texture information characteristics, so the saliency of this pixel is set to 1. If the edge pixel can only be recognized under a few thresholds, it means that the texture recognition of this pixel is more difficult, so the ability of this pixel to highlight the texture information is weaker, and the necessity of enhancing this pixel is greater.
[0051] S31: Obtain texture distinctiveness.
[0052] It should be noted that there are differences in the textures of medicinal material raw materials with poor quality and those with good quality. Therefore, some distinguishable textures are beneficial for screening medicinal material raw materials, and thus it is more necessary to enhance those distinguishable textures.
[0053] Preferably, as an example, the method for obtaining texture distinguishability includes: Using the Otsu threshold segmentation algorithm to segment the medicinal material raw material image to obtain a number of connected regions, and obtaining a preset number of connected regions with the smallest area in the number of connected regions, which are denoted as alternative connected regions; Denoting the alternative connected region with the median area as the reference connected region; Performing a matching process between the reference connected region and each other connected region to obtain a number of matching regions of the reference connected region in other connected regions, separating the number of matching regions in each other connected region, and denoting each separated sub-region as a medicinal material raw material individual region.
[0054] Obtaining the edge image with the most real edge pixel points among the edge images at all thresholds of the medicinal material raw material image, which is denoted as the reference edge image; obtaining each edge line in the medicinal material raw material individual region of the reference edge image, which is denoted as the texture line of the medicinal material raw material individual region; Calculating the similarity between each texture line of each medicinal material raw material individual region and the corresponding matching texture line of other medicinal material raw material individual regions, and taking the reciprocal of the average value of the similarities between each texture line of each medicinal material raw material individual region and the corresponding matching texture lines of all other medicinal material raw material individual regions as the texture distinguishability of this texture line; Taking the texture distinguishability of the texture line to which the pixel belongs as the texture distinguishability of this pixel.
[0055] The way to calculate the similarity between each texture line of each medicinal material raw material individual region and the corresponding matching texture lines of all other medicinal material raw material individual regions can be: Statistical the curvature of each texture line to obtain a curvature histogram, and taking the cosine similarity between the curvature histograms of each texture line of each medicinal material raw material individual region and the corresponding matching texture lines of all other medicinal material raw material individual regions as the similarity between each texture line of each medicinal material raw material individual region and the corresponding matching texture lines of all other medicinal material raw material individual regions.
[0056] Here, only an example of calculating the similarity between each texture line of each medicinal material raw material individual region and the corresponding matching texture lines of all other medicinal material raw material individual regions is given, and other existing methods can also be used for calculation, and the specific calculation method is not limited.
[0057] It should be added that the method for obtaining a number of matching regions of the reference connected region in other connected regions includes: Obtain the corresponding region of the reference connected component in the medicinal material raw material image, which is denoted as the reference region, and obtain the corresponding regions of other connected components in the medicinal material raw material image, which are denoted as the regions to be segmented; Rotate the reference region according to a preset angle, and obtain several rotated reference regions for several preset angles; Start from one side edge of the region to be segmented, slide the reference region on the region to be segmented. After each slide, match the rotated reference region with its corresponding region in the region to be segmented, and calculate the matching value. Select the maximum matching value among all the matching values of the rotated reference regions and their corresponding regions in the region to be segmented as the comprehensive matching value. Take the corresponding region with the comprehensive matching value greater than the preset matching threshold as the matching region of the reference connected component in other connected components.
[0058] It should be further supplemented that the method for obtaining the corresponding matching texture lines of each texture line in each individual region of the medicinal material raw material and the corresponding regions of other individual regions of the medicinal material raw material includes: Match each individual region of the medicinal material raw material with other individual regions of the medicinal material raw material, obtain the matching regions of each texture line in each individual region of the medicinal material raw material in other individual regions of the medicinal material raw material, and take the texture lines existing in the matching regions as the corresponding matching texture lines of each texture line in each individual region of the medicinal material raw material in other individual regions of the medicinal material raw material.
[0059] Specifically, if there are no texture lines in the matching region, set the similarity between each texture line of the individual region of the medicinal material raw material and the corresponding matching texture lines of other individual regions of the medicinal material raw material to 0.
[0060] S4: Take the product of the stretching degree and the necessity of texture enhancement as the enhancement degree of this pixel point, and take the sum of the enhancement degrees of all pixel points in the image block as the overall enhancement degree; Take the gamma value corresponding to the maximum overall enhancement degree as the target gamma value, and perform enhancement processing on the image block based on the target gamma value to achieve the screening of medicinal material raw materials.
[0061] It should be noted that if the gamma transformation baseline under a certain gamma value can stretch the value width of the local region of pixels with a greater necessity of texture enhancement to a greater extent, then the texture in the local region of this pixel can be better enhanced. Furthermore, the image enhancement under this gamma value has a better effect. Therefore, this gamma value should be more selected as the target gamma value for image enhancement processing.
[0062] S40: Take the product of the stretching degree and the necessity of texture enhancement as the enhancement degree of this pixel point, and take the sum of the enhancement degrees of all pixel points in the image block as the overall enhancement degree.
[0063] S41: taking the gamma value corresponding to the maximum value of the overall enhancement degree as the target gamma value, and performing enhancement processing on the image block based on the target gamma value.
[0064] Preferably, as an example, taking the gamma value corresponding to the maximum value of the overall enhancement degree as the target gamma value, and performing enhancement processing on the image block based on the target gamma value, includes: The gamma value corresponding to the maximum value of the overall enhancement degree is used as the target gamma value, the target gamma value is set as the gamma value of the gamma transform algorithm, and the image block is enhanced by using the gamma transform algorithm.
[0065] It should be added that all enhanced image blocks are spliced together, and the connected pixels between two enhanced image blocks are smoothed using a Gaussian filter to obtain an enhanced medicinal material raw material image.
[0066] S42: To achieve the screening of medicinal raw materials.
[0067] Preferably, as an example, to achieve the screening of medicinal materials, the method includes: A medicinal raw material screening network is constructed, and the medicinal raw material screening network is trained using the medicinal raw material image dataset. The enhanced medicinal raw material images are input into the trained medicinal raw material screening network to obtain abnormal medicinal raw material areas.
[0068] The corresponding medicinal material raw materials in the abnormal medicinal material raw material area are screened out.
[0069] In this embodiment, the YoloV10 network is used as the medicinal material screening network. Other embodiments may use other recognition networks, which are not specifically limited in this embodiment. The medicinal material image data set includes a number of labeled medicinal material images, wherein the label of the abnormal medicinal material area in the medicinal material image is 1; and the label of the non-abnormal medicinal material area in the medicinal material image is set to 0.
[0070] At this point, this embodiment is completed.
[0071] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for screening medicinal material raw materials based on machine vision, characterized in that, Including: Obtaining the image of the medicinal material raw material and the gamma transformation baseline for each gamma value; Performing block processing on the medicinal material raw material image to obtain a number of image blocks, obtaining the analysis segment of any pixel point in the image block on the gamma transformation baseline, and calculating the stretching degree according to the value width of the input value and the value width of the output value within the analysis segment. The stretching degree is positively correlated with the value width of the output value and negatively correlated with the value width of the input value; Calculating the necessity of texture enhancement for this pixel point. The necessity of texture enhancement is equal to the ratio of texture distinctiveness to saliency, where saliency reflects the difficulty of extracting the texture; texture distinctiveness reflects the difference between this texture and the corresponding textures of other individual medicinal material raw materials; Taking the product of the stretching degree and the necessity of texture enhancement as the enhancement degree of this pixel point, and taking the sum of the enhancement degrees of all pixel points in the image block as the overall enhancement degree; Taking the gamma value corresponding to the maximum value of the overall enhancement degree as the target gamma value, and performing enhancement processing on the image block based on the target gamma value to achieve the screening of the medicinal material raw material.
2. The method for screening medicinal material raw materials based on machine vision according to claim 1, wherein The performing block processing on the medicinal material raw material image to obtain a number of image blocks includes: Evenly dividing the medicinal material raw material image into a number of preset-size image blocks.
3. The method for screening medicinal material raw materials based on machine vision according to claim 1, wherein The obtaining the analysis segment of any pixel point in the image block on the gamma transformation baseline includes: Obtaining the neighborhood pixels of this pixel point, calculating the absolute value of the difference in grayscale values between this pixel point and the neighborhood pixels and recording it as the contrast value between this pixel and the neighborhood pixels, and dividing the average value of the contrast values between this pixel and all neighborhood pixels by 255 to obtain the analysis length of this pixel; Taking the normalized value of the grayscale value of this pixel as the center and intercepting a curve segment with a horizontal axis length of the analysis length on the gamma transformation baseline, which is recorded as the analysis segment of this pixel point on the gamma transformation baseline.
4. The method for screening medicinal material raw materials based on machine vision according to claim 1, characterized in that The calculating the stretching degree according to the value width of the input value and the value width of the output value within the analysis segment includes: Obtaining the value width of the analysis segment on the horizontal axis and the value width on the vertical axis, and taking the ratio of the value width on the horizontal axis to the value width on the vertical axis as the stretching degree.
5. The method for screening medicinal material raw materials based on machine vision according to claim 1, wherein The saliency satisfies the relational expression: ; Among them, edge detection is performed on the medicinal material raw material image based on different thresholds, and true edge pixel points are obtained from the edge images obtained under each threshold. Indicates the absence of a symbol. Indicates that the pixel point is a pixel point in the edge image obtained under i thresholds. Indicates a true edge pixel point. Indicates the presence of a symbol. Indicates the number of times the true edge pixel point appears in the edge images obtained under all thresholds for the pixel point. Indicates the average value of the number of times the true edge pixel point appears in the edge images obtained under all thresholds for all pixel points in the image block. norm() represents the normalization function. Indicates the saliency of the pixel point.
6. The method for screening medicinal material raw materials based on machine vision according to claim 5, characterized in that The method for obtaining the true edge pixel points includes: Obtaining edge pixel points in the edge image obtained under each threshold, taking any edge pixel point as the center and obtaining the edge pixel points existing in the neighborhood as the connected pixel points of this edge pixel point; taking any connected pixel point of this edge pixel point as the center and obtaining the connected pixel points of this connected pixel point, and so on, until there are no connected pixel points in the neighborhood of the connected pixel points, obtaining a connected chain of this edge pixel point; obtaining other connected chains according to the other connected pixel points of this edge pixel point; obtaining the longest connected chain of this edge pixel point; Recording the number of connected pixel points of each pixel on the longest connected chain of this edge pixel point as the connected head number of each pixel point, and taking the normalized value of the ratio of the number of pixel points on the longest connected chain of this edge pixel point to the average value of the connected head numbers of all pixel points on the longest connected chain as the true degree of this edge pixel point; Taking the edge pixel points with a true degree greater than the preset degree threshold as the true edge pixel points.
7. The method for screening medicinal material raw materials based on machine vision according to claim 5, wherein The method for obtaining the texture distinctiveness includes: Segment a number of individual regions of medicinal material raw materials in the image of the medicinal material raw materials; Obtain the edge image with the largest number of real edge pixels among the edge images at all thresholds of the medicinal material raw material image, and record it as the reference edge image; obtain each edge line in the individual region of the medicinal material raw material in the reference edge image, and record it as the texture line of the individual region of the medicinal material raw material; Calculate the similarity between each texture line of each individual region of the medicinal material raw material and the corresponding matching texture line of other individual regions of the medicinal material raw material, and take the reciprocal of the average similarity of each texture line of each individual region of the medicinal material raw material and the corresponding matching texture line of all other individual regions of the medicinal material raw material as the texture distinctiveness of this texture line; Take the texture distinctiveness of the texture line to which the pixel belongs as the texture distinctiveness of this pixel.
8. The method for screening medicinal material raw materials based on machine vision according to claim 7, wherein The segmenting a number of individual regions of medicinal material raw materials in the image of the medicinal material raw materials includes: Use the Otsu threshold segmentation algorithm to perform segmentation processing on the image of the medicinal material raw materials to obtain a number of connected regions, and obtain a preset number of connected regions with the smallest area among the number of connected regions, and record them as alternative connected regions; Record the alternative connected region with the median area as the reference connected region; Perform matching processing on the reference connected region and each other connected region, and based on the matching result, divide each other connected region into a number of sub-connected regions; Record each sub-connected region as an individual region of the medicinal material raw material.
9. The method for screening medicinal material raw materials based on machine vision according to claim 1, wherein After performing enhancement processing on the image block, it further includes: Stitch all the enhanced image blocks together, and perform smoothing processing on the connection regions between the enhanced image blocks to obtain the enhanced image of the medicinal material raw materials.
10. The method for screening medicinal material raw materials based on machine vision according to claim 9, wherein The realizing the screening of the medicinal material raw materials includes: Input the enhanced image of the medicinal material raw materials into the trained medicinal material raw material screening network to obtain the quality grades of each individual of the medicinal material raw materials; Screen out the individuals of the medicinal material raw materials whose quality grades meet the grade requirements.
Citation Information
Patent Citations
Fast image enhancement method based on gamma transformation
CN107527333A
Global self-adaptive grayscale image enhancement method based on double gamma correction
CN110084760A
Low-illumination image enhancement method adopting bidirectional gamma transformation
CN110288546A
Method for detecting etching quality of laminating process of computer display panel
CN116030052A
Visual positioning method for underwater robot
CN117934355A