An engine cylinder head defect detection method and system

CN122453836BActive Publication Date: 2026-08-21CHONGQING HONGYI MACHINERY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610942192.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-06-29
Publication Date
2026-08-21
Estimated Expiration
2046-06-29

AI Technical Summary

Technical Problem

[0004](1)要解决的技术问题:本发明的目的在于提供一种发动机缸盖缺陷检测方法和系统,以解决在未预清洁的灰铸铁发动机缸盖触火面图像中,两排气孔之间鼻梁区因高温服役形成氧化膜厚度差异,使背景灰度沿两排气孔圆心连线方向产生梯度变化,且该灰度梯度方向与裂纹萌生和扩展方向一致;在此条件下,如何避免固定阈值在孔边缘处误检背景、在裂纹起始端漏检裂纹,并准确统计鼻梁区裂纹长度的问题

Benefits of technology

[0015](3)有益效果:与现有技术相比,本发明的有益效果是通过从触火面图像中提取的两排气孔圆心坐标确定孔心连线方向,在鼻梁区逐位置估计背景灰度,构建沿孔心连线方向变化的分段线性阈值函数,对每个目标像素施加与其位置对应的分割阈值,解决固定全局阈值在孔边缘处背景误检与裂纹漏检的问题,提升了鼻梁区裂纹骨架像素长度统计的合理性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122453836B_ABST
    Figure CN122453836B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of visual identification, in particular to a kind of engine cylinder cover defect detection method and system, first to gray cast iron cylinder cover fire surface image pre-processing, obtain denoising gray scale chart;Two rows of gas hole profile are extracted and the hole center coordinates, connecting line unit vector and pixel length are calculated. Along the hole center connecting line equidistant sampling, take the gray scale maximum value of local strip in vertical direction as local background gray scale, combined with the preset crack gray scale upper limit, the local threshold value of sampling point is calculated, and the piecewise linear threshold function is generated by linear interpolation. The projection coordinates of cylinder cover nose bridge area pixels on connecting line are solved, the adaptive threshold is obtained by calling threshold function, and binary image is generated by pixel by pixel segmentation. The binary image is denoised and the skeleton is extracted, the skeleton pixel length is calculated using chain code, and the actual length of crack is obtained combined with camera correction factor. The present scheme can solve the fixed threshold mis-detection and missed detection problem caused by the gray scale gradient of the nose bridge area of the cylinder cover fire surface under the condition of no pre-cleaning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of visual recognition technology, specifically to a method and system for detecting defects in engine cylinder heads. Background Technology

[0002] The cylinder head is a core casting of an internal combustion engine, typically made of gray cast iron (such as HT250). Its flame-contact surface is directly exposed to the combustion chamber, enduring alternating thermal loads from cyclical high-temperature combustion gas heating (approximately 2000°C) and coolant cooling (approximately 80°C). Cyclic thermal stress is generated in the smallest cross-sectional area between the exhaust and intake ports (i.e., the nose bridge area), leading to the initiation and propagation of thermal fatigue cracks along the line connecting the centers of the two exhaust ports, originating from the edge steps of the ports and commonly known as "nose cracks." After initiation, the crack extends from the port edge towards the width of the nose bridge. Crack length is a key indicator for determining the repairability of the cylinder head: when the crack length exceeds half the width of the nose bridge, the cylinder head is not repairable and must be scrapped; when the crack length does not exceed this threshold, it can be treated with repair processes such as laser cladding, and the cylinder head still has repair value. An industrial CCD camera acquires images of the cylinder head's flame-contact surface, and image processing methods are used to detect cracks and measure their lengths. These measurements are then compared with a judgment threshold to complete the repairability assessment. After high-temperature service, an iron oxide film forms on the surface of the cast iron in the nose area of ​​the cylinder head's fire-contact surface. The thickness and density of the oxide film are positively correlated with the thermal load experienced at each location: the thermal load in the bridge area monotonically decreases from the edges of the two exhaust vents (where stress and temperature are highest, and cracks preferentially initiate) towards the center of the bridge. The oxidation rate of iron in a high-temperature oxidizing atmosphere is positively correlated with temperature; therefore, the oxide film thickness is greatest near the vent edges, resulting in the strongest absorption of visible light and a lower background grayscale in the image (measured at approximately 65–80). The oxidation is lightest in the center of the bridge, with a background grayscale close to that of normal cast iron (measured at approximately 95–115). This background grayscale gradient is distributed along the line connecting the centers of the two exhaust vents, varying by approximately 30–50 grayscale levels, and the gradient direction is consistent with the crack propagation direction.

[0003] Meanwhile, the crack's grayscale value in the image is approximately 20–75, and is relatively uniform along its entire length. Near the edge of the hole, the crack's grayscale value (approximately 20–75) overlaps with the background grayscale value (approximately 65–80) in the grayscale range of approximately 65–75; while in the middle of the bridge of the nose, there is a clear interval of approximately 20–40 grayscale levels between the background grayscale value (approximately 95–115) and the upper limit of the crack's grayscale value (approximately 75). When segmenting an image using a fixed global threshold T, several issues arise: If T is set to a high value (e.g., 85), the middle of the bridge of the nose can be correctly segmented, but some background pixels at the edge of the hole (grayscale values ​​between 65 and 80, below 85) are misidentified as crack foreground, forming a continuous false crack area near the edge of the hole. This area merges with the real crack during the morphological expansion stage, artificially increasing the length of the skeleton pixels. Ultimately, the crack length is overestimated by about 3-8 mm, misclassifying a repairable cylinder head as irreparable. If T is set to a low value (e.g., 65), the false detection of background at the edge of the hole is eliminated, but pixels near the crack initiation point at the edge of the hole (grayscale values ​​between 65 and 75) are also missed. The skeleton is truncated at the crack initiation point, and the crack length is underestimated by about 2-5 mm. This misclassifies an irreparable cylinder head close to the threshold as repairable, posing a safety hazard. Existing technologies often use general adaptive thresholding methods (such as the Sauvola algorithm and the Niblack algorithm) to estimate the local threshold by statistically analyzing the mean and standard deviation of gray levels within a local rectangular window centered on an arbitrary pixel. When the window contains both low-gray-level pixels of the crack and high-gray-level pixels of the background, the local mean is dragged down by the low-gray-level pixels of the crack, resulting in a low local threshold and missed crack detection at the edge of the hole. Summary of the Invention

[0004] (1) Technical problem to be solved: The purpose of this invention is to provide a method and system for detecting defects in engine cylinder heads, so as to solve the problem that in the image of the fire contact surface of an uncleaned gray cast iron engine cylinder head, the difference in oxide film thickness in the nose bridge area between the two exhaust holes due to high-temperature service causes the background gray level to change along the direction of the line connecting the centers of the two exhaust holes, and the direction of the gray level gradient is consistent with the direction of crack initiation and propagation; under this condition, how to avoid false detection of background at the edge of the hole by a fixed threshold, failure to detect crack at the crack initiation end, and accurate calculation of crack length in the nose bridge area.

[0005] (2) Technical solution: To achieve the above objectives, on the one hand, the present invention provides a method for detecting defects in engine cylinder heads, the method comprising: An image of the engine cylinder head contact surface is acquired and preprocessed to obtain a denoised grayscale image. The denoised grayscale image is then segmented to extract the edge contour pixel sets of the first and second exhaust holes. The edge contour pixel sets of the first and second exhaust holes are then fitted with least-squares circles to obtain the center pixel coordinates of the first and second exhaust holes. The unit vector of the line connecting the centers of the two holes and the pixel length of the line connecting the centers of the two holes are obtained from the center pixel coordinates of the first and second exhaust holes. Multiple equally spaced sampling points are taken between the edges of the first and second exhaust holes along the line connecting the centers of the two holes. At each sampling point, a local strip of a preset width is taken along the line perpendicular to the line connecting the centers of the two holes. The maximum value of the denoised grayscale values ​​of all pixels within the local strip is taken as the local background grayscale estimate of the sampling point. The local threshold of each sampling point is obtained by comparing the local background grayscale estimate with the pre-calibrated upper bound of the crack grayscale. Linear interpolation is performed between adjacent sampling points using the local threshold of each sampling point and the position coordinates of each sampling point along the line connecting the centers of the two holes to obtain a piecewise linear threshold function with the position coordinates along the line connecting the centers of the two holes as the independent variable. For each target pixel within the region between the edges of the first and second exhaust holes, the position coordinates of the target pixel in the direction of the line connecting the centers of the two holes are obtained by projecting the difference vector between the target pixel coordinates and the coordinates of the center pixel of the first exhaust hole onto a unit vector. An adaptive position threshold is then obtained for each target pixel using a piecewise linear threshold function. Target pixels with denoised grayscale values ​​not exceeding the adaptive position threshold are marked as crack foreground pixels, and the remaining pixels are marked as background pixels, resulting in a binary image. The binary image is then denoised, and a skeleton image is extracted. Chain code statistics are performed on the skeleton image to obtain the number of unidirectional and bidirectional adjacent pixels. The skeleton pixel length is obtained using these numbers. Finally, the actual crack defect length is obtained using the skeleton pixel length and a pre-calibrated camera correction factor.

[0006] Furthermore, the method for obtaining the denoised grayscale image through preprocessing includes: The engine cylinder head contact surface image is converted into a single-channel grayscale image. The single-channel grayscale image is then subjected to piecewise linear grayscale stretching to obtain a contrast-enhanced image. For each pixel to be processed in the contrast-enhanced image, a rectangular filtering window is taken, centered on the pixel and starting from a preset minimum window size. The minimum, maximum, and median grayscale values ​​of all pixels within the rectangular filtering window are obtained. When the median grayscale value falls between the minimum and maximum grayscale values, it is determined whether the pixel's own grayscale value falls between these two values. If it does, the pixel's own grayscale value is retained as the filtering output; otherwise, the median grayscale value is used as the filtering output, and the expansion of the rectangular filtering window for the pixel is stopped. When the median grayscale value does not fall between the minimum and maximum grayscale values, the rectangular filtering window is expanded by a preset step size until the window size reaches a preset maximum window size. The median grayscale value corresponding to the preset maximum window size is then used as the filtering output. After completing the above filtering output for all pixels to be processed in the contrast-enhanced image, a denoised grayscale image is obtained.

[0007] Furthermore, the method for performing piecewise linear grayscale stretching on a single-channel grayscale image to obtain a contrast-enhanced image includes: Pixels in a single-channel grayscale image whose grayscale values ​​do not exceed a pre-defined upper bound of crack grayscale are defined as crack grayscale segment pixels. A first stretching coefficient is obtained by combining the pre-defined upper bound of crack grayscale with a pre-set upper limit of the output low grayscale segment. The output grayscale value of the corresponding pixel in the contrast-enhanced image is obtained by combining the grayscale value of the crack grayscale segment pixel with the first stretching coefficient. Pixels in a single-channel grayscale image whose grayscale values ​​exceed the pre-defined upper bound of crack grayscale are defined as background grayscale segment pixels. The background grayscale range is obtained by combining a pre-set upper limit of the background grayscale range with a pre-defined upper bound of crack grayscale. The length of the high grayscale segment is obtained by using the pre-set upper limit and lower limit of the high grayscale segment. The second stretching coefficient is obtained by using the length of the background grayscale range and the length of the high grayscale segment. The output grayscale value of the corresponding pixel in the contrast-enhanced image is obtained by using the grayscale value of the background grayscale segment pixel, the background grayscale offset of the pre-calibrated upper limit of the crack grayscale, the second stretching coefficient, and the pre-set lower limit of the high grayscale segment. The pre-set upper limit of the low grayscale segment and the pre-set lower limit of the high grayscale segment are adjacent and cover the entire output grayscale range.

[0008] Furthermore, the method for extracting the edge contour pixel sets of the first and second exhaust holes from the denoised grayscale image by segmentation includes: A gray-level frequency histogram is constructed for the gray-level values ​​of all pixels in the denoised gray-level image. All gray levels in the histogram are iterated through, with each gray level serving as a candidate segmentation threshold. Pixels with gray values ​​not exceeding the candidate segmentation threshold are designated as low-gray-level regions within the hole, while pixels with gray values ​​exceeding the candidate segmentation threshold are designated as background regions on the cast iron surface. The inter-class variance corresponding to the candidate segmentation threshold is obtained by using the proportion of pixels in the low-gray-level regions within the hole, the proportion of pixels in the background regions on the cast iron surface, and the mean gray values ​​of these regions. After iterating through all candidate segmentation thresholds, the candidate segmentation threshold that maximizes the inter-class variance is selected. As a segmentation threshold, the denoised grayscale image is binarized to obtain a binary image of the hole region. Pixels belonging to the low grayscale region within the hole in the binary image of the hole region are labeled as connected regions according to the four-connected adjacency relationship. All connected regions are sorted from largest to smallest in terms of pixel count, and the two connected regions with the largest number of pixels are selected as the first vent hole region and the second vent hole region, respectively. The set of pixels directly adjacent to the background region of the cast iron surface in the first vent hole region is extracted as the first vent hole edge contour pixel set, and the set of pixels directly adjacent to the background region of the cast iron surface in the second vent hole region is extracted as the second vent hole edge contour pixel set.

[0009] Furthermore, the method for obtaining the inter-class variance corresponding to the candidate segmentation threshold by the proportion of pixels in the low grayscale region inside the hole, the proportion of pixels in the background region on the cast iron surface, and the mean grayscale values ​​of the low grayscale region inside the hole and the background region on the cast iron surface includes: Obtain the total number of pixels in the denoised grayscale image; count the number of pixels in the low grayscale region within the hole, using the candidate segmentation threshold as the boundary, and obtain the percentage of pixels in the low grayscale region within the hole by comparing the number of pixels in the low grayscale region within the hole with the total number of pixels; obtain the number of pixels in the background region of the cast iron surface by comparing the total number of pixels with the number of pixels in the low grayscale region within the hole, and obtain the percentage of pixels in the background region of the cast iron surface by comparing the number of pixels in the background region of the cast iron surface with the total number of pixels; obtain the grayscale mean of the low grayscale region within the hole by combining the cumulative sum of grayscale values ​​of all pixels in the low grayscale region within the hole with the number of pixels in the low grayscale region within the hole; obtain the grayscale mean of the background region of the cast iron surface by combining the cumulative sum of grayscale values ​​of all pixels in the denoised grayscale image, the cumulative sum of grayscale values ​​of all pixels in the low grayscale region within the hole, and the number of pixels in the background region of the cast iron surface; obtain the inter-class variance by combining the percentage of pixels in the low grayscale region within the hole, the percentage of pixels in the background region of the cast iron surface, and the difference between the grayscale mean of the low grayscale region within the hole and the grayscale mean of the background region of the cast iron surface.

[0010] Furthermore, the method for obtaining the local threshold of each sampling point by comparing the estimated local background grayscale value of each sampling point with the pre-calibrated upper bound of the crack grayscale includes: For each sampling point between the edge of the first exhaust port and the edge of the second exhaust port, the local threshold of the sampling point is obtained by averaging the local background grayscale estimate of the sampling point with the pre-calibrated upper limit of crack grayscale. It is then determined whether the difference between the local background grayscale estimate of the sampling point and the pre-calibrated upper limit of crack grayscale is less than a pre-set minimum grayscale discrimination. When the difference between the background and the upper limit of crack is less than the pre-set minimum grayscale discrimination, the adjusted local threshold is obtained by combining the pre-calibrated upper limit of crack grayscale and the pre-set minimum grayscale discrimination. The adjusted local threshold replaces the local threshold of the sampling point, and the sampling point is marked as a low-contrast region in the detection output. The pre-calibrated upper limit of crack grayscale is obtained by establishing a frequency distribution of the denoised grayscale values ​​of all pixels in the known crack area in the cylinder head contact surface image of the same model of engine, taking the grayscale value corresponding to the cumulative frequency reaching a preset percentile, and directly calling it in the batch detection of the same model of cylinder head.

[0011] Furthermore, the pre-calibrated upper bound of the crack grayscale is obtained by establishing a frequency distribution of the denoised grayscale values ​​of all pixels within a known crack area in the cylinder head contact surface image of the same model engine, and taking the grayscale value corresponding to the cumulative frequency reaching a preset percentile. The method includes: Acquire the contact surface image of a known crack sample cylinder head of the same model as the engine cylinder head to be inspected, and perform preprocessing on the contact surface image to obtain a sample denoised grayscale image; determine the pixel range of the known crack area in the sample denoised grayscale image by magnetic particle inspection or manual annotation; extract the denoised grayscale values ​​of all pixels in the known crack area, and establish a crack pixel grayscale frequency distribution according to the denoised grayscale values ​​of all pixels in the known crack area from smallest to largest; starting from the minimum grayscale value of the crack pixel grayscale frequency distribution, the frequencies corresponding to each grayscale level are accumulated to form a cumulative frequency. When the cumulative frequency first reaches the preset percentile, the grayscale value of the current grayscale level is taken as the upper limit of the crack grayscale.

[0012] Furthermore, the method for denoising a binary image and extracting a skeleton image includes: A morphological erosion operation is performed on the binary image. A square structuring element with three pixels in each row and column is scanned position by position on the binary image. When all pixels within the coverage area of ​​the square structuring element are crack foreground pixels, the position is retained as a crack foreground pixel; otherwise, the position is set as a background pixel. After completing the above scan on all positions in the binary image, an eroded binary image is obtained. A morphological dilation operation is then performed on the eroded binary image using the same square structuring element. When at least one crack foreground pixel exists within the coverage area of ​​the square structuring element, the position is restored to a crack foreground pixel. After completing the above scan on all positions in the eroded binary image, a denoised binary image is obtained. For the denoised... After denoising, the binary image undergoes skeleton thinning. In each iteration, all crack foreground pixels in the denoising binary image are scanned. For each crack foreground pixel, it is determined whether it meets one of the following two retention conditions: First, after deleting the crack foreground pixel, the connectivity between adjacent crack foreground pixels is broken; Second, the crack foreground pixel is located on the backbone path of the crack foreground region and the backbone path length is shortened after deletion. Crack foreground pixels that do not meet the above two retention conditions are set as background pixels. The above iteration process is repeated until all crack foreground pixels are not set as background pixels in a certain iteration. The binary image at the time of stopping is used as the skeleton image.

[0013] Furthermore, the method for obtaining the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels of the skeleton by performing chain code statistics on the skeleton image; and obtaining the skeleton pixel length through the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels of the skeleton includes: The process involves sequentially traversing all skeleton pixels in the skeleton image along the crack extension direction, and determining the spatial relationship of each pair of adjacent skeleton pixels: if adjacent skeleton pixels change only in either row or column coordinates, the adjacent pairs satisfying this condition are accumulated as the number of unidirectional adjacent pixels; if adjacent skeleton pixels change in both row and column coordinates, the adjacent pairs satisfying this condition are accumulated as the number of bidirectional adjacent pixels. After traversing all pairs of adjacent skeleton pixels, the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels are obtained respectively. The unidirectional cumulative skeleton length is obtained by using the number of unidirectional adjacent pixels and the unit pixel spacing; the diagonal pixel spacing is obtained by using the unit pixel spacing and the Pythagorean theorem; the bidirectional cumulative skeleton length is obtained by using the number of bidirectional adjacent pixels and the diagonal pixel spacing; and the skeleton pixel length is obtained by using the unidirectional cumulative skeleton length and the bidirectional cumulative skeleton length.

[0014] Based on the same inventive concept, in another aspect, the present invention also provides an engine cylinder head defect detection system, the system comprising: The image acquisition module is used to acquire an image of the engine cylinder head contact surface and preprocess it to obtain a denoised grayscale image. The denoised grayscale image is segmented to extract the edge contour pixel sets of the first exhaust hole and the second exhaust hole respectively. The edge contour pixel sets of the first exhaust hole and the second exhaust hole are respectively fitted with least squares circles to obtain the center pixel coordinates of the first exhaust hole and the center pixel coordinates of the second exhaust hole. The unit vector of the direction of the line connecting the centers of the two holes and the pixel length of the line connecting the centers of the two holes are obtained from the center pixel coordinates of the first exhaust hole and the center pixel coordinates of the second exhaust hole. The threshold calculation module is used to take multiple equally spaced sampling points along the line connecting the centers of the two exhaust holes between the edges of the first and second exhaust holes; at each sampling point, a local strip of a preset width is taken along the line perpendicular to the line connecting the centers of the two holes, and the maximum value of the denoised grayscale values ​​of all pixels in the local strip is taken as the local background grayscale estimate of the sampling point; the local threshold of each sampling point is obtained by comparing the local background grayscale estimate of each sampling point with the pre-calibrated upper bound of the crack grayscale; and linear interpolation is performed between adjacent sampling points using the local threshold of each sampling point and the position coordinates of each sampling point along the line connecting the centers of the two holes to obtain a piecewise linear threshold function with the position coordinates along the line connecting the centers of the two holes as the independent variable. The defect detection module is used to obtain the position coordinates of each target pixel in the region between the edge of the first exhaust hole and the edge of the second exhaust hole by projecting the difference vector between the target pixel coordinates and the center pixel coordinates of the first exhaust hole onto a unit vector along the line connecting the centers of the two holes; obtain the position adaptive threshold corresponding to the target pixel according to a piecewise linear threshold function; mark the target pixels whose denoised grayscale values ​​do not exceed the position adaptive threshold as crack foreground pixels and the remaining pixels as background pixels to obtain a binary image; denoise the binary image and extract the skeleton image; perform chain code statistics on the skeleton image to obtain the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels; obtain the skeleton pixel length using the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels; and obtain the actual crack defect length using the skeleton pixel length and a pre-calibrated camera correction factor.

[0015] (3) Beneficial effects: Compared with the prior art, the beneficial effects of the present invention are to determine the direction of the connecting line of the two rows of holes by extracting the center coordinates of the two rows of holes from the fire-contact surface image, estimate the background gray level at each position in the bridge of the nose area, construct a piecewise linear threshold function that varies along the connecting line of the holes, apply a segmentation threshold corresponding to its position to each target pixel, solve the problem of false detection of background and missed detection of cracks at the edge of the hole by fixing the global threshold, and improve the rationality of the statistical analysis of the crack skeleton pixel length in the bridge of the nose area. Attached Figure Description

[0016] The above and / or other aspects of this application will become more apparent from the description of certain embodiments with reference to the accompanying drawings, in which: Figure 1 This is a flowchart of an engine cylinder head defect detection method according to Embodiment 1 of the present invention; Figure 2 This is a block diagram of an engine cylinder head defect detection system according to Embodiment 2 of the present invention. Detailed Implementation

[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0018] Before providing examples, it is necessary to describe the application scenario of this invention. A repair inspection line for a certain model of 6-cylinder diesel engine cylinder head (gray cast iron HT250, approximately 22kg per piece) uses an industrial CCD camera (1600×1200 pixels resolution, 4.4μm×4.4μm pixel size) with a ring-shaped LED diffuse reflection light source (approximately 45° angle with the contact surface) to acquire images of the contact surface of the cylinder head to be inspected on the conveyor belt. The object distance is approximately 400mm, and the camera correction factor is approximately 0.056mm / pixel. Each cylinder head has four nose bridge areas to be inspected, and the inspection cycle time for a single piece must not exceed 500ms. The exhaust port diameter of this model of cylinder head is approximately 15mm (pixel radius approximately 134 pixels), the center distance between two exhaust ports is approximately 20.16mm (approximately 360 pixels), and the nose bridge width is approximately 25mm, corresponding to a damage judgment threshold of 12.5mm (i.e., half the nose bridge width). Before entering the inspection station, the cylinder head surface was not cleaned, and the surface exposed to the flame had an iron oxide film formed after high-temperature service. This caused the background grayscale to rise from about 65-80 at the edge of the hole to about 95-115 in the middle of the nose bridge along the line connecting the centers of the two exhaust holes.

[0019] On the engine cylinder head's contact surface, two exhaust ports are arranged side-by-side, with the solid cast iron area between them forming the nose bridge region. Each port has a circular wall, and the boundary between the port wall edge and the solid cast iron surface forms a step. Thermal fatigue cracks initiate at this step and extend inwards along the line connecting the centers of the two ports into the nose bridge region. The effective width of the nose bridge region is the distance between the edges of the two port walls, i.e., the length of the solid cast iron surface from the edge of the first exhaust port to the edge of the second exhaust port. This area is the target area for defect detection.

[0020] The engine cylinder head crack to be detected originates from the step at the edge of the exhaust port, with a gray level of approximately 65-75 at the initial stage, overlapping with the background gray level near the port edge. The crack in the middle of the bridge has a gray level of approximately 20-50, with a clear interval from the background gray level. A fixed global threshold cannot simultaneously resolve false positives and false negatives at the port edge. This application proposes to construct a piecewise linear threshold function that varies positionally along the line connecting the two exhaust port centers extracted from the image. This applies a segmentation threshold adapted to the position of each pixel in the bridge region, eliminating the aforementioned contradiction of a fixed global threshold, improving the completeness of the crack skeleton pixel length statistics, and reducing the false positive rate in boundary judgment scenarios.

[0021] Example 1: As Figure 1 As shown, this embodiment provides a method for detecting defects in an engine cylinder head, the method comprising: An image of the engine cylinder head contact surface is acquired and preprocessed to obtain a denoised grayscale image. The denoised grayscale image is then segmented to extract the edge contour pixel sets of the first and second exhaust holes. The edge contour pixel sets of the first and second exhaust holes are then fitted with least-squares circles to obtain the center pixel coordinates of the first and second exhaust holes. The unit vector of the line connecting the centers of the two holes and the pixel length of the line connecting the centers of the two holes are obtained from the center pixel coordinates of the first and second exhaust holes. Multiple equally spaced sampling points are taken between the edges of the first and second exhaust holes along the line connecting the centers of the two holes. At each sampling point, a local strip of a preset width is taken along the line perpendicular to the line connecting the centers of the two holes. The maximum value of the denoised grayscale values ​​of all pixels within the local strip is taken as the local background grayscale estimate of the sampling point. The local threshold of each sampling point is obtained by comparing the local background grayscale estimate with the pre-calibrated upper bound of the crack grayscale. Linear interpolation is performed between adjacent sampling points using the local threshold of each sampling point and the position coordinates of each sampling point along the line connecting the centers of the two holes to obtain a piecewise linear threshold function with the position coordinates along the line connecting the centers of the two holes as the independent variable. For each target pixel within the region between the edges of the first and second exhaust holes, the position coordinates of the target pixel in the direction of the line connecting the centers of the two holes are obtained by projecting the difference vector between the target pixel coordinates and the coordinates of the center pixel of the first exhaust hole onto a unit vector. An adaptive position threshold is then obtained for each target pixel using a piecewise linear threshold function. Target pixels with denoised grayscale values ​​not exceeding the adaptive position threshold are marked as crack foreground pixels, and the remaining pixels are marked as background pixels, resulting in a binary image. The binary image is then denoised, and a skeleton image is extracted. Chain code statistics are performed on the skeleton image to obtain the number of unidirectional and bidirectional adjacent pixels. The skeleton pixel length is obtained using these numbers. Finally, the actual crack defect length is obtained using the skeleton pixel length and a pre-calibrated camera correction factor.

[0022] For example, a factory conducts online defect detection on the cylinder head of a 6DL diesel engine (made of gray cast iron HT250, with a carbon content of 3.16% to 3.30%, and a single piece weighing approximately 22 kg). An industrial CCD camera (resolution 1600 pixels × 1200 pixels, pixel size 4.4 μm × 4.4 μm) is fixedly mounted directly above the contact surface of the cylinder head, at an object distance of approximately 400 mm. The light source is a ring-shaped LED diffuse reflection light source, with an angle of approximately 45° between the light source and the normal to the contact surface. After triggering the image capture, a color image of the contact surface is obtained.

[0023] The image of the fire-contact surface is preprocessed to obtain a denoised grayscale image. , The value range is from 0 to 255, and the unit is dimensionless gray level. These are pixel row and column coordinates, with the origin at the top left corner of the image. Axis to the right, The image is oriented downwards, and the unit is pixels. The preprocessing steps include grayscale conversion, piecewise linear grayscale stretching, and adaptive median filtering. These preprocessing steps will be explained in detail later.

[0024] Denoise grayscale image The edge contour pixel sets of the first and second exhaust holes are extracted by segmentation. The segmentation sub-steps include maximizing the inter-class variance of Otsu to calculate the segmentation threshold, identifying the two largest connected regions by marking the connected regions, and extracting the pixel set of the adjacent background within each hole region. Each sub-step will be explained in detail later.

[0025] By fitting the edge contour pixel sets of the first and second exhaust holes to a circle using least-squares circle fitting, the pixel coordinates of the center of the first exhaust hole are obtained. Second exhaust hole center pixel coordinates Linearized solution for least-squares circle fitting: For each pixel in the edge contour Establish equations Establish an overdetermined system of linear equations using all edge pixels. ,in for Matrix (rows) ), For all industries The column vector formed Through the normal equation Solve to obtain the coordinates of the circle's center. radius of circle Each set of exhaust port edge contour pixels is independently established and its equations are solved. Taking this cylinder head model as an example, the pixel coordinates of the center of the first exhaust port are... The pixel coordinates of the center of the second exhaust hole The two holes are arranged almost horizontally. The radius of each hole... Pixels, corresponding to a physical aperture of approximately 7.5 millimeters.

[0026] The pixel coordinates of the center of the first exhaust hole Second exhaust hole center pixel coordinates Obtain the unit vector of the direction of the line connecting the centers of the two holes. Pixel length of the line connecting the centers of the two holes : ; Taking this model of cylinder head as an example, Pixels Unit vector satisfy The direction points from the center of the first exhaust hole to the center of the second exhaust hole, and serves as the geometric reference for all subsequent coordinate calculations along the line connecting the centers of the holes.

[0027] Multiple equally spaced sampling points are taken along the line connecting the centers of the two vents, between the edges of the first and second vents. It should be noted that the inner wall of the vent through-hole has no cast iron surface and no iron oxide film background. The pixel grayscale values ​​of the local stripes outside the vent edges are low grayscale values ​​(approximately 3 to 15) of the inner wall, and their maximum values ​​do not reflect the cast iron background. Therefore, the sampling range is strictly limited to the solid area of ​​the bridge of the nose between the edges of the two vents. Taking the pixel coordinates of the center of the first vent as the origin, along... The directional position coordinates are measured in pixels. The starting position is located at the edge of the first exhaust hole. The edge of the second exhaust port corresponds to the termination position. Taking this model of cylinder head as an example, Pixels Pixels, effective length of the bridge of the nose Pixels, corresponding to a physical length of approximately Millimeters.

[0028] Take the total number of sampling points Spacing between adjacent sampling points Pixel. The first sampling points ( The position coordinates along the line connecting the centers of the two holes are: Its pixel coordinates are: ; Total number of sampling points The selection criterion is to ensure the spacing between adjacent sampling points. The resolution should not exceed 45 pixels to ensure that the spatial resolution of the background grayscale estimation meets the gradient capture requirements. Taking this cylinder head model as an example, when the effective length of the bridge area is 92 pixels, the resolution should be taken as follows: satisfy If the effective length of the nose bridge area differs for different cylinder head models, it can be re-determined according to the same criteria. .

[0029] At each sampling point The preset width is taken along the direction perpendicular to the line connecting the centers of the two holes. The local stripe, taking the maximum value of the denoised grayscale values ​​of all pixels within the local stripe as the first... Local background grayscale estimate of each sampling point Perpendicular to The unit normal vector is The set of integer pixels covered by the local stripe is satisfied with All integer coordinates , that is to Centered on, along Directional width not exceeding A strip-shaped region of pixels. (Preset width) Pixels. The reason for taking the maximum gray value of pixels within the strip instead of the mean is: the gray value of crack pixels is lower than that of cast iron background pixels. Taking the maximum value can eliminate the interference of crack pixels within the strip on the estimation of background gray value and accurately reflect the true background gray value of the cast iron surface at that location. If the mean value is taken, the crack pixels will pull the mean value down to below the true background gray value, resulting in a lower local threshold and an increased false negative rate.

[0030] Taking the measured data of the nose bridge area of ​​this model's cylinder head as an example, the coordinates of each sampling point are shown below. and local background grayscale estimation value as follows( (Measured in pixels, starting from the center of the first exhaust hole) , , ; , , ; , , ; , , ; , , ; (Middle part of the bridge of the nose) , ; , , ; , , ; , , ; , , ; , , ; , , .

[0031] It should be noted that the reason for the above-mentioned background grayscale gradient is that, under the cyclical thermal cycling of high-temperature combustion gas (approximately 2000°C) and coolant (approximately 80°C) on the heat-contacting surface of gray cast iron, the iron surface sequentially forms oxidizing atmosphere. and The high-temperature oxidation rate of iron is positively correlated with temperature. The thermal stress is greatest and the heat load is highest at the edge steps of the two rows of holes, resulting in the thickest oxide film, the strongest absorption of visible light, and the lowest gray level (measured at approximately 65 to 80). The heat load is relatively lower in the middle of the bridge of the hole, the oxide film is thinner, and the gray level is higher (measured at approximately 95 to 115). This gray level gradient is distributed along the line connecting the centers of the two holes, with a variation range of approximately 30 to 50 gray levels, consistent with the direction of crack initiation and propagation.

[0032] If a fixed global threshold is taken The middle section of the nose bridge can be correctly segmented, but the background grayscale value below 85 (approximately 65-80) at the edge of the hole is misjudged as the foreground of the crack, forming a continuous pseudo-crack area of ​​about 210 pixels near the edge of the hole. This area connects with the real crack in the subsequent noise reduction step, artificially increasing the skeleton pixel length and ultimately overestimating the crack length by about 3 to 8 millimeters. This leads to the cylinder head that can be repaired being mistakenly classified as irreparable. If a fixed global threshold is used... While background false positives at the hole edge are eliminated, pixels at the crack initiation point (those with a grayscale value between 65 and 75, higher than 65) are still missed. The skeleton is truncated at the crack initiation point, and the crack length is underestimated by approximately 2 to 5 millimeters. This leads to the misclassification of a cylinder head that is close to the decision threshold as repairable, posing a safety hazard. However, general adaptive thresholding methods (such as the Sauvola and Niblack algorithms) estimate the local threshold by statistically analyzing the mean and standard deviation of grayscale values ​​within a local rectangular window centered on any pixel. When the window contains both low-grayscale crack pixels and high-grayscale background pixels, the local mean is dragged down by the low-grayscale crack pixels, resulting in a lower local threshold and still causing missed crack detections at the hole edge.

[0033] Local background grayscale estimates at each sampling point Compared with the pre-defined upper limit of crack grayscale Obtain the local threshold of each sampling point The specific methods for local threshold calculation and low contrast processing will be explained later. Taking this model of cylinder head as an example, Minimum grayscale discrimination The local threshold for each sampling point is: (Low contrast adjustment) , , , , , , , , , (Low contrast adjustment) (Low contrast adjustment).

[0034] Local thresholds at each sampling point and the position coordinates of each sampling point along the line connecting the centers of the two holes. Linear interpolation is performed between adjacent sampling points to obtain the position coordinates along the line connecting the centers of the two holes. Piecewise linear threshold function for independent variable In the interval ( )Inside: ; exist Time to take ,exist Time to take Taking this model of cylinder head as an example, from The 80.0 at the pixel level monotonically increases to The value at the pixel is 95.5, then symmetrically reduced back to... The value 80.0 at the pixel changes continuously along the line connecting the center of the hole.

[0035] It should be noted that, because the background grayscale gradient itself exhibits an approximately monotonically smooth change in the bridge area (as shown in the measured data of this cylinder head model, the background grayscale change between adjacent sampling points ranges from 0 to 11 grayscale levels), the spacing between sampling points... The threshold error generated by piecewise linear interpolation at the pixel level does not exceed 0.5 gray levels, which meets the requirements for engineering accuracy. If other interpolation methods are used (such as cubic spline interpolation), a spline coefficient matrix containing all 12 sampling points needs to be established, which increases the computational cost slightly. However, under the condition that the background gray-level gradient is approximately linear, the difference between its interpolation result and piecewise linear interpolation does not exceed 0.5 gray levels, and the two are equivalent in the crack segmentation results in this detection scenario.

[0036] Each target pixel in the region between the edge of the first exhaust hole and the edge of the second exhaust hole The difference vector between the target pixel coordinates and the center pixel coordinates of the first exhaust hole is used. Unit vector in the direction of the line connecting the centers of the two holes Projecting onto the target pixel yields its position coordinates along the line connecting the centers of the two holes. : ; Based on the piecewise linear threshold function ,Will Substitution , obtain target pixels Corresponding position adaptive threshold . Denoising grayscale values Not exceeding the position adaptive threshold The target pixel is labeled as the crack foreground pixel, and the remaining pixels are labeled as background pixels, resulting in a binary image. : ; For example, located in A cracked pixel at pixel location (near the edge of the first exhaust hole). Insertion is worthwhile , The foreground pixel is correctly identified as a crack. A similar pixel in the cast iron background at the same location... , These are also identified as foreground pixels; pixels with grayscale values ​​between 75 and 80.3 at the edge of holes are considered low-contrast markers and are indicated as low-contrast areas in the inspection report for review. This does not directly affect the statistical calculation of the length of the crack skeleton in the middle of the nasal bridge. Located in A certain cast iron background pixel at pixel location (middle of the bridge of the nose), , , It has been correctly identified as background. Located in... A pixel with a deep crack at a given pixel location. , The condition was correctly identified as a crack prospect.

[0037] Binary image The steps of denoising and extracting the skeleton image will be discussed later. Chain code statistics will be performed on the skeleton image to obtain the number of unidirectional adjacent pixels in the skeleton. Number of bidirectional adjacent pixels and skeleton ,pass and Get the skeleton pixel length Detailed steps will be explained later.

[0038] By skeleton pixel length With pre-calibrated camera correction factor Obtain the actual crack defect length Camera correction factor This represents the actual physical length corresponding to each pixel, in millimeters per pixel. It is pre-calibrated using a standard checkerboard calibration plate. Specifically, a checkerboard with known precise spacing is placed on the plane of the cylinder head's contact surface. After image acquisition, the pixel distance between the corner points of the checkerboard is calculated and divided by the known physical distance to obtain the value. Taking the inspection configuration (object distance 400 mm) of this cylinder head model as an example, The millimeter / pixel value can be directly used in batch testing with the same camera model and object distance configuration; if the object distance or camera parameters change, recalibration is required.

[0039] Taking a specific example of this type of cylinder head: the skeleton statistics show that... , Skeleton pixel length Pixels, actual crack defect length Millimeters. Damage decision threshold. Millimeters (half the width of the nose bridge is 25 millimeters, pre-set according to the engineering standard of the same model cylinder head). The cylinder head was determined to be non-repairable. If a fixed global threshold is used... Approximately 210 pseudo-crack pixels at the edge of the hole are connected to the real crack, artificially increasing the skeleton size. The reading is approximately 21 to 26 millimeters, overestimated by about 3 to 8 millimeters; if a fixed global threshold is used... The starting end of the skeleton is cut off by about 2 to 5 millimeters. The actual crack length is approximately 12.8 to 15.8 mm. Underestimating this range could lead to misjudgment if the crack falls near the decision threshold. This method eliminates these two types of error sources by using a position-adaptive threshold, significantly reducing the misjudgment rate in boundary judgment scenarios (where the actual crack length is close to 12.5 mm).

[0040] Furthermore, the method for obtaining the denoised grayscale image through preprocessing includes: The engine cylinder head contact surface image is converted into a single-channel grayscale image. The single-channel grayscale image is then subjected to piecewise linear grayscale stretching to obtain a contrast-enhanced image. For each pixel to be processed in the contrast-enhanced image, a rectangular filtering window is taken, centered on the pixel and starting from a preset minimum window size. The minimum, maximum, and median grayscale values ​​of all pixels within the rectangular filtering window are obtained. When the median grayscale value falls between the minimum and maximum grayscale values, it is determined whether the pixel's own grayscale value falls between these two values. If it does, the pixel's own grayscale value is retained as the filtering output; otherwise, the median grayscale value is used as the filtering output, and the expansion of the rectangular filtering window for the pixel is stopped. When the median grayscale value does not fall between the minimum and maximum grayscale values, the rectangular filtering window is expanded by a preset step size until the window size reaches a preset maximum window size. The median grayscale value corresponding to the preset maximum window size is then used as the filtering output. After completing the above filtering output for all pixels to be processed in the contrast-enhanced image, a denoised grayscale image is obtained.

[0041] For example, preprocessing is performed on the image of the contact surface to obtain a denoised grayscale image. Specifically: Convert the fire-contact surface image to a single-channel grayscale image. If the input is in three-channel BGR format, for each pixel... According to the weighted formula Calculate the grayscale value and round the result to an integer between 0 and 255. If the input is already in single-channel grayscale format, then directly set... It is equal to the grayscale value of the image, ranging from 0 to 255.

[0042] Single-channel grayscale image Perform piecewise linear grayscale stretching to obtain a contrast-enhanced image. Enhance the contrast of the image. Each pixel to be processed in Centered on the pixel to be processed, from a preset minimum window size Start by taking a rectangular filtering window, and then obtain the minimum grayscale value of all pixels within the rectangular filtering window. Maximum grayscale value and grayscale median .in , , These are all statistical values ​​of the set of pixel grayscale values ​​within the rectangular filtering window, ranging from 0 to 255, and are related to the current pixel to be processed. It corresponds one-to-one with the current window size and is not shared between different pixels.

[0043] by This represents the side length of the current rectangular filter window (in pixels, odd number), initially set as follows: The rectangular filter window covers Centered Square neighborhood. Pixels located outside the image boundaries within the rectangular filtering window are filled with grayscale values ​​of 0 (considered as background pixels).

[0044] Determine the median of grayscale Does it meet the requirements? : If the following conditions are met (a valid grayscale distribution exists within the window, and the median is not an extreme value), then the grayscale value of the pixel to be processed is further determined. Does it meet the requirements? If the condition is met, the grayscale value of the pixel to be processed is determined to be within the window grayscale range (non-pulse point), and its own grayscale value is retained as the filtered output, setting the value of the denoised grayscale image at that position as... Stop expanding the rectangular filter window; if the condition is not met (its own grayscale value is an extreme value within the window, determined to be a pulse point), then replace it with the grayscale median, let... Stop expanding the rectangular filter window.

[0045] If not satisfied (If the pixel grayscale values ​​within the window are extremely uniform, and the median value itself is an extreme value, it is impossible to reliably determine whether the pixel is a pulse point within the current window), then the rectangular filtering window will be adjusted according to the preset step size. Expand (order) Repeat the above judgment until the rectangular filter window size is reached. Reach the preset maximum window size If in Still not satisfied Then Corresponding grayscale median As the filtered output, let .symbol The rectangular filter window has a side length of 1. The median grayscale value within the neighborhood of the pixel to be processed is used to distinguish it from other window sizes. .

[0046] Enhance the contrast of the image After all the pixels to be processed have undergone the above filtering process, a denoised grayscale image is obtained. Taking this model of cylinder head as an example, take... (i.e., the 3×3 minimum neighborhood). (Keep the window side length an odd number at all times). (i.e., the 7x7 maximum neighborhood). Preset maximum window size. Selection criteria: The typical width of the crack line segment in the cylinder head image of this model is approximately 2 to 4 pixels. The maximum neighborhood should not exceed twice the crack width (approximately 4 to 8 pixels), thus in The corresponding crack pixels in the neighborhood will not constitute the vast majority, and the median grayscale value can still reflect the background grayscale. The grayscale value of the crack pixels will not be replaced by the median grayscale value of the background. Preset minimum window size. It can detect isolated noise as small as a single pixel. Step size Keep the window side length an odd number and center the anchor point pixels.

[0047] For example, a pixel to be processed Gray values ​​in contrast-enhanced images (Isolated noise in bright spots), the gray values ​​of the other 8 pixels in its 3×3 neighborhood are all between 92 and 96, then , , ,satisfy Then judge yourself Not satisfied Therefore, replace, The impulse noise was eliminated. Another pixel to be processed. For cracked pixels, Within its 3×3 neighborhood, there are background pixels (grayscale approximately 90 to 96) and other crack pixels (grayscale approximately 80 to 85). , , It satisfies the median validity condition; then it judges itself. ,satisfy Preserve its own grayscale value. The grayscale values ​​of cracked pixels are not replaced.

[0048] Furthermore, the method for performing piecewise linear grayscale stretching on a single-channel grayscale image to obtain a contrast-enhanced image includes: Pixels in a single-channel grayscale image whose grayscale values ​​do not exceed a pre-defined upper bound of crack grayscale are defined as crack grayscale segment pixels. A first stretching coefficient is obtained by combining the pre-defined upper bound of crack grayscale with a pre-set upper limit of the output low grayscale segment. The output grayscale value of the corresponding pixel in the contrast-enhanced image is obtained by combining the grayscale value of the crack grayscale segment pixel with the first stretching coefficient. Pixels in a single-channel grayscale image whose grayscale values ​​exceed the pre-defined upper bound of crack grayscale are defined as background grayscale segment pixels. The background grayscale range is obtained by combining a pre-set upper limit of the background grayscale range with a pre-defined upper bound of crack grayscale. The length of the high grayscale segment is obtained by using the pre-set upper limit and lower limit of the high grayscale segment. The second stretching coefficient is obtained by using the length of the background grayscale range and the length of the high grayscale segment. The output grayscale value of the corresponding pixel in the contrast-enhanced image is obtained by using the grayscale value of the background grayscale segment pixel, the background grayscale offset of the pre-calibrated upper limit of the crack grayscale, the second stretching coefficient, and the pre-set lower limit of the high grayscale segment. The pre-set upper limit of the low grayscale segment and the pre-set lower limit of the high grayscale segment are adjacent and cover the entire output grayscale range.

[0049] For example, a single-channel grayscale image Perform piecewise linear grayscale stretching to obtain a contrast-enhanced image. Single-channel grayscale image The grayscale value does not exceed the pre-defined upper limit of the crack grayscale value. The pixels are defined as the crack grayscale segment. Taking this model of cylinder head as an example, ,Right now The pixel belongs to the crack grayscale range.

[0050] The upper limit of the crack grayscale is determined by the pre-defined upper limit. Compared with the preset upper limit of the low grayscale range of the output Obtain the first tensile coefficient .in This is the maximum grayscale value that the pixels in the crack grayscale segment will map to in the output image. Taking this model of cylinder head as an example, it is preset to... : ; The grayscale values ​​of the pixels in the crack grayscale segment With the first tensile coefficient This yields the output grayscale value of the corresponding pixel in the contrast-enhanced image. ,in ; Single-channel grayscale image The grayscale value exceeds the pre-defined upper limit of the crack grayscale value. The pixels are defined as background grayscale pixels, that is Pixels.

[0051] Based on the pre-set upper limit of the background grayscale range Compared with the pre-defined upper limit of crack grayscale Get the length of the background grayscale range .in The preset maximum grayscale value of the cast iron surface is used to limit the upper limit of the background grayscale stretching input, preventing a very small number of saturated pixels from disrupting the stretching ratio; taking this model of cylinder head as an example, the preset maximum grayscale value is... : ; By setting a pre-defined upper limit for outputting high grayscale range Compared with the preset lower limit of the high grayscale range of output Get the length of the high grayscale segment. .in satisfy (Adjacent to the upper limit of the low grayscale segment, the two segments together cover the entire output grayscale range from 0 to 255, with no mapping holes). Taking this model of cylinder head as an example, : ; By the length of the background grayscale range Length of high grayscale segment output The second tensile coefficient was obtained. : ; By the grayscale values ​​of the background grayscale pixels Compared with the pre-defined upper limit of crack grayscale Background grayscale offset Second tensile factor and the pre-set lower limit of the high grayscale range for output This yields the output grayscale value of the corresponding pixel in the contrast-enhanced image. for: ; in For grayscale values ​​exceeding For a very small number of saturated pixels, the output value calculated according to the above formula is truncated to 255 when it exceeds 255.

[0052] Preset upper limit for output low grayscale range Compared with the preset lower limit of the high grayscale range of output Adjacent, covering the entire output grayscale range.

[0053] For example, cracked pixels , , Background pixels , , After stretching, the grayscale difference between the crack pixels and the background pixels changes from the original... Expand to The contrast is improved by about 28%, which is beneficial for the subsequent adaptive median filtering step to separate crack pixels from background pixels and reduce the probability of crack pixels being mistakenly replaced by impulse noise.

[0054] The above preset parameters ( , , The parameters for this cylinder head model (HT250 material, 400 mm object distance, ring LED light source) were determined in advance through experiments and statistics. When changing the cylinder head material grade, casting process, or image acquisition equipment, the above parameters must be re-determined based on the grayscale distribution statistics of the same cylinder head image.

[0055] Furthermore, the method for extracting the edge contour pixel sets of the first and second exhaust holes from the denoised grayscale image by segmentation includes: A gray-level frequency histogram is constructed for the gray-level values ​​of all pixels in the denoised gray-level image. All gray levels in the histogram are iterated through, with each gray level serving as a candidate segmentation threshold. Pixels with gray values ​​not exceeding the candidate segmentation threshold are designated as low-gray-level regions within the hole, while pixels with gray values ​​exceeding the candidate segmentation threshold are designated as background regions on the cast iron surface. The inter-class variance corresponding to the candidate segmentation threshold is obtained by using the proportion of pixels in the low-gray-level regions within the hole, the proportion of pixels in the background regions on the cast iron surface, and the mean gray values ​​of these regions. After iterating through all candidate segmentation thresholds, the candidate segmentation threshold that maximizes the inter-class variance is selected. As a segmentation threshold, the denoised grayscale image is binarized to obtain a binary image of the hole region. Pixels belonging to the low grayscale region within the hole in the binary image of the hole region are labeled as connected regions according to the four-connected adjacency relationship. All connected regions are sorted from largest to smallest in terms of pixel count, and the two connected regions with the largest number of pixels are selected as the first vent hole region and the second vent hole region, respectively. The set of pixels directly adjacent to the background region of the cast iron surface in the first vent hole region is extracted as the first vent hole edge contour pixel set, and the set of pixels directly adjacent to the background region of the cast iron surface in the second vent hole region is extracted as the second vent hole edge contour pixel set.

[0056] For example, a denoised grayscale image The edge contour pixel sets of the first and second exhaust holes are extracted by segmentation, and the center pixel coordinates of the two holes are obtained by least-squares circle fitting. Specifically, the denoised grayscale image is processed... Build a gray-level frequency histogram for all pixels. ( ), For the gray values ​​in the image to be exactly equal to The total number of pixels, satisfying , This represents the total number of pixels in the image. Taking this particular cylinder head model as an example... The histogram shows a bimodal distribution: the left peak is concentrated in grayscale 3 to 15 (inner wall of the vent hole through hole), and the right peak is concentrated in grayscale 70 to 120 (background of cast iron surface).

[0057] Traverse all gray levels in the gray-level frequency histogram For each gray level As the candidate segmentation threshold, grayscale values ​​not exceeding [a certain threshold] are selected. The pixels are defined as low grayscale regions within the aperture, and the grayscale values ​​exceeding [a certain threshold] are [defined as] low grayscale regions. The pixels were defined as the background area of ​​the cast iron surface. Candidate segmentation thresholds were obtained by considering the proportion of pixels in the low grayscale area inside the hole, the proportion of pixels in the background area of ​​the cast iron surface, and the mean grayscale values ​​of the low grayscale area inside the hole and the background area of ​​the cast iron surface. Corresponding inter-class variance .

[0058] After iterating through all candidate segmentation thresholds, the candidate segmentation threshold that maximizes the inter-class variance is selected as the segmentation threshold. , based on the segmentation threshold For denoised grayscale images Binarization: Grayscale values ​​not exceeding The pixels in the hole region are set to 1, and the rest are set to 0, to obtain a binary image of the hole region. Taking this model of cylinder head as an example, calculations show that... Two exhaust ports at This corresponds to two consecutive foreground regions (with a value of 1).

[0059] Binary image of the hole region Pixels belonging to the low-grayscale region (value 1) within the hole are marked as connected regions according to the four-connected adjacency relationship. That is, only pixels whose row or column coordinates differ by 1 and whose other coordinate is the same are considered connected (up, down, left, and right directions). The reason for choosing four-connected over eight-connected is that there is a solid nose bridge (approximately 25 mm wide) between the two exhaust holes of this cylinder head model, and the two holes are not adjacent in the image. If eight-connected were used, there is a probability that the two holes would be incorrectly merged into a single connected region at the corner pixels of the hole by diagonal connection, while four-connected would not have this problem. All connected regions are sorted from largest to smallest in terms of pixel count, and the two connected regions with the largest pixel count are selected as the first exhaust hole regions. Second exhaust port area By center The smaller coordinate indicates the area of ​​the first exhaust port. The larger one is the area of ​​the second exhaust port. This order is consistent with the subsequent... Direction (from) point to The definition is consistent with that of ).

[0060] Extract the first exhaust port area The inner and background areas of the cast iron surface ( The set of directly adjacent pixels in the sense of four-connectivity is used as the pixel set of the edge contour of the first exhaust hole. Similarly, extract the pixel set of the edge contour of the second exhaust hole. Taking this model of cylinder head as an example, and Each contains approximately 820 to 850 pixels, covering the entire circumference of the exhaust hole.

[0061] Will Each pixel ( Substitute into the equation Establish an overdetermined system of equations ,in Each behavior , Each element is , Through the normal equation Solving for the coordinates of the center pixel of the first exhaust hole, we obtain the coordinates of the center pixel. radius of the first exhaust port .right Each pixel ( Similarly, by establishing and solving the overdetermined system of equations, the pixel coordinates of the center of the second exhaust hole can be obtained. Second exhaust port radius .

[0062] Furthermore, the method for obtaining the inter-class variance corresponding to the candidate segmentation threshold by the proportion of pixels in the low grayscale region inside the hole, the proportion of pixels in the background region on the cast iron surface, and the mean grayscale values ​​of the low grayscale region inside the hole and the background region on the cast iron surface includes: Obtain the total number of pixels in the denoised grayscale image; count the number of pixels in the low grayscale region within the hole, using the candidate segmentation threshold as the boundary, and obtain the percentage of pixels in the low grayscale region within the hole by comparing the number of pixels in the low grayscale region within the hole with the total number of pixels; obtain the number of pixels in the background region of the cast iron surface by comparing the total number of pixels with the number of pixels in the low grayscale region within the hole, and obtain the percentage of pixels in the background region of the cast iron surface by comparing the number of pixels in the background region of the cast iron surface with the total number of pixels; obtain the grayscale mean of the low grayscale region within the hole by combining the cumulative sum of grayscale values ​​of all pixels in the low grayscale region within the hole with the number of pixels in the low grayscale region within the hole; obtain the grayscale mean of the background region of the cast iron surface by combining the cumulative sum of grayscale values ​​of all pixels in the denoised grayscale image, the cumulative sum of grayscale values ​​of all pixels in the low grayscale region within the hole, and the number of pixels in the background region of the cast iron surface; obtain the inter-class variance by combining the percentage of pixels in the low grayscale region within the hole, the percentage of pixels in the background region of the cast iron surface, and the difference between the grayscale mean of the low grayscale region within the hole and the grayscale mean of the background region of the cast iron surface.

[0063] For example, the inter-class variance corresponding to the candidate segmentation threshold is obtained by using the proportion of pixels in the low grayscale region inside the hole, the proportion of pixels in the background region on the cast iron surface, and the mean grayscale values ​​of the low grayscale region inside the hole and the background region on the cast iron surface. The total number of pixels in the denoised grayscale image is then obtained. Before iterating through the candidate segmentation thresholds, calculate the total cumulative sum of all pixel grayscale values ​​in the image at once. This is used to calculate the average background grayscale value under each candidate threshold, avoiding repeated scanning of the entire image in each step.

[0064] For each candidate segmentation threshold ( ), with candidate segmentation threshold To count the number of pixels in the low grayscale region within the aperture. The number of pixels in the low grayscale region within the aperture With the total number of pixels The percentage of pixels in the low grayscale region within the aperture is obtained: ; like Skip the candidate threshold (no pixels inside the hole, inter-class variance is meaningless).

[0065] By total number of pixels The number of pixels in the low grayscale area within the aperture The number of pixels in the background area of ​​the cast iron surface is obtained. The number of pixels in the background area of ​​the cast iron surface With the total number of pixels The percentage of pixels in the background area of ​​the cast iron surface is obtained: ; like Skip the candidate threshold. Satisfy the condition. .

[0066] The sum of the gray values ​​of all pixels in the low gray area within the hole (in traversal) Accumulate gradually over time: , (The computational cost per step is constant) and the number of pixels in the low grayscale region within the aperture. The average grayscale value of the low-grayscale area within the hole is obtained: ; The sum of the gray values ​​of all pixels in the denoised grayscale image The cumulative sum of gray values ​​of all pixels in the low gray area within the aperture. and the number of pixels in the background area of ​​the cast iron surface. The average grayscale value of the background area on the cast iron surface is obtained: ; The proportion of pixels in the low gray area within the aperture. Percentage of pixels in the background area of ​​cast iron surface and the average gray level of the low gray level area inside the hole Average grayscale value of the background area on the cast iron surface The difference between the values ​​is used to obtain the candidate segmentation threshold. Corresponding inter-class variance : ; Taking this model of cylinder head as an example, in At that time: the area of ​​the through hole between the two exhaust ports was approximately Pixels , Background area , Mean gray value inside the hole average grayscale value of the background Between-class variance It reaches its maximum among all candidate thresholds, therefore .

[0067] Furthermore, the method for obtaining the local threshold of each sampling point by comparing the estimated local background grayscale value of each sampling point with the pre-calibrated upper bound of the crack grayscale includes: For each sampling point between the edge of the first exhaust port and the edge of the second exhaust port, the local threshold of the sampling point is obtained by averaging the local background grayscale estimate of the sampling point with the pre-calibrated upper limit of crack grayscale. It is then determined whether the difference between the local background grayscale estimate of the sampling point and the pre-calibrated upper limit of crack grayscale is less than a pre-set minimum grayscale discrimination. When the difference between the background and the upper limit of crack is less than the pre-set minimum grayscale discrimination, the adjusted local threshold is obtained by combining the pre-calibrated upper limit of crack grayscale and the pre-set minimum grayscale discrimination. The adjusted local threshold replaces the local threshold of the sampling point, and the sampling point is marked as a low-contrast region in the detection output. The pre-calibrated upper limit of crack grayscale is obtained by establishing a frequency distribution of the denoised grayscale values ​​of all pixels in the known crack area in the cylinder head contact surface image of the same model of engine, taking the grayscale value corresponding to the cumulative frequency reaching a preset percentile, and directly calling it in the batch detection of the same model of cylinder head.

[0068] For example, the local background grayscale values ​​at each sampling point are estimated. Compared with the pre-defined upper limit of crack grayscale Obtain the local threshold of each sampling point For each sampling point between the edge of the first exhaust port and the edge of the second exhaust port. ( ), through the local background grayscale estimation value of the sampling points Compared with the pre-defined upper limit of crack grayscale Calculate the mean to obtain the local threshold of the sampling point. : ; Determine the local background grayscale estimate of the sampling point Compared with the pre-defined upper limit of crack grayscale Difference between background and upper boundary of crack Is it less than the preset minimum grayscale discrimination? Difference between background and upper boundary of crack This measures the degree of distinguishability between the background grayscale and the upper bound of the crack grayscale at the current sampling point location: The larger the value, the greater the grayscale difference between the background and the crack, and the higher the reliability of the mean threshold segmentation. This indicates that the difference between the upper bound of the background grayscale and the crack grayscale is too small, and the mean threshold falling between the two has insufficient distinguishing margin. With only one gray level, the reliability of segmentation determination decreases.

[0069] Taking this model of cylinder head as an example, , ;when (When located at the edge step of the first exhaust port) , This triggers low contrast processing.

[0070] When the difference between the background and the upper boundary of the crack is At that time, the upper limit of the crack grayscale was determined by the pre-defined parameters. Compared with the preset minimum grayscale distinction The adjusted local thresholds are obtained together, and the adjusted local thresholds are used to replace the local thresholds of the sampling points. : ; The sampling point location is marked as a low-contrast area in the test output, and the image coordinates of the sampling point and the corresponding physical location of the bridge area are recorded in the test report and transmitted to the manual review station. Taking this model of cylinder head as an example, The sampling point that triggers low contrast adjustment is: ( ), ( , ), ( , All of them are located at the edge of the step immediately adjacent to the exhaust port.

[0071] Adjusted local threshold The meaning is: grayscale value is lower than Pixels deep within the crack are still classified as foreground ( (No one is missed); shallow cracks or edge transition pixels with gray values ​​between 75 and 79 (which almost overlap with the background gray value of 79) are marked as low contrast areas, prompting manual confirmation rather than being forcibly determined as foreground or background.

[0072] Predefined upper limit of crack grayscale The frequency distribution is established by denoising the gray values ​​of all pixels in the known crack area in the cylinder head contact surface image of the same model engine, and the gray value corresponding to the cumulative frequency reaching the preset percentile is obtained, and then directly called in the batch detection of the same model cylinder head. Minimum grayscale discrimination For this cylinder head model (HT250, this optical configuration), the physical meaning, determined through experiments and statistical analysis, is the grayscale difference threshold for low contrast judgment, with a recommended range of 5 to 15. The specific value depends on the grayscale quantitative noise level of the image sensor under this configuration (the lower the signal-to-noise ratio, the lower the grayscale difference threshold). (Should be increased appropriately). If If the value is too large (e.g., exceeding 15), the difference between the background grayscale and the crack grayscale will trigger low contrast adjustment in many sampling points in the normal middle part of the bridge of the nose (difference of about 20 to 40), resulting in too many areas being marked as low contrast regions and the actual segmentation degrading to close to the fixed threshold. This mode loses the meaning of position adaptation.

[0073] Furthermore, the pre-calibrated upper bound of the crack grayscale is obtained by establishing a frequency distribution of the denoised grayscale values ​​of all pixels within a known crack area in the cylinder head contact surface image of the same model engine, and taking the grayscale value corresponding to the cumulative frequency reaching a preset percentile. The method includes: Acquire the contact surface image of a known crack sample cylinder head of the same model as the engine cylinder head to be inspected, and perform preprocessing on the contact surface image to obtain a sample denoised grayscale image; determine the pixel range of the known crack area in the sample denoised grayscale image by magnetic particle inspection or manual annotation; extract the denoised grayscale values ​​of all pixels in the known crack area, and establish a crack pixel grayscale frequency distribution according to the denoised grayscale values ​​of all pixels in the known crack area from smallest to largest; starting from the minimum grayscale value of the crack pixel grayscale frequency distribution, the frequencies corresponding to each grayscale level are accumulated to form a cumulative frequency. When the cumulative frequency first reaches the preset percentile, the grayscale value of the current grayscale level is taken as the upper limit of the crack grayscale.

[0074] For example, the pre-defined upper bound of crack grayscale A frequency distribution is established by denoising the grayscale values ​​of all pixels within a known crack area in the contact surface image of the cylinder head of the same model. The grayscale value corresponding to the cumulative frequency reaching a preset percentile is obtained and directly used in the batch inspection of cylinder heads of the same model. Contact surface images of cylinder heads with known cracks of the same model (6DL type, HT250 material) as the cylinder head to be inspected are acquired. A total of 12 sample cylinder heads are obtained from different service mileages (100,000 to 300,000 kilometers) and different damage degrees (crack lengths of 5 mm to 20 mm). The contact surface images are preprocessed, and the preprocessing steps are the same as those for the cylinder heads to be inspected in this inspection method (grayscale conversion, piecewise linear grayscale stretching, adaptive median filtering, with consistent parameters), to obtain the denoised grayscale images of the samples. .

[0075] Magnetic particle inspection was used in the denoised grayscale image of the sample. The pixel range of the known crack region is determined to form a crack region mask. ,in Represents the pixels of the crack area. This represents pixels in the non-crack area. The magnetic particle inspection process involves placing the sample cylinder head in a magnetic field and applying ferromagnetic powder. The powder accumulates at the crack due to magnetic field leakage. The image is then observed using a UV lamp, and the crack outline is manually delineated on the image. Pixels within the delineated area are marked as... The accuracy is approximately 0.1 mm (about 2 pixels). Manual annotation is also possible: with the assistance of magnetic particle inspection results, the operator directly outlines the crack contour on the corresponding image, forming... Both methods can obtain pixel-level masks of the crack area. The sample cylinder head with completed magnetic particle inspection marking is placed back at the image acquisition station, and images are re-acquired under the same lighting and camera configuration as in the preprocessing. The crack outline displayed by the magnetic particle is then manually delineated on the image, thus forming... .

[0076] Extract the denoised grayscale values ​​of all pixels within the known crack area, and summarize the grayscale values ​​of the crack area pixels of all 12 sample cylinder heads. All pixels (Value), establish a frequency distribution of the denoised grayscale values ​​of all pixels in ascending order of grayscale value. ( ),in grayscale value The relative frequency of the crack pixels in all known crack pixels satisfies .

[0077] From the minimum gray value of the frequency distribution ( Starting from this point, the frequencies corresponding to each gray level are sequentially accumulated to form the cumulative frequency. When the cumulative frequency First time reaching the preset percentile (Recommended value expressed as a percentage) When the current gray level is at the 95th percentile (i.e., the 95th percentile), the gray level will be... The grayscale value is used as the upper bound of the crack grayscale. .

[0078] Taking this model of cylinder head as an example: the grayscale of the crack pixels is concentrated between 20 and 75. ,therefore The reason for using the 95th percentile instead of the 100th percentile is that a small number of pixels (approximately 5%) within the crack area have excessively high grayscale values ​​(80 to 90) due to localized specular reflection (specular reflection points on the steps at the edge of the vent) or image acquisition noise. Using the 100th percentile would... These few abnormal pixels were pulled up to the background grayscale range, causing the upper bound of the crack grayscale to be too high in subsequent steps, thus affecting the mean threshold. High percentile, leading to an increased false negative rate. Preset percentile. The recommended range is 0.90 to 0.98, and the specific value is determined by the statistical results of calibration data of the same model cylinder head.

[0079] The upper limit of the grayscale of the crack The stored data can be directly retrieved during batch testing of cylinder heads of the same model (6DL type, HT250 material, same optical configuration) without requiring recalibration for each piece. When the cylinder head material grade is changed, the batch difference in the casting process exceeds the statistical error range, or the parameters of the image acquisition equipment (object distance, light source type, camera model) change, the calibration must be re-executed according to the above procedure.

[0080] Furthermore, the method for denoising a binary image and extracting a skeleton image includes: A morphological erosion operation is performed on the binary image. A square structuring element with three pixels in each row and column is scanned position by position on the binary image. When all pixels within the coverage area of ​​the square structuring element are crack foreground pixels, the position is retained as a crack foreground pixel; otherwise, the position is set as a background pixel. After completing the above scan on all positions in the binary image, an eroded binary image is obtained. A morphological dilation operation is then performed on the eroded binary image using the same square structuring element. When at least one crack foreground pixel exists within the coverage area of ​​the square structuring element, the position is restored to a crack foreground pixel. After completing the above scan on all positions in the eroded binary image, a denoised binary image is obtained. For the denoised... After denoising, the binary image undergoes skeleton thinning. In each iteration, all crack foreground pixels in the denoising binary image are scanned. For each crack foreground pixel, it is determined whether it meets one of the following two retention conditions: First, after deleting the crack foreground pixel, the connectivity between adjacent crack foreground pixels is broken; Second, the crack foreground pixel is located on the backbone path of the crack foreground region and the backbone path length is shortened after deletion. Crack foreground pixels that do not meet the above two retention conditions are set as background pixels. The above iteration process is repeated until all crack foreground pixels are not set as background pixels in a certain iteration. The binary image at the time of stopping is used as the skeleton image.

[0081] Binary image The specific steps for denoising and extracting the skeleton image are: [The text abruptly ends here, likely due to an incomplete sentence or a formatting error.] Perform morphological erosion on the binary image, creating a 3x3 square (9 pixels total, anchored at the center) with three pixels in each row and column. Scan position by position. For each position... Determine the coverage area of ​​the square structural element (in terms of...) Are all pixels within a 3×3 neighborhood centered on the crack (a total of 9 pixels) considered as foreground pixels (with a value of 1)? If all pixels are 1, then the specified location is... In the erosion result, pixels that are retained as crack foreground pixels (set to 1) are used; otherwise, these locations are set as background pixels (set to 0). Pixels located at the image edges with a 3×3 neighborhood that exceed the image range are filled with background pixel values ​​of 0. The binary image is then... After completing the above scanning at all locations, a binary image after erosion is obtained. The erosion operation eliminates isolated foreground noise points with an area of ​​no more than about 4 pixels, while shrinking the edges of connected crack segments by about 1 pixel each.

[0082] Next, the binary image after erosion was analyzed. Perform morphological dilation operation using the same 3×3 square structuring element. For each position... Determine whether at least one crack foreground pixel (value 1) exists within the coverage area of ​​the square structuring element (all 9 pixels in a 3×3 neighborhood): if it exists, restore the location to a crack foreground pixel (set to 1); otherwise, keep the background pixel (set to 0). Then, process the eroded binary image... After completing the above scanning at all locations, a denoised binary image is obtained. Corrosion is followed by expansion. Isolated foreground noise points with an area smaller than 3×3 structural elements are eliminated, and the geometry and connectivity of larger crack segment regions are basically restored, with no net change in segment width.

[0083] For example, if an isolated noise point has an area of ​​2 pixels, during erosion, its 3×3 neighborhood contains background pixels, failing to meet the all-1 condition, and the noise point is set as background after erosion. During dilation, there are no foreground pixels in the 3×3 neighborhood of the noise point (already eliminated by erosion), so it is not restored, and the noise point is ultimately eliminated. A crack segment approximately 3 pixels wide retains its central 1 pixel after erosion, and after dilation, it is restored to a segment approximately 3 pixels wide, with its geometry remaining largely unchanged. The selection criteria for the 3×3 square structural element are: the typical area of ​​isolated noise points in the cylinder head image of this model is 1 to 3 pixels, and the crack segment width is approximately 2 to 4 pixels. The 3×3 structural element can reliably eliminate the former without damaging the latter.

[0084] Finally, the denoised binary image Perform skeleton refinement, scanning all crack foreground pixels in the denoised binary image in each iteration, and refining each crack foreground pixel. Determine whether it meets one of the following two retention conditions: Retention Condition 1: After deleting the crack foreground pixel, the connectivity between adjacent crack foreground pixels in the 8-connectivity sense is broken, i.e., deletion... The crack foreground pixel in its 8-connected neighborhood is then split into two or more unconnected 8-connected components.

[0085] Condition 2 for retention: The crack foreground pixel is located on the backbone path of the crack foreground region, and the backbone path length is shortened after deletion. Specific determination method: If... The number of foreground pixels with cracks in an 8-connected neighborhood does not exceed 1 (i.e. If the endpoint is a skeleton endpoint, then deleting it will reduce the skeleton length, satisfying retention condition two. In this detection method, "skeleton path" refers to the connected chain of skeleton foreground pixels. The skeleton path length refers to the number of skeleton pixels traversed from one endpoint to another. When there are no other foreground pixels (isolated points) or only one other foreground pixel (endpoint) in the 8-connected neighborhood of a foreground pixel, deleting that pixel will cause the skeleton skeleton path to decrease by that pixel, satisfying retention condition two, thereby preventing the endpoint from being excessively shrunk.

[0086] Crack foreground pixels that do not meet any of the above retention conditions are set as background pixels (value 0) in this iteration. The above iteration process is repeated until all crack foreground pixels are no longer set as background pixels in a given iteration. The iteration is then stopped, and the binary image at the point of stopping is used as the skeleton image. .

[0087] Skeleton image The following conditions must be met: the width of the foreground pixels does not exceed 1 pixel; the foreground pixels are continuously distributed along the central axis of the crack; and the total length of the skeleton lines is approximately equal to the pixel projection length of the crack. Taking this type of cylinder head as an example, skeleton refinement typically converges within 5 to 15 iterations, with a single-piece computation time of approximately 5 to 20 milliseconds.

[0088] Furthermore, the method for obtaining the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels of the skeleton by performing chain code statistics on the skeleton image; and obtaining the skeleton pixel length through the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels of the skeleton includes: The process involves sequentially traversing all skeleton pixels in the skeleton image along the crack extension direction, and determining the spatial relationship of each pair of adjacent skeleton pixels: if adjacent skeleton pixels change only in either row or column coordinates, the adjacent pairs satisfying this condition are accumulated as the number of unidirectional adjacent pixels; if adjacent skeleton pixels change in both row and column coordinates, the adjacent pairs satisfying this condition are accumulated as the number of bidirectional adjacent pixels. After traversing all pairs of adjacent skeleton pixels, the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels are obtained respectively. The unidirectional cumulative skeleton length is obtained by using the number of unidirectional adjacent pixels and the unit pixel spacing; the diagonal pixel spacing is obtained by using the unit pixel spacing and the Pythagorean theorem; the bidirectional cumulative skeleton length is obtained by using the number of bidirectional adjacent pixels and the diagonal pixel spacing; and the skeleton pixel length is obtained by using the unidirectional cumulative skeleton length and the bidirectional cumulative skeleton length.

[0089] skeleton image Chain code statistics are performed to obtain the number of unidirectional adjacent pixels of the skeleton. Number of bidirectional adjacent pixels and skeleton ,pass and Get the skeleton pixel length For skeleton images All skeleton pixels in The pixels are traversed sequentially along the crack extension direction. Traversal method: The skeleton image is scanned in ascending row and column order, and each skeleton pixel is processed sequentially. Check its right side in turn. Bottom right , directly below Bottom left To determine if pixels in each of the four directions are skeleton pixels, count each pair of adjacent skeleton pixels only once (checking in all four directions to avoid duplicate counting). For each pair of adjacent skeleton pixels, determine their spatial relationship: If adjacent skeleton pixels change only in one of their row or column coordinates (i.e., the row coordinate difference is 0 and the column coordinate difference is 1, or the row coordinate difference is 1 and the column coordinate difference is 0, meaning the two pixels are horizontally or vertically adjacent), then the adjacent pairs that satisfy the above conditions will be accumulated as the number of unidirectional adjacent pixels in the skeleton. , Add 1.

[0090] If adjacent skeleton pixels change in both row and column coordinates (i.e., the row coordinate difference is 1 and the column coordinate difference is 1, and the two pixels are adjacent in the diagonal direction), then the adjacent pairs that satisfy the above conditions are accumulated as the number of bidirectional adjacent pixels in the skeleton. , Add 1.

[0091] After traversing all adjacent skeleton pixel pairs, the number of unidirectional adjacent pixels of the skeleton is obtained. Number of bidirectional adjacent pixels and skeleton By counting the number of adjacent pixels in one direction along the skeleton. The unidirectional cumulative skeleton length is obtained by dividing the unit pixel spacing (the coordinate difference between two adjacent pixels in the horizontal or vertical direction, which is always 1 pixel). : ; The diagonal pixel spacing is obtained by using the Pythagorean theorem from the unit pixel spacing. (Euclidean distance between two pixels whose row coordinates differ by 1 and whose column coordinates differ by 1): ; By the number of bidirectional adjacent pixels in the skeleton Diagonal pixel spacing Obtain the bidirectional cumulative skeleton length : ; Stroke length accumulated unidirectionally With bidirectional cumulative skeleton length Get the skeleton pixel length : ; Taking a specific example of this cylinder head model: after traversing the skeleton image, we obtain... , : ; Skeleton pixel length The calculation essentially means: if the skeleton lines are completely horizontal or completely vertical ( ),but This is equal to the number of adjacent skeleton pixel pairs, i.e., the skeleton pixel span. If the skeleton line has a diagonally extended portion, the actual Euclidean distance between diagonally adjacent pixel pairs is... Pixels, counting directly as a logarithm of pixels will underestimate by about 29% (because) ), by separately accounting and get The error does not exceed 5% of the actual Euclidean length of the skeleton, which meets the accuracy requirements for crack length in this detection scenario.

[0092] Skeleton pixel length Input multiplied by camera correction factor Obtain the actual crack defect length Defect detection was completed. The CCD camera pixels used have the same physical size in both the horizontal and vertical directions (4.4 micrometers), therefore the camera correction factor... Isotropic, the Euclidean length of the skeleton pixels can be directly multiplied by The actual physical length is obtained without distinguishing the direction.

[0093] In conclusion, the technical solutions listed in the above embodiments are presented in their entirety: In the nose area of ​​the un-cleaned gray cast iron cylinder head's contact surface, the background grayscale gradient direction is determined by connecting the centers of the two exhaust holes. Sampling is performed along the connecting line, and the maximum grayscale value of the vertical strip is taken to estimate the local background. Then, a piecewise linear threshold function that continuously changes along the connecting line of the hole centers is generated by combining the upper limit of the grayscale of the crack in the same type of cylinder head. This function is used for crack segmentation and length measurement, thereby improving the accuracy of crack identification.

[0094] Example 2: Based on the same inventive concept, such as Figure 2 As shown, this embodiment also provides an engine cylinder head defect detection system, the system comprising: The image acquisition module is used to acquire an image of the engine cylinder head contact surface and preprocess it to obtain a denoised grayscale image. The denoised grayscale image is segmented to extract the edge contour pixel sets of the first exhaust hole and the second exhaust hole respectively. The edge contour pixel sets of the first exhaust hole and the second exhaust hole are respectively fitted with least squares circles to obtain the center pixel coordinates of the first exhaust hole and the center pixel coordinates of the second exhaust hole. The unit vector of the direction of the line connecting the centers of the two holes and the pixel length of the line connecting the centers of the two holes are obtained from the center pixel coordinates of the first exhaust hole and the center pixel coordinates of the second exhaust hole. The threshold calculation module is used to take multiple equally spaced sampling points along the line connecting the centers of the two exhaust holes between the edges of the first and second exhaust holes; at each sampling point, a local strip of a preset width is taken along the line perpendicular to the line connecting the centers of the two holes, and the maximum value of the denoised grayscale values ​​of all pixels in the local strip is taken as the local background grayscale estimate of the sampling point; the local threshold of each sampling point is obtained by comparing the local background grayscale estimate of each sampling point with the pre-calibrated upper bound of the crack grayscale; and linear interpolation is performed between adjacent sampling points using the local threshold of each sampling point and the position coordinates of each sampling point along the line connecting the centers of the two holes to obtain a piecewise linear threshold function with the position coordinates along the line connecting the centers of the two holes as the independent variable. The defect detection module is used to obtain the position coordinates of each target pixel in the region between the edge of the first exhaust hole and the edge of the second exhaust hole by projecting the difference vector between the target pixel coordinates and the center pixel coordinates of the first exhaust hole onto a unit vector along the line connecting the centers of the two holes; obtain the position adaptive threshold corresponding to the target pixel according to a piecewise linear threshold function; mark the target pixels whose denoised grayscale values ​​do not exceed the position adaptive threshold as crack foreground pixels and the remaining pixels as background pixels to obtain a binary image; denoise the binary image and extract the skeleton image; perform chain code statistics on the skeleton image to obtain the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels; obtain the skeleton pixel length using the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels; and obtain the actual crack defect length using the skeleton pixel length and a pre-calibrated camera correction factor.

[0095] It should be noted that the specific methods by which each module performs operations in the system described in the above embodiments have been described in detail in the embodiments related to the method, and will not be elaborated here.

[0096] Finally, it should be noted that although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for detecting defects in an engine cylinder head, characterized in that, The method includes: An image of the engine cylinder head contact surface is acquired and preprocessed to obtain a denoised grayscale image. The denoised grayscale image is then segmented to extract the edge contour pixel sets of the first and second exhaust holes. The edge contour pixel sets of the first and second exhaust holes are then fitted with least-squares circles to obtain the center pixel coordinates of the first and second exhaust holes. The unit vector of the line connecting the centers of the two holes and the pixel length of the line connecting the centers of the two holes are obtained from the center pixel coordinates of the first and second exhaust holes. Multiple equally spaced sampling points are taken between the edges of the first and second exhaust holes along the line connecting the centers of the two holes. At each sampling point, a local strip of a preset width is taken along the line perpendicular to the line connecting the centers of the two holes. The maximum value of the denoised grayscale values ​​of all pixels within the local strip is taken as the local background grayscale estimate of the sampling point. The local threshold of each sampling point is obtained by comparing the local background grayscale estimate with the pre-calibrated upper bound of the crack grayscale. Linear interpolation is performed between adjacent sampling points using the local threshold of each sampling point and the position coordinates of each sampling point along the line connecting the centers of the two holes to obtain a piecewise linear threshold function with the position coordinates along the line connecting the centers of the two holes as the independent variable. For each target pixel within the region between the edges of the first and second exhaust holes, the position coordinates of the target pixel in the direction of the line connecting the centers of the two holes are obtained by projecting the difference vector between the target pixel coordinates and the coordinates of the center pixel of the first exhaust hole onto a unit vector. An adaptive position threshold is then obtained for each target pixel using a piecewise linear threshold function. Target pixels with denoised grayscale values ​​not exceeding the adaptive position threshold are marked as crack foreground pixels, and the remaining pixels are marked as background pixels, resulting in a binary image. The binary image is then denoised, and a skeleton image is extracted. Chain code statistics are performed on the skeleton image to obtain the number of unidirectional and bidirectional adjacent pixels. The skeleton pixel length is obtained using these numbers. Finally, the actual crack defect length is obtained using the skeleton pixel length and a pre-calibrated camera correction factor.

2. The method for detecting defects in an engine cylinder head according to claim 1, characterized in that, The method for obtaining a denoised grayscale image through preprocessing includes: The engine cylinder head contact surface image is converted into a single-channel grayscale image. The single-channel grayscale image is then subjected to piecewise linear grayscale stretching to obtain a contrast-enhanced image. For each pixel to be processed in the contrast-enhanced image, a rectangular filtering window is taken, centered on the pixel and starting from a preset minimum window size. The minimum, maximum, and median grayscale values ​​of all pixels within the rectangular filtering window are obtained. When the median grayscale value falls between the minimum and maximum grayscale values, it is determined whether the pixel's own grayscale value falls between these two values. If it does, the pixel's own grayscale value is retained as the filtering output; otherwise, the median grayscale value is used as the filtering output, and the expansion of the rectangular filtering window for the pixel is stopped. When the median grayscale value does not fall between the minimum and maximum grayscale values, the rectangular filtering window is expanded by a preset step size until the window size reaches a preset maximum window size. The median grayscale value corresponding to the preset maximum window size is then used as the filtering output. After completing the above filtering output for all pixels to be processed in the contrast-enhanced image, a denoised grayscale image is obtained.

3. The method for detecting defects in an engine cylinder head according to claim 2, characterized in that, The method for performing piecewise linear grayscale stretching on a single-channel grayscale image to obtain a contrast-enhanced image includes: Pixels in a single-channel grayscale image whose grayscale values ​​do not exceed a pre-defined upper bound of crack grayscale are defined as crack grayscale segment pixels. A first stretching coefficient is obtained by combining the pre-defined upper bound of crack grayscale with a pre-set upper limit of the output low grayscale segment. The output grayscale value of the corresponding pixel in the contrast-enhanced image is obtained by combining the grayscale value of the crack grayscale segment pixel with the first stretching coefficient. Pixels in a single-channel grayscale image whose grayscale values ​​exceed the pre-defined upper bound of crack grayscale are defined as background grayscale segment pixels. The background grayscale range is obtained by combining a pre-set upper limit of the background grayscale range with a pre-defined upper bound of crack grayscale. The length of the high grayscale segment is obtained by using the pre-set upper limit and lower limit of the high grayscale segment. The second stretching coefficient is obtained by using the length of the background grayscale range and the length of the high grayscale segment. The output grayscale value of the corresponding pixel in the contrast-enhanced image is obtained by using the grayscale value of the background grayscale segment pixel, the background grayscale offset of the pre-calibrated upper limit of the crack grayscale, the second stretching coefficient, and the pre-set lower limit of the high grayscale segment. The pre-set upper limit of the low grayscale segment and the pre-set lower limit of the high grayscale segment are adjacent and cover the entire output grayscale range.

4. The method for detecting defects in an engine cylinder head according to claim 1, characterized in that, The method for extracting the edge contour pixel sets of the first and second exhaust holes from the denoised grayscale image by segmentation includes: A gray-level frequency histogram is constructed for the gray-level values ​​of all pixels in the denoised gray-level image. All gray levels in the histogram are iterated through, with each gray level serving as a candidate segmentation threshold. Pixels with gray values ​​not exceeding the candidate segmentation threshold are designated as low-gray-level regions within the hole, while pixels with gray values ​​exceeding the candidate segmentation threshold are designated as background regions on the cast iron surface. The inter-class variance corresponding to the candidate segmentation threshold is obtained by using the proportion of pixels in the low-gray-level regions within the hole, the proportion of pixels in the background regions on the cast iron surface, and the mean gray values ​​of these regions. After iterating through all candidate segmentation thresholds, the candidate segmentation threshold that maximizes the inter-class variance is selected. As a segmentation threshold, the denoised grayscale image is binarized to obtain a binary image of the hole region. Pixels belonging to the low grayscale region within the hole in the binary image of the hole region are labeled as connected regions according to the four-connected adjacency relationship. All connected regions are sorted from largest to smallest in terms of pixel count, and the two connected regions with the largest number of pixels are selected as the first vent hole region and the second vent hole region, respectively. The set of pixels directly adjacent to the background region of the cast iron surface in the first vent hole region is extracted as the first vent hole edge contour pixel set, and the set of pixels directly adjacent to the background region of the cast iron surface in the second vent hole region is extracted as the second vent hole edge contour pixel set.

5. The method for detecting defects in an engine cylinder head according to claim 4, characterized in that, The method for obtaining the inter-class variance corresponding to the candidate segmentation threshold by the proportion of pixels in the low grayscale region inside the hole, the proportion of pixels in the background region on the cast iron surface, and the mean grayscale values ​​of the low grayscale region inside the hole and the background region on the cast iron surface includes: Obtain the total number of pixels in the denoised grayscale image; count the number of pixels in the low grayscale region within the hole, using the candidate segmentation threshold as the boundary, and obtain the percentage of pixels in the low grayscale region within the hole by comparing the number of pixels in the low grayscale region within the hole with the total number of pixels; obtain the number of pixels in the background region of the cast iron surface by comparing the total number of pixels with the number of pixels in the low grayscale region within the hole, and obtain the percentage of pixels in the background region of the cast iron surface by comparing the number of pixels in the background region of the cast iron surface with the total number of pixels; obtain the grayscale mean of the low grayscale region within the hole by combining the cumulative sum of grayscale values ​​of all pixels in the low grayscale region within the hole with the number of pixels in the low grayscale region within the hole; obtain the grayscale mean of the background region of the cast iron surface by combining the cumulative sum of grayscale values ​​of all pixels in the denoised grayscale image, the cumulative sum of grayscale values ​​of all pixels in the low grayscale region within the hole, and the number of pixels in the background region of the cast iron surface; obtain the inter-class variance by combining the percentage of pixels in the low grayscale region within the hole, the percentage of pixels in the background region of the cast iron surface, and the difference between the grayscale mean of the low grayscale region within the hole and the grayscale mean of the background region of the cast iron surface.

6. The method for detecting defects in an engine cylinder head according to claim 1, characterized in that, The method for obtaining the local threshold of each sampling point by comparing the estimated local background grayscale value of each sampling point with the pre-calibrated upper bound of the crack grayscale includes: For each sampling point between the edge of the first exhaust port and the edge of the second exhaust port, the local threshold of the sampling point is obtained by averaging the local background grayscale estimate of the sampling point with the pre-calibrated upper limit of crack grayscale. It is then determined whether the difference between the local background grayscale estimate of the sampling point and the pre-calibrated upper limit of crack grayscale is less than a pre-set minimum grayscale discrimination. When the difference between the background and the upper limit of crack is less than the pre-set minimum grayscale discrimination, the adjusted local threshold is obtained by combining the pre-calibrated upper limit of crack grayscale and the pre-set minimum grayscale discrimination. The adjusted local threshold replaces the local threshold of the sampling point, and the sampling point is marked as a low-contrast region in the detection output. The pre-calibrated upper limit of crack grayscale is obtained by establishing a frequency distribution of the denoised grayscale values ​​of all pixels in the known crack area in the cylinder head contact surface image of the same model of engine, taking the grayscale value corresponding to the cumulative frequency reaching a preset percentile, and directly calling it in the batch detection of the same model of cylinder head.

7. The method for detecting defects in an engine cylinder head according to claim 6, characterized in that, The pre-calibrated upper bound of crack grayscale is obtained by establishing a frequency distribution of the denoised grayscale values ​​of all pixels within a known crack area in an image of the cylinder head contact surface of the same engine model, and taking the grayscale value corresponding to the cumulative frequency reaching a preset percentile. The method includes: Acquire the contact surface image of a known crack sample cylinder head of the same model as the engine cylinder head to be inspected, and perform preprocessing on the contact surface image to obtain a sample denoised grayscale image; determine the pixel range of the known crack area in the sample denoised grayscale image by magnetic particle inspection or manual annotation; extract the denoised grayscale values ​​of all pixels in the known crack area, and establish a crack pixel grayscale frequency distribution according to the denoised grayscale values ​​of all pixels in the known crack area from smallest to largest; starting from the minimum grayscale value of the crack pixel grayscale frequency distribution, the frequencies corresponding to each grayscale level are accumulated to form a cumulative frequency. When the cumulative frequency first reaches the preset percentile, the grayscale value of the current grayscale level is taken as the upper limit of the crack grayscale.

8. The method for detecting defects in an engine cylinder head according to claim 1, characterized in that, The method for denoising a binary image and extracting a skeleton image includes: A morphological erosion operation is performed on the binary image. A square structuring element with three pixels in each row and column is scanned position by position on the binary image. When all pixels within the coverage area of ​​the square structuring element are crack foreground pixels, the position is retained as a crack foreground pixel; otherwise, the position is set as a background pixel. After completing the above scan on all positions in the binary image, an eroded binary image is obtained. A morphological dilation operation is then performed on the eroded binary image using the same square structuring element. When at least one crack foreground pixel exists within the coverage area of ​​the square structuring element, the position is restored to a crack foreground pixel. After completing the above scan on all positions in the eroded binary image, a denoised binary image is obtained. For the denoised... After denoising, the binary image undergoes skeleton thinning. In each iteration, all crack foreground pixels in the denoising binary image are scanned. For each crack foreground pixel, it is determined whether it meets one of the following two retention conditions: First, after deleting the crack foreground pixel, the connectivity between adjacent crack foreground pixels is broken; Second, the crack foreground pixel is located on the backbone path of the crack foreground region and the backbone path length is shortened after deletion. Crack foreground pixels that do not meet the above two retention conditions are set as background pixels. The above iteration process is repeated until all crack foreground pixels are not set as background pixels in a certain iteration. The binary image at the time of stopping is used as the skeleton image.

9. The method for detecting defects in an engine cylinder head according to claim 8, characterized in that, The method for obtaining the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels in the skeleton by performing chain code statistics on the skeleton image, and obtaining the skeleton pixel length using the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels, includes: The process involves sequentially traversing all skeleton pixels in the skeleton image along the crack extension direction, and determining the spatial relationship of each pair of adjacent skeleton pixels: if adjacent skeleton pixels change only in either row or column coordinates, the adjacent pairs satisfying this condition are accumulated as the number of unidirectional adjacent pixels; if adjacent skeleton pixels change in both row and column coordinates, the adjacent pairs satisfying this condition are accumulated as the number of bidirectional adjacent pixels. After traversing all pairs of adjacent skeleton pixels, the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels are obtained respectively. The unidirectional cumulative skeleton length is obtained by using the number of unidirectional adjacent pixels and the unit pixel spacing; the diagonal pixel spacing is obtained by using the unit pixel spacing and the Pythagorean theorem; the bidirectional cumulative skeleton length is obtained by using the number of bidirectional adjacent pixels and the diagonal pixel spacing; and the skeleton pixel length is obtained by using the unidirectional cumulative skeleton length and the bidirectional cumulative skeleton length.

10. An engine cylinder head defect detection system, characterized in that, The system includes: The image acquisition module is used to acquire an image of the engine cylinder head contact surface and preprocess it to obtain a denoised grayscale image. The denoised grayscale image is segmented to extract the edge contour pixel sets of the first exhaust hole and the second exhaust hole respectively. The edge contour pixel sets of the first exhaust hole and the second exhaust hole are respectively fitted with least squares circles to obtain the center pixel coordinates of the first exhaust hole and the center pixel coordinates of the second exhaust hole. The unit vector of the direction of the line connecting the centers of the two holes and the pixel length of the line connecting the centers of the two holes are obtained from the center pixel coordinates of the first exhaust hole and the center pixel coordinates of the second exhaust hole. The threshold calculation module is used to take multiple equally spaced sampling points along the line connecting the centers of the two exhaust holes between the edges of the first and second exhaust holes; at each sampling point, a local strip of a preset width is taken along the line perpendicular to the line connecting the centers of the two holes, and the maximum value of the denoised grayscale values ​​of all pixels in the local strip is taken as the local background grayscale estimate of the sampling point; the local threshold of each sampling point is obtained by comparing the local background grayscale estimate of each sampling point with the pre-calibrated upper bound of the crack grayscale; and linear interpolation is performed between adjacent sampling points using the local threshold of each sampling point and the position coordinates of each sampling point along the line connecting the centers of the two holes to obtain a piecewise linear threshold function with the position coordinates along the line connecting the centers of the two holes as the independent variable. The defect detection module is used to obtain the position coordinates of each target pixel in the region between the edge of the first exhaust hole and the edge of the second exhaust hole by projecting the difference vector between the target pixel coordinates and the center pixel coordinates of the first exhaust hole onto a unit vector along the line connecting the centers of the two holes; obtain the position adaptive threshold corresponding to the target pixel according to a piecewise linear threshold function; mark the target pixels whose denoised grayscale values ​​do not exceed the position adaptive threshold as crack foreground pixels and the remaining pixels as background pixels to obtain a binary image; denoise the binary image and extract the skeleton image; perform chain code statistics on the skeleton image to obtain the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels; obtain the skeleton pixel length using the number of unidirectional adjacent pixels and the number of bidirectional adjacent pixels; and obtain the actual crack defect length using the skeleton pixel length and a pre-calibrated camera correction factor.

Citation Information

Patent Citations

  • Construction method of inner wall multi-scale thermal field pattern based on sector ring interpolation

    CN115063310A

  • System and method for valve seat gap evaluation

    US20100230598A1