An intelligent detection method for parts produced by CNC machine tools
By calculating the reference weight and correction frequency of the grayscale value, combined with superpixel point segmentation, local histogram equalization is performed, which solves the problem of histogram equalization ignores local details, and significantly improves image processing quality and detection accuracy.
Patent Information
- Application Number
- CN202411064858.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2044-08-05
AI Technical Summary
In the prior art, histogram equalization ignores the local details and structure of the image, resulting in a significant increase in contrast in some areas in the image, while the contrast in other areas does not change significantly, affecting the accuracy of part detection results.
By calculating the reference weights and correction frequency of each grayscale value, a local histogram is constructed, combined with superpixel point segmentation to calculate the environment grayscale value, and weighted processing is performed to form an enhanced surface image, which significantly improves the quality and effect of image processing.
The quality of image processing and the accuracy of detection results are improved, so that the processed images are more in line with the visual perception of the human eye, the balance of contrast is enhanced, and the accuracy of part detection is improved.
Smart Images

Figure CN118570216B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and more specifically, to an intelligent detection method for parts produced by a numerically controlled machine tool. Background Art
[0002] CNC machine tools are usually used to produce high-precision, complex-structured parts, so it is necessary to ensure that the size, shape, surface quality, etc. of each part meet the requirements to avoid affecting the overall assembly and use effect. Testing the produced parts can ensure that the parts meet the design requirements and technical standards and ensure stable product quality, which is an indispensable part of modern manufacturing.
[0003] In the related technology, for example, the Chinese patent application document with publication number CN117764983A discloses a method for visual inspection of binocular recognition for intelligent manufacturing production lines, including: grayscale processing of RGB images collected by binocular recognition detection equipment, and then preprocessing the image through image filtering and histogram equalization; Gamma correction processing to adjust the brightness and contrast of the image, using Canny edge detection and segmentation algorithm to segment disordered stacked parts and evaluate the segmentation effect, using Canny operator gradient method to segment the ROI area of the parts, and performing three-dimensional reconstruction, calculation, and posture acquisition.
[0004] In the related art, the image is preprocessed by histogram equalization, but conventional histogram equalization is based on the global histogram of the entire image, ignoring the local details and structure of the image, which will cause the contrast of certain areas in the image to be significantly enhanced, while the contrast changes in other areas are not obvious, ultimately resulting in unsatisfactory image enhancement effects, which in turn affects the accuracy of part detection results. Summary of the invention
[0005] In order to solve the technical problem that the above-mentioned conventional histogram equalization ignores the local details and structures of the image, which will cause the contrast of some areas in the image to be significantly enhanced, while the contrast change of other areas is not obvious, and ultimately leads to unsatisfactory image enhancement effect, thereby affecting the accuracy of the part detection results, the present invention provides solutions in the following multiple aspects.
[0006] In a first aspect, the present invention provides an intelligent detection method for parts produced by CNC machine tools, comprising: acquiring a surface image of a part produced by a CNC machine tool; for a target grayscale value among all grayscale values of the surface image, calculating a reference weight of each reference grayscale value according to the distance between a pixel point corresponding to each reference grayscale value of the target grayscale value and a pixel point corresponding to the target grayscale value; correcting the frequency of the target grayscale value according to the reference weight of each reference grayscale value and the number of pixel points whose reference distance among all pixel points corresponding to each reference grayscale value is less than a preset distance, wherein the reference distance refers to the minimum value of the distance between a pixel point corresponding to the reference grayscale value and all pixel points corresponding to the target grayscale value; constructing a first grayscale histogram according to the corrected frequencies of all grayscale values, and performing histogram analysis on the first grayscale histogram. The method comprises the following steps: performing equalization to obtain a first mapping grayscale value of each grayscale value; performing superpixel segmentation on the surface image to obtain all superpixel blocks; for a target pixel among all pixels of the surface image, calculating the environmental grayscale value of the target pixel according to the grayscale value and coordinates of the four corner points of the maximum inscribed rectangle of the superpixel block to which the target pixel belongs; constructing a second grayscale histogram according to the environmental grayscale values of all pixels; performing histogram equalization on the second grayscale histogram to obtain a second mapping grayscale value of each environmental grayscale value; weighting the first mapping grayscale value of the grayscale value of each pixel and the second mapping grayscale value of the environmental grayscale value to calculate a third mapping grayscale value of each pixel; forming an enhanced surface image from the third mapping grayscale values of all pixels; and detecting the enhanced surface image.
[0007] According to the distribution of neighboring grayscale values of the target grayscale value, the frequency of the target grayscale value is corrected according to the reference weight of each reference grayscale value and the number of pixels whose reference distance is less than the preset distance among all pixels corresponding to each reference grayscale value, so that the corrected frequency of the obtained target grayscale value can reflect the local details of the target grayscale value in the surface image; by performing superpixel segmentation on the surface image, the environmental grayscale value of each pixel is calculated according to the grayscale value inside each superpixel block. Superpixel segmentation can help retain the local details of the surface image, so that the obtained environmental grayscale value can better reflect the locality of each pixel; therefore, histogram equalization is subsequently performed according to the corrected frequency of all grayscale values and according to the environmental grayscale value of each pixel. Compared with the traditional histogram equalization method, different local areas in the surface image can be better distinguished and processed, making the contrast enhancement more balanced, significantly improving the quality and effect of surface image processing, making the processed surface image more in line with the visual perception of the human eye, and thus improving the accuracy of the part detection results.
[0008] Preferably, the method for obtaining each reference grayscale value of the target grayscale value includes: taking the grayscale values within the range of [hK, h-1] and [h+1, h+K] as the reference grayscale values of the target grayscale value, K represents the preset length, and h represents the target grayscale value.
[0009] Preferably, the reference weight of the reference gray value satisfies the expression: ; In the formula, q represents the reference weight of the reference gray value, L represents the reference distance of the pixel corresponding to the reference gray value, Indicates the preset distance. Indicates the number of pixels whose reference distance L is less than the preset distance among all pixels corresponding to the reference gray value. Represents the reference distance of the i-th pixel corresponding to the reference gray value, Represents an exponential function with a natural constant as its base.
[0010] The reference weight of the reference gray value is determined by the distance between the pixel corresponding to the reference gray value and the pixel corresponding to the target gray value, so that the reference weight of the reference gray value can reflect the local details of the target gray value in the image.
[0011] Preferably, the frequency of the target gray value is corrected according to the reference weight of each reference gray value and the number of pixels whose reference distance is less than a preset distance among all pixels corresponding to each reference gray value, including: the corrected frequency of the target gray value satisfies the expression: ; In the formula, represents the correction frequency of the target gray value h, h represents the target gray value, K represents the preset length, represents the reference weight of the kth reference gray value of the target gray value, The number of pixels whose reference distance L is less than the preset distance among all pixels corresponding to the kth reference gray value of the target gray value, where L represents the reference distance of the pixels corresponding to the reference gray value. represents the preset distance, N represents the total number of all pixels in the surface image, Represents the frequency of the target grayscale value h; the frequency of the target grayscale value h refers to the ratio of the number of pixels corresponding to the target grayscale value h to the total number of all pixels in the surface image.
[0012] According to the distribution of neighboring grayscale values of the target grayscale value, the frequency of the target grayscale value is corrected according to the reference weight of each reference grayscale value and the number of pixels whose reference distance is less than the preset distance among all pixels corresponding to each reference grayscale value. This allows the corrected frequency of the target grayscale value to reflect the local details of the target grayscale value in the image. Compared with the traditional histogram equalization method, the quality and effect of image processing are significantly improved, making the processed image more in line with the visual perception of the human eye, thereby improving the accuracy of the inspection results of parts.
[0013] Preferably, the calculation of the ambient grayscale value of the target pixel includes: among the pixels corresponding to the four corner points of the maximum inscribed rectangle of the superpixel block to which the target pixel belongs, the pixels corresponding to the lower left corner, upper left corner, upper right corner and lower right corner are respectively recorded as the first neighboring pixel point, the second neighboring pixel point, the third neighboring pixel point and the fourth neighboring pixel point corresponding to the target pixel point; four distance weights are calculated according to the horizontal and vertical coordinates of the four neighboring pixel points and the horizontal and vertical coordinates of the target pixel point; the ambient grayscale value of the target pixel point is calculated according to the four distance weights and the grayscale values of the four neighboring pixel points.
[0014] By performing superpixel segmentation on the surface image and calculating the ambient grayscale value of each pixel based on the grayscale value inside each superpixel block, superpixel segmentation can help retain the local details of the image, so that the obtained ambient grayscale value can better reflect the locality of each pixel. Subsequently, histogram equalization is performed based on the ambient grayscale value of each pixel, which can better distinguish and process different local areas in the image, so that the contrast enhancement is more balanced.
[0015] Preferably, the method for obtaining the four distance weights includes: taking the average of the horizontal coordinates of the first neighboring pixel point and the second neighboring pixel point, and the average of the horizontal coordinates of the third neighboring pixel point and the fourth neighboring pixel point as the first horizontal coordinate and the second horizontal coordinate, respectively; taking the average of the vertical coordinates of the first neighboring pixel point and the third neighboring pixel point, and the average of the vertical coordinates of the second neighboring pixel point and the fourth neighboring pixel point as the first vertical coordinate and the second vertical coordinate; then the first distance weight ; Second distance weight ; Third distance weight ; Fourth distance weight ;in, , Respectively represent the horizontal and vertical coordinates of the target pixel point, , denote the first horizontal coordinate and the second horizontal coordinate respectively, , Represent the first ordinate and the second ordinate respectively.
[0016] Preferably, the ambient grayscale value of the target pixel satisfies the expression: ; In the formula, Represents the ambient gray value of the target pixel. , , , Respectively represent the first distance weight, the second distance weight, the third distance weight and the fourth distance weight, , , , Respectively represent the grayscale values of the first neighboring pixel point, the second neighboring pixel point, the third neighboring pixel point and the fourth neighboring pixel point.
[0017] Calculating the ambient grayscale value of each pixel based on the results of superpixel segmentation can reduce the introduction of noise in the equalization process and the enhancement of the original noise. Compared with the traditional histogram equalization method, it significantly improves the quality and effect of image processing, thereby improving the accuracy of part detection results.
[0018] Preferably, the third mapping grayscale value of the pixel satisfies the expression: ; In the formula, Represents the third mapping grayscale value of the a-th pixel, , denote the first weight and the second weight respectively, and , The first mapping gray value representing the gray value of the a-th pixel, The second mapped grayscale value representing the ambient grayscale value of the a-th pixel.
[0019] The beneficial effects of the present invention are:
[0020] According to the distribution of neighboring grayscale values of the target grayscale value, the frequency of the target grayscale value is corrected according to the reference weight of each reference grayscale value and the number of pixels whose reference distance is less than the preset distance among all pixels corresponding to each reference grayscale value, so that the corrected frequency of the obtained target grayscale value can reflect the local details of the target grayscale value in the surface image; by performing superpixel segmentation on the surface image, the environmental grayscale value of each pixel is calculated according to the grayscale value inside each superpixel block. Superpixel segmentation can help retain the local details of the surface image, so that the obtained environmental grayscale value can better reflect the locality of each pixel; therefore, histogram equalization is subsequently performed according to the corrected frequency of all grayscale values and according to the environmental grayscale value of each pixel. Compared with the traditional histogram equalization method, different local areas in the surface image can be better distinguished and processed, making the contrast enhancement more balanced, significantly improving the quality and effect of surface image processing, making the processed surface image more in line with the visual perception of the human eye, and thus improving the accuracy of the part detection results. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The above and other purposes, features and advantages of the exemplary embodiments of the present invention will become readily understood by reading the detailed description below through the accompanying drawings. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:
[0022] Figure 1 The flowchart schematically shows an intelligent detection method for parts produced by a CNC machine tool in the present invention. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0024] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0025] The embodiment of the present invention discloses an intelligent detection method for parts produced by a CNC machine tool, referring to Figure 1 , comprising steps S1 to S5:
[0026] S1. Collect surface images of parts produced by CNC machine tools.
[0027] It should be noted that CNC machine tools are usually used to produce high-precision, complex structure parts, so it is necessary to ensure that the size, shape, surface quality, etc. of each part meet the requirements to avoid affecting the overall assembly and use effect. Testing the produced parts can ensure that the parts meet the design requirements and technical standards and ensure stable product quality, which is an indispensable part of modern manufacturing.
[0028] Specifically, the surface image of the produced parts is collected by a camera installed on the CNC machine tool production line, and the surface image is a grayscale image.
[0029] S2. For a target grayscale value among all grayscale values of the surface image, a reference weight of each reference grayscale value of the target grayscale value is calculated, and the frequency of the target grayscale value is corrected according to the reference weight of each reference grayscale value and the number of pixel points whose reference distance is less than a preset distance among all pixel points corresponding to each reference grayscale value; a first grayscale histogram is constructed according to the corrected frequency of all grayscale values in the surface image, and histogram equalization is performed on the first grayscale histogram to obtain a first mapped grayscale value of each grayscale value in the surface image.
[0030] It should be noted that in surface image processing, conventional histogram equalization is a widely used method, which makes the surface image more visually balanced and clear by adjusting the grayscale distribution of the surface image. Conventional histogram equalization is based on the global histogram of the entire surface image, ignoring the local details and structure of the image, which will cause the contrast of some areas in the image to be significantly enhanced, while the contrast of other areas does not change significantly, ultimately resulting in unsatisfactory image enhancement effects, which in turn affects the accuracy of the parts inspection results.
[0031] Therefore, this embodiment introduces a reference grayscale value for each grayscale value in the surface image, calculates a reference weight for the reference grayscale value, and corrects the frequency of each grayscale value according to the reference weight of each reference grayscale value in the surface image and the number of pixels whose reference distance is less than a preset distance among all pixels corresponding to each reference grayscale value. Compared with the traditional histogram equalization method, the quality and effect of surface image processing are significantly improved, so that the processed surface image is more in line with the visual perception of the human eye, thereby improving the accuracy of the inspection results of the parts.
[0032] S201. Obtain an initial grayscale histogram of the surface image.
[0033] Specifically, the frequency of each grayscale value in the surface image is counted, and the frequency refers to the ratio of the number of pixel points corresponding to each grayscale value to the total number of all pixel points in the surface image; according to the frequency of each grayscale value in the surface image, an initial grayscale histogram of the surface image is constructed, and the horizontal axis of the initial grayscale histogram is each grayscale value, and the vertical axis is the frequency of each grayscale value.
[0034] S202. Calculate the reference weights of the reference gray values of the target gray value.
[0035] Specifically, any grayscale value in the surface image is taken as the target grayscale value, and 2K grayscale values adjacent to the target grayscale value in the grayscale histogram are taken as reference grayscale values of the target grayscale value. That is, the grayscale values in the range of [hK, h-1] and [h+1, h+K] are taken as reference grayscale values of the target grayscale value, K represents the preset length, and h represents the target grayscale value.
[0036] Among them, the specific value of the preset length can be set according to the actual application scenario and requirements, and the preset length is an integer not less than 2. The present invention sets the preset number to 5.
[0037] Further, the reference weight of each reference gray value is calculated according to the distance between the pixel point corresponding to each reference gray value of the target gray value and the pixel point corresponding to the target gray value; then the reference weight of the reference gray value satisfies the expression:
[0038] ;
[0039] In the formula, q represents the reference weight of the reference gray value, L represents the reference distance of the pixel corresponding to the reference gray value, Indicates the preset distance. Indicates the number of pixels whose reference distance L is less than the preset distance among all pixels corresponding to the reference gray value. Represents the reference distance of the i-th pixel corresponding to the reference gray value, Represents an exponential function with a natural constant as its base.
[0040] Among them, the method for obtaining the reference distance is: for any pixel point corresponding to the reference grayscale value, calculate the distance between the pixel point and all pixel points corresponding to the target grayscale value, and take the minimum value of the distance as the reference distance of the pixel point, and the distance is the Euclidean distance.
[0041] The specific value of the preset distance can be set according to actual application scenarios and requirements. The present invention sets the preset distance to 7.
[0042] It should be noted that for the pixel points corresponding to the reference grayscale value, the smaller the reference distance, the closer the pixel point is to the pixel point corresponding to the target grayscale value, and the more the pixel point can reflect the local details of the target grayscale value in the surface image. Therefore, the weight of the reference grayscale value is calculated according to the reference distance of these pixels corresponding to the reference grayscale value, that is, the closer the reference grayscale value is to the target grayscale value, the higher the weight.
[0043] S203. Correct the frequency of the target gray value according to the reference weight of each reference gray value and the number of pixels whose reference distance is less than a preset distance among all pixels corresponding to each reference gray value.
[0044] Specifically, the correction frequency of the target gray value satisfies the expression:
[0045] ;
[0046] In the formula, represents the correction frequency of the target gray value h, h represents the target gray value, K represents the preset length, represents the reference weight of the kth reference gray value of the target gray value, The number of pixels whose reference distance L is less than the preset distance among all pixels corresponding to the kth reference gray value of the target gray value, where L represents the reference distance of the pixels corresponding to the reference gray value. represents the preset distance, N represents the total number of all pixels in the surface image, Indicates the frequency of the target gray value h.
[0047] It should be noted that, for all pixels corresponding to the kth reference gray value of the target gray value, only the pixels whose reference distance L is less than the preset distance can reflect the local details of the target gray value in the surface image. Therefore, the number of pixels whose reference distance L is less than the preset distance is set to The total number of all pixels in the surface image is used as the weight of the kth reference gray value of the target gray value.
[0048] It should be noted that the present invention not only relies on the global statistical results of the target grayscale value, but also takes into account the distribution of the neighboring grayscale values of the target grayscale value. The frequency of the target grayscale value is corrected according to the reference weight of each reference grayscale value and the number of pixels whose reference distance is less than the preset distance among all pixels corresponding to each reference grayscale value. The corrected frequency of the target grayscale value obtained can reflect the local details of the target grayscale value in the surface image. Compared with the traditional histogram equalization method, the quality and effect of surface image processing are significantly improved, so that the processed surface image is more in line with the visual perception of the human eye, thereby improving the accuracy of the inspection results of the parts.
[0049] S204. Construct a first grayscale histogram according to the correction frequencies of all grayscale values in the surface image; perform histogram equalization on the first grayscale histogram to obtain a first mapped grayscale value of each grayscale value in the surface image.
[0050] Specifically, according to the correction frequencies of all gray values in the surface image, a first gray histogram of the surface image is constructed, wherein the abscissa of the first gray histogram is the gray values in the surface image, and the ordinate is the correction frequency of the gray values in the surface image.
[0051] It should be noted that the histogram equalization is a well-known technology and will not be described in detail here.
[0052] S3. Calculate the environmental grayscale value of each pixel in the surface image, construct a second grayscale histogram according to the environmental grayscale values of all pixels, perform histogram equalization on the second grayscale histogram, and obtain a second mapped grayscale value of each environmental grayscale value.
[0053] S301. Calculate the environmental grayscale value of each pixel in the surface image.
[0054] Specifically, the surface image is segmented into superpixels to obtain all superpixel blocks; any pixel in the surface image is taken as the target pixel, and the ambient grayscale value of the target pixel is calculated according to the grayscale values and coordinates of the pixels corresponding to the four corner points of the maximum inscribed rectangle of the superpixel block to which the target pixel belongs.
[0055] Among them, calculating the environmental grayscale value of the target pixel point includes: among the pixels corresponding to the four corner points of the maximum inscribed rectangle of the superpixel block to which the target pixel point belongs, recording the pixel point corresponding to the lower left corner point as the first neighboring pixel point corresponding to the target pixel point; recording the pixel point corresponding to the upper left corner point as the second neighboring pixel point corresponding to the target pixel point; recording the pixel point corresponding to the lower right corner point as the third neighboring pixel point corresponding to the target pixel point; recording the pixel point corresponding to the upper right corner point as the fourth neighboring pixel point corresponding to the target pixel point; calculating four distance weights according to the horizontal and vertical coordinates of the four neighboring pixels and the horizontal and vertical coordinates of the target pixel point; and calculating the environmental grayscale value of the target pixel point according to the four distance weights and the grayscale values of the four neighboring pixels.
[0056] Among them, the four distance weights are calculated according to the abscissa and ordinate of the four neighboring pixel points and the abscissa and ordinate of the target pixel point, including: taking the average of the abscissas of the first neighboring pixel point and the second neighboring pixel point as the first abscissa; taking the average of the abscissas of the third neighboring pixel point and the fourth neighboring pixel point as the second abscissa; taking the average of the ordinates of the first neighboring pixel point and the third neighboring pixel point as the first ordinate, and taking the average of the ordinates of the second neighboring pixel point and the fourth neighboring pixel point as the second ordinate; then the first distance weight, the second distance weight, the third distance weight and the fourth distance weight respectively satisfy the expressions:
[0057] ;
[0058] ;
[0059] ;
[0060] ;
[0061] in, , , , Respectively represent the first distance weight, the second distance weight, the third distance weight and the fourth distance weight, , Respectively represent the horizontal and vertical coordinates of the target pixel point, , denote the first horizontal coordinate and the second horizontal coordinate respectively, , Represent the first ordinate and the second ordinate respectively.
[0062] Among them, the environmental gray value of the target pixel satisfies the expression:
[0063] ;
[0064] In the formula, Represents the ambient gray value of the target pixel. , , , Respectively represent the first distance weight, the second distance weight, the third distance weight and the fourth distance weight, , , , Respectively represent the grayscale values of the first neighboring pixel point, the second neighboring pixel point, the third neighboring pixel point and the fourth neighboring pixel point.
[0065] It should be noted that by performing superpixel segmentation on the surface image and calculating the ambient grayscale value of each pixel according to the grayscale value inside each superpixel block, superpixel segmentation can help retain the local details of the surface image, so that the obtained ambient grayscale value can better reflect the locality of each pixel. Subsequently, histogram equalization is performed according to the ambient grayscale value of each pixel, which can better distinguish and process different local areas in the surface image, so that the contrast enhancement is more balanced.
[0066] It should be further explained that calculating the ambient grayscale value of each pixel based on the result of superpixel segmentation can reduce the introduction of noise in the equalization process and the enhancement of the original noise. Compared with the traditional histogram equalization method, it significantly improves the quality and effect of surface image processing, thereby improving the accuracy of part inspection results.
[0067] S302. Construct a second grayscale histogram according to the environmental grayscale values of all pixels in the surface image; perform histogram equalization on the second grayscale histogram to obtain a second mapped grayscale value of each environmental grayscale value.
[0068] Specifically, according to the environmental grayscale values of all pixels in the surface image, the frequency of each environmental grayscale value is statistically obtained; according to the frequency of each environmental grayscale value, a second grayscale histogram of the surface image is constructed, and the horizontal axis of the second grayscale histogram is the environmental grayscale value, and the vertical axis is the frequency of each environmental grayscale value.
[0069] It should be noted that the histogram equalization is a well-known technology and will not be described in detail here.
[0070] S4. Calculate the third mapping grayscale value of each pixel in the surface image; and combine the third mapping grayscale values of all pixels in the surface image into an enhanced surface image.
[0071] Specifically, according to the first mapping grayscale value of the grayscale value of each pixel in the surface image and the second mapping grayscale value of the environment grayscale value of each pixel in the surface image, the third mapping grayscale value of each pixel in the surface image is calculated, and the third mapping grayscale value of the a-th pixel in the surface image satisfies the expression:
[0072] ;
[0073] In the formula, Represents the third mapping grayscale value of the a-th pixel, , denote the first weight and the second weight respectively, The first mapping gray value representing the gray value of the a-th pixel, The second mapped grayscale value representing the ambient grayscale value of the a-th pixel.
[0074] For the first weight and the second weight ,Require ,and and The specific value of needs to be set according to the requirements. In the present invention, the first weight Set to 0.75, the second weight is 0.25.
[0075] It should be noted that the correction frequency of the grayscale value in the surface image can reflect the local details of the grayscale value in the surface image, and the ambient grayscale value of each pixel in the surface image can better reflect the locality of each pixel. Therefore, the third mapping grayscale value of each pixel in the surface image calculated according to the first mapping grayscale value of the grayscale value of each pixel in the surface image and the second mapping grayscale value of the ambient grayscale value of each pixel in the surface image can better distinguish and process different local areas in the surface image, making the contrast enhancement more balanced, significantly improving the quality and effect of surface image processing, and making the processed surface image more in line with the visual perception of the human eye, thereby improving the accuracy of the inspection results of parts.
[0076] S5. Detect the enhanced surface image.
[0077] Specifically, the enhanced surface image is detected through a convolutional neural network to obtain the type of the part, which includes normal and multiple defect types, including but not limited to chip defects, burr defects, fragmentation defects and built-up edge defects.
[0078] Among them, the pre-training process of the convolutional neural network is as follows: personnel with relevant experience mark the surface images in the training set, mark the normal surface images as 0, mark the surface images corresponding to each defect type without duplication, and train the convolutional neural network through the labeled training set; the convolutional neural network encoder-decoder network, the loss function is the cross entropy loss function.
[0079] In the description of this specification, "plurality" or "several" means at least two, such as two, three or more, etc., unless otherwise clearly and specifically defined.
[0080] Although this specification has shown and described a number of embodiments of the present invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Those skilled in the art will conceive of many modifications, changes and alternatives without departing from the ideas and spirit of the present invention. It should be understood that in the practice of the present invention, alternatives to the embodiments of the present invention described herein may be employed.
Claims
1. An intelligent detection method for parts produced by CNC machine tools, characterized in that: include: Collect surface images of parts produced by CNC machine tools; For the target grayscale value among all grayscale values of the surface image, the reference weight of each reference grayscale value is calculated according to the distance between the pixel point corresponding to each reference grayscale value of the target grayscale value and the pixel point corresponding to the target grayscale value; The method for obtaining each reference grayscale value of the target grayscale value includes: taking the grayscale values within the range of [hK, h-1] and [h+1, h+K] as the reference grayscale values of the target grayscale value, K represents the preset length, and h represents the target grayscale value; correcting the frequency of the target grayscale value according to the reference weight of each reference grayscale value and the number of pixel points whose reference distance is less than the preset distance among all pixel points corresponding to each reference grayscale value, and the corrected frequency of the target grayscale value satisfies the expression: ; In the formula, represents the correction frequency of the target gray value h, represents the reference weight of the kth reference gray value of the target gray value, The number of pixels whose reference distance L is less than the preset distance among all pixels corresponding to the kth reference gray value of the target gray value, where L represents the reference distance of the pixels corresponding to the reference gray value. represents the preset distance, N represents the total number of all pixels in the surface image, represents the frequency of the target gray value h; the frequency of the target gray value h refers to the ratio of the number of pixels corresponding to the target gray value h to the total number of all pixels in the surface image; the reference distance refers to the minimum value of the distance between the pixel corresponding to the reference gray value and all the pixels corresponding to the target gray value; according to the correction frequency of all gray values, a first gray histogram is constructed, and the first gray histogram is histogram equalized to obtain a first mapping gray value of each gray value; The surface image is segmented into superpixels to obtain all superpixel blocks; for a target pixel among all pixels of the surface image, the environment grayscale value of the target pixel is calculated according to the grayscale values and coordinates of the pixels corresponding to the four corner points of the maximum inscribed rectangle of the superpixel block to which the target pixel belongs, including: among the pixels corresponding to the four corner points of the maximum inscribed rectangle of the superpixel block to which the target pixel belongs, the pixels corresponding to the corner points of the lower left corner, the upper left corner, the upper right corner and the lower right corner are respectively recorded as the first neighboring pixel point, the second neighboring pixel point, the third neighboring pixel point and the fourth neighboring pixel point corresponding to the target pixel point; four distance weights are calculated according to the abscissa and ordinate of the four neighboring pixels and the abscissa and ordinate of the target pixel; the environment grayscale value of the target pixel is calculated according to the four distance weights and the grayscale values of the four neighboring pixels, satisfying the expression: ; In the formula, Represents the ambient gray value of the target pixel. , , , Respectively represent the first distance weight, the second distance weight, the third distance weight and the fourth distance weight, , , , Respectively represent the grayscale values of the first neighboring pixel point, the second neighboring pixel point, the third neighboring pixel point and the fourth neighboring pixel point; construct a second grayscale histogram according to the environmental grayscale values of all pixels; perform histogram equalization on the second grayscale histogram to obtain a second mapping grayscale value of each environmental grayscale value; The first mapping grayscale value of the grayscale value of each pixel and the second mapping grayscale value of the environment grayscale value are weighted to calculate the third mapping grayscale value of each pixel; the third mapping grayscale values of all pixels are combined into an enhanced surface image; and the enhanced surface image is detected.
2. The intelligent detection method for parts produced by CNC machine tools according to claim 1 is characterized in that: The reference weight of the reference gray value satisfies the expression: ; In the formula, q represents the reference weight of the reference gray value, L represents the reference distance of the pixel corresponding to the reference gray value, Indicates the preset distance. It indicates the number of pixels whose reference distance L is less than the preset distance among all pixels corresponding to the reference gray value. Represents the reference distance of the i-th pixel corresponding to the reference gray value, Represents an exponential function with a natural constant as its base.
3. The intelligent detection method for parts produced by CNC machine tools according to claim 1 is characterized in that: The method for obtaining the four distance weights includes: The average of the horizontal coordinates of the first neighboring pixel point and the second neighboring pixel point, and the average of the horizontal coordinates of the third neighboring pixel point and the fourth neighboring pixel point are used as the first horizontal coordinate and the second horizontal coordinate respectively; the average of the vertical coordinates of the first neighboring pixel point and the third neighboring pixel point, and the average of the vertical coordinates of the second neighboring pixel point and the fourth neighboring pixel point are used as the first vertical coordinate and the second vertical coordinate; The first distance weight ; Second distance weight ; Third distance weight ; Fourth distance weight ;in, , Respectively represent the horizontal and vertical coordinates of the target pixel point, , denote the first horizontal coordinate and the second horizontal coordinate respectively, , Represent the first ordinate and the second ordinate respectively.
4. The intelligent detection method for parts produced by CNC machine tools according to claim 1 is characterized in that: The third mapping grayscale value of the pixel satisfies the expression: ; In the formula, Represents the third mapping grayscale value of the a-th pixel, , denote the first weight and the second weight respectively, and , The first mapping gray value representing the gray value of the a-th pixel, The second mapped grayscale value representing the ambient grayscale value of the a-th pixel.
