An image contour extraction method, device, equipment and readable storage medium

CN123015587APending Publication Date: 2026-10-30HANGZHOU IECHO SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611201919.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-10
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

目前的基于形态学处理的图像分离方法难以有效断开此类多临近图像中的局部黏连,导致轮廓提取结果不准确

Benefits of technology

[0015]本申请所提供的图像轮廓提取方法,包括:获取原始图像,对原始图像进行前景与背景的分离处理,得到前景蒙版图;对原始图像进行边缘检测,得到边缘图,并基于前景蒙版图,将边缘图中对应于背景区域的像素去除,得到第一处理图像;查找第一处理图像中的轮廓,将面积最大的轮廓确定为包含边线的整体轮廓,基于整体轮廓的填充图去除第一处理图像中边线外的噪声,得到第二处理图像;对第二处理图像中的四周边线区域进行第一边线去除处理,以去除四周边线中满足第一预设条件的像素;对经过第一边线去除处理后的图像中的四周边线区域进行第二边线去除处理,以去除残留的边线像素,得到第三处理图像;对第三处理图像进行轮廓查找,对查找到的每个轮廓进行凸度缺陷检测,获取凸度缺陷点对;若凸度缺陷点对满足预设距离阈值条件和预设轮廓索引差值条件,则将凸度缺陷点对确定为分离点对,在第三处理图像中断开分离点对之间的连接,以分离局部黏连的图案,得到第四处理图像;对第四处理图像进行轮廓提取,得到各图案的轮廓。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123015587A_ABST
    Figure CN123015587A_ABST
Patent Text Reader

Abstract

The application discloses an image contour extraction method, device and equipment and a readable storage medium. The method comprises the following steps: obtaining an original image, performing foreground and background separation to obtain a foreground mask image; performing edge detection on the original image to obtain an edge image, removing background pixels based on the foreground mask image to obtain a first processing image; searching for a contour, taking an area maximum contour as an overall contour containing a boundary line, removing noise outside the boundary line based on a filling image to obtain a second processing image; performing first boundary line removal processing and second boundary line removal processing on a peripheral boundary line area to obtain a third processing image; performing contour searching and convexity defect detection on the third processing image, determining a separation point pair and disconnecting connection based on a preset distance threshold condition and a preset contour index difference condition, separating a local adhesion pattern, and obtaining a fourth processing image; and performing contour extraction on the fourth processing image to obtain a pattern contour. The application can accurately extract each pattern contour existing in local adhesion from multiple adjacent images.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to an image contour extraction method, apparatus, device, and readable storage medium. Background Technology

[0002] With the widespread application of computer vision technology in industrial manufacturing, image contour extraction has become one of the key technologies for achieving automated inspection and processing. In scenarios such as clothing fabric cutting, to maximize material savings, the distance between adjacent patterns is extremely small, and they may even be locally adhered. Simultaneously, the material is often marked with edge lines, and these edges may also be locally adhered to the patterns, forming a multi-neighbor image where one target pattern is locally adhered to multiple other patterns and edges. Current morphological processing-based image separation methods struggle to effectively break down these local adhesions in multi-neighbor images, leading to inaccurate contour extraction results.

[0003] In summary, how to accurately extract the contours of each pattern from multiple neighboring images is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0004] The purpose of this application is to provide an image contour extraction method that can accurately extract the contours of each pattern from multiple neighboring images where there is local adhesion between patterns and edge adhesion. Another purpose of this application is to provide an image contour extraction device, apparatus, and computer-readable storage medium.

[0005] To solve the above-mentioned technical problems, this application provides the following technical solution: An image contour extraction method, comprising: The original image is acquired, and the foreground and background are separated to obtain a foreground mask image. Edge detection is performed on the original image to obtain an edge map, and based on the foreground mask map, pixels corresponding to the background area in the edge map are removed to obtain a first processed image; Find the contours in the first processed image, determine the contour with the largest area as the overall contour including the edge, and remove the noise outside the edge in the first processed image based on the fill map of the overall contour to obtain the second processed image. The first edge removal process is performed on the perimeter region of the second processed image to remove pixels in the perimeter that meet the first preset condition; A second edge removal process is performed on the perimeter regions of the image after the first edge removal process to remove the residual edge pixels, resulting in a third processed image. Contour search is performed on the third processed image, and convexity defect detection is performed on each found contour to obtain convexity defect point pairs; If the convexity defect point pair satisfies the preset distance threshold condition and the preset contour index difference condition, then the convexity defect point pair is determined as a separation point pair, and the connection between the separation point pairs is broken in the third processed image to separate the locally adhered pattern and obtain the fourth processed image. Contour extraction is performed on the fourth processed image to obtain the contours of each pattern.

[0006] In one specific embodiment of this application, if the convexity defect point pair satisfies a preset distance threshold condition and a preset contour index difference condition, then the convexity defect point pair is determined as a separation point pair, including: If the Euclidean distance between two points in the convexity defect point pair is less than a preset distance threshold, and the absolute value of the difference between the indices of the two points on the corresponding contour is greater than a preset index threshold, and the farthest distance between each of the two points and the corresponding convex hull is greater than a preset lower distance limit, then the convexity defect point pair is determined as a separation point pair.

[0007] In one specific embodiment of this application, a first edge removal process is performed on the perimeter region of the second processed image, including: Determine the rectangular regions corresponding to the four perimeter lines; wherein, the vertical lines correspond to the left and right rectangular regions, and the horizontal lines correspond to the upper and lower rectangular regions; Within the rectangular area corresponding to the vertical edge, count the number of pixels that meet the preset pixel conditions row by row. If the number of pixels is less than the preset vertical edge width threshold, remove the pixels in the current row. Within the rectangular area corresponding to the horizontal edge, count the number of pixels that meet the preset pixel conditions column by column. If the number of pixels is less than the preset horizontal edge width threshold, remove the pixels in the current column.

