Method for identifying surface defects of compressor cast iron parts based on multi-scale texture analysis
By employing multi-scale texture analysis and adaptive threshold determination, the problems of low sensitivity and high false alarm rate in detecting minute defects on the surface of compressor cast iron parts have been solved, achieving efficient and stable defect identification in complex backgrounds.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAN ISE MACHINERY CO LTD
- Filing Date
- 2026-04-28
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies suffer from low sensitivity in detecting minute defects on the surface of compressor cast iron parts under complex backgrounds, and are susceptible to interference, leading to high rates of missed detections and false alarms.
A method based on multi-scale texture analysis is adopted. By statistically analyzing the gradient histogram through a sliding detection window, the tool mark concentration and texture entropy value are calculated. Combined with adaptive threshold judgment, the normal processing background and defect area are distinguished, and the judgment benchmark is dynamically adjusted to adapt to complex working conditions.
It significantly improves the sensitivity and noise resistance of detecting minute defects on the surface of cast iron parts, reduces the false alarm and missed detection rates, adapts to the changes in surface processing characteristics of different batches of parts, and enhances the operational stability of the system under complex working conditions.
Smart Images

Figure CN122115440A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image processing technology, specifically relating to a method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis. Background Technology
[0002] In modern equipment manufacturing, compressors, as core power equipment, directly determine the sealing performance and service life of the entire machine through the machining quality of their pressure-bearing cast iron components. To ensure the overall quality of the machine, rigorous surface defect detection must be carried out on the machining production line for critical surfaces to accurately eliminate workpieces with minute defects such as porosity, cracks, or shrinkage cavities. With the ever-increasing pace of automated production, industrial sites place extremely high demands on the real-time performance, accuracy, and anti-interference capabilities of surface defect detection under complex backgrounds.
[0003] To meet the demands of rapid pre-shipment inspection, the industry currently typically employs traditional machine vision technology for automated screening. After acquiring a grayscale image of the workpiece surface, these techniques often rely directly on a preset fixed grayscale threshold for global segmentation, or use a local binary model with a single set scale and edge detection operators to extract abnormal regions. The core logic lies in applying a uniform feature extraction algorithm and fixed judgment criteria to the entire image under inspection, attempting to quickly filter out abnormal pixel clusters and intercept defective workpieces.
[0004] However, in practical engineering applications, traditional methods reveal significant limitations when dealing with cast iron parts. After machining, cast iron parts exhibit an extremely complex physical morphology, not only covered with periodic, regular tool marks left by turning and other machining processes, but also interwoven with randomly distributed graphite spots inherent in the material itself. Faced with this complex background of multiple morphologies, single-scale feature extraction methods simply cannot meet the needs of defect detection at different sizes. If a smaller observation scale is used, the system is very likely to misjudge normally present and fragmented graphite spots as defects, resulting in a large number of false alarms; if a larger observation scale is used, the signals of real and fatal small defects such as microcracks will be diluted by the large area of periodic tool mark background, leading to serious missed detection problems.
[0005] Furthermore, during the continuous production of parts in the same batch, slight variations in workpiece surface roughness are inevitable, causing an overall shift in image grayscale and texture baseline. Traditional methods using fixed threshold mechanisms cannot adapt to this underlying baseline shift and are ill-equipped to withstand the transient disturbances caused by complex lighting fluctuations and random noise from camera sensors in the production environment. The combined technical shortcomings of single-scale measurement and fixed thresholds result in persistently high false alarm and false negative rates in existing detection systems under complex operating conditions. Summary of the Invention
[0006] The purpose of this invention is to propose a method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis, in order to solve the technical problems of low sensitivity in detecting small surface defects under complex backgrounds and high rates of missed detection and false alarms due to interference in the prior art.
[0007] To address the aforementioned problems, the technical solution provided by this invention for a method of identifying surface defects in compressor cast iron parts based on multi-scale texture analysis is as follows: A method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis includes: sliding a detection window on a grayscale image of the surface of the cast iron part to be inspected, and constructing a gradient histogram by statistically analyzing the gradient magnitude and gradient direction of each pixel in the detection window and calculating the weighted pixel count in each direction interval. The ratio of the maximum weighted pixel count in the gradient histogram to the sum of the weighted pixel counts in all directional intervals is calculated to obtain the knife mark concentration of the detection window; the knife mark concentration is compared with a preset concentration threshold to determine the window category of the detection window. Taking the principal gradient direction of the detection window as the starting angle, binary texture encoding is performed on the detection window at multiple preset scales, and the normalized texture entropy value of each preset scale is calculated as the entropy anomaly of each preset scale; the principal inspection scale is selected from the multiple preset scales according to the window category, and the entropy anomaly corresponding to the principal inspection scale is taken as the principal entropy anomaly. Calculate the proportion of uniform patterns after normalization of the binary texture encoding at each preset scale to obtain the uniform anomaly quantity at each preset scale, and take the uniform anomaly quantity corresponding to the main inspection scale as the main uniform anomaly quantity. In response to the main entropy anomaly being greater than a first preset threshold and the main uniform anomaly being less than a second preset threshold, the detection window is determined to be a defect window, and the defect identification result is output based on the position information of each defect window.
[0008] This invention combines underlying gradient features with texture structure analysis, and relies on the physical properties of cast iron parts to distinguish between normal processing background and defect areas. It can suppress interference caused by light fluctuations, avoid the dilution of defect signals by background features, and evaluate defects from the perspectives of texture disorder and regular structure, effectively improving the accuracy of identifying small defects on the surface of cast iron parts.
[0009] Further, the first preset threshold and the second preset threshold are adaptive dynamic thresholds; before the response to the main entropy anomaly being greater than the first preset threshold and the main uniformity anomaly being less than the second preset threshold, the method further includes: Obtain the preset initial entropy threshold and the preset initial uniformity threshold; Obtain a preset constant reference value, calculate the difference between the constant reference value and the tool mark concentration, and obtain the dynamic adjustment coefficient; The product of the initial entropy threshold and the dynamic adjustment coefficient is used as the first preset threshold; The product of the initial uniform threshold and the dynamic adjustment coefficient is used as the second preset threshold.
[0010] This scheme enables the judgment benchmark to adapt in real time to changes in local texture structure, improves the detection sensitivity of small defects in areas dominated by tool marks, suppresses interference from natural background in non-dominant areas, and enhances the operational stability of the system under complex working conditions.
[0011] Further, determining the window category of the detection window includes: Calculate the absolute value of the difference between the concentration of the tool marks and the concentration threshold; In response to the absolute value of the difference not being greater than a preset boundary tolerance, the window category of the detection window is determined to be a transition window; In response to the fact that the concentration of the knife marks is greater than the sum of the concentration threshold and the boundary tolerance, the window category of the detection window is determined to be the dominant region; In response to the fact that the concentration of the knife marks is less than the difference between the concentration threshold and the boundary tolerance, the window category of the detection window is determined to be a non-dominant area.
[0012] This classification method closely matches the actual texture distribution on the surface of cast iron parts, eliminating the problem of window category jumps caused by fluctuations in tool mark concentration near the threshold, and providing a stable and reliable classification basis for subsequent multi-scale texture analysis.
[0013] Further, the calculation of the normalized texture entropy value for each preset scale as the entropy anomaly for each preset scale includes: Calculate the distribution frequency of the binary texture encoding at each preset scale; The initial texture entropy at each preset scale is calculated based on the negative of the sum of the products of the distribution frequencies and their logarithms. Obtain the mean and standard deviation of the background entropy of the defect-free standard part in each inspection window; Calculate the difference between the initial texture entropy and the mean background entropy, and use the ratio of the difference to the standard deviation of the background entropy as the entropy anomaly at each preset scale.
[0014] This scheme eliminates baseline differences between different observation scales, adapts to baseline drift caused by minor differences in the surface of different batches of parts, and provides a unified comparison standard for the degree of anomalies at each scale.
[0015] Further, the step of selecting the primary inspection scale from the plurality of preset scales based on the window category includes: Multiple preset scales include a first preset scale, a second preset scale, and a third preset scale arranged in ascending order; in response to the window category of the detection window being a transition window, the second preset scale is used as the main inspection scale; in response to the window category of the detection window being a dominant area, the first preset scale is used as the main inspection scale; in response to the window category of the detection window being a non-dominant area, the third preset scale is used as the main inspection scale.
[0016] Further, the calculation of the proportion of uniform patterns after normalization of the binary texture encoding at each preset scale to obtain the uniform anomaly quantity at each preset scale includes: The number of target codes in the binary texture encoding with no more than two binary bit transitions is counted. Calculate the ratio of the number of target codes to the total number of pixels in the detection window to obtain the initial mode proportion for each preset scale; Calculate the difference between the initial pattern proportion and the preset background pattern mean, and use the ratio of the difference to the preset background pattern standard deviation as the uniform outlier for each preset scale.
[0017] This scheme assesses the extent to which defects damage textures from the perspective of changes in the proportion of regular structures, forming a complementary judgment criterion with entropy anomalies, thus eliminating false detection problems caused by random noise under single judgment conditions.
[0018] Furthermore, the method for obtaining the principal gradient direction of the detection window includes: From the various directional intervals of the gradient histogram, the target directional interval with the largest weighted pixel count is selected; The center angle corresponding to the target direction interval is used as the main gradient direction of the detection window.
[0019] This scheme can accurately determine the main direction of the texture within the window, providing a unified starting angle for binary texture encoding, reducing encoding fluctuations of normal background textures, and improving the stability of the encoding results.
[0020] Furthermore, the step of outputting the defect identification result based on the position information of each defect window includes: Based on the location information, spatially adjacent defect windows are merged into connected components to obtain continuous defect candidate regions; Obtain the bounding rectangle of each defect candidate region and calculate the equivalent physical diameter of each defect candidate region; In response to the equivalent physical diameter being not less than the preset minimum filter diameter, a defect identification result containing the actual defect location is output.
[0021] Furthermore, the method for obtaining the preset concentration threshold includes: Obtain the tool mark concentration of each inspection window corresponding to multiple defect-free standard parts; Calculate the mean and standard deviation of tool mark concentration for all defect-free standard parts; Calculate the difference between the concentration mean and the concentration standard deviation, and use the difference as a preset concentration threshold.
[0022] Further, the step of constructing a gradient histogram by calculating the weighted pixel counts for each directional interval based on the gradient magnitude and gradient direction of each pixel within the detection window includes: obtaining the gradient magnitude and gradient direction of each pixel within the detection window using an edge detection operator; dividing a preset angle range into multiple equally divided directional intervals and mapping the gradient direction of each pixel to the corresponding directional interval; accumulating the gradient magnitudes of each pixel mapped to that directional interval within each directional interval to obtain the weighted pixel count for each directional interval; and constructing the gradient histogram based on the weighted pixel counts for all directional intervals.
[0023] The beneficial effects of this invention are as follows: This invention can effectively avoid the dilution of defect signals by background features, significantly improve the sensitivity and noise resistance of small defect detection under complex backgrounds of polymorphic interweaving, reduce the false alarm rate and false detection rate of defect detection, adapt to the slight changes in the surface processing characteristics of different batches of parts, suppress random disturbances caused by ambient light and sensor noise, accurately distinguish between normal processing background and defect areas, stably output true and reliable defect identification results, and enhance the operational stability of the system under complex working conditions. Attached Figure Description
[0024] Figure 1 This is a flowchart illustrating the steps of the method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis provided in this embodiment. Figure 2 This embodiment provides a grayscale image of the surface of the cast iron part to be inspected. Figure 3 This is a distribution map of the principal entropy anomalies for each pixel provided in this embodiment; Figure 4 This is a distribution map of the principal uniform anomalies of each pixel provided in this embodiment; Figure 5 The defect identification results of the surface of the cast iron part to be inspected are provided in this embodiment. Detailed Implementation
[0025] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0026] like Figure 1As shown, the surface defect identification method for compressor cast iron parts based on multi-scale texture analysis in this embodiment is applied to the surface quality inspection process of the core pressure-bearing cast iron parts of the compressor before they leave the factory. Specifically, it includes the following steps: S1. Slide the detection window on the grayscale image of the surface of the cast iron part to be inspected, and construct a gradient histogram by calculating the weighted pixel count of each direction interval based on the gradient magnitude and gradient direction of each pixel in the detection window.
[0027] Specifically, for the sealing surface of the valve seat of a piston compressor, after casting, shot blasting, and turning, an area array industrial camera and a ring-shaped diffuse white light-emitting diode light source are used to photograph and collect images of the sealing surface of each part, thereby obtaining grayscale images of the surface of the cast iron part to be inspected. For example... Figure 2 As shown, the grayscale image clearly shows that the surface of the part is not only covered with periodic and regular tool marks left by turning, but also interspersed with randomly distributed graphite spots inherent in the material itself. Furthermore, there are faint micro-cracks and defects hidden at the edges of some structures. The grayscale image truly shows the complex detection background of the multi-modal interweaving.
[0028] After acquiring a grayscale image of the surface of the cast iron part to be inspected, in order to accurately evaluate the directional features of the surface texture in the grayscale image and avoid low-amplitude noise interfering with the determination of the main direction, the underlying gradient features of the grayscale image are extracted in a structured manner. Specifically, a detection window is slid across the grayscale image of the surface of the cast iron part to be inspected according to a preset sliding step size. In this embodiment, the sliding step size can be set to 1 pixel, and the size of the detection window is set to 7×7 pixels. The actual physical size corresponding to this size is approximately 1mm×1mm. This parameter setting is determined by the calibration results of the industrial camera and the minimum defect size, which can effectively cover typical defects with an equivalent physical diameter of 0.5mm.
[0029] For each sliding position of the detection window, the gradient magnitude and gradient direction of each pixel within the detection window are obtained using an edge detection operator. The standard Sobel edge detection operator is preferred. A preset angle range of 0 to 180 degrees is then set for directional symmetry folding, and this preset angle range is divided into multiple equally divided directional intervals. In this embodiment, the preset angle range is divided into eight equally divided directional intervals, ensuring that each directional interval precisely covers 22.5 degrees. Next, the gradient direction of each pixel within the detection window is mapped to the aforementioned divided directional intervals.
[0030] Within each directional interval, instead of simply counting the number of pixels, the gradient magnitudes of each pixel mapped to that directional interval are accumulated to obtain a weighted pixel count for each directional interval. After this accumulation, the gradient histogram of the detection window can be constructed based on the weighted pixel counts of all directional intervals.
[0031] When analyzing the feature distribution of statistical directional intervals, the weighted pixel counts for each directional interval satisfy the following relationship:
[0032] In the formula, Indicates the first The weighted pixel count for each directional interval, expressed as pixels multiplied by gray levels. The value of is a natural number from 1 to 8, which corresponds to the 8 equally divided directional intervals mentioned above. Indicates mapping to the first Each element in the set of gradient magnitude values of all pixels within a given directional interval.
[0033] Understandably, the above relationship shows that the weighted pixel count within each directional interval is positively correlated with the gradient magnitude of the pixels falling within that interval. By accumulating the gradient magnitudes instead of simply counting the number of pixels, the contribution of weak edges, such as shallow scratches or slight sensor noise, can be naturally suppressed. This mathematical aggregation transformation not only reduces the data dimensionality but also highlights the strong edge directional characteristics of real tool marks or obvious defects, enabling the final gradient histogram to highly and losslessly reproduce the manufacturable structural features of the cast iron surface.
[0034] Thus, by constructing a gradient histogram within a specific sliding window using gradient magnitude as the weight for statistically calculating pixel counts in the directional interval, weak noise interference caused by minute illumination fluctuations is suppressed directly at the low-level feature level after image acquisition. This step enables the extracted gradient histogram to realistically and stably reflect the periodic tool mark features left by machining, providing a reliable and high signal-to-noise ratio data foundation for accurately distinguishing normal machining backgrounds from abnormal defect areas, and greatly improving the anti-interference capability of engineering inspection sites against complex cast iron backgrounds.
[0035] S2. Calculate the ratio of the maximum weighted pixel count in the gradient histogram to the sum of the weighted pixel counts in all directional intervals to obtain the knife mark concentration of the detection window; compare the knife mark concentration with a preset concentration threshold to determine the window category of the detection window.
[0036] To accurately distinguish between normal machining backgrounds and potential defect areas, a quantitative analysis of the distribution pattern of the gradient histogram constructed in the previous step is required. After machining such as turning, the tool moves along a fixed trajectory, leaving periodic tool marks with consistent direction and height on the part surface. These tool marks are characterized by the vast majority of gradient vectors concentrating in the tool mark normal direction, resulting in a sharp, single-peaked gradient histogram. Based on this physical characteristic, this step constructs a tool mark concentration to reflect the gradient aggregation state. The tool mark concentration satisfies the following relationship:
[0037] In the formula, This represents the concentration of knife marks within the detection window. It is a dimensionless parameter with a value greater than 0 and not greater than 1. This represents the maximum weighted pixel count in the gradient histogram constructed in the previous step; This represents the weighted sum of pixel counts across all directional intervals in the gradient histogram.
[0038] Understandably, the numerator of the tool mark concentration is the intensity in the principal direction, and the denominator is the total intensity in all directions. This ratio reflects the proportion of the principal direction in the total gradient. When normal tool marks dominate within the detection window, the gradient is highly concentrated, and the tool mark concentration approaches 1. When defects such as porosity or cracks exist, the defect edges are randomized, the gradient directions are dispersed, and the tool mark concentration is significantly reduced. This mathematical aggregation transformation compresses the features of multiple directional intervals into a single-dimensional concentration index, which not only significantly reduces the data dimensionality of subsequent processing but also directly and accurately assesses the manufacturable structural features of the part surface.
[0039] To provide an objective and adaptable benchmark for subsequent inspection window classification, this step obtains a preset concentration threshold. The method for obtaining the preset concentration threshold includes acquiring the tool mark concentration of each inspection window corresponding to multiple defect-free standard parts. To meet the basic requirements of engineering statistics, at least 30 defect-free standard parts of the same type are selected as a sample set. Subsequently, the mean and standard deviation of the tool mark concentration of all defect-free standard parts are statistically analyzed. Based on this, the difference between the mean and standard deviation of the concentration is calculated, and this difference is directly used as the preset concentration threshold. In this embodiment, the preferred reference value for the preset concentration threshold is set to 0.5. This threshold acquisition method based on real statistical distribution can adaptively absorb baseline drift caused by slight changes in surface roughness in different batches of parts, eliminating the need for repeated manual adjustments based on experience, and ensuring the robustness and reliability of the judgment benchmark in practical engineering applications.
[0040] After obtaining the tool mark concentration and the preset concentration threshold of the inspection window, the inspection window needs to be finely classified according to their relative magnitudes to determine the window category. The classification process first requires calculating the absolute value of the difference between the tool mark concentration and the preset concentration threshold. Then, a three-state classification logic is executed based on the comparison between this absolute value and a preset boundary tolerance. The preset boundary tolerance is preferably set to 0.05, a value determined by the local density of the tool mark concentration distribution in a defect-free standard part.
[0041] When the absolute value of the difference is not greater than a preset boundary tolerance, the detection window is classified as a transition window, indicating that periodic tool marks and natural graphite distribution coexist within the current detection window. When the tool mark concentration is greater than the sum of a preset concentration threshold and a preset boundary tolerance, the detection window is classified as a dominant region, indicating that the texture within the detection window is dominated by periodic tool marks. When the tool mark concentration is less than the difference between a preset concentration threshold and a preset boundary tolerance, the detection window is classified as a non-dominant region, indicating that the tool marks within the detection window have extremely weak directionality, and the texture is mainly composed of random graphite spots or curved transitions. By introducing a preset boundary tolerance to construct independent transition windows, the classification logic based on tool mark concentration corresponds to the three real physical states of the cast iron surface, eliminating the problem of abrupt changes in the classification of adjacent detection windows caused by small fluctuations in tool mark concentration near the preset concentration threshold.
[0042] In this way, by calculating the concentration of tool marks and combining the concentration threshold and boundary tolerance obtained based on statistical laws, the detection window is classified into three states. The physical structural properties of the part machining itself are directly used to distinguish the background and potential defect areas, effectively avoiding the introduction of complex image segmentation algorithms. While ensuring extremely low computational latency, it provides highly reliable structured label guidance for the precise implementation of subsequent multi-scale analysis.
[0043] S3. Using the principal gradient direction of the detection window as the starting angle, perform binary texture encoding on the detection window at multiple preset scales, calculate the normalized texture entropy value of each preset scale as the entropy anomaly of each preset scale; select the principal inspection scale from the multiple preset scales according to the window category, and take the entropy anomaly corresponding to the principal inspection scale as the principal entropy anomaly.
[0044] To eliminate encoding sequence differences caused by different rotation directions of parts with similar tool marks before binary texture encoding, it is necessary to align the starting direction of the encoding. Specifically, the principal gradient direction of the detection window needs to be obtained. Since a gradient histogram has already been constructed in the previous step, this process directly selects the target direction interval with the largest weighted pixel count from each direction interval of the gradient histogram. Subsequently, the center angle corresponding to the target direction interval is used as the principal gradient direction of the detection window. This step does not require recalculating the gradient, greatly reducing computational redundancy. Using the extracted principal gradient direction as the starting angle for binary texture encoding makes the encoding sequence of similar tool mark backgrounds tend to be consistent, effectively reducing statistical fluctuations in normal backgrounds.
[0045] After obtaining the principal gradient direction of the detection window, the standard Local Binary Pattern (LCB) algorithm is used as the starting angle to perform binary texture encoding on the detection window at multiple preset scales, thereby obtaining the binary texture encoding at each preset scale. To evaluate the disorder of the texture distribution within the detection window, the normalized texture entropy value of each preset scale is calculated as the entropy anomaly at each preset scale. This calculation process first calculates the distribution frequency of the binary texture encoding at each preset scale, and then calculates the initial texture entropy at each preset scale based on the negative of the sum of the products of the distribution frequency and its logarithm.
[0046] To eliminate the difference in absolute baseline values caused by the varying total number of codes at different preset scales, and to ensure uniform comparability of anomaly levels across all preset scales, it is necessary to further obtain the mean and standard deviation of background entropy of defect-free standard parts statistically analyzed at each inspection window. The sample size of these defect-free standard parts is preferably at least 30 pieces to ensure that the accuracy of the background statistical parameters meets engineering error requirements. Subsequently, the difference between the initial texture entropy and the mean background entropy is calculated, and the ratio of this difference to the standard deviation of the background entropy is used as the entropy anomaly at each preset scale. The entropy anomaly at each preset scale satisfies the following mathematical relationship:
[0047] In the formula, Indicates the first An entropy anomaly at a preset scale is a dimensionless deviation. This represents the first value calculated using the standard Shannon information entropy formula. The initial texture entropy at a preset scale, in bits. This represents the average background entropy at the same scale, obtained from statistical analysis of defect-free standard parts of the same type, expressed in bits. It represents the standard deviation of background entropy at the same scale obtained from statistics of defect-free standard parts, in bits.
[0048] Understandably, when the initial texture entropy is greater than the average background entropy, the numerator is positive, indicating that the binary texture encoding of the current detection window is more chaotic than the normal background, the texture regularity is destroyed, and a real defect is hidden. When the entropy anomaly is not greater than 0, it indicates that the texture regularity of the current detection window is normal. This calculation method based on difference and ratio essentially standardizes the initial texture entropy, which not only effectively eliminates the baseline difference between various preset scales, but also has a high degree of adaptive compensation capability for baseline drift caused by slight differences in surface roughness between different batches of parts.
[0049] For different types of detection windows, due to the varying physical dimensions of potential defects, differentiated scale matching is required. Therefore, this step selects a master inspection scale from multiple preset scales based on the window category of the detection window, and uses the entropy anomaly corresponding to the master inspection scale as the master entropy anomaly. The multiple preset scales include a first preset scale, a second preset scale, and a third preset scale arranged in ascending order. The sampling radius of the first preset scale is preferably one pixel, representing a small observation scale, corresponding to the order of tool mark spacing; the sampling radius of the second preset scale is preferably two pixels, corresponding to the order of graphite spot diameter; and the sampling radius of the third preset scale is preferably four pixels, corresponding to the order of large size of pores or shrinkage profiles.
[0050] Based on the classification results from the previous step, the window category corresponding to the detection window is a transition window. Since this area is in a mixed state of tool marks and graphite, the diameter of the graphite spots corresponds exactly to the observation range of the second preset scale. Therefore, the second preset scale is used as the primary inspection scale. The window category corresponding to the detection window is a dominant area. Since the periodic tool marks in this area are highly regular, the first preset scale is most sensitive to the micro-cracks within it. Therefore, the first preset scale is used as the primary inspection scale. The window category corresponding to the detection window is a non-dominant area. Since this area is dominated by large areas of graphite, the texture at small scales is inherently chaotic. The third preset scale has the highest distinguishability for large-sized real defects. Therefore, the third preset scale is used as the primary inspection scale.
[0051] By aligning the encoding starting angle with the principal gradient direction, combining the calculation of normalized entropy anomalies based on statistical baselines, and driving the strict selection of differential principal test scales based on classification results, the engineering problem of background texture diluting effective defect features during equal-weight fusion of multi-scale features is solved, enabling the scale signal most sensitive to defects in each region to be extracted losslessly and accurately.
[0052] like Figure 3As shown in the pseudo-color distribution map, it can be intuitively observed that the actual defect areas, i.e., the locations of micro-cracks, exhibit a significantly high anomaly value distribution in bright areas. This is because the actual cracks not only disrupt the regularity of the original tool marks but also cause the binary texture encoding to tend towards a severely disordered state. Meanwhile, the principal entropy anomalies in the normal periodic tool mark areas and graphite spot areas remain at a lower, darker baseline level. This distribution map indirectly confirms that the extracted principal entropy anomaly index can effectively highlight abnormal areas where the texture regularity is deeply disrupted, significantly improving the detection sensitivity for various micro-defects on the surface of complex cast iron parts.
[0053] S4. Calculate the proportion of uniform patterns after normalization of the binary texture encoding at each preset scale, obtain the uniform anomaly quantity at each preset scale, and take the uniform anomaly quantity corresponding to the main inspection scale as the main uniform anomaly quantity.
[0054] To independently quantify the degree of texture destruction from the perspective of the proportion of regular structure, and to form physically complementary dual evidence with the main entropy anomalies extracted in the previous steps, this step performs in-depth statistics on the transition features within the binary texture encoding at each scale. The proportion of uniform patterns after normalization of the binary texture encoding at each preset scale is calculated to obtain the uniform anomaly quantity at each preset scale. This includes counting the number of target codes in the binary texture encoding with no more than two binary bit transitions, calculating the ratio of the number of target codes to the total number of pixels in the detection window, and obtaining the initial pattern proportion at each preset scale. The difference between the initial pattern proportion and the preset mean of the background patterns is calculated, and the ratio of this difference to the preset standard deviation of the background patterns is used as the uniform anomaly quantity at each preset scale.
[0055] In binary texture encoding, codes where the number of binary bits transitioning from 0 to 1 or from 1 to 0 is no more than two correspond to smooth texture edges or regular transition structures. These target codes are the main texture components of normal machined surfaces. For each detection window, the initial pattern proportion at each preset scale is obtained by dividing the number of target codes by the total number of pixels within the detection window. This is a dimensionless parameter with a value between 0 and 1. It should be noted that this initial pattern proportion is directly derived from the binary texture codes at each preset scale constructed in the previous step, without requiring any re-extraction or filtering of the image. The computational cost is extremely low, and the data flow is completely inherited.
[0056] To eliminate baseline differences caused by varying total target codes at different preset scales and to ensure uniform comparability of anomaly levels across scales, the uniform anomaly quantity at each preset scale satisfies the following relationship:
[0057] In the formula, Indicates the first A uniform anomaly of a preset scale, which is a dimensionless deviation. The value of corresponds to the first preset scale, the second preset scale, and the third preset scale in the previous step. Represents the calculated first... The initial pattern proportion of each preset scale. This represents the mean value of a preset background pattern at the same scale, obtained from statistics of defect-free standard parts. It is a dimensionless parameter. This represents the standard deviation of the preset background pattern at the same scale, obtained from statistics of defect-free standard parts. After obtaining the uniform outlier, based on the principal inspection scale selected in the previous step, the uniform outlier corresponding to that principal inspection scale is directly extracted as the principal uniform outlier.
[0058] Understandably, when the proportion of the initial pattern is lower than the preset average of the background patterns (i.e., the numerator is negative, causing the calculated uniform anomaly quantity to be less than 0), it indicates that the regular texture structure has been destroyed under the corresponding inspection scale, and the larger the absolute value of the uniform anomaly quantity, the deeper the destruction. The physical manifestation of real defects not only increases the texture entropy value, leading to overall disorder in the encoding, but also destroys the structured nature of the texture, causing a significant decrease in the proportion of regular structures. While camera sensor noise or instantaneous fluctuations in lighting in industrial settings may cause a slight increase in the texture entropy value, due to the randomness of the noise, it will not systematically cause a synchronous decrease in the uniform anomaly quantity.
[0059] like Figure 4 As shown in the distribution map, in areas where microcracks occur, the normal machining texture components representing smooth texture edges or regular transition structures are significantly reduced, leading to significant abnormal fluctuations in the principal uniformity anomaly, which are displayed as bright colors in the map. This distribution map accurately measures the structural damage of defects to the machined surface from the physical aspect of the decrease in the proportion of regular structures.
[0060] Thus, by calculating the number of jumps in the binary texture encoding and extracting the main uniform anomaly, the structural damage of defects to the machined surface was accurately assessed, forming physical complementary evidence with the aforementioned entropy anomaly, which has natural noise resistance.
[0061] S5. In response to the main entropy anomaly being greater than a first preset threshold and the main uniform anomaly being less than a second preset threshold, the detection window is determined to be a defect window, and the defect identification result is output based on the position information of each defect window.
[0062] To maintain consistency and stability of the judgment criteria under different texture backgrounds and overcome the problem of missed or false detections that easily occur when dealing with complex processed surfaces using fixed thresholds, this step introduces a dynamic adaptive mechanism to adjust the judgment benchmark. Specifically, the first preset threshold and the second preset threshold are adaptive dynamic thresholds. The dynamic threshold calculation process needs to be performed before the principal entropy anomaly exceeds the first preset threshold and the principal uniformity anomaly is less than the second preset threshold.
[0063] The process first obtains a preset initial entropy threshold and a preset initial uniformity threshold, and simultaneously obtains a preset constant benchmark value; then, it calculates the difference between the preset constant benchmark value and the tool mark concentration obtained in the previous steps, thereby obtaining the dynamic adjustment coefficient; subsequently, the product of the preset initial entropy threshold and the dynamic adjustment coefficient is directly used as the first preset threshold, and the product of the preset initial uniformity threshold and the dynamic adjustment coefficient is used as the second preset threshold.
[0064] To achieve the above dynamic adjustment mechanism, the first preset threshold and the second preset threshold satisfy the following relationship:
[0065]
[0066] In the formula, This represents the first preset threshold, which is a dimensionless dynamic judgment criterion. This represents the second preset threshold, which is also a dimensionless dynamic judgment criterion. The preset initial entropy threshold is preferably determined by analyzing the subject operating characteristic curve of the labeled samples. That is, during the development stage, using a set of manually labeled images of known defect locations, the true positive rate and false positive rate curves under different thresholds are plotted, and the threshold corresponding to the maximum difference between the true positive rate and the false positive rate is determined as the preset initial entropy threshold. In this embodiment, it is set to 2. This represents the preset initial uniformity threshold, which is set to 2 in this embodiment. This represents a preset constant reference value. The calibration steps for the preset constant reference value are as follows: acquire multiple grayscale images of defect-free standard parts, and traverse the sliding window to calculate the tool mark concentration of each window. Statistics of all 99th percentile of the value To ensure that the dynamic adjustment coefficient is always positive and has a reasonable adjustment range, a minimum adjustment intensity parameter also needs to be set. , The value range is from 0.2 to 0.5; therefore, the preset constant reference value is... satisfy: . This indicates the concentration of tool marks calculated in the previous step.
[0067] Understandably, the tool mark concentration directly reflects the salience of normal machining textures within the current detection window. When the detection window is in the dominant region, the tool mark concentration is high, causing the dynamic adjustment coefficient obtained by subtracting the preset constant benchmark value from the tool mark concentration to decrease, thereby driving the first and second preset thresholds to adaptively decrease. This threshold reduction physically improves the system's detection sensitivity to defects that disrupt the regularity of tool marks, such as micro-cracks. Conversely, in the non-dominant region, the tool mark concentration is low, the calculated dynamic adjustment coefficient increases, and the judgment threshold is adaptively increased, effectively suppressing the interference of natural background noise caused by random graphite spots or curved surface transitions. Through this product mapping of dynamic adjustment coefficients, the dual judgment criteria can adaptively follow the local changes in the underlying physical structure.
[0068] After obtaining the dynamic first and second preset thresholds, the principal entropy anomaly and principal uniformity anomaly of the principal inspection scale obtained in the previous steps are combined to perform a dual-evidence joint judgment. The specific judgment logic is as follows: in response to the principal entropy anomaly being greater than the first preset threshold and the principal uniformity anomaly being less than the second preset threshold, the detection window is determined to be a defect window. This logical relationship is equivalent to a logical AND operation; that is, the two complementary physical conditions—the texture disorder state represented by the increase in texture entropy and the structural damage represented by the decrease in the proportion of uniform patterns—must be satisfied simultaneously to ultimately determine the detection window as a true defect window.
[0069] After completing defect determination for all detection windows, since a single real defect often spans multiple adjacent detection windows spatially, it is necessary to transform the discrete window determination results into continuous defect regions with engineering guidance significance. This process outputs defect identification results based on the location information of each defect window. In specific implementation, spatially adjacent defect windows are merged into connected components based on their location information to obtain continuous defect candidate regions. For the connected component merging operation, the standard four-connectivity labeling algorithm is preferably used to seamlessly merge spatially adjacent defect windows into a continuous whole.
[0070] After obtaining consecutive candidate defect regions, the bounding rectangle of each candidate region is acquired, and the equivalent physical diameter of each candidate region is calculated. The equivalent physical diameter is calculated by converting the total number of pixels contained in each candidate region with the pixel physical size obtained from the industrial camera calibration, and its unit is millimeters. Finally, in response to the condition that the equivalent physical diameter is not less than the preset minimum filtering diameter, the defect identification result containing the actual defect location is output. The preset minimum filtering diameter is determined by the process standard of the compressor pressure-bearing components, and its recommended reference value is 0.3mm. Through the size filtering mechanism of the bounding rectangle and the equivalent physical diameter, not only can the actual spatial coordinates of the defect be accurately located, but also extremely small, unreliable, isolated noise points can be effectively eliminated.
[0071] like Figure 5 As shown in the figure, this is the final defect identification result. After connected component merging and equivalent physical diameter filtering, the system accurately locates and marks the actual spatial coordinates of the microcrack defect on the grayscale image of the original cast iron part surface using a prominent circumscribed rectangle. This intuitively demonstrates the high sensitivity and accurate interception effect of this invention on minute defects in complex and multifaceted environments.
[0072] By dynamically adaptively adjusting the threshold based on tool mark concentration and combining dual evidence of principal entropy anomalies and principal uniform anomalies for joint judgment, and finally using connected component merging and physical diameter filtering to output defect results, a data flow closed loop from low-level grayscale feature extraction to high-level defect localization is achieved. The entire judgment process uses only the background statistical parameters of defect-free standard parts as the driving force, reducing the calibration and debugging costs during production line changeovers. Furthermore, while meeting the engineering requirement of extremely low false alarm rate in factory inspection, it ensures high-sensitivity identification and accurate output of various minute defects in complex cast iron backgrounds.
[0073] While various embodiments of the invention have been shown and described in this specification, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Many modifications, alterations, and alternatives will occur to those skilled in the art without departing from the spirit and essence of the invention.
Claims
1. A method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis, characterized in that, include: Slide the detection window on the grayscale image of the surface of the cast iron part to be inspected, and construct a gradient histogram by calculating the weighted pixel count of each direction interval based on the gradient magnitude and gradient direction of each pixel in the detection window. The ratio of the maximum weighted pixel count in the gradient histogram to the sum of the weighted pixel counts in all directional intervals is calculated to obtain the knife mark concentration of the detection window; the knife mark concentration is compared with a preset concentration threshold to determine the window category of the detection window. Taking the main gradient direction of the detection window as the starting angle, binary texture encoding is performed on the detection window at multiple preset scales, and the normalized texture entropy value of each preset scale is calculated as the entropy anomaly of each preset scale. Based on the window category, a primary inspection scale is selected from the plurality of preset scales, and the entropy anomaly corresponding to the primary inspection scale is taken as the primary entropy anomaly. Calculate the proportion of uniform patterns after normalization of the binary texture encoding at each preset scale to obtain the uniform anomaly quantity at each preset scale, and take the uniform anomaly quantity corresponding to the main inspection scale as the main uniform anomaly quantity. In response to the main entropy anomaly being greater than a first preset threshold and the main uniform anomaly being less than a second preset threshold, the detection window is determined to be a defect window, and the defect identification result is output based on the position information of each defect window.
2. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, The first preset threshold and the second preset threshold are adaptive dynamic thresholds; Before responding to the main entropy anomaly being greater than a first preset threshold and the main uniform anomaly being less than a second preset threshold, the method further includes: Obtain the preset initial entropy threshold and the preset initial uniformity threshold; Obtain a preset constant reference value, calculate the difference between the constant reference value and the tool mark concentration, and obtain the dynamic adjustment coefficient; The product of the initial entropy threshold and the dynamic adjustment coefficient is used as the first preset threshold; The product of the initial uniform threshold and the dynamic adjustment coefficient is used as the second preset threshold.
3. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, Determining the window category of the detection window includes: Calculate the absolute value of the difference between the concentration of the tool marks and the concentration threshold; In response to the absolute value of the difference not being greater than a preset boundary tolerance, the window category of the detection window is determined to be a transition window; In response to the fact that the concentration of the knife marks is greater than the sum of the concentration threshold and the boundary tolerance, the window category of the detection window is determined to be the dominant region; In response to the fact that the concentration of the knife marks is less than the difference between the concentration threshold and the boundary tolerance, the window category of the detection window is determined to be a non-dominant area.
4. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, The calculation of the normalized texture entropy value for each preset scale as the entropy anomaly for each preset scale includes: Calculate the distribution frequency of the binary texture encoding at each preset scale; The initial texture entropy at each preset scale is calculated based on the negative of the sum of the products of the distribution frequencies and their logarithms. Obtain the mean and standard deviation of the background entropy of the defect-free standard part in each inspection window; Calculate the difference between the initial texture entropy and the mean background entropy, and use the ratio of the difference to the standard deviation of the background entropy as the entropy anomaly at each preset scale.
5. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 3, characterized in that, The step of selecting the primary inspection scale from the plurality of preset scales based on the window category includes: Multiple preset scales include a first preset scale, a second preset scale, and a third preset scale arranged in ascending order; in response to the window category of the detection window being a transition window, the second preset scale is used as the main inspection scale; in response to the window category of the detection window being a dominant area, the first preset scale is used as the main inspection scale; in response to the window category of the detection window being a non-dominant area, the third preset scale is used as the main inspection scale.
6. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, The calculation of the uniform pattern proportion after normalization of the binary texture encoding at each preset scale, to obtain the uniform anomaly amount at each preset scale, includes: The number of target codes in the binary texture encoding with no more than two binary bit transitions is counted. Calculate the ratio of the number of target codes to the total number of pixels in the detection window to obtain the initial mode proportion for each preset scale; Calculate the difference between the initial pattern proportion and the preset background pattern mean, and use the ratio of the difference to the preset background pattern standard deviation as the uniform outlier for each preset scale.
7. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, The method for obtaining the principal gradient direction of the detection window includes: From the various directional intervals of the gradient histogram, the target directional interval with the largest weighted pixel count is selected; The center angle corresponding to the target direction interval is used as the main gradient direction of the detection window.
8. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, The step of outputting defect identification results based on the location information of each defect window includes: Based on the location information, spatially adjacent defect windows are merged into connected components to obtain continuous defect candidate regions; Obtain the bounding rectangle of each defect candidate region and calculate the equivalent physical diameter of each defect candidate region; In response to the equivalent physical diameter being not less than the preset minimum filter diameter, a defect identification result containing the actual defect location is output.
9. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, The method for obtaining the preset concentration threshold includes: Obtain the tool mark concentration of each inspection window corresponding to multiple defect-free standard parts; Calculate the mean and standard deviation of tool mark concentration for all defect-free standard parts; Calculate the difference between the concentration mean and the concentration standard deviation, and use the difference as a preset concentration threshold.
10. The method for identifying surface defects in compressor cast iron parts based on multi-scale texture analysis according to claim 1, characterized in that, The step of constructing a gradient histogram by calculating the weighted pixel counts for each directional interval based on the gradient magnitude and gradient direction of each pixel within the detection window includes: obtaining the gradient magnitude and gradient direction of each pixel within the detection window using an edge detection operator; dividing a preset angle range into multiple equally divided directional intervals and mapping the gradient direction of each pixel to the corresponding directional interval; accumulating the gradient magnitudes of each pixel mapped to that directional interval within each directional interval to obtain the weighted pixel count for each directional interval; and constructing the gradient histogram based on the weighted pixel counts for all directional intervals.