A method and system for segmenting hole defects in aluminum alloy forgings
By using a local adaptive filtering method, the problem that global filters cannot adapt to local texture changes on the surface of forgings is solved, and efficient and accurate segmentation of hole defects in aluminum alloy forgings is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-17
- Publication Date
- 2026-04-07
AI Technical Summary
In existing technologies, static filters using global Fourier transform cannot adapt to the locally varying textures on the surface of forgings, leading to missed detections and misjudgments in the detection of hole defects in aluminum alloy forgings.
A local adaptive filtering method is adopted. By processing the forging image in blocks, the energy direction and adaptive bandwidth of the local spectrum are calculated, an adaptive filtering kernel is constructed, frequency domain filtering is performed, and combined with two-dimensional inverse Fourier transform, texture interference is removed and defect information is preserved.
It improves the accuracy of hole defect segmentation, avoids missed detections and misjudgments, and enhances the reliability of test results.
Smart Images

Figure CN121353317B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image data processing technology, and in particular to a method and system for segmenting hole defects in aluminum alloy forgings. Background Technology
[0002] Aluminum alloy forgings, due to their superior properties of high strength and light weight, are frequently used in the manufacture of aerospace equipment, high-end automotive parts, and precision machinery. Their internal quality directly affects the safety and reliability of the final product. During the forging process, voids and defects are easily formed inside and on the surface of the forgings. Therefore, accurate and efficient non-destructive testing of aluminum alloy forgings is a necessary step to ensure product quality.
[0003] Currently, automated inspection technology based on machine vision has become mainstream. In automated inspection based on machine vision, the forging flow lines on the surface of forgings, which are generated by the plastic deformation of metal, have complex and varied shapes, which interfere with the detection of potential hole defects.
[0004] In related technologies, frequency domain filtering techniques based on global Fourier transform can convert images from the spatial domain to the frequency domain. This technique utilizes the difference in energy distribution between streamline textures and hole defects on the spectrum to design static band-stop filters to filter out specific frequency components representing textures, thereby highlighting defects in the image. This method is based on global information analysis and aims to process the dominant texture in the image. However, in practical applications, the streamline texture on the surface of forgings is not always uniformly distributed: its direction often bends with the geometric curvature of the forging, and its density may also vary in different areas. When faced with such locally varying textures, static filters designed based on the globally dominant texture will encounter problems: in areas where texture features do not match, defects may be missed due to incomplete texture filtering; in areas with weak or no texture, the filtering operation will destroy the characteristics of small defects, leading to misjudgment and ultimately affecting the accuracy of the detection results. Summary of the Invention
[0005] To address the technical problem that the global Fourier transform, which uses a static filter designed with a globally dominant texture, cannot adapt to local variations in the texture of the forging surface, thus leading to missed defects and misjudgments, the present invention provides solutions in the following aspects.
[0006] In a first aspect, the present invention provides a method for segmenting hole defects in aluminum alloy forgings, the method comprising the steps of:
[0007] The original image of the forging is acquired and preprocessed to obtain a grayscale image of the forging. The grayscale image of the forging is divided into blocks to obtain several image blocks. A two-dimensional Fourier transform is performed on each image block to obtain its local spectrogram. Based on the energy distribution characteristics of the local spectrogram, the spectral energy direction of the image block is determined. The projection distance of the frequency point of the local spectrogram on the spectral energy direction is calculated to obtain the frequency domain distance. The adaptive bandwidth of the image block is calculated based on the frequency characteristics of the local spectrogram. The frequency domain distance and the adaptive bandwidth are fused to obtain the adaptive filtering kernel of the image block. The response value of the adaptive filtering kernel at each frequency point is positively correlated with the frequency domain distance of the frequency point and negatively correlated with the adaptive bandwidth of the image block. The adaptive filtering kernel is applied to the local spectrogram for frequency domain filtering to obtain a filtered spectrogram. A two-dimensional inverse Fourier transform is performed on the filtered spectrogram to obtain a filtered spatial domain image block. All the filtered spatial domain image blocks are fused to obtain a textureless image. The textureless image is segmented to obtain the segmentation result of the hole defect.
[0008] This invention first divides the grayscale image of the forging into blocks and obtains the local spectrum of each image block. Second, based on the spectral energy distribution of the local spectrum of each image block, its spectral energy direction is determined to adapt to the local orientation of the streamline texture. Next, an adaptive bandwidth is calculated by combining frequency characteristics to respond to changes in texture sharpness. Then, an adaptive filter kernel is constructed by fusing the frequency domain distance and the adaptive bandwidth. Its response value is positively correlated with the frequency domain distance and negatively correlated with the bandwidth, achieving accurate suppression of texture frequencies. Finally, this filter kernel is applied for frequency domain filtering, effectively preserving defect information. The fusion process yields a texture-free image and completes segmentation, avoiding missed detections and misjudgments, and improving the accuracy of hole defect segmentation.
[0009] Preferably, determining the spectral energy direction of the image block based on the energy distribution characteristics of the local spectrogram includes: calculating the second-order central moment of the local spectrogram; and calculating the spectral energy direction of the image block based on the second-order central moment.
[0010] This invention calculates the second-order central moment of the local spectrogram and then calculates the spectral energy direction based on the second-order central moment. The second-order central moment can accurately reflect the extension and tilt trend of the energy distribution in the local spectrogram, and can capture the distribution inertial principal axis of the bright band formed by the streamline texture in the frequency domain, providing a stable and reliable directional basis for the subsequent construction of a directional adaptive filter kernel.
[0011] Preferably, the spectral energy direction of the image patch satisfies the following relationship:
[0012] ;
[0013] in, It is the first The spectral energy direction of each image patch; , , They are the first The second-order mixing central moments of each image patch, the second-order... Directional moment, second order Directional moment; It is the arctangent function.
[0014] This invention utilizes the arctangent function acting on twice the second-order mixed central moment and the second-order... Directional moment and second order The ratio of the difference in directional moments is taken as half, and the statistical characteristics of the energy distribution are converted into accurate angle parameters. This ensures the stability and reproducibility of the calculation, making the directional positioning of the adaptive filter kernel more accurate.
[0015] Preferably, the step of calculating the adaptive bandwidth of the image patch based on the frequency characteristics of the local spectrogram includes: calculating the ratio of the energy variance of the local spectrogram in the spectral energy direction to the energy variance in the orthogonal direction of the spectral energy direction to obtain the texture cohesion; calculating the adaptive bandwidth based on the texture cohesion; the adaptive bandwidth is negatively correlated with the texture cohesion.
[0016] This invention defines frequency domain distance as the projection distance of a frequency point in a local spectrogram onto the spectral energy direction. This frequency domain distance characterizes the position of the current frequency point energy on the bright band axis of the spectrum, and its squared value is convenient for subsequent substitution into Butterworth and other filter models for smooth attenuation calculation, providing a key distance parameter for realizing directional band-stop filtering.
[0017] Preferably, the step of calculating the adaptive bandwidth based on the texture cohesion includes: obtaining the negative exponential function of the texture cohesion and multiplying it by a preset base bandwidth value to obtain the adaptive bandwidth.
[0018] Preferably, the adaptive filter kernel is a Butterworth band-stop filter, and its response value satisfies the following relationship:
[0019] ;
[0020] in, It is the first The adaptive filtering kernel of each image patch in the frequency domain coordinates The response value at the location; Frequency The square of the frequency domain distance; It is the preset filter center frequency; It is the first Adaptive bandwidth for each image patch; It is the order of the Butterworth filter; It is a preset micro value.
[0021] This invention clarifies the control mechanism between adaptive bandwidth and texture cohesion. When texture cohesion is high, it indicates that the texture is clear and the energy is concentrated. At this time, the adaptive bandwidth is reduced to form a narrow and deep suppression band to accurately filter out the texture. When texture cohesion is low, it indicates that the texture is blurry or non-existent. The adaptive bandwidth is increased and the filtering effect is weakened to protect the defect signal and background information. This negative correlation is the key to realizing the adaptive control of the filter and balancing texture suppression and detail preservation.
[0022] Preferably, the step of dividing the grayscale image of the forging into several image blocks includes: dividing the grayscale image of the forging into several image blocks; and applying a two-dimensional Hanning window to each image block.
[0023] Preferably, the step of fusing all the filtered spatial domain image blocks to obtain a textureless image includes: calculating the weighted average of the corresponding pixel values under the local coordinates of all filtered spatial domain image blocks covering the same global coordinate point to obtain the pixel value of the global coordinate point; the weighting weight is the same as the window function value of the two-dimensional Hanning window.
[0024] Preferably, the step of segmenting the textureless image to obtain the segmentation result of the hole defect includes: applying the Otsu adaptive thresholding method to the textureless image to obtain a binary image; performing a morphological opening operation on the binary image to obtain an open binary image; and using connected component analysis on the open binary image to take each independent connected region as the segmentation result of the hole defect.
[0025] In a second aspect, the present invention provides a hole defect segmentation system for aluminum alloy forgings. The hole defect segmentation system for aluminum alloy forgings includes a memory and a processor. The memory stores computer program instructions, and when the computer program instructions are executed by the processor, the hole defect segmentation method for aluminum alloy forgings according to the first aspect of the present invention is implemented.
[0026] By adopting the above technical solution, a computer program is generated from the method for segmenting hole defects in aluminum alloy forgings according to the first aspect of the present invention, and stored in a memory so that it can be loaded and executed by a processor. A terminal device can then be made based on the memory and the processor for convenient use.
[0027] The beneficial effects of this invention are as follows: First, the grayscale image of the forging is divided into blocks, and a local spectrum map of each image block is obtained. Second, the unique spectral energy direction is determined based on the energy distribution characteristics of the local spectrum map to adapt to the local direction of the streamline texture. Next, the adaptive bandwidth of the image block is calculated based on the frequency characteristics of the local spectrum map to respond to changes in the clarity of the local texture. Then, by calculating the frequency domain distance of the frequency points and fusing the frequency domain distance and the adaptive bandwidth, an adaptive filtering kernel is constructed for each image block. The response value of the adaptive filtering kernel at each frequency point is designed to be positively correlated with the frequency domain distance of the frequency point and negatively correlated with the adaptive bandwidth, thereby achieving accurate control of different frequency components. Finally, the local spectrum map is frequency filtered using the adaptive filtering kernel, which can specifically suppress specific texture frequencies in the current image block while preserving defect information to the maximum extent. The texture-free image is obtained through fusion processing and then segmented, effectively avoiding missed detections due to incomplete texture filtering or misjudgments due to over-filtering, and improving the accuracy of hole defect segmentation. Attached Figure Description
[0028] Figure 1 A flowchart of a method for segmenting hole defects in aluminum alloy forgings provided in an embodiment of the present invention;
[0029] Figure 2 The original image of the forging provided in the embodiment of the present invention;
[0030] Figure 3 This is a schematic diagram illustrating the results of defect detection using conventional methods without texture removal, as provided in an embodiment of the present invention.
[0031] Figure 4 This is a schematic diagram of the defect detection result of a textureless image obtained after processing by the local adaptive frequency domain filtering method according to an embodiment of the present invention.
[0032] Figure 5 This is a structural block diagram of a hole defect segmentation system for aluminum alloy forgings provided in an embodiment of the present invention. Detailed Implementation
[0033] The first aspect of this invention provides a method for segmenting hole defects in aluminum alloy forgings, such as... Figure 1 As shown, the method includes steps S100-S500:
[0034] Step S100: Acquire the original image of the forging and preprocess it to obtain a grayscale image of the forging.
[0035] It should be noted that raw images of aluminum alloy forgings directly captured by industrial cameras in industrial settings typically contain color information irrelevant to the defect segmentation task. This information increases the complexity of subsequent calculations. Furthermore, the images may be affected by fluctuations in ambient lighting, leading to inconsistent grayscale distributions under different acquisition conditions, which in turn affects the accuracy of subsequent detection. Therefore, preprocessing of the raw images is necessary to eliminate these interfering factors.
[0036] Specifically, firstly, raw images of the aluminum alloy forgings are acquired using an industrial camera and a ring light source; then, to eliminate color information interference and simplify data dimensions, the acquired RGB color images are converted into grayscale images; finally, to address slight fluctuations in lighting conditions that may exist in industrial settings, histogram equalization is applied to the grayscale images, linearly mapping their pixel values to a standardized... Gray-scale range enhances image contrast and ensures consistency of gray-scale distribution under different acquisition conditions.
[0037] like Figure 2 The image shown is the original image of the forging. The image contains three white areas and a complex oblique forging flow line texture covering the entire image. These three white areas are real hole defects. The texture direction bends with the geometric curvature of the forging, and the density is uneven. It has the characteristics of non-uniformity and multi-scale, and is a source of interference.
[0038] This completes the preprocessing of the forging image, resulting in a grayscale image.
[0039] Step S200: Divide the grayscale image of the forging into blocks to obtain several image blocks. Perform a two-dimensional Fourier transform on each image block to obtain its local spectrum map. Based on the energy distribution characteristics of the local spectrum map, determine the spectral energy direction of the image block.
[0040] It should be noted that the forging streamline texture on the surface of forgings is the main source of interference in the detection of hole defects. Filtering methods based on global Fourier transform assume that the texture direction and frequency on the forging surface are constant, which cannot adapt to the complex and variable local characteristics of the streamline texture on real forgings, such as bending, turning, and density variations, thus limiting the accuracy and robustness of segmentation. This invention introduces the concept of short-time Fourier transform to perform local analysis and adaptive frequency domain filtering on the image, accurately removing the interference of changing streamline textures while preserving the characteristics of hole defects to the greatest extent possible.
[0041] It should be further explained that, in order to perform local analysis and adaptive frequency domain filtering, it is first necessary to obtain the local region and analyze the accurate direction of the streamline texture in each local region. In the spatial domain, the streamline texture is represented as continuous lines along a specific direction; in the corresponding local frequency domain, these textures converge into a high-energy spectral bright band, and the direction of the spectral bright band is strictly orthogonal to the direction of the spatial domain texture.
[0042] Specifically, obtaining the accurate orientation of the streamline texture within each local region includes:
[0043] It should be noted that only by dividing the entire image into multiple image blocks can we analyze the spectral energy direction of the local characteristics of the image blocks, and then adapt to the changes in texture in different regions. This is a prerequisite for realizing local adaptive filtering.
[0044] First, the grayscale image of the forging is segmented to obtain several image blocks. ,in, The image blocks are indexed by row and column: a sliding window segmentation strategy is used to segment the grayscale image of the forging, resulting in several overlapping image blocks; the overlap rate between each image block is preset to a certain value. ,set up The overlap ratio is used to coordinate with subsequent weighted fusion using a two-dimensional Hanning window, ensuring a smooth transition at image block stitching points and avoiding block artifacts. The overlap ratio can be... The size of the image block is chosen to strike a balance between computational complexity and stitching smoothness. The size of the image block should be adapted to the average width of the typical streamline texture on the forging surface. Preferably, the side length of the image block should be no less than twice the average width to ensure that one or more texture cycles can be completely captured. In this embodiment, for the aluminum alloy forging, the streamline texture cycle is approximately... Pixels, therefore choose Image patches of pixels can acquire robust spectral characteristics. The size and overlap rate of the image patches can also be set by the implementer as needed.
[0045] It's important to note that the Hanning window is a commonly used window function in signal processing. Its smooth transition to zero at both ends effectively suppresses edge effects caused by image block segmentation, preventing abrupt changes between edge pixels and adjacent image blocks from generating spurious energy in the frequency domain, thus ensuring the accuracy of spectral analysis. The two-dimensional Fast Fourier Transform (FFT) is the core operation for converting image blocks from the spatial domain to the frequency domain. Through this transformation, continuous streamline textures in the spatial domain appear as concentrated high-energy regions in the frequency domain, providing a foundation for subsequent analysis of texture direction and design of filtering strategies. This is also a key step in achieving local adaptive filtering. Besides the Hanning window, other window functions with smooth attenuation at both ends, such as the Hamming window and the Blackman window, can also be used.
[0046] Secondly, a two-dimensional Hanning window is applied to each image patch to reduce spectral leakage, followed by a two-dimensional fast Fourier transform to obtain its local spectrogram. .
[0047] It should be noted that the second-order central moment is an important parameter for evaluating the energy distribution characteristics of a local spectrogram. Directional Moment Second order Directional Moment Reflecting energy in , The extent of directional distribution extension; second-order mixed central moment These three parameters reflect the tilting trend of energy distribution. By using these three parameters, the distribution inertial axis of the bright band of the spectrum formed by the streamline texture in the frequency domain can be accurately captured, providing data support for the subsequent derivation of the texture direction.
[0048] Then, the second central moments of the local spectrogram are calculated. How to calculate the second central moments is an existing technique and will not be elaborated here.
[0049] It should be noted that after obtaining the second-order central moments, the spectral energy direction needs to be derived based on these parameters. Then, based on the orthogonality between the frequency domain and spatial domain directions, it is converted into the texture direction in the spatial domain. The spectral energy direction is determined by the principal axis of the distribution inertia of the spectral bright bands. The angle of this principal axis cannot be directly observed and needs to be calculated through the combination of the second-order central moments. At the same time, since the spectral bright band direction is orthogonal to the spatial domain texture direction, the calculation result also needs to be converted into the spatial domain texture direction. This spectral energy direction is the key basis for the subsequent design of directional filters and accurate removal of streamline textures.
[0050] Based on the above logic, the spectral energy direction of each image block satisfies the following relationship:
[0051] ;
[0052] in, It is the first The spectral energy direction of each image patch; , , They are the first The second-order mixing central moments of each image patch, the second-order... Directional moment, second order Directional moment; It is the arctangent function.
[0053] In this relation, It is twice the second-order mixed central moment, and the second-order... Directional moment minus second order The ratio of the differences obtained from the directional moments is essentially the tangent of twice the angle of the principal axis of inertia of the spectral energy distribution. This ratio can be used to convert energy distribution characteristics into angular parameters. By performing an arctangent operation, twice this angle can be obtained, and multiplying it by 1 / 2 yields the actual angle of the spectral bright band, which is the spectral energy direction. .
[0054] At this point, the spectral energy direction of each image block has been obtained.
[0055] Step S300: Calculate the projection distance of the frequency point of the local spectrogram in the spectral energy direction to obtain the frequency domain distance; calculate the adaptive bandwidth of the image block based on the frequency characteristics of the local spectrogram; fuse the frequency domain distance and the adaptive bandwidth to obtain the adaptive filtering kernel of the image block.
[0056] It should be noted that the clarity of texture varies in real forging images. In areas with clear texture, a narrow and deep filter is needed to accurately remove texture frequencies; while in areas with blurred texture or no texture, such as inside holes or defects or on smooth surfaces, a wide and shallow filter, or even no filtering, should be used to avoid incorrectly filtering out defect signals or introducing artifacts. Therefore, this step constructs an adaptive filter for each image block that can automatically adjust its bandwidth based on the local texture clarity.
[0057] It should be further explained that the selection of the filter kernel is crucial to the final result. Traditional filters have overly steep cutoff characteristics in the frequency domain, which can produce severe ringing effects and create artifacts when the image is inversely transformed back to the spatial domain. In contrast, the Butterworth band-stop filter has a smooth frequency response curve without abrupt changes, which can effectively filter out the target frequency while avoiding ringing effects and ensuring image realism.
[0058] Specifically, this step uses a Butterworth band-stop filter as the basic model and designs adaptive parameters for it. The final process of calculating the local adaptive filter kernel includes: constructing the filter bandwidth based on the local spectrogram; calculating the frequency domain distance based on the spectral energy direction of the image patch; and obtaining the filter kernel by combining the filter bandwidth and the frequency domain distance.
[0059] It should be noted that the filtering bandwidth is a key parameter that determines the filtering range of the Butterworth band-stop filter: a narrower bandwidth is needed in areas with clear textures to accurately filter out the texture, while a wider bandwidth is needed in non-textured areas or defective areas to reduce the filtering intensity and avoid falsely suppressing defective features. Therefore, the bandwidth must be dynamically adjusted according to the local texture characteristics. The core premise for achieving dynamic adjustment is to first obtain an index that can evaluate the clarity of the texture, and then calculate the adaptive bandwidth based on the index, so as to achieve the adaptation effect of narrower bandwidth as the texture is clearer.
[0060] Based on the above logic, the adaptive bandwidth satisfies the following relationship:
[0061] ;
[0062] in, It is the first Adaptive bandwidth for each image patch; This is the base bandwidth value; It is the first Texture cohesion of an image patch; It is a natural exponential function.
[0063] In this relationship, when the texture cohesion At a very high level, Approaching 0, bandwidth It becomes very narrow, enabling accurate filtering of sharp textures; when When very low, Approaching 1, bandwidth Widening approaches The filtering effect is weakened, thus preserving useful information in non-textured areas.
[0064] It should be noted that the base bandwidth value This characterizes the filter bandwidth when there is no texture at all. Its value should be greater than the size of the largest possible defect on the forging surface in the frequency domain to avoid excessive suppression of defect signals in textureless areas. In this embodiment, it is preferably set to 2.
[0065] Obtaining texture cohesion includes: calculating the local spectrogram of an image patch along the principal direction of spectral energy. The energy variance on the second direction is related to the energy variance on the third direction. The ratio of energy variance in orthogonal directions is denoted as texture cohesion. The larger the ratio, the more concentrated the energy of the image patch is in the bright band of the spectrum, the clearer the texture, and the higher the cohesion. The calculation of energy variance is existing technology and will not be elaborated here.
[0066] It should be noted that the Butterworth band-stop filter needs to accurately locate the bright spectral band corresponding to the streamline texture in the frequency domain. This bright spectral band is usually represented by a line passing through the origin of the coordinate system. and along the direction The extended straight line therefore requires calculation of each frequency point in the frequency domain. The projection distance on this direction axis can be regarded as the one-dimensional frequency of this frequency point in the bright band of the spectrum. The closer the distance, the more likely the frequency point belongs to the texture energy band that needs to be suppressed and should be filtered out. The farther the distance, the more likely it is a defect or background energy that should be retained.
[0067] Based on the above logic, the frequency point The square of the projected distance along the bright band of the spectrum satisfies the following relationship:
[0068] ;
[0069] in, Frequency The square of the projected distance along the bright band of the spectrum; It is the first The spectral energy direction of each image patch; These are the coordinates of the frequency points; It is its horizontal frequency component; It is its vertical frequency component.
[0070] In this relationship, frequency point It can be viewed as a coordinate vector originating from the origin. In the relation Used to calculate this coordinate vector In the direction of the bright band in the spectrum The projection length on the frequency point The parallel distance to the center line of the bright band in the spectrum passing through the origin, squared, gives the result. This facilitates subsequent substitution into the Butterworth filter equation for smooth attenuation calculation.
[0071] It should be noted that after obtaining the adaptive bandwidth and the projection distance from each frequency point to the bright band axis of the spectrum, it is necessary to combine these two parameters with the basic structure of the Butterworth band-stop filter to generate a local adaptive filter kernel. This allows the filter kernel to both directionally block texture energy and adjust the blocking range according to the texture clarity, ultimately achieving local adaptive filtering.
[0072] Finally, the adaptive filter kernel is calculated, the first... The adaptive filtering kernel of each image patch in the frequency domain coordinates The response value at that location satisfies the following relationship:
[0073] ;
[0074] in, It is the first The adaptive filtering kernel of each image patch in the frequency domain coordinates The response value at the location; Frequency The square of the projected distance along the bright band of the spectrum; It is the preset filter center frequency; It is the first Adaptive bandwidth for each image patch; It is the order of the Butterworth filter; It is a preset microvalue used to prevent the denominator from being 0, and can be set to 0.001.
[0075] In this relation, The molecular component in the filter determines the transition band width and attenuation rate. When the texture cohesion is high, The smaller the value, the smaller the molecule, which in turn causes the function to move away from the molecule. The region that is more likely to approach 0 forms a narrow and deep inhibition band, accurately eliminating clear textures; conversely, when the texture is blurred or missing, close to the base value The numerator is larger, resulting in weaker inhibition and preventing accidental damage to defect signals; the denominator part Measure the current frequency edge Projection frequency of the axis to the target suppression frequency The degree of offset, when near When the denominator approaches zero, Approaching 0, achieving strong suppression of texture energy; when Significantly greater than or less than As the denominator increases, the fraction approaches 0, and the final value... Approaching 1, this ratio preserves background and defect information. After exponentiation, a smooth nonlinear response is formed, constructing a [structure / mechanism]. Centered on, width by The adjusted concave band, due to the continuous differentiability of the Butterworth filter response, avoids the steep transitions of the ideal filter, suppresses ringing artifacts in the spatial domain after the inverse transform, and ensures image authenticity.
[0076] It should be noted that the filter center frequency... Corresponding to the dominant frequency in the frequency domain of the streamline texture that needs to be suppressed, this value can be determined by performing spectral analysis on a typical texture sample image without defects to find the frequency corresponding to its energy peak. In this embodiment, the energy peak of the typical streamline texture appears at a frequency of 15, therefore... The default value is 15.
[0077] At this point, the adaptive filtering kernel for each image block has been obtained.
[0078] Step S400: Apply the adaptive filtering kernel to the local spectrogram to perform frequency domain filtering to obtain the filtered spectrogram. Perform a two-dimensional inverse Fourier transform on the filtered spectrogram to obtain filtered spatial domain image blocks. Perform fusion processing on all the filtered spatial domain image blocks to obtain a textureless image.
[0079] It should be noted that if a simple image patching method is used to reconstruct the image after frequency domain filtering and inverse transformation back to the spatial domain, obvious blocky effects and discontinuity artifacts will occur at the boundaries of image patches, especially in overlapping areas. To alleviate this problem, the overlapping areas need to be smoothly blended. This invention adopts a weighted average method based on window functions, which can achieve a natural transition in overlapping areas, effectively suppress abrupt boundary changes, and is computationally simple and easy to implement, balancing the visual continuity of the reconstructed image with processing efficiency.
[0080] Specifically, firstly, for each image patch, its local spectrogram is... Its corresponding adaptive filter kernel The filtered spectrum is obtained by performing point-by-point multiplication in the frequency domain. Then, a two-dimensional inverse Fourier transform is performed on the filtered spectrum to obtain the filtered spatial domain image patch. Finally, the final textureless image is obtained by weighted averaging.
[0081] Based on the above logic, the pixels in the textureless image The pixel values satisfy the following relationship:
[0082] ;
[0083] in, It is a textureless image at global coordinates. Pixel value at; It covers all global coordinate points Image blocks Perform summation; It is the first Image patches in frequency domain coordinates Spectral values at; It is the first Image patches in frequency domain coordinates Adaptive filter kernel at the location; It is the first After applying the corresponding adaptive filter kernel to the spectrum of each image patch, performing an inverse Fourier transform yields the filtered spatial domain image patch in its local coordinates. Pixel value at; It is the local coordinate of the pixel in its image patch. The weight value at the point is obtained by applying a two-dimensional Hanning window when dividing the grayscale image of the forging into blocks. The center weight of the window function is 1, and the weight at the edge will be smoothly transitioned to 0.
[0084] In this relationship, the numerator is used to calculate the global coordinates of all covered points. The sum of the weighted pixel values contributed by the image patch at that point, due to In image patches, the center has a high weight and the edge has a low weight. This means that the value of a pixel is mainly determined by the central region of the image patch it belongs to, and is less affected by the edge region; the denominator is used to calculate the global coordinates. The sum of weights across all overlapping windows is used to normalize the total weighted sum, ensuring that the final pixel value is within the correct amplitude range. Because this formula uses a two-dimensional Hanning window with a 50% overlap, the total weight is theoretically constant across all overlapping regions. Therefore, normalizing using this denominator accurately reconstructs the original signal amplitude, ensuring a natural and continuous textureless image in the final output and avoiding blocky artifacts.
[0085] S500. The textureless image is segmented to obtain the segmentation result of the hole defect.
[0086] It should be noted that after filtering, the complex and non-uniform streamline background is effectively suppressed, and the holes and defects are preserved and enhanced as highlight areas, providing a good foundation for segmentation. This step uses a textureless image to perform the segmentation operation and extract the final defect results.
[0087] Specifically, firstly, the Otsu adaptive thresholding method is applied to the textureless image to generate a binary mask image, where only the bright, potentially defective regions remain and are marked as the foreground. It should be noted that while the Otsu method is a classic algorithm in image segmentation, finding the threshold that maximizes inter-class variance by iterating through all possible grayscale thresholds, this invention uses the Otsu method because it is adaptive, does not rely on empirically set fixed thresholds, and is more robust.
[0088] Next, morphological opening is performed on the binarized mask image. The erosion operation erodes the edges of the foreground region, effectively eliminating tiny, isolated noise points caused by filter residue or noise. The subsequent dilation operation restores the size of the real defect region that has been eroded, ultimately achieving noise reduction without affecting the main defect morphology.
[0089] Finally, the connected component analysis algorithm is used to analyze the morphologically processed binarized image. This algorithm traverses the image, identifies and aggregates all spatially connected foreground pixels to form independent connected regions. For example, foreground pixels satisfying 8-connectivity are clustered into the same connected region, and a unique label is assigned to each independent connected region. Each labeled independent connected region is the segmented hole defect. It should be noted that the Otsu adaptive thresholding method, morphological opening operation, and connected component analysis algorithm used in this step are all existing technologies and will not be elaborated upon here.
[0090] like Figure 3The image shown is the result of defect detection using traditional methods without removing texture. Because the complex streamline texture is not removed, the highlighted parts in the streamline texture are easily misjudged as potential defect areas during the detection process, resulting in the final detection result containing areas that are not actually defects. This reduces the accuracy and reliability of the detection.
[0091] like Figure 4 As shown, the defect detection result of the textureless image obtained after processing by the local adaptive frequency domain filtering method is shown. The background in the image is cleaner, and the only three real hole defect areas are clearly preserved and highlighted. Performing defect detection under these conditions can more accurately identify the actual defect location, reduce misjudgments caused by texture interference, and thus improve the accuracy of the detection results.
[0092] The second aspect of this embodiment provides a hole defect segmentation system for aluminum alloy forgings, such as Figure 5 As shown, the aluminum alloy forging hole defect segmentation system includes a memory and a processor. The memory stores computer program instructions, and when the computer program instructions are executed by the processor, a method for segmenting aluminum alloy forging hole defects according to the first aspect of the present invention is implemented.
[0093] The aluminum alloy forging hole defect segmentation system also includes other components well known to those skilled in the art, such as communication buses and communication interfaces. Their setup and functions are known in the art and will not be described in detail here.
[0094] In this invention, the aforementioned memory can be any tangible medium containing or storing a program that can be used or combined with an instruction execution system, apparatus, or device. For example, a computer-readable storage medium can be any suitable magnetic or magneto-optical storage medium, such as resistive random access memory (DRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (DRAM), high-bandwidth memory, hybrid memory cube, etc., or any other medium that can be used to store desired information and can be accessed by an application, module, or both. Any such computer storage medium can be part of a device or accessible to or connected to a device.
[0095] The above are all preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Therefore, all equivalent changes made in accordance with the structure, shape and principle of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A method for segmenting hole defects in aluminum alloy forgings, characterized in that, Including the following steps: The original image of the forging is acquired and preprocessed to obtain a grayscale image of the forging; The grayscale image of the forging is divided into blocks to obtain several image blocks. A two-dimensional Fourier transform is performed on each image block to obtain its local spectrum. Based on the energy distribution characteristics of the local spectrum, the spectral energy direction of the image block is determined. Calculate the projection distance of the frequency point in the local spectrogram along the spectral energy direction to obtain the frequency domain distance; the projection distance represents the position of the current frequency point energy on the spectral bright band axis. The closer the projection distance, the greater the probability that the frequency point belongs to the texture energy band that needs to be suppressed, and it needs to be filtered out. The farther the projection distance, the greater the probability that the frequency point belongs to a defect or background energy, and it should be retained; The adaptive bandwidth of an image patch is calculated based on the frequency characteristics of the local spectrogram, including: calculating the ratio of the energy variance of the local spectrogram in the spectral energy direction to the energy variance in the orthogonal direction of the spectral energy direction to obtain the texture cohesion; the adaptive bandwidth is calculated based on the texture cohesion. The larger the texture cohesion, the more concentrated the energy of the image patch is in the spectral bright band, the clearer the texture, and the narrower the adaptive bandwidth; the adaptive bandwidth is negatively correlated with the texture cohesion. By fusing frequency domain distance and adaptive bandwidth, an adaptive filter kernel for the image patch is obtained. The response value of the adaptive filter kernel at each frequency point is positively correlated with the frequency domain distance of the frequency point and negatively correlated with the adaptive bandwidth of the image patch. The adaptive filter kernel is a Butterworth band-stop filter, and its response value satisfies the following relationship: ; in, It is the first The adaptive filtering kernel of each image patch in the frequency domain coordinates The response value at the location; Frequency The square of the frequency domain distance; It is the preset filter center frequency; It is the first Adaptive bandwidth for each image patch; It is the order of the Butterworth filter; It is a preset micro value; An adaptive filtering kernel is applied to the local spectrogram to perform frequency domain filtering, resulting in a filtered spectrogram. A two-dimensional inverse Fourier transform is then performed on the filtered spectrogram to obtain filtered spatial domain image patches. All filtered spatial domain image patches are then fused to obtain a textureless image. The textureless image is segmented to obtain the segmentation results of the hole defect.
2. The method for segmenting hole defects in aluminum alloy forgings according to claim 1, characterized in that, Determining the spectral energy direction of the image patch based on the energy distribution characteristics of the local spectrogram includes: Calculate the second-order central moments of the local spectrogram; The spectral energy direction of the image patch is calculated based on the second-order central moment.
3. The method for segmenting hole defects in aluminum alloy forgings according to claim 2, characterized in that, The spectral energy direction of the image patch satisfies the following relationship: ; in, It is the first The spectral energy direction of each image patch; , , They are the first The second-order mixing central moments of each image patch, the second-order... Directional moment, second order Directional moment; It is the arctangent function.
4. The method for segmenting hole defects in aluminum alloy forgings according to claim 1, characterized in that, The calculation of adaptive bandwidth based on the texture cohesion includes: Obtain the negative exponential function of the texture cohesion, and multiply it by a preset base bandwidth value to obtain the adaptive bandwidth.
5. The method for segmenting hole defects in aluminum alloy forgings according to claim 1, characterized in that, The grayscale image of the forging is divided into blocks to obtain several image blocks, including: The grayscale image of the forging is divided into blocks to obtain several image blocks; For each of the image blocks, a two-dimensional Hanning window is applied.
6. The method for segmenting hole defects in aluminum alloy forgings according to claim 5, characterized in that, The step of fusing all the filtered spatial domain image blocks to obtain a textureless image includes: For all filtered spatial domain image blocks covering the same global coordinate point, calculate the weighted average of the corresponding pixel values under their local coordinates to obtain the pixel value of the global coordinate point; The weights used in the weighting are the same as the window function values of the two-dimensional Hanning window.
7. The method for segmenting hole defects in aluminum alloy forgings according to claim 1, characterized in that, The segmentation process of the textureless image to obtain the segmentation result of the hole defect includes: The Otsu adaptive thresholding method is applied to the textureless image to obtain a binary image; Perform a morphological opening operation on the binary image to obtain the binary image after the opening operation; The binary image after the opening operation is analyzed using connected component analysis, and each independent connected region is used as the segmentation result of the hole defect.
8. A hole defect segmentation system for aluminum alloy forgings, characterized in that, The aluminum alloy forging hole defect segmentation system includes a processor and a memory. The memory stores computer program instructions, which, when executed by the processor, implement the aluminum alloy forging hole defect segmentation method according to any one of claims 1-7.
Citation Information
Patent Citations
Cloth surface defect detection method
CN115330784A
Cable shielding layer braiding density detection system based on image analysis
CN121147212A