[0008] In one specific embodiment of this application, a second edge removal process is performed on the perimeter regions of the image after the first edge removal process, including: Morphological opening operations are performed on the rectangular regions corresponding to the four perimeter lines respectively; wherein, the kernel size corresponding to the vertical edge region is determined according to the width of the vertical edge, and the kernel size corresponding to the horizontal edge region is determined according to the width of the horizontal edge.

[0009] In one specific embodiment of this application, the original image is subjected to foreground and background separation processing to obtain a foreground mask image, including: A straight line of preset width is added to the boundary position of the original image. Image segmentation is performed on the image after adding the straight line. Contour search and filtering are performed on the segmentation results. The filtered contours are filled to obtain the foreground mask image.

[0010] In one specific embodiment of this application, the contour with the largest area is defined as the overall contour including the edge lines, including: The found contours are filtered based on their width, height, and area. The contours that meet the filtering conditions are sorted by area, and the first contour with the larger area in the sorted result is determined as the overall contour containing the edge.

[0011] In one specific embodiment of this application, edge detection is performed on the original image, including: The original image is subjected to Gaussian filtering to obtain the filtered image; Laplacian edge detection is performed on the filtered image.

[0012] An image contour extraction device, comprising: The foreground mask acquisition module is used to acquire the original image, perform foreground and background separation processing on the original image, and obtain the foreground mask. The first image processing module is used to perform edge detection on the original image to obtain an edge map, and based on the foreground mask map, remove pixels in the edge map that correspond to the background region to obtain the first processed image. The second image processing module is used to find the contour in the first image processing, determine the contour with the largest area as the overall contour including the edge, and remove noise outside the edge in the first image based on the fill map of the overall contour to obtain the second image processing. The pixel removal module is used to perform a first edge removal process on the perimeter area of ​​the second processed image to remove pixels in the perimeter that meet the first preset condition. The third image processing module is used to perform a second edge removal process on the perimeter area of ​​the image after the first edge removal process to remove the residual edge pixels and obtain the third processed image. The convexity defect point pair acquisition module is used to perform contour search on the third processed image, and to perform convexity defect detection on each found contour to obtain convexity defect point pairs. The fourth image processing module is used to determine the convexity defect point pair as a separation point pair if the convexity defect point pair meets the preset distance threshold condition and the preset contour index difference condition, and disconnect the connection between the separation point pairs in the third image to separate the locally adhered pattern and obtain the fourth image. The pattern contour acquisition module is used to extract contours from the fourth processed image to obtain the contours of each pattern.

[0013] An image contour extraction device, comprising: Memory, used to store computer programs; A processor is used to implement the steps of the image contour extraction method as described above when executing the computer program.

[0014] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the image contour extraction method as described above.

[0015] The image contour extraction method provided in this application includes: acquiring an original image; performing foreground and background separation processing on the original image to obtain a foreground mask image; performing edge detection on the original image to obtain an edge map, and removing pixels corresponding to background areas in the edge map based on the foreground mask image to obtain a first processed image; searching for contours in the first processed image, determining the contour with the largest area as the overall contour including the edge, and removing noise outside the edge in the first processed image based on the fill map of the overall contour to obtain a second processed image; and performing a first edge removal processing on the perimeter region of the second processed image to remove the perimeter regions that satisfy the first edge removal process. A preset set of pixels; a second edge removal process is performed on the perimeter regions of the image after the first edge removal process to remove residual edge pixels, resulting in a third processed image; contour search is performed on the third processed image, and convexity defect detection is performed on each found contour to obtain convexity defect point pairs; if the convexity defect point pairs meet the preset distance threshold condition and the preset contour index difference condition, the convexity defect point pairs are determined as separation point pairs, and the connection between the separation point pairs is broken in the third processed image to separate the locally adhered patterns, resulting in a fourth processed image; contour extraction is performed on the fourth processed image to obtain the contours of each pattern.

[0016] As can be seen from the above technical solution, since the background noise is first removed by combining the foreground mask map with edge detection, and then the peripheral interference is removed by a two-stage method combining the first edge removal process and the second edge removal process, and the separation point pairs are determined based on the convexity defect detection with the dual constraints of distance condition and index difference condition to break the local adhesion between patterns, and finally the contour is extracted, the technical problem that the current morphological processing method cannot effectively handle the local adhesion patterns and edge interference in multi-neighbor images can be solved, and the technical effect of accurately extracting the contours of each pattern from multi-neighbor images with local adhesion between patterns and edge adhesion can be achieved.

[0017] Accordingly, this application also provides an image contour extraction apparatus, device, and computer-readable storage medium corresponding to the above-mentioned image contour extraction method, which have the above-mentioned technical effects, and will not be described in detail here. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 This is a flowchart illustrating the implementation of an image contour extraction method according to an embodiment of this application. Figure 2 This is a schematic diagram of an original image in an embodiment of this application; Figure 3 This is a schematic diagram illustrating partial adhesion between patterns in an embodiment of this application; Figure 4 This is a schematic diagram illustrating partial adhesion between a pattern and a border in an embodiment of this application. Figure 5 This is a foreground mask image in one embodiment of this application; Figure 6 This is a schematic diagram of an edge map in an embodiment of this application; Figure 7 This is a schematic diagram of a first processed image in an embodiment of this application; Figure 8 This is a filled map based on the overall contour in an embodiment of this application; Figure 9 This is a schematic diagram of a second processed image in an embodiment of this application; Figure 10 This is a schematic diagram of an image after partial edge line removal in an embodiment of this application; Figure 11 This is a filled image obtained by contour generation of an image after partial edge line removal in an embodiment of this application; Figure 12 This is a schematic diagram of a third image processing embodiment of this application; Figure 13 This is an enlarged view of a partial pattern with local adhesion between some parts in an embodiment of this application; Figure 14 This is an enlarged view of a partial pattern with local adhesion between some parts in an embodiment of this application; Figure 15 This is a schematic diagram of a fourth image processing embodiment of this application; Figure 16 This is an enlarged view of a local separation effect in an embodiment of this application; Figure 17 This is an enlarged view of another local separation effect in an embodiment of this application; Figure 18This is a display effect diagram of extracting all pattern outlines in one embodiment of this application; Figure 19 This is a structural block diagram of an image contour extraction device according to an embodiment of this application; Figure 20 This is a structural block diagram of an image contour extraction device according to an embodiment of this application; Figure 21 This is a schematic diagram of the specific structure of an image contour extraction device provided in an embodiment of this application. Detailed Implementation

[0020] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are merely some embodiments of the present application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0021] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0022] See Figure 1 , Figure 1 This is a flowchart illustrating an image contour extraction method according to an embodiment of this application. The method may include the following steps: S101: Obtain the original image, perform foreground and background separation processing on the original image, and obtain the foreground mask image.

[0023] See Figure 2 , Figure 2 This is a schematic diagram of an original image in an embodiment of this application. Taking a clothing fabric cutting scenario as an example, the original image is obtained. Figure 2 The white foreground represents the area of ​​material to be cut, while the dark background represents felt. To minimize fabric waste, adjacent patterns are spaced very close together, sometimes even sticking together in places. See also Figure 3 , Figure 3 This is a schematic diagram illustrating partial adhesion between patterns in an embodiment of this application. See also... Figure 4 , Figure 4This is a schematic diagram illustrating partial adhesion between a pattern and its edge in an embodiment of this application. Simultaneously, edge markings are printed around the material, and partial adhesion may also occur between the edge and the pattern, forming a multi-neighbor image where one target pattern is partially adhered to multiple other patterns and edge lines within an image.

[0024] The original image undergoes foreground and background separation. Since some image boundaries are not fully closed, straight lines of a preset width are added to the boundaries of the original image. For example, a horizontal line with a width of 3 pixels and a grayscale value of 255 is added to the top of the image to close the image region. Image segmentation is then performed on the image after adding the line. The segmentation results are then subjected to contour finding and filtering. The filtered contours are filled to obtain the foreground mask image. See also... Figure 5 , Figure 5 This is a foreground mask image according to an embodiment of this application. In the foreground mask image, the pixel values ​​of the foreground area can be marked as a first grayscale value (e.g., 255), and the pixel values ​​of the background area can be marked as a second grayscale value (e.g., 0).

[0025] S102: Perform edge detection on the original image to obtain an edge map, and based on the foreground mask map, remove the pixels in the edge map that correspond to the background area to obtain the first processed image.

[0026] Edge detection is performed on the original image to obtain an edge map. Specifically, Gaussian filtering is first applied to the original image to smooth it and reduce noise. Then, Laplacian edge detection is performed on the filtered image to extract edge information. Finally, image segmentation is performed to obtain the edge map. See also... Figure 6 , Figure 6 This is a schematic diagram of an edge map in an embodiment of this application. Figure 6 It can be seen that some patterns are partially adhered to other patterns and edges.

[0027] To remove background noise interference and improve the speed and accuracy of subsequent contour extraction, a foreground mask image is used to remove background noise from the edge image. Specifically, the foreground region (i.e., the region with a pixel value of the first grayscale value) in the foreground mask image is designated as the first region, and the background region (i.e., the region with a pixel value of the second grayscale value) is designated as the second region. Pixels corresponding to the first region in the edge image are retained, while pixels corresponding to the second region in the edge image are removed, resulting in the first processed image after background noise removal. See also... Figure 7 , Figure 7 This is a schematic diagram of a first processed image in an embodiment of this application.

[0028] S103: Locate the contour in the first processed image, determine the contour with the largest area as the overall contour including the edge, remove the noise outside the edge in the first processed image based on the fill map of the overall contour, and obtain the second processed image.

[0029] Contour search is performed on the first processed image. The found contours are filtered based on their width, height, and area. Contours that meet the filtering criteria are sorted by area. The first contour with the largest area in the sorted result is taken as the overall contour including its surrounding lines.

[0030] See Figure 8 , Figure 8 This is a filling image based on an overall contour in an embodiment of this application. A filling image is generated based on this overall contour. The region corresponding to the foreground region in the filling image is designated as the third region, and the region corresponding to the background region is designated as the fourth region. Pixels corresponding to the third region in the first processed image are retained, while pixels corresponding to the fourth region in the first processed image are removed to remove noise outside the edges, resulting in a second processed image. See also... Figure 9 , Figure 9 This is a schematic diagram of a second processed image in an embodiment of this application.

[0031] S104: Perform a first edge removal process on the perimeter region of the second processed image to remove pixels in the perimeter that meet the first preset condition.

[0032] After removing noise outside the edges, the first edge removal process is performed on the perimeter regions of the second processed image. First, the minimum bounding rectangle of the overall contour is obtained. Based on the minimum bounding rectangle, the rectangular regions corresponding to the perimeter lines are determined, where the vertical edges correspond to the left and right rectangular regions, and the horizontal edges correspond to the upper and lower rectangular regions.

[0033] Within the rectangular area corresponding to the vertical edge line, the number of pixels that meet the preset pixel conditions (e.g., the number of pixels with a pixel value equal to the first grayscale value) is counted row by row. If this number of pixels is less than the preset vertical edge line width threshold, it indicates that the pixels in that row only contain the edge line and do not extend into the pattern area, so the pixels in that row are removed; otherwise, the pixels in that row are retained. Similarly, within the rectangular area corresponding to the horizontal edge line, the number of pixels that meet the preset pixel conditions is counted column by column. If this number of pixels is less than the preset horizontal edge line width threshold, the pixels in that column are removed. After the traversal is complete, the rows and columns of pixels in the edge area that only contain the edge line and do not contain the pattern extension are removed, thus completing the first edge line removal process. See also Figure 10 , Figure 10 This is a schematic diagram of an image after partial edge line removal in an embodiment of this application.

[0034] S105: Perform a second edge removal process on the perimeter area of ​​the image after the first edge removal process to remove the residual edge pixels and obtain the third processed image.

[0035] After the first edge removal process, some residual edge pixels may still remain. First, a contour search is performed on the image after the first edge removal process, and the contours are filtered based on their width, height, and area. Contours that meet the filtering criteria are used to generate filled images. See [link to documentation]. Figure 11 , Figure 11 This is a filled image obtained by contour generation of an image after partial edge line removal in an embodiment of this application.

[0036] Then, a second edge removal process is performed on the perimeter regions of the image after the first edge removal process to remove residual edge pixels, resulting in a third processed image. This can be achieved by performing morphological opening operations on the rectangular regions corresponding to the perimeter edges to remove residual edge pixels. The specific operations of the morphological opening operation can include: first performing an erosion operation to eliminate fine residual edge connections, and then performing a dilation operation to restore the pattern boundaries. For the vertical edge regions (left and right rectangular regions), the kernel size is determined based on the vertical edge width; for example, the kernel size can be set to (2 × vertical edge width - 1, 1). For the horizontal edge regions (upper and lower rectangular regions), the kernel size is determined based on the horizontal edge width; for example, the kernel size can be set to (1, 2 × horizontal edge width - 1). Through the morphological opening operation, the residual edge pixels are removed, resulting in the third processed image. See also... Figure 12 , Figure 12 This is a schematic diagram of a third processed image in an embodiment of this application. Figure 12 It can be seen that some patterns still exhibit local adhesion.

[0037] S106: Perform contour search on the third processed image, perform convexity defect detection on each found contour, and obtain convexity defect point pairs.

[0038] Contour detection is performed on the third-processed image, and filtering is performed based on the width, height, and area of ​​the contours, retaining contours that meet the criteria. See also Figure 13 , Figure 13 This is an enlarged view showing partial adhesion between some patterns in an embodiment of this application. See also... Figure 14 , Figure 14 This is an enlarged view of another embodiment of the present application where some patterns are partially adhered. The details of the partially adhered areas can be observed more clearly.

[0039] For each found contour, perform convexity defect detection and store the detection results in a defect set. Traverse each convex defect in the defect set and obtain the coordinates of the two points that are farthest from the convex hull of the two convex defects, denoted as the first defect point and the second defect point, thus obtaining the convexity defect point pair.

[0040] S107: If the convexity defect point pair meets the preset distance threshold condition and the preset contour index difference condition, then the convexity defect point pair is determined as a separation point pair, and the connection between the separation point pairs is broken in the third processed image to separate the locally adhered pattern and obtain the fourth processed image.

[0041] After obtaining the convexity defect point pairs, it is determined whether each convexity defect point pair meets the separation condition. Specifically, the Euclidean distance between the first and second defect points in the convexity defect point pair is calculated, and the difference between the indices of the first and second defect points on their respective contours is calculated. If the following conditions are met simultaneously, the first and second defect points are determined as a separated point pair: the Euclidean distance between the first and second defect points is less than a preset distance threshold; the absolute value of the difference between the indices of the first and second defect points on their respective contours is greater than a preset index threshold; and the farthest distance between each of the first and second defect points and its corresponding convex hull is greater than a preset lower distance limit (e.g., greater than 10 pixels).

[0042] After traversing all convexity defects of the current contour, the pixels between each determined separation point pair are removed in the third processed image, thus breaking the connection between the separation point pairs and completing the local adhesion separation of a contour. By traversing all contours sequentially, the separation of all local adhesion patterns can be completed, resulting in the fourth processed image. See also... Figure 15 , Figure 15 This is a schematic diagram of a fourth image processing embodiment of this application. See also... Figure 16 , Figure 16 This is an enlarged view of a local separation effect in an embodiment of this application. See also: Figure 17 , Figure 17 This is an enlarged view of another local separation effect in an embodiment of this application.

[0043] S108: Extract contours from the fourth processed image to obtain the contours of each pattern.

[0044] The fourth processed image undergoes contour finding, filtering based on contour width, height, and area. Contours meeting the filtering criteria are determined as the final contours of each pattern. The extracted pattern contours can be plotted onto the original image for visualization. See also... Figure 18 , Figure 18 This is a display effect diagram of extracting all pattern outlines in one embodiment of this application.

[0045] As can be seen from the above technical solution, since the background noise is first removed by combining the foreground mask map with edge detection, and then the peripheral interference is removed by a two-stage method combining the first edge removal process and the second edge removal process, and the separation point pairs are determined based on the convexity defect detection with the dual constraints of distance condition and index difference condition to break the local adhesion between patterns, and finally the contour is extracted, the technical problem that the current morphological processing method cannot effectively handle the local adhesion patterns and edge interference in multi-neighbor images can be solved, and the technical effect of accurately extracting the contours of each pattern from multi-neighbor images with local adhesion between patterns and edge adhesion can be achieved.

[0046] It should be noted that, based on the above embodiments, this application also provides corresponding improvement solutions. In subsequent embodiments, steps that are the same as or corresponding to those in the above embodiments can be referred to each other, and the corresponding beneficial effects can also be referred to each other. These improvements will not be elaborated upon in the following improved embodiments.

[0047] In one specific embodiment of this application, if a pair of convexity defect points satisfies a preset distance threshold condition and a preset contour index difference condition, then the pair of convexity defect points is determined as a separation point pair, which may include the following steps: If the Euclidean distance between two points in a convexity defect point pair is less than a preset distance threshold, and the absolute value of the difference between the indices of the two points on the corresponding contour is greater than a preset index threshold, and the farthest distance between each of the two points and the corresponding convex hull is greater than a preset lower limit, then the convexity defect point pair is determined as a separated point pair.

[0048] Determining whether a pair of convexity defect points meets the preset distance threshold and preset contour index difference conditions can be achieved through triple constraints, allowing for more accurate identification of whether the pair of convexity defect points corresponds to a local adhesion location between patterns. During convexity defect detection, each contour is searched for its convexity defects, obtaining convexity defect point pairs, which include the first and second defect points furthest from the convex hull. The Euclidean distance between the first and second defect points is calculated, and it is determined whether this distance is less than a preset distance threshold. The absolute value of the difference between the indices of the first and second defect points on their corresponding contours is calculated, and it is determined whether this absolute value is greater than a preset index threshold. Finally, it is determined whether the furthest distances between the first and second defect points and their corresponding convex hulls are both greater than a preset lower distance limit. Only when all three conditions are met simultaneously is the current pair of convexity defect points identified as a separation point pair. Through triple constraints, misidentification of convexity defects in non-adhesive areas as separation points is effectively avoided, improving the accuracy of local adhesion separation. The distance threshold controls the maximum spacing between separation point pairs, preventing defect point pairs with excessively large spacing from being incorrectly broken. The index difference threshold ensures that two defect points are far enough apart on the contour to belong to different pattern branches rather than the same pattern's depressions. The lower limit of the convex hull distance excludes defect points that are too close to the convex hull contour, avoiding unnecessary or incorrect break-off operations at shallow depressions in the contour.

[0049] In one specific embodiment of this application, performing a first edge removal process on the perimeter region of the second processed image may include the following steps: Step 1: Determine the rectangular areas corresponding to the four perimeter lines; the vertical lines correspond to the left and right rectangular areas, and the horizontal lines correspond to the upper and lower rectangular areas. Step 2: Within the rectangular area corresponding to the vertical edge, count the number of pixels that meet the preset pixel conditions row by row. If the number of pixels is less than the preset vertical edge width threshold, remove the pixels in the current row. Step 3: Within the rectangular area corresponding to the horizontal edge, count the number of pixels that meet the preset pixel conditions column by column. If the number of pixels is less than the preset horizontal edge width threshold, remove the pixels in the current column.

[0050] For ease of description, the three steps above can be combined for explanation.

[0051] Obtain the minimum bounding rectangle of the defined overall outline. Based on the minimum bounding rectangle, determine the rectangular regions corresponding to the four perimeter lines, where the left vertical edge corresponds to the left rectangular region, the right vertical edge corresponds to the right rectangular region, the upper horizontal edge corresponds to the upper rectangular region, and the lower horizontal edge corresponds to the lower rectangular region.

[0052] For the vertical edge region, the pixels in the second processed image corresponding to the left and right rectangular regions are traversed row by row. The number of pixels in each row that meet the preset pixel condition (e.g., the pixel value equals the first grayscale value) is counted. If the number of pixels is less than the preset vertical edge width threshold, it indicates that the pixels in that row only contain the edge and not the pattern extension, so the pixels in that row are removed; otherwise, if the number of pixels is greater than or equal to the preset vertical edge width threshold, it indicates that the row contains the pattern, so the pixels in that row are retained.

[0053] For the horizontal edge region, the pixels in the second processed image corresponding to the upper and lower rectangular regions are traversed column by column, and the number of pixels in each column that meet the preset pixel conditions is counted. If the number of pixels is less than the preset horizontal edge width threshold, it indicates that the pixels in that column only contain the edge and not the extended part of the pattern, so the pixels in that column are removed; otherwise, the pixels in that column are retained. After the traversal is completed, the first edge removal process is finished. By analyzing the pixel distribution based on line width features, clear edge regions can be effectively removed, while avoiding accidental damage to patterns extending near the edge.

[0054] In one specific embodiment of this application, performing a second edge removal process on the perimeter regions of an image after the first edge removal process may include the following steps: Morphological opening operations are performed on the rectangular regions corresponding to the four perimeter lines; the kernel size for the vertical perimeter region is determined based on the width of the vertical perimeter, and the kernel size for the horizontal perimeter region is determined based on the width of the horizontal perimeter.

[0055] After the first edge removal process, some residual edge pixels may still remain. First, contour finding is performed on the image after the first edge removal process, and filtering is applied based on the width, height, and area of ​​the contours. Contours that meet the filtering criteria are used to generate filled images. Then, morphological opening operations are performed on the rectangular regions corresponding to the four edges to remove the residual edge pixels.

[0056] By setting the kernel size corresponding to the vertical edge region based on the width of the vertical edge, and the kernel size corresponding to the horizontal edge region based on the width of the horizontal edge, a kernel size that is compatible with the width of the edge in that region can be adopted. Morphological opening operation can effectively remove residual edges while maintaining the integrity of the pattern boundary to the greatest extent, avoiding excessive erosion of the pattern due to an excessively large kernel size.

[0057] In one specific embodiment of this application, separating the foreground and background of the original image to obtain a foreground mask image may include the following steps: Add a straight line of preset width to the boundary of the original image, perform image segmentation on the image after adding the line, perform contour search and filtering on the segmentation results, fill the filtered contours to obtain the foreground mask image.

[0058] When the boundaries of the original image are not closed (e.g., the top of the image is not closed), direct image segmentation may lead to inaccurate results. To address this, a straight line of a preset width is first added to the boundaries of the original image to close them. For example, if the top of the image is not closed, a horizontal line with a preset number of pixels (e.g., 3 pixels) and a preset grayscale value (e.g., 255) is added to the top of the image. After adding the line, image segmentation is performed, and the segmentation results are analyzed for contour finding and filtering. The filtered contours are then filled to obtain the foreground mask. This boundary completion process solves the segmentation failure problem caused by unclosed image boundaries, ensuring the accuracy of the foreground mask and providing a reliable foundation for subsequent background noise removal.

[0059] In one specific embodiment of this application, determining the contour with the largest area as the overall contour including the edge lines may include the following steps: The found contours are filtered based on their width, height, and area. Contours that meet the filtering criteria are sorted by area, and the first contour with the larger area in the sorted result is determined as the overall contour including the edge.

[0060] After contour finding is complete, all found contours are filtered based on their width, height, and area to remove contours that are too small or whose shapes clearly do not meet the requirements. Contours that meet the filtering criteria are then sorted by area, and the first contour with the largest area in the sorted result is determined as the overall contour including the edge. Through triple filtering by width, height, and area, along with area sorting, the largest contour including the edge can be located quickly and accurately, eliminating interference from subtle noise and other small-area contours, thus improving the reliability of overall contour determination.

