Disclosure of Invention
In order to solve the technical problems that the traditional threshold segmentation method cannot acquire an accurate optimal threshold value, so that the crack defect of a hard carbon electrode cannot be accurately detected, and further the quality detection reliability and accuracy of the hard carbon electrode are low, the invention aims to provide a hard carbon electrode production quality detection method, which adopts the following specific technical scheme:
acquiring a gray image of a hard carbon electrode to be detected;
acquiring a connected domain of the image of the gray image under different threshold segmentation; taking any threshold value as a target threshold value, and obtaining a suspected defect area according to the gray value of a pixel point in a corresponding area in the gray image of a connected area of the image under the target threshold value; obtaining a final defect region according to the difference of gray values of the edge pixel points of each suspected defect region and the neighborhood pixel points in the preset neighborhood;
obtaining shape characteristic parameters of the final defect areas according to the distribution of pixel points in each final defect area and the corresponding suspected defect area; obtaining an optimal degree parameter of the target threshold according to the area of the final defect area, the area of the suspected defect area and the shape characteristic parameter of the final defect area;
obtaining an optimal threshold according to the optimal degree parameters of all the thresholds; obtaining a segmentation result of the gray level image of the hard carbon electrode to be detected according to the optimal threshold; and obtaining the quality of the hard carbon electrode to be detected according to the segmentation result.
Further, the method for acquiring the suspected defect area comprises the following steps:
acquiring a gray gradient value of each pixel point in the gray image;
taking the average value of the gray gradient values of all pixel points in the corresponding region of each connected region in the gray image as a first average gray gradient value, the variance of the gray values as a first gray variance, and the average value of the gray values as a first gray average;
taking the average value of the gray gradient values of all pixel points in the gray image as a second average gray gradient value, taking the variance of the gray values as a second gray variance and taking the average value of the gray values as a second gray average value;
and taking a corresponding region of a connected region with the first average gray gradient value larger than the second average gray gradient value, the first gray variance smaller than the second gray variance and the first gray mean smaller than the second gray mean in the gray image as a suspected defect region.
Further, the method for acquiring the final defect area includes:
taking any suspected defect area as a defect area to be detected;
taking the difference between the second gray average value and the first gray average value of the defect area to be detected as a gray difference value;
taking any edge pixel point in the defect area to be detected as an edge pixel point to be detected; and carrying out adjustment analysis on the edge pixel points to be detected according to the gray level difference value to obtain the final defect area.
Further, the adjusting and analyzing the edge pixel point to be detected according to the gray level difference value to obtain the final defect area includes:
taking the difference of gray values of each neighborhood pixel point and the center pixel point as neighborhood gray difference in a preset neighborhood taking the edge pixel point to be detected as the center;
acquiring the minimum value of all the neighborhood gray level differences corresponding to the central pixel point, and if the minimum value is smaller than the gray level difference value, taking the neighborhood pixel point corresponding to the minimum value as an updated edge pixel point to be detected; continuing to perform adjustment analysis on the updated edge pixel points to be detected; if the minimum value is greater than or equal to the gray scale difference value, stopping adjusting analysis;
if all the edge pixel points to be detected are updated, the updated edge pixel points to be detected enclose the final defect area; otherwise, the non-updated edge pixel points to be detected and the updated edge pixel points enclose the final defect area.
Further, the method for acquiring the shape characteristic parameter comprises the following steps:
taking any final defect area as a target area;
taking the centroid of the suspected defect area corresponding to the target area as a starting point to obtain a scribing line in a preset direction;
taking the number of intersection points of the scribing line and the target area as a first number of intersection points;
taking the number of intersection points of the scribing line and the suspected defect area corresponding to the target area as a second number of intersection points;
and taking the ratio of the first intersection number to the second intersection number as the shape characteristic parameter of the target area.
Further, the method for obtaining the optimal degree parameter comprises the following steps:
adding the areas of all the final defect areas to obtain the total area of the final defect areas;
adding the areas of all the suspected defect areas to obtain the total area of the suspected defect areas;
taking the ratio of the total area of the final defect area to the total area of the suspected defect area as an area ratio;
taking the average value of the shape characteristic parameters of all the defect areas as an average value characteristic value;
taking the difference between the area ratio and a preset constant as a difference characteristic value; and carrying out negative correlation mapping and normalization on the difference characteristic value, and multiplying the difference characteristic value by the mean characteristic value to serve as the optimal degree parameter.
Further, the method for obtaining the optimal threshold value comprises the following steps:
and taking the threshold corresponding to the maximum value of all the optimal degree parameters as the optimal threshold.
Further, the preset neighborhood is a four-neighborhood.
Further, the preset direction is an eight-chain code direction.
Further, the method for acquiring the gray level image of the hard carbon electrode to be detected comprises the following steps:
and obtaining an initial image of the hard carbon electrode to be detected, and carrying out average method graying on the initial image to obtain the gray image of the hard carbon electrode to be detected.
The invention has the following beneficial effects:
the invention aims to obtain the optimal threshold value during threshold segmentation, so that the crack defect of the hard carbon electrode can be accurately detected, and the reliability and the accuracy of quality detection are improved; firstly, a gray level image of a hard carbon electrode is acquired, and then the gray level image is analyzed; because the cracks have the characteristic of regional concentration, the connected domain of the gray image can be acquired, and meanwhile, because the aim is to acquire the optimal threshold value, the images of dividing the gray image under different threshold values can be acquired, so that the subsequent evaluation on different threshold values is facilitated; further, since the gray value of the pixel point in the crack region has the characteristics of low variation, the connected region can be screened to obtain a suspected defect region; because the acquisition of the connected domain may be interfered by image noise, the suspected defect region may be further analyzed to obtain an accurate final defect region; further, since the crack has obvious shape characteristics, the shape characteristic parameter of each final defect area can be obtained, and then the shape characteristic parameter is combined with the area of the final defect area and the area of the suspected defect area to evaluate the current threshold value to obtain the optimal degree parameter of the current threshold value; and then the optimal threshold value can be obtained by comparing the optimal degree parameters based on all the threshold values; then, the gray level image can be segmented based on an optimal threshold value to obtain an accurate segmentation result, and finally, the quality detection is performed on the hard carbon electrode based on the accurate segmentation result. According to the invention, the suspected defect region in the gray level image is further analyzed to obtain an accurate final defect region, the threshold value is evaluated by combining the suspected defect region with the shape characteristics of the crack defect, the optimal threshold value is accurately obtained, and the image segmentation is performed, so that the crack defect of the hard carbon electrode can be accurately detected, and the reliability and the accuracy of the quality detection of the hard carbon electrode are further improved.
Detailed Description
In order to further describe the technical means and effects adopted by the present invention to achieve the preset purpose, the following detailed description refers to specific embodiments, structures, features and effects of a hard carbon electrode production quality detection method according to the present invention with reference to the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" means that the embodiments are not necessarily the same. Furthermore, the particular features, structures, or characteristics of one or more embodiments may be combined in any suitable manner.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
The following specifically describes a specific scheme of the method for detecting the production quality of the hard carbon electrode provided by the invention with reference to the accompanying drawings.
Referring to fig. 1, a method flowchart of a hard carbon electrode production quality detection method according to an embodiment of the invention is shown, where the method includes:
step S1: and acquiring a gray image of the hard carbon electrode to be detected.
According to the embodiment of the invention, the gray level image of the hard carbon electrode to be detected is analyzed to obtain the optimal threshold value, so that an accurate segmentation result is obtained to finish the quality detection of the hard carbon electrode, and the gray level image of the hard carbon electrode to be detected is needed to be obtained first.
Preferably, the method for acquiring the gray scale image of the hard carbon electrode to be measured in one embodiment of the present invention includes:
and acquiring images of the hard carbon electrode on the conveyor belt in a fixed light source mode through an industrial camera, and then carrying out average method graying treatment on the acquired images to obtain gray images of the hard carbon electrode to be detected. It should be noted that, the deployment of the specific image capturing device, the view angle range of the camera, and other parameter settings, the implementer can adjust according to the specific implementation scenario, which is not limited and described herein in detail; the average gray scale method is a technical means well known to those skilled in the art, and other gray scale methods may be used in other embodiments of the present invention, and specifically, the average gray scale method may be, for example, a maximum value method, a weighted gray scale method, etc., which are not limited and described herein.
The gray level image of the hard carbon electrode to be detected is obtained, and the subsequent analysis process of the gray level image of the hard carbon electrode to be detected can be completed.
Step S2: acquiring a connected domain of an image of the gray image under different threshold segmentation; taking any threshold value as a target threshold value, and obtaining a suspected defect area according to the gray value of a pixel point in a corresponding area in a gray image of a connected area of the image under the target threshold value; and obtaining a final defect region according to the difference between the gray value of the edge pixel point of each suspected defect region and the gray value of the neighborhood pixel point in the preset neighborhood.
The purpose of the embodiment of the invention is to acquire the optimal threshold value and further finish the quality detection of the hard carbon electrode, so that the threshold value can be traversed firstly, the gray level image of the hard carbon electrode to be detected in the step S1 is binarized, and at the moment, the binary image of the gray level image under different threshold values can be acquired. Since the crack defect has the characteristic of region concentration, the connected domain analysis can be performed on each binary image, and the connected domain in each binary image can be obtained. For ease of analysis and explanation, any threshold is used as the target threshold in embodiments of the present invention. In the embodiment of the present invention, 0 is used to represent the crack defect area in the binary image, that is, black represents the foreground area; the method for obtaining the connected domain is an operation process well known to those skilled in the art, and will not be described herein in detail; the range of the traversal threshold may be, for example, (0, 255), and may be adjusted according to the implementation scenario, but is not limited herein, since too large or too small a threshold may cause image loss details or excessive noise retention.
Because the obtained connected domain is directly regarded as a crack area not accurate enough, a larger error can be caused, the connected domain needs to be further screened to obtain a suspected defect area; the screening condition can be based on the gray value of the pixel point in the corresponding region of the connected domain in the gray image in the binary image; the reason is that the gray value of the pixel point in the crack area is generally low, the gray value in the crack area is changed less, and the gray gradient value of the pixel point at the edge of the crack area is larger.
Preferably, the method for acquiring the suspected defect area in one embodiment of the present invention includes:
firstly, acquiring a gray gradient value of each pixel point in a gray image of a hard carbon electrode to be detected; then accumulating the gray gradient values of all pixel points in the corresponding region of each connected region in the gray image, averaging to obtain a first average gray gradient value, taking the variance of the gray value as a first gray variance, and taking the average value of the gray value as a first gray average value; and then taking the average gray gradient value of all pixel points in the gray image as a second average gray gradient value, taking the variance of the gray value as a second gray variance, and taking the average value of the gray value as a second gray average value. Based on the analysis, the gray value of the pixel point in the crack area is generally low, the gray value change in the crack area is small, and the gray gradient value of the pixel point at the edge of the crack area is large, so that the connected domain with the first gray average value being smaller than the second gray average value is used as a suspected defect area in the gray image, wherein the first average gray gradient value is larger than the second average gray gradient value, the first gray variance is smaller than the second gray variance, and the connected domain with the first gray average value being smaller than the second gray average value is used as the suspected defect area in the gray image.
Because the connected domain obtained after the threshold segmentation is further screened to obtain the suspected defect region, image details may be lost and noise may be interfered in the process of obtaining the connected domain, so that the obtained connected domain is not accurate enough, the suspected defect region is not accurate enough at this time, and further analysis of the suspected defect region is required to obtain an accurate final defect region; because the gray value of the pixel point in the crack defect area presents obvious small characteristics, the analysis process can be completed based on the gray value difference between the edge pixel point of the suspected defect area and the neighborhood pixel point in the preset neighborhood.
Preferably, the method for acquiring the final defect area in one embodiment of the present invention includes:
for convenience of analysis and explanation, any suspected defect area is used as a defect area to be detected; according to the analysis of the gray scale characteristics of the crack region, the gray scale values of the pixel points in the crack defect region have obvious small characteristics, so that a second gray scale average value, namely the average value of the gray scale values of all the pixel points in the gray scale image, is firstly obtained, then the difference between the second gray scale average value and the first gray scale average value of the defect region to be detected is obtained, and the difference is used as a gray scale difference value; taking any edge pixel point in the defect area to be detected as an example, taking the edge pixel point as the edge pixel point to be detected, and then carrying out adjustment analysis on the edge pixel point to be detected based on the gray level difference value to obtain the final defect area.
The purpose of the adjustment analysis is to obtain a more accurate final defect region, and at the same time, the adjustment analysis reduces the suspected defect region. If the suspected defect area is enlarged in the adjustment and analysis process, the segmentation result obtained by segmentation under the corresponding threshold is extremely inaccurate, the corresponding threshold can be directly removed, and the subsequent analysis is not performed.
Preferably, in one embodiment of the present invention, adjustment analysis is performed on an edge pixel point to be detected according to a gray level difference value to obtain a final defect area, including:
in a preset neighborhood taking an edge pixel point to be detected as a center, acquiring the difference of gray values of each neighborhood pixel point and the center pixel point, and taking the difference as a neighborhood gray difference; because the gray gradient of the pixel points in the crack area is small, the minimum value in all neighborhood gray differences corresponding to the central pixel point is obtained, and the minimum neighborhood gray difference is compared with the gray difference value, so that the characteristic that the gray value of the pixel points in the crack area is generally smaller can be combined with the characteristic that the gray gradient of the pixel points in the crack area is small; and if the minimum neighborhood gray level difference is smaller than the gray level difference value, taking the neighborhood pixel point corresponding to the minimum neighborhood gray level difference as an updated edge pixel point to be detected, and then continuing to carry out adjustment analysis on the updated edge pixel point to be detected until the minimum neighborhood gray level difference value is not smaller than the gray level difference value, and stopping the adjustment analysis. After finishing adjustment analysis on all edge pixel points to be detected, if all edge pixel points to be detected are updated, taking all updated edge pixel points to be detected as edge pixel points, and enclosing a final defect area; if the edge pixel points to be detected which do not need to be updated exist, the edge pixel points to be detected which are not updated and the edge pixel points to be detected which are updated are taken as the edge pixel points to be detected, and a final defect area is formed.
Preferably, the preset neighborhood is set to be a four-neighborhood in one embodiment of the present invention.
The suspected crack region is further analyzed based on the gray value characteristics of the crack region, an accurate final crack region is obtained, and then subsequent analysis and processing can be performed.
Step S3: obtaining shape characteristic parameters of the final defect areas according to the distribution of pixel points in each final defect area and the corresponding suspected defect area; and obtaining the optimal degree parameter of the target threshold according to the area of the final defect area, the area of the suspected defect area and the shape characteristic parameter of the final defect area.
By the steps, an accurate crack area can be obtained, so that the target threshold value can be evaluated to obtain the optimal degree parameter of the current threshold value. Because the crack region has thin and long shape characteristics, the shape characteristic parameters can be obtained by analyzing the shape characteristics of the crack region, the possibility that the crack region obtained in the step S2 is an actual crack can be further characterized by the shape characteristic parameters, and the reliability of the subsequent analysis result can be further improved.
Preferably, in one embodiment of the present invention, the method for acquiring the shape characteristic parameter includes:
taking any defect area in the step S2 as a target area as an example, drawing lines in a preset direction by taking the centroid of a suspected defect area corresponding to the target area as a starting point to obtain a plurality of scribing lines, then obtaining the number of intersection points of the scribing lines in each preset direction and the target area, and taking the number of intersection points as a first number of intersection points; then obtaining the number of intersection points of the scribing line in the preset direction and the suspected defect area corresponding to the target area, and taking the number of intersection points as a second number of intersection points; then taking the ratio of the first intersection point number to the second intersection point number as a shape characteristic parameter of the target area; because the target area should be smaller than the corresponding suspected defect area and combine the shape features of thin and long cracks, when the number of intersection points of the scribing line and the target area is larger, namely the molecules are larger, and the number of intersection points of the scribing line and the suspected defect area corresponding to the target area is smaller, namely the denominator is smaller, the overall ratio is larger, the suspected defect area can be reflected to be similar to the corresponding target area, and the situation that the target area meets the shape features of the cracks can be also indicated.
Preferably, the preset direction in one embodiment of the present invention is an eight-chain code direction.
The method for acquiring the shape characteristic parameters can analyze each final defect area to acquire the shape characteristic parameters of each final defect area. And then, the shape characteristic parameters of the final defect area, the area of the suspected defect area and the area of the final defect area can be combined to finish the evaluation of the target threshold value, and the optimal degree parameters of the target threshold value are obtained.
Preferably, the method for obtaining the optimal degree parameter in one embodiment of the present invention includes:
judging the optimal degree parameter of the threshold value, wherein the ratio of the area of the suspected defect area acquired under the current threshold value to the area of the accurate final defect area acquired by further analysis in the step S2 can be used as one of evaluation indexes, so that the area of each final defect area is firstly acquired, and then the areas of all the final defect areas are added to obtain the total area of the final defect area; obtaining the area of each suspected defect area, adding the areas of all the suspected defect areas to obtain the total area of the suspected defect areas, and taking the ratio of the total area of the final defect area to the total area of the suspected defect area as an area ratio; the closer the area ratio is to 1, the higher the accuracy of the suspected defective region acquired at the current threshold to the final defective region is.
Since the crack region also has a thin and long shape feature, the shape feature parameter can also be used as one of the evaluation indexes of the optimum degree of the evaluation threshold; accumulating and summing the shape characteristic parameters of all the final defect areas to obtain an average value, and taking the average value as an average value characteristic value; taking the difference between the area ratio and the preset constant as a difference characteristic value, since the analysis shows that the closer the area ratio is to 1, the higher the accuracy of the suspected defect area obtained under the current threshold value is to be the final defect area, the preset constant is set to be 1 in the embodiment of the invention; and then carrying out negative correlation mapping and normalization on the difference characteristic values, and multiplying the difference characteristic values by the mean characteristic values to obtain the optimal degree parameters. The formula model of the optimal degree parameter may specifically be, for example:
wherein,,representing the optimal degree parameter>Represents the area ratio>Representing the mean characteristic value>Expressed as natural constant->An exponential function of the base.
In the formula model of the optimal degree parameter, when the area ratio is different from the preset constant, namely the difference characteristic valueThe smaller the area ratio is, the closer to 1 is, the better the segmentation result under the current threshold value is reflected, and the difference is 0, soUse->Normalizing the sample; then when mean feature value->The larger each shape feature parameter, the greater the likelihood that the crack region obtained at the current threshold, i.e., the final defect region, is an actual crack. Thus->Smaller (less)>The larger at the same time->The greater the optimum degree parameter +.>The larger the current threshold, i.e. the better the segmentation effect.
So far, the optimal degree parameter of each threshold value can be obtained based on the above operation, and then the subsequent analysis process is completed.
Step S4: obtaining an optimal threshold according to the optimal degree parameters of all the thresholds; obtaining a segmentation result of the gray level image of the hard carbon electrode to be detected according to the optimal threshold value; and obtaining the quality of the hard carbon electrode to be detected according to the segmentation result.
After the optimal degree parameters of all the thresholds are obtained, the optimal thresholds can be obtained by comparing the optimal degree parameters.
Preferably, the method for acquiring the optimal threshold value in one embodiment of the present invention includes:
based on the analysis in step S3, it is known that, when the optimal degree parameter is larger, the segmentation effect of the current threshold is better, so in the embodiment of the present invention, the threshold corresponding to the maximum value of all the optimal degree parameters is used as the optimal threshold. It should be noted that if the optimal degree parameter of the plurality of thresholds occursIf the threshold value is the same, one of the threshold values is selected as the optimal threshold value.
After the optimal threshold value is obtained, the gray level image of the hard carbon electrode to be detected can be subjected to threshold segmentation by utilizing the optimal threshold value, so that a more accurate segmentation result is obtained, the cracks on the surface of the hard carbon electrode can be accurately and clearly displayed and identified, and if the cracks are detected on the surface of the hard carbon electrode, the hard carbon electrode is a defective product; if no crack exists, the hard carbon electrode is a qualified product, and the embodiment of the invention improves the reliability and accuracy of the quality detection of the hard carbon electrode by acquiring the optimal threshold value, and is convenient for analyzing the cause of crack generation according to the characteristics of the crack and then improving the production line.
In summary, according to the embodiment of the invention, through analyzing the gray level image of the hard carbon electrode to be detected, the connected domain of the image of the gray level image segmented under different thresholds is obtained, and then the connected domain is screened based on the gray level value characteristics of the defect region, so as to obtain the suspected defect region; because the connected domain may be interfered by noise during the process of obtaining the connected domain, further analysis of the connected domain is required to obtain an accurate final defect region. And then, as the actual crack area not only has obvious gray value characteristics, but also has thin and long shape characteristics, the shape characteristic parameters of the final defect area are obtained, and the shape characteristic parameters, the area of the final defect area and the area of the suspected defect area are combined to finish the evaluation of the optimal degree of the threshold value, namely, the optimal degree parameters of the threshold value are obtained. And then the optimal degree parameters of all the thresholds can be compared to obtain an optimal threshold, and then the segmentation of the gray level image is completed based on the optimal threshold, so that a precise segmentation result is obtained. And finally, the quality detection of the hard carbon electrode can be finished according to the accurate segmentation result, the reliability and the accuracy of the quality detection of the hard carbon electrode are improved, and meanwhile, the method is beneficial to analyzing the cause of crack generation according to the characteristics of the crack so as to improve the production line.
It should be noted that: the sequence of the embodiments of the present invention is only for description, and does not represent the advantages and disadvantages of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments.