Cold shut defect detection method based on defect recognition detection
By initially segmenting and fitting curve processing of the grayscale image of metal castings, the problem of inaccurate cold space defect detection in the prior art is solved, and the precise positioning and accurate segmentation of cold space defect areas are realized, and the accuracy of detection is improved sex.
Patent Information
- Application Number
- CN202411390237.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2044-10-08
AI Technical Summary
The method for detecting cold septum defects in the prior art relies on neural network training. Inaccurate sample data can easily lead to inaccurate detection results, and easily misjudged the surface texture as cold septum defects, resulting in inaccurate detection.
By obtaining the grayscale image of the metal casting, calculating the grayscale histogram, segmenting the initial cold partition area, building a fitting curve, resegmenting the target cold partition area, and determining the edge of the cold partition area based on the probability and threshold of the pixel point, achieving cold Accurate positioning of septum defects.
It improves the precise segmentation of cold septal defect areas, reduces misjudgment, realizes the precise positioning of cold septal defect locations, and enhances the accuracy of detection.
Smart Images

Figure CN118898608B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of material testing and analysis, and in particular to a cold shut defect detection method based on defect recognition detection. Background Art
[0002] The parts where cold shut occurs in aluminum alloy die castings are usually the wide surface and thin wall of the casting away from the gate. The cold shut defect is caused by the flow of metal flow divided into several streams. The flow front of each stream has already shown a condensed state, which is called the solidification front. However, it is still filled under the push of the following metal flow. When the metal flow that meets it also has a solidification front, the solidified layers that meet can no longer be fused, and a gap appears at the joint. The two metal flows are butt-joined but not completely fused. The bonding force of the two metals is very weak. Severe cold shut affects the use of castings. Measures must be taken to remove the flow marks and cold shut water mark defects that appear in the aluminum alloy die casting process, so as not to affect the quality and normal use of the die castings.
[0003] The method for detecting cold shut defects in the prior art is to train a neural network and then identify the cold shut defects. This method requires a large number of samples for training and learning. Inaccurate sample data can easily lead to inaccurate detection results, and it is easy to mistake the surface texture for a cold shut defect, resulting in inaccurate cold shut area detection.
[0004] Therefore, it is necessary to provide a cold shut defect detection method based on defect recognition detection to solve the above problems. Summary of the invention
[0005] The present invention provides a cold shut defect detection method based on defect recognition detection to solve the existing problems.
[0006] The cold shut defect detection method based on defect recognition detection of the present invention adopts the following technical solution: the method comprises:
[0007] Acquire a surface image of the metal casting to be inspected and obtain a grayscale image thereof;
[0008] Obtain a grayscale histogram of the grayscale image, obtain grayscale values corresponding to two trough points in the grayscale histogram, and segment the grayscale image according to the grayscale values corresponding to the two trough points to obtain an initial cold isolation area;
[0009] Acquire multiple windows along the edge of the initial cold isolation area. When the number of pixels in each window is greater than a preset number threshold, take the center of the window as a center point, connect all adjacent center points to form multiple straight lines, and calculate the gradient direction angle of the straight line according to the angle between each straight line and the vertical direction.
[0010] Obtain a fitting curve of the initial cold shut region according to the center point corresponding to each straight line segment of the initial cold shut region and the gradient direction angle of the straight line, and re-segment the initial cold shut region according to the fitting curve to obtain a target cold shut region;
[0011] Calculate the grayscale difference between each pixel in the target cold isolation area and the pixels in its 8 neighborhoods, and calculate the probability that the pixel is a pixel in the target cold isolation area based on the grayscale difference and the frequency of the grayscale value corresponding to the pixel;
[0012] The edge pixels of the target cold cutoff area are determined according to the probability of the pixels on the target cold cutoff area and the preset threshold, and the target cold cutoff area is segmented according to the edge pixels to obtain the final cold cutoff area.
[0013] Furthermore, the step of segmenting the grayscale image according to the grayscale values corresponding to the two trough points to obtain the initial cold isolation area includes:
[0014] Get all the pixels corresponding to the grayscale value of the trough point;
[0015] Calculate the gradient direction of each pixel corresponding to the trough point;
[0016] All the pixels corresponding to each trough point are connected into a region along the gradient direction, and this region is recorded as the initial cold isolation region.
[0017] Furthermore, the step of acquiring a plurality of windows along the edge of the initial cold isolation area includes:
[0018] Obtain edge pixel points on the edge of the initial cold isolation area;
[0019] Set the window size to 2*2;
[0020] Multiple windows are obtained in sequence in the edge direction of the initial cold isolation area, and the edge pixels in two adjacent windows are different.
[0021] Furthermore, the step of calculating the gradient direction angle of the straight line according to the angle between each straight line segment and the vertical direction includes:
[0022] Get the number n of pixels corresponding to the horizontal projection of each straight line;
[0023] Get the number m of pixel points corresponding to the projection of each straight line in the vertical direction;
[0024] Calculate the angle between each straight line and the vertical direction according to the ratio of the number n of pixels corresponding to the projection of the straight line in the horizontal direction to the number m of pixels corresponding to the projection of the straight line in the vertical direction;
[0025] The angle between the straight line and the vertical direction is recorded as the gradient direction angle of the straight line.
[0026] Furthermore, a fitting curve is obtained according to the center point corresponding to each straight line and its gradient direction angle using a Bezier curve algorithm.
[0027] Furthermore, the step of re-segmenting the initial cold shut area according to the fitting curve to obtain the target cold shut area includes:
[0028] The fitting curve is used as the boundary line of the corresponding initial cold shut area;
[0029] The initial cold cut area is re-segmented according to the dividing line to obtain the target cold cut area.
[0030] Furthermore, the step of calculating the grayscale difference between each pixel in the target cold isolation area and the pixels in its 8 neighborhoods includes:
[0031] Each pixel point on the target cold isolation area is taken as the central pixel point;
[0032] Get the grayscale values of the pixels in the 8-neighborhood of the central pixel;
[0033] Calculate the grayscale difference between the grayscale value of the central pixel and the grayscale value of each other pixel in the 8-neighborhood;
[0034] The grayscale difference value of the central pixel is calculated based on the grayscale difference value and the number of pixels in the 8-neighborhood.
[0035] Furthermore, it also includes:
[0036] Get the grayscale histogram of the cold isolation area;
[0037] Equalize the grayscale histogram of the cold isolation area to obtain the cold isolation enhancement area image;
[0038] The cold shut enhancement area image is depicted to obtain the final cold shut area.
[0039] The beneficial effects of the present invention are as follows: the cold shut defect detection method based on defect recognition detection of the present invention first performs initial segmentation on the grayscale image according to the grayscale histogram to obtain an initial cold shut area, then processes the edge of the initial cold shut area to construct a fitting curve, and re-segments the initial cold shut area according to the fitting curve to obtain a target cold shut area, and determines the edge pixel points of the target cold shut area according to the probability that the pixel points on the edge of the target cold shut area are edge pixel points according to the probability and the probability threshold, and then segments the cold shut area according to the edge pixel points, completes the segmentation of the cold shut area, and realizes the precise positioning of the cold shut defect position, and secondly enhances the cold shut area through image enhancement technology, thereby improving the precise segmentation of the cold shut defect area. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0041] Figure 1 A flowchart of the overall steps of an embodiment of a cold shut defect detection method based on defect recognition detection of the present invention;
[0042] Figure 2 A schematic diagram of the structure of connecting adjacent center points to form multiple straight lines. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] The embodiment of the cold shut defect detection method based on defect recognition detection of the present invention is aimed at processing metal castings containing only cold shut defects, such as Figure 1 As shown, the method includes:
[0045] S1. Collecting a metal casting image with a camera, processing the metal casting image using a threshold segmentation method to obtain a surface image containing only the metal casting, and obtaining a grayscale image of the surface image of the metal casting.
[0046] S2. When the collected surface image contains cold shut defects, because the surface of the metal casting has other textures, which will affect the judgment of the defect, the local threshold segmentation method is used to segment the cold shut defect area image from other area images, obtain the grayscale histogram of the grayscale image, obtain the grayscale values corresponding to the two trough points in the grayscale histogram, and use the grayscale values corresponding to the two trough points as two local thresholds, that is, the grayscale image is segmented according to the grayscale values corresponding to the two local thresholds to obtain the initial cold shut area without other areas of the casting;
[0047] Specifically, all pixel points corresponding to the grayscale value of the trough point are obtained; the gradient direction of each pixel point corresponding to the trough point is calculated; all pixel points corresponding to each trough point are connected into an area along the gradient direction, and the area is recorded as the initial cold shut area, wherein, since the grayscale of the cold shut area is relatively small relative to the texture of the casting, the area corresponding to the trough point with a small grayscale value is the initial cold shut area; the area corresponding to the trough point with a large grayscale value is the initial casting texture area.
[0048] S3. Because the gray value of the trough corresponds to a point within the gray range of the boundary between the edge of the initial cold shut area and the initial casting texture area and the surface of the metal casting, multiple windows are obtained along the edge of the initial cold shut area. When the number of pixel points in each window is greater than a preset number threshold, the center of the window is taken as a center point, and all adjacent center points are connected to form multiple straight lines. The gradient direction angle of the straight line is calculated according to the angle between each straight line and the vertical direction.
[0049] Specifically, Figure 2 As shown, the step of acquiring multiple windows along the edge of the initial cold isolation area includes: acquiring edge pixel points on the edge of the initial cold isolation area; setting the window size to 2*2; and acquiring multiple windows in sequence along the edge direction of the initial cold isolation area, and the edge pixel points in two adjacent windows are different.
[0050] Specifically, when the number of pixel points in each window is greater than a preset number threshold, the step of taking the center of the window as a center point includes: setting the number threshold to 2; when the number of pixel points in the window is greater than the number threshold, recording the center of the window as the initial center point; and recording the initial center point closest to the edge of the initial cold isolation area among all the initial center points as the center point.
[0051] Specifically, obtain the number n of pixels corresponding to the projection of each straight line in the horizontal direction; obtain the number m of pixels corresponding to the projection of each straight line in the vertical direction; calculate the angle between each straight line and the vertical direction according to the ratio of the number n of pixels corresponding to the projection of the straight line in the horizontal direction to the number m of pixels corresponding to the projection of the straight line in the vertical direction; record the angle between the straight line and the vertical direction as the gradient direction angle of the straight line, that is, calculate the gradient direction angle of the straight line according to the following formula (1):
[0052] (1)
[0053] in, represents the gradient direction angle of the straight line AC, Indicates the number of pixels corresponding to the horizontal projection of the straight line AC. Indicates the number of pixels corresponding to the projection of line AC in the vertical direction.
[0054] S4. According to the center point and the gradient direction angle corresponding to each straight line segment, a fitting curve of the initial cold cut area is obtained by using a Bezier curve algorithm. According to the fitting curve, the initial cold cut area is re-segmented to obtain a target cold cut area. Specifically, the fitting curve is used as a dividing line of the initial cold cut area corresponding to the fitting curve. According to the dividing line, the initial cold cut area is re-segmented to obtain a target cold cut area.
[0055] S5. Calculate the grayscale difference between each pixel in the target cold isolation area and the pixels in its 8 neighborhoods, and calculate the probability that the pixel is a pixel in the corresponding target cold isolation area according to the grayscale difference and the frequency of the grayscale value corresponding to the pixel.
[0056] Specifically, each pixel point on the target cold isolation area is taken as the central pixel point; the grayscale values of the pixels in the 8 neighborhoods of the central pixel point are obtained; the grayscale difference between the grayscale value of the central pixel point and the grayscale value of each other pixel point in the 8 neighborhoods is calculated; the grayscale difference value of the central pixel point is calculated according to the grayscale difference value and the number of pixels in the 8 neighborhoods, wherein the grayscale difference value is calculated according to the following formula (2):
[0057] (2)
[0058] in, represents the grayscale difference between the i-th central pixel and the other pixels in its 8-neighborhood; n represents the number of pixels in the 8-neighborhood of the central pixel, Represents the gray value of the center pixel, Represents the gray value of the i-th pixel in the 8-neighborhood of the central pixel.
[0059] The probability that a pixel point is in the target cold isolation area is calculated according to the following formula (3):
[0060] (3)
[0061] in, Indicates the probability that the pixel is a pixel in the target cold isolation area, Indicates the frequency of the gray value corresponding to the i-th pixel, Represents the grayscale difference between the central pixel and the i-th pixel in its 8-neighborhood.
[0062] S6. Determine edge pixels of the target cold-isolated area according to the probability of pixels on the target cold-isolated area and a preset threshold, and segment the target cold-isolated area according to the edge pixels to obtain a final cold-isolated area.
[0063] The method also includes: obtaining a grayscale histogram of the cold insulation area; equalizing the grayscale histogram of the cold insulation area to obtain a cold insulation enhancement area image; and depicting the cold insulation enhancement area image to obtain a final cold insulation area.
[0064] In summary, the present invention provides a cold shut defect detection method based on defect recognition detection, which first performs initial segmentation on the grayscale image according to the grayscale histogram to obtain an initial cold shut area, then processes the edge of the initial cold shut area to construct a fitting curve, and re-segments the initial cold shut area according to the fitting curve to obtain a target cold shut area, and determines the edge pixel points of the target cold shut area according to the probability that the pixel points on the edge of the target cold shut area are edge pixel points according to the probability and the probability threshold, and then segments the cold shut area according to the edge pixel points, completes the segmentation of the cold shut area, realizes the accurate positioning of the cold shut defect position, and provides a reference basis for the subsequent cold shut defect judgment, and secondly enhances the cold shut area through the image enhancement technology, thereby improving the accurate segmentation of the cold shut defect area.
[0065] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A cold shut defect detection method based on defect recognition detection, characterized in that: The method includes: Acquire a surface image of the metal casting to be inspected and obtain a grayscale image thereof; Obtain a grayscale histogram of the grayscale image, obtain grayscale values corresponding to two trough points in the grayscale histogram, and segment the grayscale image according to the grayscale values corresponding to the two trough points to obtain an initial cold isolation area; Acquire multiple windows along the edge of the initial cold isolation area. When the number of pixels in each window is greater than a preset number threshold, take the center of the window as a center point, connect all adjacent center points to form multiple straight lines, and calculate the gradient direction angle of the straight line according to the angle between each straight line and the vertical direction. Obtain a fitting curve of the initial cold shut region according to the center point corresponding to each straight line segment of the initial cold shut region and the gradient direction angle of the straight line, and re-segment the initial cold shut region according to the fitting curve to obtain a target cold shut region; Calculate the grayscale difference between each pixel in the target cold isolation area and the pixels in its 8 neighborhoods, and calculate the probability that the pixel is a pixel in the target cold isolation area based on the grayscale difference and the frequency of the grayscale value corresponding to the pixel; Determine the edge pixel points of the target cold cutoff area according to the probability of the pixel points on the target cold cutoff area and the preset threshold, and segment the target cold cutoff area according to the edge pixel points to obtain the final cold cutoff area; The step of segmenting the grayscale image according to the grayscale values corresponding to the two trough points to obtain the initial cold isolation area includes: Get all the pixels corresponding to the grayscale value of the trough point; Calculate the gradient direction of each pixel corresponding to the trough point; All pixel points corresponding to each trough point are connected into a region along the gradient direction, and the region is recorded as an initial cold isolation region; the step of obtaining multiple windows along the edge of the initial cold isolation region includes: Obtain edge pixel points on the edge of the initial cold isolation area; Set the window size to 2*2; Multiple windows are obtained in sequence in the edge direction of the initial cold isolation area, and the edge pixels in two adjacent windows are different; The steps of calculating the gradient direction angle of a straight line according to the angle between each straight line segment and the vertical direction include: Get the number n of pixels corresponding to the horizontal projection of each straight line; Get the number m of pixel points corresponding to the projection of each straight line in the vertical direction; Calculate the angle between each straight line and the vertical direction according to the ratio of the number n of pixels corresponding to the projection of the straight line in the horizontal direction to the number m of pixels corresponding to the projection of the straight line in the vertical direction; The angle between the straight line and the vertical direction is recorded as the gradient direction angle of the straight line; A fitting curve is obtained by using a Bezier curve algorithm according to the center point and the gradient direction angle corresponding to each straight line; The steps of re-segmenting the initial cold shut area according to the fitting curve to obtain the target cold shut area include: The fitting curve is used as the boundary line of the corresponding initial cold shut area; The initial cold cut area is re-segmented according to the dividing line to obtain the target cold cut area.
2. The cold shut defect detection method based on defect recognition detection according to claim 1 is characterized in that: The steps of calculating the grayscale difference value of each pixel point in the target cold isolation area and the pixels in its 8 neighborhoods include: Each pixel point on the target cold isolation area is taken as the central pixel point; Get the grayscale values of the pixels in the 8-neighborhood of the central pixel; Calculate the grayscale difference between the grayscale value of the central pixel and the grayscale value of each other pixel in the 8-neighborhood; The grayscale difference value of the central pixel is calculated based on the grayscale difference value and the number of pixels in the 8-neighborhood.
3. The cold shut defect detection method based on defect recognition detection according to claim 1 is characterized in that: Also includes: Get the grayscale histogram of the cold isolation area; Equalize the grayscale histogram of the cold isolation area to obtain the cold isolation enhancement area image; The cold shut enhancement area image is depicted to obtain the final cold shut area.