[0061] In one specific embodiment of this application, edge detection of the original image may include the following steps: Step 1: Apply Gaussian filtering to the original image to obtain the filtered image; Step 2: Perform Laplacian edge detection on the filtered image.

[0062] For ease of description, the two steps above can be combined for explanation.

[0063] The original image is subjected to Gaussian filtering, and convolution is performed using a Gaussian kernel to smooth the image and suppress high-frequency noise, reducing false edges that may appear in subsequent edge detection. Then, Laplacian edge detection is performed on the filtered image, using a second-order differential operator to detect edge locations and highlight areas with drastic grayscale changes, resulting in an edge map. The combination of Gaussian filtering and Laplacian edge detection can effectively suppress noise while accurately extracting edge information from the image. After obtaining the edge map, image segmentation can be performed to further distinguish between edge and non-edge regions.

[0064] The pixel removal and contour filling operations described in the above steps can be implemented based on pixel value marking. For example, in the foreground mask image, the pixel values ​​of the foreground region can be marked as a first grayscale value (e.g., 255), and the pixel values ​​of the background region can be marked as a second grayscale value (e.g., 0). In the edge image, removing the pixels corresponding to the second grayscale value in the foreground mask image will remove background noise. Similarly, operations such as edge noise removal, edge pixel removal, and local adhesion breaking can all be implemented using a method based on region marking and selective pixel retention.

[0065] The specific process of this method can be understood by referring to the following more detailed embodiments. First, read the original image (corresponding to...) Figure 2 The white foreground represents the material to be cut, and the dark background represents felt. Since the top of the image is not closed, a horizontal line with a width of 3 pixels and a grayscale value of 255 is added to the top of the image. Then, image segmentation, contour finding, and contour filtering are performed. Contours that meet the criteria are filled to obtain the foreground mask image (corresponding to...). Figure 5 The original image is subjected to Gaussian filtering and Laplacian edge detection, followed by image segmentation to obtain an edge map (corresponding to...). Figure 6 As shown in the image, some patterns are partially adhered to other patterns and edges. To improve contour extraction speed and remove background interference: the area corresponding to a pixel value of 255 in the foreground mask image is designated as the foreground region, and the area corresponding to a pixel value of 0 is designated as the background region; the pixel values ​​corresponding to the foreground region in the edge image are retained, while the pixel values ​​corresponding to the background region in the edge image are removed, resulting in an image with background noise removed (corresponding to...). Figure 7 ).

[0066] Contour detection is performed on the image after background noise removal, and the contours are filtered by width, height, and area. Contours that meet the criteria are sorted by area from largest to smallest and stored in a first contour set. The first contour in the first contour set, i.e., the largest contour containing the edge, is used to generate a filled image (corresponding to...). Figure 8The foreground region in the filled image is designated as the first filled region, and the background region as the second filled region. Pixels corresponding to the first filled region are retained in the image after background noise removal, while pixels corresponding to the second filled region are removed to eliminate noise outside the edges (corresponding to...). Figure 9 ).

[0067] Obtain the minimum bounding rectangle of the largest outline. Based on the minimum bounding rectangle, determine four rectangular regions containing four sides, denoted as the left, right, top, and bottom rectangular regions. Iterate through the pixels in the image regions corresponding to the left and right rectangular regions row by row. If the number of pixels with the first gray value in each row is less than the vertical edge width threshold, remove those pixels; otherwise, leave them unchanged. After this iteration, part of the left and right vertical edges will be removed. Similarly, iterate through the pixels in the image regions corresponding to the top and bottom rectangular regions column by column. If the number of pixels with the first gray value in each column is less than the horizontal edge width threshold, remove those pixels; otherwise, leave them unchanged. After this iteration, part of the top and bottom horizontal edges will be removed. Figure 10 ).

[0068] After partially removing the edges, perform contour finding on the image and filter by the width, height, and area of ​​the contours. Generate a filled map for the contours that meet the criteria. Figure 11 Morphological operations are performed on the four rectangular regions respectively. The left and right rectangular regions undergo a morphological opening operation with a kernel of (2 × vertical edge width - 1, 1), while the upper and lower rectangular regions undergo a morphological opening operation with a kernel of (1, 2 × horizontal edge width - 1). This yields an image with all four borders completely removed (corresponding to...). Figure 12 ),from Figure 12 It can be seen that there is local adhesion between some patterns, as shown in the magnified image. Figure 13 and Figure 14 As shown.

[0069] For an image with all perimeter lines removed, perform contour lookup and filter by contour width, height, and area. Contours meeting the criteria are stored in a second contour set. Iterate through each contour in the second set, searching for convexity defects and storing the results in a defect set. For each convexity defect in the defect set, obtain the coordinates of the points furthest from the convex hull for each defect (denoted as the first defect point and the second defect point). Calculate the Euclidean distance between these two points and the difference in their corresponding indices on the original contour. If all conditions are met simultaneously: the Euclidean distance is less than a set distance threshold, the difference in indices is greater than a set index threshold, and the furthest distances from both the first and second defect points to the convex hull are greater than a preset value (e.g., greater than 10), then store the first and second defect points in a separation point set. After traversing all convexity defects of the current contour, remove the pixels between every two points in the separation point set from the image, and then continue to the next contour. When all contours have been traversed, the separation of the locally adhered patterns is complete (corresponding to...). Figure 15 , Figure 16 and Figure 17 ).

[0070] After separating locally adhered images, contours are searched and filtered by their width, height, and area. Contours that meet the criteria are identified as the final contours for each pattern. These contours can then be drawn onto the original image for display. Figure 18 This completes the entire process of the image contour extraction method of this application (corresponding to...). Figure 1 This application's embodiments achieve the goal of accurately extracting the outlines of each pattern from multiple neighboring images where there is local adhesion between patterns and adhesion of edges by removing the background, removing the perimeter lines, and separating the local adhesion of patterns.

[0071] Corresponding to the above method embodiments, this application also provides an image contour extraction device, and the image contour extraction device described below can be referred to in correspondence with the image contour extraction method described above.

