CN117197141B - Method for detecting surface defects of automobile parts - Google Patents

Method for detecting surface defects of automobile parts Download PDF

Info

Publication number
CN117197141B
CN117197141B CN202311466906.8A CN202311466906A CN117197141B CN 117197141 B CN117197141 B CN 117197141B CN 202311466906 A CN202311466906 A CN 202311466906A CN 117197141 B CN117197141 B CN 117197141B
Authority
CN
China
Prior art keywords
value
gray
area
defect
threshold
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202311466906.8A
Other languages
Chinese (zh)
Other versions
CN117197141A (en
Inventor
吕宏振
曹虓
李明杰
许涛
闫培鹏
丛晶
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong Yuandun Network Technology Co ltd
Original Assignee
Shandong Yuandun Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong Yuandun Network Technology Co ltd filed Critical Shandong Yuandun Network Technology Co ltd
Priority to CN202311466906.8A priority Critical patent/CN117197141B/en
Publication of CN117197141A publication Critical patent/CN117197141A/en
Application granted granted Critical
Publication of CN117197141B publication Critical patent/CN117197141B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention relates to the technical field of image analysis, in particular to a method for detecting surface defects of automobile parts. Acquiring a gray level image of the surface of an automobile part, determining an initial threshold value according to the gray level value of a pixel point, and further acquiring a threshold value to be detected, a preliminary defect area and a normal area; due to the influence of illumination, the highlight areas can be misjudged, so that the defect discontinuous areas are screened through the trend and the position relation among the final defect areas; obtaining an illumination influence value based on the gray value of the pixel point, and further adjusting the gray value of the pixel point and obtaining a gray adjustment value by combining the gray value of the pixel point in the normal area; and obtaining a contrast threshold according to the adjusted gray value of the pixel point, comparing the contrast threshold with a threshold to be detected, and obtaining an optimal threshold to detect the defects of the gray image. According to the method, the illumination influence is analyzed, so that the optimal threshold value is obtained, and the defect detection accuracy is effectively improved.

Description

Method for detecting surface defects of automobile parts
Technical Field
The invention relates to the technical field of image analysis, in particular to a method for detecting surface defects of automobile parts.
Background
The quality and reliability of the automobile as a vehicle part are critical to driving safety and user experience. Therefore, a very important step is to detect defects of automobile parts. The scratch defect on the surface of the automobile part belongs to a defect which is not easy to detect, and can influence the functionality, appearance and service life of the part; therefore, scratch defect detection needs to be carried out on the surfaces of the automobile parts, so that the products are ensured to meet the quality standard.
In the prior art, when scratch defect detection is carried out on the surface of a part of an automobile, a threshold segmentation method is often adopted, but when the surface of the part is affected by illumination, the distribution of gray values of pixel points in an image is complicated, so that a threshold segmentation result is inaccurate, and further the defect detection accuracy is affected.
Disclosure of Invention
In order to solve the technical problems that in the prior art, a threshold segmentation method is adopted to detect scratch defects, but the distribution of gray values of pixel points is complex due to the influence of illumination, so that threshold segmentation results are inaccurate and the accuracy of defect detection is further influenced, the invention aims to provide a method for detecting the surface defects of automobile parts, which adopts the following specific technical scheme:
acquiring a gray level image of the surface of an automobile part to be tested;
obtaining an initial threshold value when the image is segmented according to the gray value of the pixel point in the gray image; iterating the initial threshold value, and performing iterative updating on the initial threshold value according to the iteration times to obtain a threshold value to be detected; performing threshold segmentation on the gray level image according to the threshold to be detected to obtain a preliminary defect area and a normal area;
obtaining a highlight region and a final defect region according to the gray value of the pixel point in each preliminary defect region; screening defect discontinuous areas in the highlight areas according to gray gradient distribution and position relation of edge pixel points among final defect areas;
obtaining an illumination influence value according to the change condition of the gray value of the pixel point in the defect discontinuous area; obtaining the adjustment weight of the gray value of the pixel point in the corresponding defect intermittent area according to the illumination influence value; obtaining a gray adjustment value according to the gray value of the pixel point in the defect intermittent area, the adjustment weight and the gray value of the pixel point in the normal area;
obtaining a contrast threshold according to the gray value of the pixel point in the final defect area and the gray adjustment value; stopping iteration when the difference between the comparison threshold and the threshold to be detected is smaller than a preset judgment threshold, and taking the comparison threshold as an optimal threshold; and performing defect detection on the gray level image according to the optimal threshold value.
Further, the obtaining the highlight region and the final defect region according to the gray value of the pixel point in each preliminary defect region includes:
taking the pixel point with the gray value larger than the preset gray value in each preliminary defect area as a target pixel point;
taking a region formed by all target pixel points in the preliminary defect region as a target region, carrying out region growth on the target region, stopping growth when an intersection point exists between the region and the edge of the preliminary defect region in the growth process, and taking a region formed by the growth of the target region as the highlight region;
and taking the area except the highlight area in the preliminary defect area as a final defect area.
Further, the screening the defect intermittent area in the highlight area according to the gray gradient distribution and the position relation of the edge pixel points among the final defect areas includes:
taking the average value of gray gradients of all edge pixel points in each final defect area as an extending direction;
acquiring the mass center of each final defect area; taking the value of the distance between the centroids of the final defect areas at the two sides of the highlight area in the preliminary defect area as a distance parameter, normalizing the difference between the extending directions of the final defect areas at the two sides of the highlight area and taking the value after negative correlation mapping as a direction parameter;
and taking the product of the distance parameter and the direction parameter as a similarity index, and when the similarity index is smaller than a preset similarity threshold value, taking the highlight area as a defect discontinuous area.
Further, the obtaining the illumination influence value according to the change condition of the gray value of the pixel point in the defect intermittent area includes:
connecting the centroids of two final defect areas corresponding to the defect intermittent areas to obtain an illumination change direction, and taking a pixel point with the maximum gray value of the defect intermittent areas in the illumination change direction as a central pixel point; making a vertical line of the illumination change direction through the central pixel point, taking a preset first number of pixel points on the vertical line as target pixel points, and taking a preset second number of pixel points of each target pixel point on a straight line parallel to the illumination change direction as pixel points to be detected;
carrying out normal fitting on the gray value of the pixel point to be detected corresponding to each target pixel point to obtain a gray fitting value; carrying out negative correlation mapping on the difference between the gray value of each pixel to be detected of each target pixel and the corresponding gray fitting value to obtain a gray difference value, and accumulating the gray difference values of all the pixel to be detected corresponding to each target pixel to obtain a gray characteristic value;
and taking the average value of the accumulated gray characteristic values of all the target pixel points as the illumination influence value.
Further, the method for acquiring the adjustment weight comprises the following steps:
and taking the value of the illumination influence value corresponding to each defect interruption area after carrying out negative correlation mapping as the adjustment weight of the gray value of the pixel point in the defect interruption area.
Further, the method for acquiring the gray scale adjustment value includes:
taking the sum value of the number of the pixel points in the intermittent area of all defects and the number of the pixel points in the normal area as a number sum value;
multiplying the gray values of all pixel points in each defect discontinuous area with corresponding adjustment weights, accumulating the multiplied gray values to obtain area gray sum values, and taking the accumulated area gray sum values of all defect discontinuous areas as discontinuous area gray values;
taking the sum of the gray values of all pixel points in the normal area as the gray value of the normal area; and taking the ratio of the sum value of the normal region gray level value and the intermittent region gray level value to the sum value as the gray level adjustment value.
Further, the obtaining a contrast threshold according to the gray value of the pixel point in the final defect area and the gray adjustment value includes:
taking the average value of the gray values of all pixel points in the final defect area as a foreground gray value;
the average of the front Jing Huidu value and the gray scale adjustment value is taken as the contrast threshold.
Further, the method for acquiring the initial threshold value comprises the following steps:
taking the average value of the maximum gray value and the minimum gray value of the pixel points in the gray image as a reference threshold value;
and taking the value obtained by adding the reference threshold value and a preset constant as the initial threshold value.
Further, the step of iterating the initial threshold value, and performing iterative updating on the initial threshold value according to the iteration times to obtain a threshold value to be tested includes:
and taking the value obtained by adding the times of each iteration and the initial threshold value as a threshold value to be detected in each iteration process.
Further, the defect detection on the gray level image according to the optimal threshold value includes:
threshold segmentation is carried out on the gray level image based on the optimal threshold value, and a foreground area is obtained; and taking a corresponding region of the foreground region in the gray level image as a defect region.
The invention has the following beneficial effects:
the invention aims to obtain the optimal threshold value when the gray level image on the surface of the automobile part is segmented, thereby improving the accuracy of defect detection; therefore, firstly, acquiring a gray level image of the surface of the automobile part, and then analyzing the gray level image; determining an initial threshold according to the gray value of a pixel point in a gray image, then obtaining a threshold in each iteration process based on the initial threshold and the iteration times through iteration traversal, and taking the threshold as a threshold to be tested; further, the segmented image can be divided into a preliminary defect area and a normal area by analyzing the image segmented under the threshold to be detected; however, due to the influence of illumination, a reflection phenomenon is generated, which results in complex gray value distribution of the pixel points, and the highlight region appearing in the gray image is divided into preliminary defect regions, and the highlight region may not be a defect region, so that further analysis is required: if the highlight region is also a scratch defect region, final defect regions on two sides of the highlight region should have consistent trend and relatively close distance, so the highlight region which is a defect discontinuous region can be screened based on the distribution and the position relation of gray gradient of edge pixel points of the final defect region; the effect of illumination was then analyzed: the illumination can cause the gray value of the pixel point to change, so that an illumination influence value is obtained based on the change condition of the gray value of the pixel point in the defect intermittent area, and further the gray value of the pixel point in the defect intermittent area is adjusted and corrected according to the illumination influence value, and a gray adjustment value is obtained by combining the gray value of the pixel point in the normal area; at this time, the gray level adjustment value integrates the information of illumination influence, so that the information can be more accurate, and a contrast threshold value is obtained according to the gray level value and the gray level adjustment value of the pixel point in the final defect area; and comparing the comparison threshold with the threshold to be detected, stopping iteration if the judgment condition is met, and performing defect detection on the gray image by taking the comparison threshold as an optimal threshold. In summary, the invention further analyzes the highlight or reflective area generated by the influence of illumination, thereby being capable of more accurately judging whether the area is a defective area, thereby obtaining the optimal threshold value, improving the accuracy of the segmentation result, and simultaneously effectively improving the accuracy of defect detection.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions and advantages of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are only some embodiments of the invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a method for detecting surface defects of an automobile part according to an embodiment of the present invention.
Detailed Description
In order to further describe the technical means and effects adopted by the invention to achieve the preset aim, the following detailed description refers to specific implementation, structure, characteristics and effects of the method for detecting the surface defects of the automobile part according to the invention by combining the attached drawings and the preferred embodiment. 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 surface defects of the automobile parts provided by the invention with reference to the accompanying drawings.
Referring to fig. 1, a flowchart of a method for detecting surface defects of an automobile part according to an embodiment of the invention is shown, the method includes the following steps:
step S1: and acquiring a gray level image of the surface of the automobile part to be tested.
According to the embodiment of the invention, the surface gray level image of the automobile part is analyzed to obtain the optimal threshold value, so that an accurate segmentation result is obtained, and the defect detection is completed; a gray scale image of the surface of the automobile part is first acquired.
The conveyor belt is arranged in the quality inspection process of the automobile parts, and the fixed light source and the camera are arranged above the conveyor belt for image acquisition, and because the lengths of the automobile parts are different, in order to ensure the integrity of image information acquisition, the shooting time interval is set asWherein->For the longest width of all vehicle parts, < > for>For conveyor belt speed; after the surface image of the part to be tested is obtained, carrying out average graying treatment on the surface image, and obtaining the surface gray image of the part to be tested. It should be noted that the average graying process is a technique well known to those skilled in the art, and other graying methods may be used in other embodiments of the present invention, and specifically, the method may be, for example, a maximum value method, a weighted graying method, etc., which are not limited and described herein.
Thus, the surface gray level image of the automobile part to be tested is obtained, and the subsequent analysis process of the surface gray level image of the automobile part to be tested can be completed.
Step S2: obtaining an initial threshold value when the image is segmented according to the gray value of the pixel point in the gray image; iterating the initial threshold value, and carrying out iterative updating on the initial threshold value according to the iteration times to obtain a threshold value to be detected; and carrying out threshold segmentation on the gray level image according to the threshold to be detected to obtain a preliminary defect area and a normal area.
In the embodiment of the invention, the image processing can be carried out on the gray image in a threshold segmentation mode, in order to determine the optimal threshold value, the threshold value is iterated, so that the segmentation effect of the threshold value in each iteration process is evaluated and analyzed, the optimal threshold value is conveniently obtained, and an initial threshold value is needed to be obtained according to the gray value of the pixel point in the gray image before iteration.
Preferably, the method for acquiring the initial threshold value in one embodiment of the present invention includes:
since the maximum value and the minimum value of the gray values of all the pixels in the image can represent two extreme ends of the distribution of the pixels in the image, the average value of the maximum value and the minimum value can be used for representing the gray level of the whole image, and the obtained reference threshold value is more objective, so that the average value of the maximum gray value and the minimum gray value of the pixels in the gray image is used as the reference threshold value. However, because noise influence may exist in the image, the maximum value and the minimum value of the gray value deviate from the actual situation, so in the embodiment of the invention, the value obtained by adding the reference threshold and the preset constant is used as the initial threshold, and at the moment, the initial threshold can be more stable, and meanwhile, the influence of noise can be reduced. The formula model of the reference threshold is:
wherein,represents a baseline threshold value->Maximum gray value representing pixel point in gray image,/->Representing the minimum gray value of a pixel in the gray image.
It should be noted that, in the embodiment of the present invention, the preset constant is set to 3, and the specific numerical value implementation can be adjusted according to the implementation scenario, which is not limited herein.
After the initial threshold is obtained, iteration can be carried out on the initial threshold, the threshold after each iteration is obtained through the initial threshold and the iteration times, the threshold after each iteration is used as a threshold to be tested, and then the segmented image under the threshold to be tested is analyzed, so that whether the threshold to be tested is the optimal threshold is evaluated.
Preferably, in one embodiment of the present invention, the iteration is performed on an initial threshold, and the initial threshold is updated iteratively according to the iteration number to obtain a threshold to be measured, including:
the initial threshold value is added with the iteration times of each iteration to obtain the threshold value of each iteration, and then the value is used as the threshold value of each iteration, namely the threshold value to be measured. The method for obtaining the threshold to be measured is illustrated here: if the iteration times are 1 in the first iteration, the threshold to be detected in the first iteration is 1 in the initial threshold; if the iteration times are 2 in the second iteration, the threshold to be detected in the second iteration is the initial threshold plus 2; and so on.
After the threshold to be detected in each iteration process is obtained, the segmented image under the threshold to be detected in each iteration process can be analyzed, and the gray image is segmented according to the threshold to be detected based on threshold segmentation to obtain a preliminary defect area and a normal area; because the scratch defect area is uneven, scattering and diffuse reflection phenomena are generated when the scratch area is illuminated, so that the scratch defect area emits light, and therefore, in the embodiment of the invention, the gray value of a pixel point with the gray value larger than or equal to the threshold value to be detected is set as 255, the pixel point is marked as a foreground area, and the corresponding area of the foreground area in a gray image is used as a preliminary defect area; and setting the gray value of the pixel point with the gray value smaller than the threshold to be detected as 0, marking the pixel point as a background area, and taking the corresponding area of the background area in the gray image as a normal area.
Thus, a preliminary defect area and a normal area under the threshold to be detected are obtained, and can be subjected to subsequent analysis.
Step S3: obtaining a highlight region and a final defect region according to the gray value of the pixel point in each preliminary defect region; and screening defect discontinuous areas in the highlight areas according to gray gradient distribution and position relation of edge pixel points among the final defect areas.
The scratch defect area is uneven, so that phenomena such as refraction and diffuse reflection are easy to occur when the scratch defect area is illuminated, meanwhile, a highlight area is caused to occur due to a reflection phenomenon, the complexity of gray value distribution of pixel points in an image is increased, and the highlight area is further segmented into the preliminary defect area in the segmentation process, but the highlight area is not the scratch defect area but the scratch discontinuous area, so that the segmentation precision is poor.
Preferably, the obtaining the highlight region and the final defect region according to the gray value of the pixel point in each preliminary defect region in one embodiment of the present invention includes:
when the highlight region in the preliminary defect region is obtained, a preset gray value is set, pixel points with gray values larger than the preset gray value in each preliminary defect region are marked to serve as target pixel points, then the region formed by all target pixel points is used as a target region, the target region is subjected to region growth, when an intersection point exists between the target region and the edge of the preliminary defect region to which the target region belongs in the growth process, the growth can be stopped, then the region formed by the target region after the region growth is used as the highlight region, and the region except the highlight region in the preliminary defect region is used as a final defect region. It should be noted that, the region growing process is a technical means well known to those skilled in the art, and is not described herein in detail; since the light is a point light source, the affected area is relatively concentrated, and thus the target pixel is relatively concentrated, the preliminary defective area may be divided into at least three parts, i.e., at least two final defective areas and one highlight area, and the final defective areas may be distributed on both sides of the highlight area in this process.
If the highlight region belongs to the scratch region, the final defect regions at two sides of the highlight region should be the same scratch, whereas if the highlight region belongs to the same scratch, the trend of the final defect regions at two sides should be consistent, and the distance between the final defect regions at two sides is also closer, and the gray gradient can represent the trend of the final defect regions, so the embodiment of the invention screens the defect discontinuous regions based on the gray gradient and the distance between the final defect regions.
Preferably, in one embodiment of the present invention, the screening of the defect interruption area in the highlight area according to the gray gradient distribution and the positional relationship of the edge pixel points between the final defect areas includes:
as the edge in the image can show color or brightness change, when the scratch defect occurs, the gray value of the pixel point of the defect area can obviously change, and the gray gradient direction points to the direction of the fastest brightness change in the image, so that the extending direction can be obtained according to the gray gradient direction of the edge pixel point in the final defect area. The method comprises the following steps: taking the average value of the gray gradient of all the edge pixel points in each final defect area as the extending direction of the final defect area. The formula model of the extending direction is as follows:
wherein,indicates the extending direction,/->Representing the total number of edge pixels, +.>Indicate->Gray scale gradient of each edge pixel point.
Based on the above analysis, if the final defect areas on both sides of the highlight area belong to one scratch, the extending directions of the final defect areas on both sides should be consistent and the distances should be close, so that after the extending direction of each final defect area is obtained, the defect discontinuous area can be screened out in the highlight area according to the extending direction and the position relation between the final defect areas on both sides of each highlight area.
Because the centroid is a geometric center and has better invariance to the overall position of the regions, the centroid can be used as a reference to measure the distance between the two regions, the centroid of each final defect region is obtained, and the value of the distance between the centroids of the final defect regions on both sides of the highlight region is used as a distance parameter; and then analyzing the difference between the extending directions, normalizing the difference of the extending directions of the final defect areas at the two sides of the highlight area, and performing negative correlation mapping to obtain a value as a direction parameter. And finally taking the product of the distance parameter and the direction parameter as a similarity index, and when the similarity index of the final defect areas at the two sides of the highlight area is smaller than a preset similarity threshold value, indicating that the final defect areas at the two sides of the highlight area do not belong to the same scratch, wherein the highlight area is the defect discontinuous area. The final defect areas on both sides of the highlight area are respectively denoted as a final defect area 1 and a final defect area 2, and the formula model of the similar index may specifically be, for example:
wherein,representing a similarity index->Indicates the extending direction of the final defective area 1 on the highlight area side, +.>Indicates the extension direction of the final defective area 2 on the other side of the highlight area, +.>Representing the distance between the centroids of the final defective area 1 and the final defective area 2,/o>Representing the normalization function.
In the formula model of the similarity index, when the distance value between the centroids of the two final defect areas, namely the distance parameterThe smaller the time, the closer the distance between the two final defect areas is, the greater the probability that the two final defect areas belong to the same scratch defect; meanwhile, when the difference of the extending directions of the two final defect areas is smaller, the more consistent the trend of the two final defect areas is, namely the more likely to belong to the same scratch defect, so the two final defect areas are opposite>And carrying out normalization and negative correlation mapping to finish logic relation correction and obtain a direction parameter, wherein the smaller the distance parameter is, the larger the direction parameter is, the larger the similarity index is, namely the more likely that two final defect areas are the same scratch defect. Therefore, when the similarity index of the two final defect areas is smaller than the preset similarity threshold, the highlight area between the two final defect areas is the defect discontinuous area.
It should be noted that, the obtaining of the edge pixel point and the gray gradient direction may use Sobel operator or Canny operator, which are all technical means known to those skilled in the art, and are not described and limited herein; in the embodiment of the invention, the preset similarity threshold is set to be 5, and a specific numerical value implementer can adjust according to implementation scenes, so that the method is not limited; the method for obtaining the centroid is an operation process well known to those skilled in the art, and will not be described in detail herein; meanwhile, when the distance is obtained, the position of the pixel point at the left lower corner of the whole gray level image can be used as an origin, the horizontal direction is a horizontal axis, the vertical direction is a vertical axis, a coordinate system is established, the coordinate is obtained, so that the distance is calculated, and the distance calculation method is an operation process well known to a person skilled in the art and is not described in detail herein.
The highlight region in the preliminary defect region is obtained, and the defect discontinuous region is screened from the highlight region through analysis of the extending direction and the position relation of the final defect regions at the two sides of the highlight region, namely, the defect discontinuous region is misjudged as the normal region of the preliminary defect region; subsequent analysis of the illumination effect may then be performed on the defective intermittent areas.
Step S4: obtaining an illumination influence value according to the change condition of the gray value of the pixel point in the defect intermittent area; obtaining the adjustment weight of the gray value of the pixel point in the corresponding defect intermittent area according to the illumination influence value; and obtaining a gray adjustment value according to the gray value of the pixel point in the defect discontinuous area, the adjustment weight and the gray value of the pixel point in the normal area.
When the light is affected by the light to generate the reflection, the defect interruption area obtained in step S3 may be highlighted in the middle position, and the reflection degree of the light is different due to the presence of scratches on both sides, so that the position of the defect interruption area near the final defect area on both sides is weaker in brightness than the middle position, and a gradual change may be formed from the middle to the direction of the final defect area on both sides, so that the light influence value may be obtained according to such a change.
Preferably, in one embodiment of the present invention, obtaining the illumination influence value according to the change condition of the gray value of the pixel point in the defect intermittent area includes:
based on the analysis, firstly, the middle position can be determined according to the gray value of the pixel point, the centroids of two final defect areas corresponding to the defect intermittent areas are connected, the connecting line is used as the illumination change direction, and then the pixel point with the maximum gray value of the defect intermittent area in the illumination change direction is used as the central pixel point; and then making a vertical line in the illumination change direction through the central pixel point, and taking a preset first number of pixel points on the vertical line as target pixel points. Since the objective is to obtain the illumination influence value, analysis is required along the illumination change direction, and a preset second number of pixels of each objective pixel on a line parallel to the illumination change direction are used as the pixels to be measured. Then, the gray value of the pixel point to be measured corresponding to each target pixel point is subjected to normal fitting, so that a gray fitting value can be obtained, and the gray fitting value is recorded as. Analyzing the difference between the gray value of each pixel to be detected of each target pixel and the corresponding gray fitting value, performing negative correlation mapping on the difference to obtain a gray difference value, and accumulating the gray difference values corresponding to all the pixels to be detected of each target pixel to obtain a gray characteristic value; and finally, taking the average value of the accumulated gray characteristic values of all the target pixel points as an illumination influence value. The formula model of the illumination influence value may specifically be, for example:
wherein,representing the illumination influence value,/->Representing the total number of target pixels, +.>Representing the total number of the pixel points to be detected corresponding to each target pixel point,/for>Indicate->Gray fitting value corresponding to each target pixel, < >>Indicate->The +.>Gray values of the pixel points to be detected.
In the formula model of the illumination influence value, when the gray fitting value of the pixel point to be detected corresponding to each target pixel point is larger, the fitting effect is better, and the illumination influence is larger; therefore, the difference between each pixel point to be detected of each target pixel point and the corresponding gray fitting valueWhen the illumination influence is smaller, the illumination influence is larger, so that negative correlation mapping is carried out on the illumination influence, logic relation correction is completed, and difference negative correlation mapping between all pixel points to be detected of each target pixel point and corresponding gray fitting values is accumulated to obtain gray characteristic values>The method comprises the steps of carrying out a first treatment on the surface of the Based on the analysis, the larger the gray characteristic value is, the larger the illumination influence is, so that the gray characteristic values of all target pixel points are accumulated and averaged,the mean value is taken as the illumination influence value.
It should be noted that normal fitting is a technical means well known to those skilled in the art, and is not described herein; simultaneously presetting a first number to be 10, 5 on each side of a central pixel point on a vertical line, and presetting a second number to be 10, wherein the first number is five on each side of a target pixel point on a line parallel to the illumination change direction; according to the embodiment of the invention, the illumination influence value of the whole defect intermittent area influenced by illumination is represented by analyzing the preset number of pixel points in the defect intermittent area, and specific number of operators can be adjusted according to the implementation scene, so that the method is not limited.
The normal area which is to be shown as the highlight area is misjudged as the scratch defect due to the influence of illumination, and the gray value of the pixel point in the normal area is lower than that of the scratch defect, so that the weight of the gray value of the pixel point in the defect intermittent area needs to be reduced when a comparison threshold value is obtained later, and the embodiment of the invention obtains the adjustment weight of the gray value of the pixel point in the corresponding defect intermittent area according to the illumination influence value.
Preferably, the method for acquiring the adjustment weight in one embodiment of the present invention includes:
in view of the defect interruption areas with larger illumination influence, the gray value of the pixel point should be weighted smaller, so that the value of the illumination influence value corresponding to each defect interruption area after the negative correlation mapping is used as the adjustment weight of the gray value of the pixel point in the defect interruption area. The formula model for adjusting the weight may specifically be, for example:
wherein,representing adjustment weights, ++>Representing the illumination impact value.
In the formula model for adjusting the weight, based on the analysis, the larger the illumination influence is, the larger the illumination influence value is, and the smaller the corresponding weight is, so that the negative correlation mapping is performed on the illumination influence value, the logic relation correction is realized, and the adjustment weight is obtained.
Based on the above-mentioned procedure, it is known that the defective intermittent area is a normal area misjudged as a defective area, that is, a background area, and an adjustment weight of the gray value of the pixel point in each defective intermittent area is obtained, so that the gray adjustment value can be obtained according to the gray value of the pixel point in the defective intermittent area, the adjustment weight, and the gray value of the pixel point in the normal area obtained in step S2.
Preferably, the method for acquiring the gray scale adjustment value in one embodiment of the present invention includes:
the gray scale adjustment value is mainly that the gray scale value of the pixel point in the defect intermittent area is corrected according to the adjustment weight, and then the gray scale value is combined with the gray scale value of the pixel point in the normal area to obtain the average value of the gray scale values of the pixel point in the complete background area, so that the comparison threshold value can be conveniently obtained subsequently; the gray values of all pixel points in each defect discontinuous area are multiplied by the corresponding adjusting weights and accumulated to be used as area gray sum values, and then the value obtained by accumulating the area gray sum values of all defect discontinuous areas is used as a discontinuous area gray value; and finally, taking the sum of the gray values of all the pixel points in the normal area obtained in the step S2 as the gray value of the normal area; taking the sum of the number of the pixel points in the intermittent area of all defects and the number of the pixel points in the normal area as a number sum; and taking the ratio of the sum value of the normal region gray level value and the discontinuous region gray level value to the sum value as a gray level adjustment value. The formula model of the gray scale adjustment value is:
wherein,representing gray scale adjustment values +.>Representing the total number of defective intermittent areas, < > and->Representing the total number of pixel points in each defective break area, < > of>Indicate->Adjusting weights corresponding to the defect discontinuity areas, +.>Indicate->Defective intermittent area->Gray value of each pixel, +.>Representing the total number of pixels in the normal area, +.>Indicating the%>Gray values of individual pixels.
In a formula model of gray scale adjustment values, gray scale values of all pixel points in each defect intermittent area are multiplied by corresponding adjustment weights and accumulated to obtain area gray scale sum valuesThen, the gray values of the discontinuous areas are integrated by accumulating the gray values of the discontinuous areas>The gray value of the discontinuous region characterizesAll the highlight areas which are misjudged as scratch defects, namely gray values and values after gray value adjustment of all pixel points in the defect intermittent areas; then the gray values of all pixel points in the normal area are accumulated to obtain the gray value +.>The method comprises the steps of carrying out a first treatment on the surface of the And then accumulating the gray value of the discontinuous region and the gray value of the normal region, and dividing the accumulated gray value by the total number of pixel points in the defect discontinuous region and the normal region to obtain a gray adjustment value, wherein the gray adjustment value can be used as an index for subsequently acquiring a comparison threshold value.
Therefore, the illumination influence value is obtained by analyzing the gray value change condition, so that the gray value of the pixel point in the defect intermittent area is adjusted based on the illumination influence value, the influence of the illumination influence value on the gray value average value of the pixel point in the background area can be reduced, and the accuracy of the subsequent acquisition of the contrast threshold value is improved.
Step S5: obtaining a contrast threshold according to the gray value and the gray adjustment value of the pixel point in the final defect area; stopping iteration when the difference between the comparison threshold and the threshold to be detected is smaller than a preset judgment threshold, and taking the comparison threshold as an optimal threshold; and performing defect detection on the gray level image according to the optimal threshold value.
Based on the step S4, the average value of the gray values of the pixel points in the background area, that is, the gray adjustment value, can be obtained, so that the average value can be combined with the gray values of the pixel points in the foreground area to obtain a comparison threshold value for comparison with the current threshold value to be tested, and whether the threshold value is accurate is evaluated.
Preferably, in one embodiment of the present invention, obtaining the contrast threshold according to the gray value and the gray adjustment value of the pixel point in the final defect area includes:
the final defect area is a foreground area, so that the average value of the gray values of all pixel points in all the final defect areas is used as a foreground gray value; the background gray value is the gray adjustment value, so that the average value of the foreground gray value and the gray adjustment value is used as the contrast threshold value. The formula model for the comparison threshold is:
wherein,represents a contrast threshold value->Representing gray scale adjustment values +.>Representing foreground gray values.
In the formula model of the contrast threshold, the contrast threshold is obtained by combining the gray value of the pixel point in the foreground area with the gray value of the pixel point in the background area, and at this time, the contrast threshold is more accurate than the current threshold to be tested because the gray value of part of the pixel points in the background area is corrected.
After the comparison threshold is obtained, the comparison threshold can be compared with the current threshold to be detected, and the difference between the comparison threshold and the current threshold to be detected is obtained, if the difference is smaller than the preset judgment threshold, the comparison threshold is very close to the comparison threshold at the moment, and compared with the threshold to be detected, the comparison threshold is more accurate because the influence of illumination is analyzed, the gray value of part of pixel points is corrected, so that the iteration process can be stopped, and the comparison threshold is taken as the optimal threshold. If the difference is greater than or equal to the preset judgment threshold, the difference between the threshold to be tested and the comparison threshold is greater, and the threshold to be tested is considered to be extremely inaccurate, so that the reference value of the comparison threshold obtained by analyzing the illumination influence and the like on the basis of the threshold to be tested is not high, and iteration is still needed to be continued, namely, the analysis in the process is continued on the next threshold to be tested until the difference between the threshold to be tested and the update is smaller than the preset judgment threshold, and the optimal threshold is obtained. It should be noted that, in the embodiment of the present invention, the preset determination threshold is set to 0.1, and the specific numerical value implementation person may be adjusted according to the implementation scenario, which is not limited herein.
After the optimal threshold is obtained, defect detection can be completed based on the optimal threshold.
Preferably, in one embodiment of the present invention, defect detection is performed on a gray scale image according to an optimal threshold, including:
threshold segmentation is carried out on the gray image based on the optimal threshold, the gray value of the pixel point which is larger than or equal to the optimal threshold is set as 255, the foreground area is marked, the gray value of the pixel point which is smaller than the optimal threshold is set as 0, and the background area is marked; and taking the corresponding area of the foreground area in the gray level image as a defect area to finish the defect detection of the surface of the automobile part.
In summary, according to the embodiment of the invention, through analyzing the surface gray level image of the automobile part, an initial threshold value is obtained according to the gray level value of the pixel point in the gray level image, then iteration is performed on the initial threshold value, the initial threshold value and the iteration times are added to be used as the threshold value in each iteration, and the threshold value is recorded as the threshold value to be tested; then obtaining a segmentation result based on threshold segmentation according to a threshold to be detected, and dividing the segmentation result into a preliminary defect area and a normal area; due to the influence of illumination, a situation may occur in which a highlight region generated by reflection is misjudged as a defective region, and thus the edge pixel point in the preliminary defective region is divided into a highlight region and a final defective region according to its gray value; further, the extending direction of the final defect area is obtained according to the gradient direction of the edge pixel points of the final defect area, so that a defect discontinuous area is screened out according to the extending direction and the position relation between the final defect areas, and the defect discontinuous area is a misjudged normal area; further, since the illumination can form a gradual change phenomenon in the defect intermittent area and influence the change of the gray value of the pixel point, the illumination influence value can be obtained according to the change condition of the gray value of the pixel point in the defect intermittent area; further, the gray value of the pixel point in the defect intermittent area is adjusted according to the illumination influence value, and the gray value average value of the pixel point in the background area is obtained by combining the gray value of the pixel point in the normal area and is recorded as a gray adjustment value; then obtaining the average value of gray values of pixel points in a foreground region, namely a final defect region, and obtaining a contrast threshold value by combining the gray adjustment value; then comparing the comparison threshold with the current threshold to be detected to obtain an optimal threshold; and finally, threshold segmentation is carried out on the gray level image based on the optimal threshold, so that a more accurate segmentation result can be obtained, and the defect detection precision is improved.
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.

Claims (7)

1. A method for detecting surface defects of an automobile part, the method comprising:
acquiring a gray level image of the surface of an automobile part to be tested;
obtaining an initial threshold value when the image is segmented according to the gray value of the pixel point in the gray image; iterating the initial threshold value, and performing iterative updating on the initial threshold value according to the iteration times to obtain a threshold value to be detected; performing threshold segmentation on the gray level image according to the threshold to be detected to obtain a preliminary defect area and a normal area;
obtaining a highlight region and a final defect region according to the gray value of the pixel point in each preliminary defect region; screening defect discontinuous areas in the highlight areas according to gray gradient distribution and position relation of edge pixel points among final defect areas;
obtaining an illumination influence value according to the change condition of the gray value of the pixel point in the defect discontinuous area; obtaining the adjustment weight of the gray value of the pixel point in the corresponding defect intermittent area according to the illumination influence value; obtaining a gray adjustment value according to the gray value of the pixel point in the defect intermittent area, the adjustment weight and the gray value of the pixel point in the normal area;
obtaining a contrast threshold according to the gray value of the pixel point in the final defect area and the gray adjustment value; stopping iteration when the difference between the comparison threshold and the threshold to be detected is smaller than a preset judgment threshold, and taking the comparison threshold as an optimal threshold; performing defect detection on the gray level image according to the optimal threshold value;
the step of obtaining the highlight region and the final defect region according to the gray value of the pixel point in each preliminary defect region comprises the following steps:
taking the pixel point with the gray value larger than the preset gray value in each preliminary defect area as a target pixel point;
taking a region formed by all target pixel points in the preliminary defect region as a target region, carrying out region growth on the target region, stopping growth when an intersection point exists between the region and the edge of the preliminary defect region in the growth process, and taking a region formed by the growth of the target region as the highlight region;
taking the area except the highlight area in the preliminary defect area as a final defect area;
the screening of the defect interruption area in the highlight area according to the gray gradient distribution and the position relation of the edge pixel points among the final defect areas comprises the following steps:
taking the average value of gray gradients of all edge pixel points in each final defect area as an extending direction;
acquiring the mass center of each final defect area; taking the value of the distance between the centroids of the final defect areas at the two sides of the highlight area in the preliminary defect area as a distance parameter, normalizing the difference between the extending directions of the final defect areas at the two sides of the highlight area and taking the value after negative correlation mapping as a direction parameter;
taking the product of the distance parameter and the direction parameter as a similarity index, and when the similarity index is smaller than a preset similarity threshold value, the highlight area is a defect discontinuous area;
the obtaining the illumination influence value according to the change condition of the gray value of the pixel point in the defect intermittent area comprises the following steps:
connecting the centroids of two final defect areas corresponding to the defect intermittent areas to obtain an illumination change direction, and taking a pixel point with the maximum gray value of the defect intermittent areas in the illumination change direction as a central pixel point; making a vertical line of the illumination change direction through the central pixel point, taking a preset first number of pixel points on the vertical line as target pixel points, and taking a preset second number of pixel points of each target pixel point on a straight line parallel to the illumination change direction as pixel points to be detected;
carrying out normal fitting on the gray value of the pixel point to be detected corresponding to each target pixel point to obtain a gray fitting value; carrying out negative correlation mapping on the difference between the gray value of each pixel to be detected of each target pixel and the corresponding gray fitting value to obtain a gray difference value, and accumulating the gray difference values of all the pixel to be detected corresponding to each target pixel to obtain a gray characteristic value;
and taking the average value of the accumulated gray characteristic values of all the target pixel points as the illumination influence value.
2. The method for detecting surface defects of an automobile part according to claim 1, wherein the method for acquiring the adjustment weight comprises:
and taking the value of the illumination influence value corresponding to each defect interruption area after carrying out negative correlation mapping as the adjustment weight of the gray value of the pixel point in the defect interruption area.
3. The method for detecting surface defects of an automobile part according to claim 1, wherein the method for acquiring the gradation adjustment value comprises:
taking the sum value of the number of the pixel points in the intermittent area of all defects and the number of the pixel points in the normal area as a number sum value;
multiplying the gray values of all pixel points in each defect discontinuous area with corresponding adjustment weights, accumulating the multiplied gray values to obtain area gray sum values, and taking the accumulated area gray sum values of all defect discontinuous areas as discontinuous area gray values;
taking the sum of the gray values of all pixel points in the normal area as the gray value of the normal area; and taking the ratio of the sum value of the normal region gray level value and the intermittent region gray level value to the sum value as the gray level adjustment value.
4. The method for detecting surface defects of automotive parts according to claim 1, wherein the obtaining a contrast threshold value according to the gray value of the pixel point in the final defect area and the gray adjustment value comprises:
taking the average value of the gray values of all pixel points in the final defect area as a foreground gray value;
the average of the front Jing Huidu value and the gray scale adjustment value is taken as the contrast threshold.
5. The method for detecting surface defects of an automobile part according to claim 1, wherein the method for acquiring the initial threshold value comprises:
taking the average value of the maximum gray value and the minimum gray value of the pixel points in the gray image as a reference threshold value;
and taking the value obtained by adding the reference threshold value and a preset constant as the initial threshold value.
6. The method for detecting surface defects of an automobile part according to claim 1, wherein iterating the initial threshold value, iteratively updating the initial threshold value according to the iteration number, and obtaining a threshold value to be detected comprises:
and taking the value obtained by adding the times of each iteration and the initial threshold value as a threshold value to be detected in each iteration process.
7. The method for detecting surface defects of an automobile part according to claim 1, wherein the defect detection of the gray-scale image according to the optimal threshold value comprises:
threshold segmentation is carried out on the gray level image based on the optimal threshold value, and a foreground area is obtained; and taking a corresponding region of the foreground region in the gray level image as a defect region.
CN202311466906.8A 2023-11-07 2023-11-07 Method for detecting surface defects of automobile parts Active CN117197141B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311466906.8A CN117197141B (en) 2023-11-07 2023-11-07 Method for detecting surface defects of automobile parts

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311466906.8A CN117197141B (en) 2023-11-07 2023-11-07 Method for detecting surface defects of automobile parts

Publications (2)

Publication Number Publication Date
CN117197141A CN117197141A (en) 2023-12-08
CN117197141B true CN117197141B (en) 2024-01-26

Family

ID=89002022

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311466906.8A Active CN117197141B (en) 2023-11-07 2023-11-07 Method for detecting surface defects of automobile parts

Country Status (1)

Country Link
CN (1) CN117197141B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117408890B (en) * 2023-12-14 2024-03-08 武汉泽塔云科技股份有限公司 Video image transmission quality enhancement method and system
CN117437248B (en) * 2023-12-19 2024-03-08 中国海洋大学 Disease area segmentation method for blueberry quality detection
CN117876360A (en) * 2024-03-08 2024-04-12 卡松科技股份有限公司 Intelligent detection method for lubricating oil quality based on image processing

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016172827A1 (en) * 2015-04-27 2016-11-03 武汉武大卓越科技有限责任公司 Stepwise-refinement pavement crack detection method
WO2021000524A1 (en) * 2019-07-03 2021-01-07 研祥智能科技股份有限公司 Hole protection cap detection method and apparatus, computer device and storage medium
CN114723701A (en) * 2022-03-31 2022-07-08 南通博莹机械铸造有限公司 Gear defect detection method and system based on computer vision
CN115409833A (en) * 2022-10-28 2022-11-29 一道新能源科技(衢州)有限公司 Hot spot defect detection method of photovoltaic panel based on unsharp mask algorithm
CN115578389A (en) * 2022-12-08 2023-01-06 青岛澳芯瑞能半导体科技有限公司 Defect detection method of groove MOS device
CN115601367A (en) * 2022-12-15 2023-01-13 苏州迈创信息技术有限公司(Cn) LED lamp wick defect detection method
CN115880248A (en) * 2022-12-13 2023-03-31 哈尔滨耐是智能科技有限公司 Surface scratch defect identification method and visual detection equipment
CN115994904A (en) * 2023-03-22 2023-04-21 山东万重山电子有限公司 Garment steamer panel production quality detection method based on computer vision
WO2023077404A1 (en) * 2021-11-05 2023-05-11 宁德时代新能源科技股份有限公司 Defect detection method, apparatus and system
CN116385448A (en) * 2023-06-07 2023-07-04 深圳市华伟精密陶瓷有限公司 Alumina ceramic surface machining defect detection method based on machine vision
CN116664567A (en) * 2023-07-26 2023-08-29 山东艾迈科思电气有限公司 Solid insulation switch cabinet quality assessment method and system
KR20230139164A (en) * 2022-03-25 2023-10-05 주식회사 우드앤소프트 Defect detecting method of log and wood product surface

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016172827A1 (en) * 2015-04-27 2016-11-03 武汉武大卓越科技有限责任公司 Stepwise-refinement pavement crack detection method
WO2021000524A1 (en) * 2019-07-03 2021-01-07 研祥智能科技股份有限公司 Hole protection cap detection method and apparatus, computer device and storage medium
WO2023077404A1 (en) * 2021-11-05 2023-05-11 宁德时代新能源科技股份有限公司 Defect detection method, apparatus and system
KR20230139164A (en) * 2022-03-25 2023-10-05 주식회사 우드앤소프트 Defect detecting method of log and wood product surface
CN114723701A (en) * 2022-03-31 2022-07-08 南通博莹机械铸造有限公司 Gear defect detection method and system based on computer vision
CN115409833A (en) * 2022-10-28 2022-11-29 一道新能源科技(衢州)有限公司 Hot spot defect detection method of photovoltaic panel based on unsharp mask algorithm
CN115578389A (en) * 2022-12-08 2023-01-06 青岛澳芯瑞能半导体科技有限公司 Defect detection method of groove MOS device
CN115880248A (en) * 2022-12-13 2023-03-31 哈尔滨耐是智能科技有限公司 Surface scratch defect identification method and visual detection equipment
CN115601367A (en) * 2022-12-15 2023-01-13 苏州迈创信息技术有限公司(Cn) LED lamp wick defect detection method
CN115994904A (en) * 2023-03-22 2023-04-21 山东万重山电子有限公司 Garment steamer panel production quality detection method based on computer vision
CN116385448A (en) * 2023-06-07 2023-07-04 深圳市华伟精密陶瓷有限公司 Alumina ceramic surface machining defect detection method based on machine vision
CN116664567A (en) * 2023-07-26 2023-08-29 山东艾迈科思电气有限公司 Solid insulation switch cabinet quality assessment method and system

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
基于微焦点X射线的SMT焊点缺陷检测仿真;王付军;刘兰英;;计算机仿真(第09期);433-436 *
基于机器视觉的玻璃缺陷检测;亓宁宁;常敏;刘雨翰;;光学仪器(第01期);28-34 *
基于空间二进制编码的阈值分割方法研究;李红岩;;计算机仿真(第07期);202-205 *

Also Published As

Publication number Publication date
CN117197141A (en) 2023-12-08

Similar Documents

Publication Publication Date Title
CN117197141B (en) Method for detecting surface defects of automobile parts
CN115294113B (en) Quality detection method for wood veneer
CN116843678B (en) Hard carbon electrode production quality detection method
JP7210873B2 (en) Defect inspection method and defect inspection apparatus
CN116030060B (en) Plastic particle quality detection method
CN113570605A (en) Defect detection method and system based on liquid crystal display panel
CN109540925B (en) Complex ceramic tile surface defect detection method based on difference method and local variance measurement operator
CN114494210A (en) Plastic film production defect detection method and system based on image processing
CN115100206B (en) Printing defect identification method for textile with periodic pattern
CN114881915A (en) Symmetry-based mobile phone glass cover plate window area defect detection method
CN116563279B (en) Measuring switch detection method based on computer vision
CN117095004B (en) Excavator walking frame main body welding deformation detection method based on computer vision
CN109523540A (en) Yarn break detection method based on Hough transformation
CN115049736B (en) Method for accurately positioning surface defects of cable
CN115984272B (en) Semitrailer axle defect identification method based on computer vision
CN117237368A (en) Bridge crack detection method and system
CN115908362A (en) Method for detecting wear resistance of skateboard wheel
CN117115153A (en) Intelligent printed circuit board quality detection method based on visual assistance
CN115272256A (en) Sub-pixel level sensing optical fiber path Gaussian extraction method and system
CN115953409A (en) Injection molding surface defect detection method based on image processing
CN117408995A (en) Power adapter appearance quality detection method based on multi-feature fusion
CN114820529A (en) Method and system for detecting bubbles of rubber product
CN114170165A (en) Chip surface defect detection method and device
CN115601623A (en) Target area acquisition method and teaching method for visual inspection image
KR20220154345A (en) Contour detection device using gaussian-weighted least squares and contour detection method thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant