A method for merging defective regions
By introducing directional structural elements and linear feature parameter filtering, the problem of erroneous merging of defect regions in existing technologies is solved, and accurate and complete defect region detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XIAMEN WEIXINTAI TECH CO LTD
- Filing Date
- 2025-10-31
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies are prone to merging irrelevant regions when dealing with complex morphological defects such as discontinuous and linear defects, leading to deviations in detection results. Furthermore, small discontinuous linear defects may be misjudged as noise and filtered out, affecting the accuracy of detection.
Directional structural elements are used to directionally merge linear feature defects, and parameters such as aspect ratio and skeleton length are used for filtering to remove irrelevant areas and obtain accurate and complete linear defect areas.
It effectively improves the accuracy and completeness of defect area merging, prevents the erroneous merging of irrelevant areas and the misjudgment of minor linear defects, and enhances the accuracy of detection results.
Smart Images

Figure CN121330270B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection, and more specifically to a method for merging defect regions. Background Technology
[0002] In current industrial production, machine vision-based automated inspection equipment is widely used in appearance inspection, where the accuracy of defect extraction is crucial to the inspection results. Currently, the industry commonly uses grayscale thresholding for initial defect region extraction, followed by morphological processing techniques such as opening and closing operations to merge defect regions and improve their accuracy and completeness. However, these traditional morphological methods are prone to mismerging irrelevant defect regions due to the isotropic nature of structural elements when dealing with discontinuous or linear defects, leading to significant deviations between the merged results and the target defect shape. If merging is completely abandoned, discontinuous, small linear defect components may be misjudged as noise and filtered out in subsequent screening stages based on features such as area, resulting in a loss of defect region integrity and ultimately affecting inspection accuracy.
[0003] To address this issue, directional structural elements are introduced to directionally merge linear feature defects. By combining two types of aspect ratios and skeleton lengths, the merged region is further filtered to effectively remove irrelevant areas, thereby obtaining an accurate and complete linear defect region. Summary of the Invention
[0004] The purpose of this invention is to overcome the aforementioned defects or problems existing in the prior art or to provide a material basis for overcoming the aforementioned defects or problems existing in the prior art, and to provide a method for merging defect areas.
[0005] To achieve the above objectives, the present invention and its preferred embodiments employ the following technical solutions, but the embodiments are not limited to the following solutions:
[0006] Option 1, a defect region merging method, includes the following steps:
[0007] Obtain several defect regions, perform a closing operation on all defect regions, and obtain several defect region modules;
[0008] The density of each defect region module is calculated, and those with a density greater than or equal to the density threshold are classified as non-clustered modules.
[0009] The defect areas of the non-bulk modules are transformed to obtain the skeleton contours corresponding to the defect areas of the non-bulk modules.
[0010] Connect and merge skeleton contours that meet the connection parameter conditions into a single contour. The connection parameters include the offset angle and merging distance between skeleton contours.
[0011] The length of the merged contours is filtered to remove short branch contours that are less than or equal to the length threshold, thus obtaining the directional structural elements of the linear defect region.
[0012] Based on the directional structural elements corresponding to all linear defect regions, intersection and hit operations are performed with the defect regions to determine the defect regions corresponding to the directional structural elements, and the defect regions corresponding to each directional structural element are merged.
[0013] Option 2, based on Option 1, sets up a rectangular or circular structural element, and performs a closing operation on all defect areas based on the rectangular or circular structural element to obtain several defect area modules.
[0014] Option 3, based on Option 1, involves filtering the defect area modules based on the number of defects and area characteristics before performing density calculations on each defect area module, removing defect area modules with a defect number less than or equal to the defect number threshold and an area threshold.
[0015] Option 4, based on Option 1, performs a rectangular closing operation on the defect area module, and divides the number of merged areas by the number of areas before merging to obtain the density.
[0016] Option 5, based on Option 1, divides areas with a density less than the density threshold into cluster modules, merges the cluster modules with rectangular structural elements, and obtains the complete area of the cluster defect.
[0017] Option 6, based on Option 1, transforms the defective regions of non-bulk modules into skeletons, obtains the regional skeletons of non-bulk modules, and converts all skeletons of non-bulk modules into skeleton contours to obtain the skeleton contours corresponding to all non-bulk defective regions.
[0018] Option 7, based on Option 6, converts the region skeleton into line segments, marks the connection points between the line segments, and generates a contour ending at the connection points to obtain the skeleton contour.
[0019] Option 8, based on Option 1, transforms the contours into regions according to the directional structural elements corresponding to all linear defect regions, intersects the transformed regions with the original defect regions, and merges the original defect regions with an intersection area greater than 0.
[0020] Option 9, based on Option 8, fills the outline with pixels and then connects the beginning and end to close it, so as to transform the outline into a region.
[0021] As can be seen from the above description of the present invention and its preferred embodiments, compared with the prior art, the technical solution of the present invention and its preferred embodiments have the following beneficial effects due to the adoption of the following technical means:
[0022] A method for merging defective regions includes the following steps:
[0023] Several defect regions are obtained, and a closing operation is performed on all defect regions to obtain several defect region modules. The closing operation process is to first dilate and then erode, which can fill small holes in the region, smooth the region outline, and connect adjacent regions to connect adjacent regions to obtain a whole containing several regions.
[0024] The density of each defect region module is calculated, and those with a density greater than or equal to the density threshold are classified as non-cluster modules; in order to filter out non-cluster modules and improve the merging speed of linear defects.
[0025] The defect area of the non-cluster module is transformed to obtain the skeleton contour corresponding to the defect area of the non-cluster module. The skeleton contour is closer to the central axis of the area and can better represent the linear relationship of the area. The skeleton contour can express the directionality (angle) of the main body of the area. Therefore, the skeleton contour can be merged with other skeleton contours that are collinear with it.
[0026] Skeleton contours that meet the connection parameter conditions are connected and merged into a single contour. The connection parameters include the offset angle and merging distance between skeleton contours. These connection parameters can directly reflect the linear characteristics of the defect, so that skeleton contours that do not meet the corresponding conditions are not merged.
[0027] The length of the merged contours is filtered to remove short branch contours that are less than or equal to the length threshold, thus obtaining the directional structural elements of the linear defect region and preventing interference from shorter branch contours.
[0028] Based on the directional structural elements corresponding to all linear defect regions, intersection and hit operations are performed with the defect regions to determine the defect regions corresponding to the directional structural elements. By merging the defect regions corresponding to each directional structural element, a complete defect region containing linear features can be obtained.
[0029] This scheme transforms the merging of defect regions into the merging of contours. The contours are obtained based on the defects, and then converted into linear structural elements. Defects are merged based on these linear structural elements, enabling defects with linear features to be merged linearly without being incorporated into other defect regions. Attached Figure Description
[0030] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments are briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1This is a schematic diagram of the defect area module in Embodiment 1, where different colored bands indicate that each defect area is independent;
[0032] Figure 2 This refers to the defect skeleton in Example 1;
[0033] Figure 3 The outline of the defect skeleton in Example 1;
[0034] Figure 4 The outline after connection and merging in Example 1;
[0035] Figure 5 The defect area (within the frame) after merging in Example 1;
[0036] Figure 6 This refers to the merging effect 1 in Example 1;
[0037] Figure 7 This is the merging effect 2 in Example 1;
[0038] Figure 8 This is a schematic diagram of the rectangular structural element in Example 1;
[0039] Figure 9 This is a schematic diagram of the circular structural element in Example 1;
[0040] Figure 10 This is a schematic diagram of the offset angles between the skeleton contours in Example 1;
[0041] Figure 11 This is a schematic diagram of the merging distance in Example 1;
[0042] Figure 12 This is a schematic diagram of the connection parameters (red skeleton outline) not conforming to the first embodiment;
[0043] Figure 13 This is a schematic diagram of the outline of the short branch in Example 1;
[0044] Figure 14 This is a schematic diagram of the contour-to-region conversion in Example 1. Detailed Implementation
[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are preferred embodiments of the present invention and should not be considered as excluding other embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0046] Unless otherwise expressly defined, the use of terms such as "first," "second," or "third" in the claims, description, and accompanying drawings of this invention is for distinguishing different objects and not for describing a specific order.
[0047] Unless otherwise expressly defined, in the claims, description, and accompanying drawings of this invention, the use of directional terms such as "center," "lateral," "longitudinal," "horizontal," "vertical," "top," "bottom," "inner," "outer," "upper," "lower," "front," "rear," "left," "right," "clockwise," and "counterclockwise" to indicate orientation or positional relationships is based on the orientation and positional relationships shown in the accompanying drawings and is only for the convenience of describing the invention and simplifying the description, and is not intended to indicate or imply that the device or element referred to must have a specific orientation or be constructed and operated in a specific orientation, and therefore should not be construed as limiting the specific scope of protection of this invention.
[0048] Unless otherwise expressly defined, the terms "fixed connection" or "fixed connection" used in the claims, description and drawings of this invention should be interpreted broadly to refer to any connection in which there is no displacement or relative rotation relationship between the two parties, including non-removable fixed connection, detachable fixed connection, integral connection and fixed connection by other means or components.
[0049] In the claims, description and accompanying drawings of this invention, the terms "comprising," "having," and variations thereof are used to mean "including but not limited to."
[0050] A method for merging defective regions includes the following steps:
[0051] Several defect regions are obtained from the image, and a rectangular or circular structuring element (both width and height can be open) is set. All defect regions are closed based on the rectangular or circular structuring element to obtain several defect region modules.
[0052] Rectangular structure: For example, creating a 10*10 rectangle, where the area expands and erodes according to the rectangle's directions (top, bottom, left, and right). Figure 8 Demonstrating the expansion corrosion of a rectangular structure:
[0053] Circular structure: Expanding outwards or eroding inwards according to the radius of the circle, such as... Figure 9 Expansion corrosion of the circular structure shown.
[0054] The mathematical expression for the closing operation is: Where: A represents the region, B represents the structuring element, and ⊕ represents the expansion operation. Representing the erosion operation, the closing operation involves first dilation and then erosion. This fills small holes within a region, smooths the region's outline, and connects adjacent regions to form a unified whole containing several regions, such as... Figure 1 The image shows three defect area modules. Two of these modules contain only one area each. The red outline module is the module that needs to be processed later, where the independent areas within it are merged into one area.
[0055] After the previous step, the defect region modules are filtered based on the number of defects and their area characteristics. Defect region modules with a defect number less than or equal to a defect number threshold and an area threshold less than or equal to a defect area threshold are removed, such as removing modules with a single defect region. Figure 1 The two defect area modules at the top center are removed here only for the calculations described below. When outputting the final defect result, the removed defect area modules will be displayed and output as usual. This also removes interference from extremely small areas, such as areas of 1-2 pixels, to reduce unnecessary areas and improve processing speed.
[0056] The defect region modules after screening are traversed, and the density of each defect region module is calculated. Modules with a density greater than or equal to the density threshold are classified as non-cluster modules, while those with a density less than the density threshold are classified as cluster modules.
[0057] Denseness calculation: A small-size rectangular closing operation is performed within the defect area module. The number of merged areas divided by the number of areas before merging is used to obtain the density. The smaller the value, the greater the density. A density threshold can be set accordingly. If the density is less than the density threshold, it meets the condition and is classified as a cluster module; otherwise, it is a non-cluster module. The size of the "small size" is adjustable.
[0058] For clumped modules: The clumped module is merged with rectangular structural elements to obtain the complete area of the clumped defect, and the processing of the clumped module ends.
[0059] For non-clustered modules:
[0060] The defective regions of the non-clustered modules are transformed to obtain the corresponding skeleton contours. Specifically, the defective regions of the non-clustered modules are transformed into skeletons (main methods include: iterative erosion based on morphology: gradually peeling away pixels at the edge of the region until only the center line remains; distance transformation based: calculating the shortest distance from each internal point in the region to the boundary), thus obtaining the region skeleton of the non-clustered modules, such as... Figure 2 Convert all skeletons of non-clump-shaped modules into skeleton contours to obtain the skeleton contours corresponding to all non-clump-shaped defect regions, such as... Figure 3The specific conversion method is as follows: convert the region skeleton into line segments, mark the connection points between the line segments, and generate the contours ending at the connection points to obtain the skeleton contours.
[0061] Connect and merge the skeleton contours that meet the connection parameter conditions into a single contour, refer to Figure 4 The skeletal outline is closer to the central axis of the region, and can better represent the linear relationship of the region. The skeletal outline can express the directionality (angle) of the main body of the region. Therefore, the skeletal outline can be merged with other skeletal outlines that are collinear with it. Collinearity: lying on approximately a straight line, the position can have slight deviations, but the overall direction should be consistent. Achieving collinear merging of regions is based on merging the skeletal outlines of the regions. By merging the skeletal outlines into one outline, and then merging the regions containing the outline (described below), collinear merging is finally achieved. Therefore, merging the corresponding skeletons of regions into one outline is actually a prerequisite for merging collinear, independent regions into one region.
[0062] Connection parameters include the offset angle and merging distance between skeleton contours; offset angle: when connecting two skeleton contours pairwise, straight lines are fitted respectively, and the angular deviation between the two straight lines is the offset angle; for example... Figure 10 In the context of α; the merge distance: the distance between the projections of the two contours onto the collinear lines, such as... Figure 11 As shown in section a; the skeleton contours are connected pairwise, with the longer contour being the main contour, and fitted to a straight line (first, the coordinate points of the skeleton contours are obtained, and then a straight line is fitted using the least squares method), i.e., collinear; when the angle and merging distance of the other skeleton contour meet the requirements (both less than or equal to the set value), the two skeleton contours are connected and merged. The purpose of the above conditions is to ensure the connection of collinear skeleton contours and avoid the influence of adjacent skeleton contours with large angle differences, such as... Figure 12 As shown, the purpose is to connect the two black skeleton outlines, rather than connecting the red skeleton outline.
[0063] After merging the contours, perform length filtering to remove short branch contours that are less than or equal to a length threshold (e.g., remove...). Figure 13 Similarly, when outputting the final defect result, the outline pointed to by the arrow will be displayed and output as usual (the area corresponding to the removed short branch outline), thus obtaining the main outline of the defect area containing linear features (the above 4 connection parameters directly reflect the linear features of the defect), that is, the directional structural elements of the linear defect area.
[0064] Based on the directional structural elements (i.e., the filtered merged contours) corresponding to all linear defect regions, intersection and hit operations are performed with the defect regions to determine the defect regions corresponding to the directional structural elements. The defect regions corresponding to each directional structural element are then merged. Specifically, based on the directional structural elements corresponding to all linear defect regions, the contours are converted into regions (contour to region: contours are sub-pixel; the contours are filled with pixels, and then the beginning and end are connected to close the region). Figure 14 The cells shown are the areas obtained by contour conversion. The converted areas are intersected with the original defect areas. The original defect areas (hit areas) with an intersection area greater than 0 are selected and merged.
[0065] Figure 5 This demonstrates the merged result where no other defect areas around the defect are affected.
[0066] Figure 6 This demonstrates how two defects with linear characteristics were not affected by other defects during merging. For example, the merging of the red and yellow areas did not affect each other, and the small cyan and purple areas were not considered major components of the linear defects in relation to the red and yellow areas, so they were not merged in.
[0067] Figure 7 This demonstrates that two extremely adjacent linear defects can be merged separately without affecting each other.
[0068] This scheme transforms the merging of defect regions into the merging of contours. The contours are obtained based on the defects, and then converted into linear structural elements. Defects are merged based on these linear structural elements, enabling defects with linear features to be merged linearly without being incorporated into other defect regions.
[0069] Compared with the prior art, this embodiment has the following beneficial effects:
[0070] In one exemplary embodiment, a defect region merging method includes the following steps:
[0071] Several defect regions are obtained, and a closing operation is performed on all defect regions to obtain several defect region modules. The closing operation process is to first dilate and then erode, which can fill small holes in the region, smooth the region outline, and connect adjacent regions to connect adjacent regions to obtain a whole containing several regions.
[0072] The density of each defect region module is calculated, and those with a density greater than or equal to the density threshold are classified as non-cluster modules; in order to filter out non-cluster modules and improve the merging speed of linear defects.
[0073] The defect area of the non-cluster module is transformed to obtain the skeleton contour corresponding to the defect area of the non-cluster module. The skeleton contour is closer to the central axis of the area and can better represent the linear relationship of the area. The skeleton contour can express the directionality (angle) of the main body of the area. Therefore, the skeleton contour can be merged with other skeleton contours that are collinear with it.
[0074] Skeleton contours that meet the connection parameter conditions are connected and merged into a single contour. The connection parameters include the offset angle and merging distance between skeleton contours. These connection parameters can directly reflect the linear characteristics of the defect, so that skeleton contours that do not meet the corresponding conditions are not merged.
[0075] The length of the merged contours is filtered to remove short branch contours that are less than or equal to the length threshold, thus obtaining the directional structural elements of the linear defect region and preventing interference from shorter branch contours.
[0076] Based on the directional structural elements corresponding to all linear defect regions, intersection and hit operations are performed with the defect regions to determine the defect regions corresponding to the directional structural elements. By merging the defect regions corresponding to each directional structural element, a complete defect region containing linear features can be obtained.
[0077] This scheme transforms the merging of defect regions into the merging of contours. The contours are obtained based on the defects, and then converted into linear structural elements. Defects are merged based on these linear structural elements, enabling defects with linear features to be merged linearly without being incorporated into other defect regions.
[0078] In one exemplary embodiment, a rectangular or circular structural element is set, and all defect regions are closed based on the rectangular or circular structural element to obtain several defect region modules. The rectangular or circular structural element can be selected for processing according to the corresponding requirements to obtain a suitable defect region module.
[0079] In one exemplary embodiment, before performing density calculations on each defect region module, the defect region modules are screened based on defect quantity and area characteristics, removing defect region modules with defect quantity less than or equal to a defect quantity threshold and area less than or equal to a threshold. This removes interference from individual defect modules or small-area defect modules, improving processing speed.
[0080] In one exemplary embodiment, a rectangular closing operation is performed on the defect area module. The number of merged areas divided by the number of areas before merging is used to obtain the density. The smaller the value, the greater the density, which can be used to represent the density.
[0081] In one exemplary embodiment, areas with a density less than a density threshold are divided into clustered modules. The clustered modules are then merged using rectangular structural elements to obtain the complete area of the clustered defect, thereby processing the corresponding clustered module defect.
[0082] The foregoing description of the specifications and embodiments is intended to explain the scope of protection of this invention, but does not constitute a limitation on the scope of protection of this invention. Modifications, equivalent substitutions, or other improvements to the embodiments of this invention or a portion thereof that can be obtained by those skilled in the art through logical analysis, reasoning, or limited experimentation, based on the teachings of this invention or the foregoing embodiments, in conjunction with common knowledge, general technical knowledge, and / or existing technology, should all be included within the scope of protection of this invention.
Claims
1. A method of merging defect areas, the method comprising: Includes the following steps: Obtain several defect regions, perform a closing operation on all defect regions, and obtain several defect region modules; The density of each defect region module is calculated, and those with a density greater than or equal to the density threshold are classified as non-clustered modules. The defect areas of the non-bulk modules are transformed into skeletons to obtain the regional skeletons of the non-bulk modules. All skeletons of the non-bulk modules are transformed into skeleton contours to obtain the skeleton contours corresponding to all non-bulk defect areas. Among them, the regional skeletons are transformed into line segments, the connection points between the line segments are marked, and the contours ending at the connection points are generated to obtain the skeleton contours. Connect and merge skeleton contours that meet the connection parameter conditions into a single contour. The connection parameters include the offset angle and merging distance between skeleton contours. The length of the merged contours is filtered to remove short branch contours that are less than or equal to the length threshold, thus obtaining the directional structural elements of the linear defect region. Based on the directional structural elements corresponding to all linear defect regions, intersection and hit operations are performed with the defect regions to determine the defect regions corresponding to the directional structural elements, and the defect regions corresponding to each directional structural element are merged.
2. The method of claim 1, wherein: Set a rectangular or circular structuring element, and perform a closing operation on all defect regions based on the rectangular or circular structuring element to obtain several defect region modules.
3. The method of claim 1, wherein: Before performing density calculations on each defect region module, the defect region modules are screened based on the number of defects and area characteristics, removing defect region modules whose number of defects is less than or equal to the defect number threshold and whose area is less than or equal to the area threshold.
4. The method of claim 1, wherein: A rectangular closing operation is performed on the defect area module, and the value obtained by dividing the number of merged areas by the number of areas before merging is used to obtain the density.
5. The method of claim 1, wherein: Areas with a density less than the density threshold are divided into cluster modules. The cluster modules are then merged into rectangular structural elements to obtain the complete region of the cluster defect.
6. The method of claim 1, wherein: Based on the directional structural elements corresponding to all linear defect regions, the contours are transformed into regions. The intersection of the transformed regions with the original defect regions is calculated, and the original defect regions with an intersection area greater than 0 are merged.
7. A method of merging defective areas as defined in claim 6, characterized by: The outline is filled with pixels and then closed by connecting the beginning and end to transform the outline into a region.