[0072] See Figure 19 , Figure 19 This is a structural block diagram of an image contour extraction device according to an embodiment of this application. The device may include: The foreground mask acquisition module 11 is used to acquire the original image, perform foreground and background separation processing on the original image, and obtain the foreground mask. The first image processing module 12 is used to perform edge detection on the original image to obtain an edge map, and remove the pixels corresponding to the background area in the edge map based on the foreground mask map to obtain the first processed image. The second image processing module 13 is used to find the contour in the first image, determine the contour with the largest area as the overall contour including the edge, and remove noise outside the edge in the first image based on the fill map of the overall contour to obtain the second image. The pixel removal module 14 is used to perform a first edge removal process on the perimeter area of ​​the second processed image to remove pixels in the perimeter that meet the first preset condition. The third image processing module 15 is used to perform a second edge removal process on the perimeter area of ​​the image after the first edge removal process to remove the residual edge pixels and obtain the third processed image. The convexity defect point pair acquisition module 16 is used to perform contour search on the third processed image, perform convexity defect detection on each found contour, and obtain convexity defect point pairs. The fourth image processing module 17 is used to determine the convexity defect point pair as a separation point pair if the convexity defect point pair meets the preset distance threshold condition and the preset contour index difference condition, and disconnect the connection between the separation point pairs in the third image to separate the locally adhered pattern and obtain the fourth image. The pattern contour acquisition module 18 is used to extract contours from the fourth processed image to obtain the contours of each pattern.

[0073] As can be seen from the above technical solution, since the background noise is first removed by combining the foreground mask map with edge detection, and then the peripheral interference is removed by a two-stage method combining the first edge removal process and the second edge removal process, and the separation point pairs are determined based on the convexity defect detection with the dual constraints of distance condition and index difference condition to break the local adhesion between patterns, and finally the contour is extracted, the technical problem that the current morphological processing method cannot effectively handle the local adhesion patterns and edge interference in multi-neighbor images can be solved, and the technical effect of accurately extracting the contours of each pattern from multi-neighbor images with local adhesion between patterns and edge adhesion can be achieved.

[0074] In one specific embodiment of this application, the fourth image processing module 17 is specifically a module that determines the convexity defect point pair as a separated point pair if the Euclidean distance between two points in the convexity defect point pair is less than a preset distance threshold, the absolute value of the difference between the indices of the two points on the corresponding contour is greater than a preset index threshold, and the farthest distance between each of the two points and the corresponding convex hull is greater than a preset lower limit value.

[0075] In one specific embodiment of this application, the pixel removal module 14 may include: The rectangular region determination submodule is used to determine the rectangular regions corresponding to the four perimeter lines; among them, the vertical lines correspond to the left and right rectangular regions, and the horizontal lines correspond to the upper and lower rectangular regions. The first pixel removal submodule is used to count the number of pixels that meet the preset pixel conditions row by row within the rectangular area corresponding to the vertical edge. If the number of pixels is less than the preset vertical edge width threshold, the pixels in the current row are removed. The second pixel removal submodule is used to count the number of pixels that meet the preset pixel conditions column by column within the rectangular area corresponding to the horizontal edge. If the number of pixels is less than the preset horizontal edge width threshold, the pixels in the current column are removed.

[0076] In one specific embodiment of this application, the third image processing module 15 specifically performs morphological opening operations on the rectangular regions corresponding to the four perimeter lines; wherein, the kernel size corresponding to the vertical edge region is determined according to the width of the vertical edge, and the kernel size corresponding to the horizontal edge region is determined according to the width of the horizontal edge.

[0077] In one specific embodiment of this application, the foreground mask image acquisition module 11 is specifically a module that adds a straight line of preset width at the boundary position of the original image, performs image segmentation on the image after adding the straight line, performs contour search and filtering on the segmentation results, and fills the filtered contours to obtain the foreground mask image.

[0078] In one specific embodiment of this application, the second image processing module 13 is specifically a module that filters the found contours based on the width, height and area of ​​the contours, sorts the contours that meet the filtering conditions by area, and determines the first contour at the larger end of the sorted result as the overall contour including the edge lines.

[0079] In one specific embodiment of this application, the first image processing module 12 may include: The filtered image acquisition submodule is used to perform Gaussian filtering on the original image to obtain the filtered image; The edge detection submodule is used to perform Laplacian edge detection on the filtered image.

[0080] For the method embodiments described above, see [link to relevant documentation]. Figure 20 , Figure 20 This is a schematic diagram of the image contour extraction device provided in this application, which may include: Memory 332 is used to store computer programs; The processor 322 is used to implement the steps of the image contour extraction method of the above method embodiment when executing a computer program.

[0081] For details, please refer to Figure 21 , Figure 21This is a schematic diagram illustrating the specific structure of an image contour extraction device provided in this embodiment. The image contour extraction device can vary significantly due to different configurations or performance. It may include a processor (central processing unit, CPU) 322 (e.g., one or more processors) and a memory 332. The memory 332 stores one or more computer programs 342 or data 344. The memory 332 can be temporary or persistent storage. The program stored in the memory 332 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the data processing device. Furthermore, the processor 322 may be configured to communicate with the memory 332 and execute the series of instruction operations stored in the memory 332 on the image contour extraction device 301.

[0082] The image contour extraction device 301 may also include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input / output interfaces 358, and / or one or more operating systems 341.

[0083] The steps in the image contour extraction method described above can be implemented by the structure of the image contour extraction device.

[0084] Corresponding to the above method embodiments, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can perform the following steps: The process involves: acquiring the original image; performing foreground and background separation to obtain a foreground mask image; performing edge detection on the original image to obtain an edge map; and removing pixels corresponding to background areas from the edge map based on the foreground mask image to obtain a first processed image; identifying contours in the first processed image and determining the contour with the largest area as the overall contour including the edge; removing noise outside the edge in the first processed image based on the fill map of the overall contour to obtain a second processed image; and performing a first edge removal process on the perimeter region of the second processed image to remove pixels in the perimeter region that meet a first preset condition. A second edge removal process is performed on the perimeter regions of the image after the first edge removal process to remove residual edge pixels, resulting in a third processed image. Contour search is performed on the third processed image, and convexity defect detection is performed on each found contour to obtain convexity defect point pairs. If the convexity defect point pairs meet the preset distance threshold condition and the preset contour index difference condition, the convexity defect point pairs are determined as separation point pairs, and the connection between the separation point pairs is broken in the third processed image to separate the locally adhered patterns, resulting in a fourth processed image. Contour extraction is performed on the fourth processed image to obtain the contours of each pattern.

[0085] The computer-readable storage medium may include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0086] For a description of the computer-readable storage medium provided in this application, please refer to the above method embodiments; further details will not be repeated here.

[0087] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatuses, devices, and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.

[0088] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the technical solutions and core ideas of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of this application.

Claims

1. An image contour extraction method, characterized in that, include: The original image is acquired, and the foreground and background are separated to obtain a foreground mask image. Edge detection is performed on the original image to obtain an edge map, and based on the foreground mask map, pixels corresponding to the background area in the edge map are removed to obtain a first processed image; Find the contours in the first processed image, determine the contour with the largest area as the overall contour including the edge, and remove the noise outside the edge in the first processed image based on the fill map of the overall contour to obtain the second processed image. The first edge removal process is performed on the perimeter region of the second processed image to remove pixels in the perimeter that meet the first preset condition; A second edge removal process is performed on the perimeter regions of the image after the first edge removal process to remove the residual edge pixels, resulting in a third processed image. Contour search is performed on the third processed image, and convexity defect detection is performed on each found contour to obtain convexity defect point pairs; If the convexity defect point pair satisfies the preset distance threshold condition and the preset contour index difference condition, then the convexity defect point pair is determined as a separation point pair, and the connection between the separation point pairs is broken in the third processed image to separate the locally adhered pattern and obtain the fourth processed image. Contour extraction is performed on the fourth processed image to obtain the contours of each pattern.

2. The image contour extraction method according to claim 1, characterized in that, If the convexity defect point pair satisfies the preset distance threshold condition and the preset contour index difference condition, then the convexity defect point pair is determined as a separation point pair, including: If the Euclidean distance between two points in the convexity defect point pair is less than a preset distance threshold, and the absolute value of the difference between the indices of the two points on the corresponding contour is greater than a preset index threshold, and the farthest distance between each of the two points and the corresponding convex hull is greater than a preset lower distance limit, then the convexity defect point pair is determined as a separation point pair.

3. The image contour extraction method according to claim 1, characterized in that, The first edge removal process is performed on the perimeter region of the second processed image, including: Determine the rectangular regions corresponding to the four perimeter lines; wherein, the vertical lines correspond to the left and right rectangular regions, and the horizontal lines correspond to the upper and lower rectangular regions; Within the rectangular area corresponding to the vertical edge, count the number of pixels that meet the preset pixel conditions row by row. If the number of pixels is less than the preset vertical edge width threshold, remove the pixels in the current row. Within the rectangular area corresponding to the horizontal edge, count the number of pixels that meet the preset pixel conditions column by column. If the number of pixels is less than the preset horizontal edge width threshold, remove the pixels in the current column.

4. The image contour extraction method according to claim 3, characterized in that, The second edge removal process is performed on the perimeter regions of the image after the first edge removal process, including: Morphological opening operations are performed on the rectangular regions corresponding to the four perimeter lines respectively; wherein, the kernel size corresponding to the vertical edge region is determined according to the width of the vertical edge, and the kernel size corresponding to the horizontal edge region is determined according to the width of the horizontal edge.

5. The image contour extraction method according to any one of claims 1 to 4, characterized in that, The original image is subjected to foreground and background separation processing to obtain a foreground mask image, including: A straight line of preset width is added to the boundary position of the original image. Image segmentation is performed on the image after adding the straight line. Contour search and filtering are performed on the segmentation results. The filtered contours are filled to obtain the foreground mask image.

6. The image contour extraction method according to claim 1, characterized in that, The contour with the largest area is defined as the overall contour including the edges, including: The found contours are filtered based on their width, height, and area. The contours that meet the filtering conditions are sorted by area, and the first contour with the larger area in the sorted result is determined as the overall contour containing the edge.

7. The image contour extraction method according to claim 1, characterized in that, Edge detection is performed on the original image, including: The original image is subjected to Gaussian filtering to obtain the filtered image; Laplacian edge detection is performed on the filtered image.

8. An image contour extraction device, characterized in that, include: The foreground mask acquisition module is used to acquire the original image, perform foreground and background separation processing on the original image, and obtain the foreground mask. The first image processing module is used to perform edge detection on the original image to obtain an edge map, and based on the foreground mask map, remove pixels in the edge map that correspond to the background region to obtain the first processed image. The second image processing module is used to find the contour in the first image processing, determine the contour with the largest area as the overall contour including the edge, and remove noise outside the edge in the first image based on the fill map of the overall contour to obtain the second image processing. The pixel removal module is used to perform a first edge removal process on the perimeter area of ​​the second processed image to remove pixels in the perimeter that meet the first preset condition. The third image processing module is used to perform a second edge removal process on the perimeter area of ​​the image after the first edge removal process to remove the residual edge pixels and obtain the third processed image. The convexity defect point pair acquisition module is used to perform contour search on the third processed image, and to perform convexity defect detection on each found contour to obtain convexity defect point pairs. The fourth image processing module is used to determine the convexity defect point pair as a separation point pair if the convexity defect point pair meets the preset distance threshold condition and the preset contour index difference condition, and disconnect the connection between the separation point pairs in the third image to separate the locally adhered pattern and obtain the fourth image. The pattern contour acquisition module is used to extract contours from the fourth processed image to obtain the contours of each pattern.

9. An image contour extraction device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the image contour extraction method as described in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the image contour extraction method as described in any one of claims 1 to 7.