Edge detection method, edge detection device and computer readable storage medium
By filtering and connecting domain analysis of strong edge and weak edge binary images on the template pixel images, the connectivity domain that meets the specified threshold is selected, solving the problem of indistinguishable noise and short edges in edge detection, and achieving more accurate edge detection.
Patent Information
- Application Number
- CN202011023157.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-25
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2040-09-25
AI Technical Summary
The prior art cannot effectively distinguish between noise and short edges in template pixel images in edge detection, resulting in high noise and inaccurate edge images.
By obtaining the strong edge binary image and the weak edge binary image of the template pixel image, the strong edge binary image is filtered, and the target edge binary image is obtained, and the connection domain is selected. The target connection domain with the number of continuous edge pixels in the cluster exceeds the specified threshold is selected to detect the edge image of the template pixel image.
Effectively reduce noise interference, improve edge detection accuracy, and obtain edge images with appropriate edge length.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to an edge detection method, an edge detection device, and a computer-readable storage medium. Background Art
[0002] Edge detection is a basic problem in image processing and computer vision. It is mainly used to extract edge information of template images and save it as the basis for subsequent template matching operations. In industrial visual positioning tasks, template matching methods based on edge contour features are often used to locate the detection target. The contour template matching method is based on comparing the existing detection target contour template with the search image to obtain the position and angle of the target in the search image.
[0003] In the related art, when creating an edge contour template, the Canny algorithm is usually used in advance to extract the edge contour of the template pixel image, and then the edge image of the template pixel image is obtained, and the obtained edge image is used as the edge contour template. However, the Canny algorithm is used for edge detection, which cannot distinguish between noise and short edges in the template pixel image, resulting in the obtained edge image being noisy and inaccurate. Summary of the invention
[0004] In order to overcome the problems existing in the related art, the present disclosure provides an edge detection method, an edge detection device and a computer-readable storage medium.
[0005] According to a first aspect of an embodiment of the present disclosure, there is provided an edge detection method, comprising: obtaining a template pixel image, and determining a strong edge binary image and a weak edge binary image of the template pixel image. Performing strong edge image screening based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image, wherein the target edge binary image has the same size as the weak edge binary image. Performing connected domain selection on the target edge binary image to obtain a plurality of connected domains, wherein the connected domain includes at least one cluster of continuous edge pixels. Among the plurality of connected domains, screening out a target connected domain in which the number of continuous edge pixels in the cluster exceeds a specified threshold. Detecting the edge image of the template pixel image based on the target connected domain.
[0006] In one embodiment, the selecting of connected domains from the target edge binary image to obtain multiple connected domains includes: scanning continuous edge pixels in the target edge binary image row by row. Based on the continuous edge pixels scanned in each row, multiple clusters are determined, and the multiple clusters are marked, wherein the marked content includes the starting edge pixel of the cluster, the ending edge pixel of the cluster, and the row number where the cluster is located. The multiple connected domains are determined based on the multiple clusters.
[0007] In another embodiment, the method of determining a plurality of clusters based on the continuous edge pixels scanned in each row and marking the plurality of clusters comprises: for the i-th row in the target edge binary image, the scanned continuous edge pixels are grouped into a first cluster. The scanning of all rows of the target edge binary image is completed to obtain a plurality of clusters, and the plurality of clusters are marked. If the edge pixels in the first cluster have the same column coordinates as the edge pixels in a marked second cluster in the i-1th row, the first cluster is marked with the same marking content as the second cluster. If the edge pixels in the first cluster have the same column coordinates as the edge pixels in multiple marked second clusters in the i-1th row, the first cluster is marked to match the marking content of the first cluster, and the multiple second clusters are marked as equivalent pairs.
[0008] In another embodiment, determining the multiple connected domains based on the multiple clusters includes: traversing the tag content of each cluster in the multiple clusters and searching for equivalent pairs. Determining multiple connected domains based on the found equivalent pairs, wherein each equivalent pair corresponds to a connected domain.
[0009] In yet another embodiment, before selecting a target connected domain whose number of continuous edge pixels within a cluster exceeds a specified threshold value from among the multiple connected domains, the edge detection method further comprises: determining the specified threshold value based on the number of continuous edge pixels included in each of the multiple connected domains.
[0010] In another embodiment, the edge detection method further includes: comparing a connected domain whose number of continuous edge pixels within a cluster does not exceed a specified threshold with the target edge binary image, and if the connected domain has overlapping edge pixels with the target edge binary image, taking the connected domain as the target connected domain. If the connected domain does not have overlapping edge pixels with the target edge binary image, filtering out the connected domain.
[0011] According to a second aspect of an embodiment of the present disclosure, there is provided an edge detection device, comprising: an acquisition unit, for acquiring a template pixel image, and determining a strong edge binary image and a weak edge binary image of the template pixel image. A screening unit, for performing strong edge image screening based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image, and screening out target connected domains in which the number of continuous edge pixels within the cluster exceeds a specified threshold from among multiple connected domains, wherein the target edge binary image has the same size as the weak edge binary image. A selection unit, for performing connected domain selection on the target edge binary image to obtain the multiple connected domains, wherein the connected domain includes at least one cluster consisting of continuous edge pixels. A detection unit, for detecting an edge image of the template pixel image based on the target connected domain.
[0012] In one embodiment, the selection unit selects connected domains from the target edge binary image in the following manner to obtain multiple connected domains: scanning continuous edge pixels in the target edge binary image row by row. Based on the continuous edge pixels scanned in each row, multiple clusters are determined, and the multiple clusters are marked, wherein the marked content includes the starting edge pixels and the ending edge pixels of the cluster, and the row number where the cluster is located. The multiple connected domains are determined based on the multiple clusters.
[0013] In another embodiment, the selection unit determines a plurality of clusters based on the continuous edge pixels scanned in each row, and marks the plurality of clusters in the following manner: for the i-th row in the target edge binary image, the scanned continuous edge pixels are grouped into a first cluster. After scanning all rows of the target edge binary image, a plurality of clusters are obtained, and the plurality of clusters are marked. If the edge pixels in the first cluster have the same column coordinates as the edge pixels in a marked second cluster in the i-1th row, the first cluster is marked with the same marking content as the second cluster. If the edge pixels in the first cluster have the same column coordinates as the edge pixels in multiple marked second clusters in the i-1th row, the first cluster is marked to match the marking content of the first cluster, and the multiple second clusters are marked as equivalent pairs.
[0014] In another embodiment, the selection unit determines the multiple connected domains based on the multiple clusters in the following manner: traverse the tag content of each cluster in the multiple clusters and search for equivalent pairs. Determine multiple connected domains based on the found equivalent pairs, wherein each equivalent pair corresponds to a connected domain.
[0015] In yet another embodiment, before screening out a target connected domain whose number of continuous edge pixels within a cluster exceeds a specified threshold among the multiple connected domains, the edge detection device further includes: a determination unit for determining the specified threshold based on the number of continuous edge pixels included in each of the multiple connected domains.
[0016] In another embodiment, the screening unit is further used to: compare the connected domain whose number of continuous edge pixels within the cluster does not exceed the specified threshold with the target edge binary image, and if the connected domain has overlapping edge pixels with the target edge binary image, use the connected domain as the target connected domain. If the connected domain does not have overlapping edge pixels with the target edge binary image, screen out the connected domain.
[0017] According to a third aspect of an embodiment of the present disclosure, an edge detection device is provided, comprising: a memory for storing instructions; and a processor for calling the instructions stored in the memory to execute any one of the above-mentioned edge detection methods.
[0018] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, storing instructions, and when the instructions are executed by a processor, any one of the above-mentioned edge detection methods is executed.
[0019] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: through the edge detection method provided by the present disclosure, the length of the edge of the template pixel image can be screened according to the number of continuous edge pixels, and then the target connected domain whose continuous edge pixels within the cluster exceed the specified threshold can be screened out to obtain the edge of appropriate length, thereby helping to reduce noise interference and improve the accuracy of edge detection.
[0020] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0022] Figure 1 The figure is a flow chart of an edge detection method according to an exemplary embodiment.
[0023] Figure 2 is a flow chart of another edge detection method according to an exemplary embodiment.
[0024] Figure 3 The figure is a flowchart of a method for selecting a connected domain according to an exemplary embodiment.
[0025] Figure 4 The figure is a flow chart of a tagging group according to an exemplary embodiment.
[0026] Figure 5 is a flow chart of yet another edge detection method according to an exemplary embodiment.
[0027] Figure 6 The figure is a schematic diagram of an edge detection workflow according to an exemplary embodiment.
[0028] Figure 7a The figure is a schematic diagram of a binary edge image according to an exemplary embodiment.
[0029] Figure 7b is another schematic diagram of a binary edge image according to an exemplary embodiment.
[0030] Figure 8 is a block diagram of an edge detection device according to an exemplary embodiment. DETAILED DESCRIPTION
[0031] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0032] In the related art, when performing edge detection, the Canny algorithm is usually used as the algorithm for edge contour extraction. When using the Canny algorithm for detection, a double threshold is often used to detect the edge strength, and then the contour edge of the template pixel image is obtained by adjusting the double threshold. However, the limitation of the double threshold can only control the gradient strength of the pixel point, and cannot adjust the length of the filtered edge. Furthermore, during detection, the contour image often contains some noise or short edges caused by the presence of small textures. As a result, the final edge image contains too much unnecessary noise, which affects the detection effect and further affects the user experience.
[0033] In view of this, the present disclosure provides an edge detection method, which can screen out the target connected domain whose continuous edge pixels within the cluster exceed a specified threshold according to the number of edge pixels in each cluster in the target edge binary image based on the template pixel image, thereby avoiding noise interference and improving the edge detection accuracy, thereby obtaining an edge image with appropriate edge length.
[0034] Figure 1 is a flow chart of an edge detection method according to an exemplary embodiment. Figure 1 As shown, the edge detection method includes the following steps S11 to S15.
[0035] In step S11, a template pixel image is acquired, and a strong edge binary image and a weak edge binary image of the template pixel image are determined.
[0036] In an embodiment of the present disclosure, the template pixel image can be any image with an object, and then when edge detection is performed, the edge contour in the template pixel image can be obtained. The template pixel image can come from a local database or the cloud, which is not limited in the present disclosure. In order to improve the accuracy of edge detection, the edge contour of the template pixel image is determined in advance by extracting an edge extraction operator, and then the edge condition of the template pixel image is determined, and a strong edge binary image and a weak edge binary image of the template pixel image are obtained, so as to facilitate the detection of real edges and potential edges in the template pixel image. The edge extraction operator may include: Sobel operator, Laplace operator, Privitt operator or Roberts cross edge detection, which is not limited in the present disclosure.
[0037] In step S12, a strong edge image is screened based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image.
[0038] In the disclosed embodiment, the division of strong edge and weak edge depends on the gradient strength of each pixel in the template pixel image, and the strong edge threshold and the weak edge threshold are defined for screening, thereby obtaining two binary images, a strong edge binary image and a weak edge binary image. Among them, the strong edge threshold is greater than the weak edge threshold. In the strong edge binary image, the pixel value of each edge pixel is high, and the edge of the generated image may not be closed. In the weak edge binary image, there may be some noise or false edges generated due to other reasons, and each edge contour in the strong edge binary image is included. Based on this, each pixel in the strong edge binary image is used as a reference pixel, and the strong edge binary image and the weak edge binary image are combined, thereby eliminating some noise and false edges in the weak edge binary image, and obtaining a target edge binary image with low noise and relatively closed edge contours. Among them, the target edge binary image has the same size as the weak edge binary image, which helps to keep the pixel clarity the same as the image quality of the weak edge binary image.
[0039] In step S13, connected domains are selected from the target edge binary image to obtain multiple connected domains.
[0040] In the disclosed embodiment, since the length of the edge contour in the target edge binary image is uneven, and the existence of the short edge contour easily interferes with the extraction of the edge contour template. Therefore, when extracting the edge image, the target edge binary image is selected for the connected domain, and the sequence composed of each continuous edge pixel in the target edge binary image is marked, that is, one or more clusters in the target edge binary image are determined. Then, the connectivity relationship between each edge pixel is determined, and each connected domain in the target edge binary image is determined, thereby obtaining multiple connected domains.
[0041] In step S14, a target connected domain whose number of continuous edge pixels within the cluster exceeds a specified threshold is screened out from the multiple connected domains.
[0042] In the disclosed embodiment, the length of the cluster can be determined according to the number of continuous edge pixels in the cluster, and then the length of its connected domain can be determined, that is, the length of the edge contour can be determined. In order to eliminate the interference of short edges on the edge image, the length of the connected domain is limited by specifying a threshold, and then the number of edge pixels in each cluster in each connected domain is determined according to the obtained multiple connected domains, so that the number of edge pixels in each cluster is compared with the specified threshold, and the cluster of the target connected domain whose number of edge pixels in the cluster exceeds the specified threshold is retained to obtain an edge of appropriate length, so that the obtained edge image can clearly represent the edge contour of the template pixel image, and reduce the interference of false edges caused by noise or other factors.
[0043] In step S15, an edge image of the template pixel image is detected based on the target connected component.
[0044] In the disclosed embodiment, the target connected domain obtained after screening is the edge contour that can represent the surface texture or structural shape of the object in the template pixel image. Then, the edge image of the template pixel image is obtained through the target connected domain to complete the edge detection of the template pixel image.
[0045] Through the above embodiments, in the process of edge detection, the length of the edge contour is filtered based on the connected domain, and then the target connected domain in which the continuous edge pixels within the cluster exceed the specified threshold is filtered out, and the edge of the target edge binary image with a suitable length is obtained, thereby reducing the interference of false edges caused by noise or other factors, thereby improving the clarity and accuracy of the edge image, which is beneficial to improving the user experience.
[0046] Figure 2 is a flow chart of another edge detection method according to an exemplary embodiment. Figure 2 As shown, the edge detection method includes the following steps S21 to S26.
[0047] In step S21, a template pixel image is acquired, and a strong edge binary image and a weak edge binary image of the template pixel image are determined.
[0048] In step S22, a strong edge image is screened based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image.
[0049] In step S23, connected domains are selected from the target edge binary image to obtain multiple connected domains.
[0050] In step S24, a designated threshold is determined based on the number of continuous edge pixels included in each of the plurality of connected domains.
[0051] In the disclosed embodiment, in order to accurately filter the edge length, the specified threshold is adapted to the actual situation. Therefore, the specified threshold is determined according to the number of edge pixels in each connected domain in the target edge binary image, thereby avoiding excessive screening or invalid screening.
[0052] In one example, the number of continuous edge pixels of each group in the connected domain is placed in a length array, and the values are sorted from small to large and the average is taken. The average is then used as a specified threshold to determine the length distribution of each connected domain in the target edge binary image, so that reasonable screening can be performed during screening.
[0053] In another example, based on the number of continuous edge pixels included in each connected domain, they are sorted from large to small according to the value and combined with the number of values, the corresponding value at the specified percentage position is used as the specified threshold, thereby avoiding over-screening. Therefore, when determining the specified connected domain, it is possible to automatically screen according to the acquired target edge binary image. For example: in the length array [21, 19, 18, 12, 9, 7, 7, 6, 5, 3], the value corresponding to the 60% position in the length array is selected as the specified threshold. That is, in the length array, a total of 10 values are included, 60% is the number ranked in the 6th position, and its corresponding value is 7. Therefore, 7 is the specified threshold. Then, when screening the connected domain, the connected domain with a continuous edge pixel number greater than 7 is retained as the target connected domain.
[0054] In step S25, a target connected domain whose number of continuous edge pixels within the cluster exceeds a specified threshold is screened out from the multiple connected domains.
[0055] In step S26, an edge image of the template pixel image is detected based on the target connected component.
[0056] The following is an explanation of the process of obtaining each connected domain in the target edge binary image in the embodiment of the present disclosure.
[0057] Figure 3 is a flow chart of a method for selecting a connected domain according to an exemplary embodiment. Figure 3 As shown, the connected domain selection method includes the following steps S31 to S33.
[0058] In step S31, continuous edge pixels in the target edge binary image are scanned row by row.
[0059] In the embodiment of the present disclosure, in order to facilitate the determination of the connectivity relationship between edge pixels in the target edge binary image, each edge pixel in the target edge binary image is scanned row by row, thereby avoiding omission or loss of edge pixels.
[0060] In step S32, a plurality of clusters are determined based on the continuous edge pixels scanned in each row, and the plurality of clusters are marked.
[0061] In the embodiment of the present disclosure, during the scanning of edge pixels in each row, multiple continuous edge pixels in each row are determined, and then the multiple adjacent and continuous edge pixels in the row are combined into a cluster, and the starting edge pixel of each cluster and the ending edge pixel of the cluster, as well as the row number of the cluster are marked. Different clusters have different labels, which makes it easier to distinguish between clusters.
[0062] In step S33 , a plurality of connected domains are determined based on the plurality of cliques.
[0063] In the embodiment of the present disclosure, based on the obtained multiple clusters, the positional relationship between the clusters is determined, and then a closed curve, that is, a connected domain, is obtained. The connected domain may include a simply connected domain or a multiply connected domain.
[0064] The presently disclosed embodiment will now describe the process of labeling a group.
[0065] Figure 4 is a flow chart showing a marking group according to an exemplary embodiment. Figure 4 As shown, the marking group includes the following steps S41 to S42.
[0066] In step S41, for the i-th row in the target edge binary image, the scanned continuous edge pixels are grouped into a first cluster.
[0067] In the disclosed embodiment, i can be any number starting from 1, and the maximum value of i depends on the number of pixel rows of the target edge binary image. In order to facilitate the determination of the continuous relationship between the edge pixels, the target edge binary image is scanned row by row, and then the continuous edge pixels of each row are determined, so as to facilitate the combination and marking. When scanning the i-th row of the target edge binary image, the scanned continuous edge pixels are formed into a first cluster, which helps to determine that multiple edge pixels in the cluster belong to the same connected domain.
[0068] In step S42, the scanning of all rows of the target edge binary image is completed to obtain a plurality of clusters, and the plurality of clusters are marked.
[0069] In the disclosed embodiment, after the target edge binary image is completely scanned, the relationship between the clusters in the target edge binary image can be determined based on the clusters marked in each row. Then, all the clusters in the target edge binary image are traversed, and the clusters that can be combined with the marks are re-marked, thereby improving the accuracy of the connected domain selection.
[0070] In one embodiment, the equivalent relationship between the clusters can be determined by traversing the tag content of each cluster in the multiple clusters, and then the equivalent pairs with the equivalent relationship in each cluster can be determined. Among them, the equivalent pair can be two or more clusters, and each equivalent pair corresponds to a connected domain. Therefore, two or more clusters marked as equivalent pairs are merged and marked with new tags, and the remaining single clusters maintain the original tags, so as to distinguish the single connected domain and the multi-connected domain in the target edge binary image.
[0071] In one example, before marking the first cluster in the i-th row, the coordinate domain of each edge pixel in the first cluster is compared with the coordinate domain of the marked second cluster in the i-1th row. If the edge pixels in the first cluster and the edge pixels in the second cluster have overlapping column coordinates, it means that there are connected edge pixels between the first cluster and the second cluster, and the first cluster and the second cluster can form the same simply connected domain. Therefore, the first cluster is marked with the same marking content as the second cluster, that is, the marking of the second cluster is given to the first cluster.
[0072] In another example, the coordinate domain of each edge pixel in the first cluster is compared with the coordinate domain of the marked second cluster in the i-1th row. If the edge pixels in the first cluster overlap with the edge pixels in multiple second clusters in the i-1th row, it means that there are connected edge pixels between the first cluster and the multiple second clusters, and the multiple second clusters in the i-1th row can form the same multi-connected domain. Therefore, it can be considered that the multiple second clusters in the i-1th row belong to equivalent pairs of each other. The first cluster is marked with a different mark from the second cluster, or the first cluster is marked to match the content of the first cluster mark, so as to distinguish the first cluster from the second cluster.
[0073] Figure 5 is a flow chart of another edge detection method according to an exemplary embodiment. Figure 5 As shown, the edge detection method includes the following steps S51 to S56.
[0074] In step S51, a template pixel image is acquired, and a strong edge binary image and a weak edge binary image of the template pixel image are determined.
[0075] In step S52, a strong edge image is screened based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image.
[0076] In step S53, connected domains are selected from the target edge binary image to obtain multiple connected domains.
[0077] In step S54, a target connected domain whose number of continuous edge pixels within the cluster exceeds a specified threshold is screened out from the multiple connected domains.
[0078] In step S551, the connected domain whose number of continuous edge pixels within the cluster does not exceed the specified threshold is compared with the target edge binary image. If the connected domain has overlapping edge pixels with the target edge binary image, the connected domain is used as the target connected domain.
[0079] In the embodiment of the present disclosure, in order to improve the accuracy of edge detection, the connected domains whose number of continuous edge pixels in the cluster does not exceed the specified threshold are screened twice, and the connected domains are compared with the target edge binary image to determine whether there are overlapping edge pixels. If, after comparison, it is determined that the connected domain and the target edge binary image have overlapping edge pixels, it indicates that the connected domain is part of the edge contour, so it is retained as the target connected domain.
[0080] In step S552, if there are no overlapping edge pixels between the connected domain and the target edge binary image, the connected domain is screened out.
[0081] In the embodiment of the present disclosure, if it is determined through comparison that the connected domain does not have overlapping edge pixels with the target edge binary image, it indicates that the connected domain is not part of the edge contour and may be a false contour generated by noise or other reasons. Therefore, it is screened out to improve the accuracy of edge contour extraction.
[0082] In step S56, an edge image of the template pixel image is detected based on the target connected component.
[0083] Through the above embodiments, it is possible to avoid erroneous screening of short edges, thereby improving the accuracy of edge detection, making the obtained edge image more accurate, which is conducive to enhancing the user experience.
[0084] In one embodiment, the strong edge binary image and the weak edge binary image can be obtained based on the Canny algorithm. In order to reduce the interference of noise on edge detection, a Gaussian filter is used to smooth the image, and then the noise in the template pixel image is filtered. The gradient intensity and direction of each pixel in the image are calculated by the Sobel operator, and then the edge grayscale change in the template pixel image is highlighted to obtain a gradient intensity image and a gradient direction image. Based on non-maximum suppression, non-edge pixels in the gradient intensity image are screened out, so that the interference pixels in the new gradient intensity image obtained are reduced as much as possible, and the edge detection band is eliminated. The stray response. Thus, a strong edge binary image and a weak edge binary image are obtained by using double threshold detection. In one example, the interference of noise on edge detection can be reduced by using a median filter to eliminate it, which helps to suppress salt and pepper noise and prevent salt and pepper noise from affecting the edge extraction results.
[0085] In one implementation scenario, Figure 6 A schematic diagram of an edge detection workflow is shown in FIG. When detecting the edge of a template pixel image, the following can be used: Figure 6 The edge detection workflow shown is used for detection.
[0086] In the present disclosure, for the convenience of explanation, this embodiment and the following embodiments will be described by taking an arbitrary pixel position (i, j) in a template pixel image f as an example. The size of the template pixel image f is a*b. The letters are arbitrary constants.
[0087] like Figure 6 As shown, the edge detection workflow includes the following steps S61 to S613.
[0088] In step S61, the template pixel image is denoised by a Gaussian filter to obtain a denoised template pixel image.
[0089] In the present disclosure, the Gaussian filter is h, the pixel position for Gaussian filtering is (k, l), and the corresponding grayscale value is h(k, l). For example:
[0090]
[0091] After Gaussian filtering the template pixel image, the denoised template pixel image g is obtained. In the denoised template pixel image g, the original grayscale value h(i,j) of the pixel position (i,j) is changed to g(i,j) after Gaussian filtering. The formula of Gaussian filtering is as follows:
[0092]
[0093] In step S62, a gradient intensity image and a gradient direction image are obtained based on the denoised template pixel image.
[0094] In the present disclosure, the gray value g(i,j) of the point (i,j) in the denoised template pixel image g is convolved using the x-direction convolution template and the y-direction convolution template of the Sobel operator to obtain the edge image Gx(x,y) in the x-direction and the edge image Gy(x,y) in the y-direction. For example: Figure 7a and Figure 7b Schematic diagram of a binary edge image shown. Figure 7a is the edge image Gx(x,y) in the x direction, Figure 7b is the edge image Gy(x,y) in the y direction. Then, the gradient strength G(x,y) at point (i,j) and the gradient direction G at point (i,j) are determined by the gradient strength formula. dir (x,y). The formula for gradient strength is: The formula for the gradient direction is: G dir (x,y)=atcran(Gy(x,y) / Gx(x,y)).
[0095] In step S63, based on the gradient direction image, non-maximum suppression is performed on the gradient intensity of each pixel in the gradient intensity image to obtain a new gradient intensity image.
[0096] In the present disclosure, in the gradient intensity image, pixels with gradient intensity G(x,y)>0 are selected to determine whether these pixels are at the maximum value in the direction indicated by the gradient direction Gdir(x,y). If it is the maximum value, the gradient intensity G(x,y) of the point remains unchanged; if it is not the maximum value, the gradient intensity G(x,y) of the point is set to 0. Finally, a new gradient intensity image G(x,y)' after non-maximum suppression is obtained.
[0097] In step S64, dual threshold segmentation is used to perform edge detection on the acquired new gradient intensity image to determine a strong edge binary image and a weak edge binary image of the template pixel image.
[0098] In the present disclosure, a first threshold value threshold1 and a second threshold value threshold2 are preset, wherein the first threshold value threshold1 is greater than the second threshold value threshold2. The grayscale values of each edge pixel in the new gradient intensity image G(x, y)' are compared with the first threshold value and the second threshold value, thereby obtaining a weak edge binary image Edeg1(x, y) and a strong edge binary image Edeg2(x, y). The edge binary image obtained after comparison with the second threshold value is a weak edge binary image, and the edge binary image obtained after comparison with the first threshold value is a strong edge binary image. In the weak edge binary image: In a binary image with strong edges:
[0099] In step S65, a strong edge image is screened based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image.
[0100] In the present disclosure, an image EdgeResult is created that is the same size as the weak edge binary image Edgeg1(x,y) but has a pixel value of 0. If the weak edge binary image (x,y)>1, determine whether there is an edge pixel point of the strong edge binary image Edge2(xi,yi)=1 in the 4-domain or 8-domain of the (x,y) point. If so, EdgeResult(x,y)=1 is output at the position of the (x,y) point in the image EdgeResult. If not, EdgeResult(x,y)=0 is output at the position of the (x,y) point in the image EdgeResult. Then the target edge binary image is obtained.
[0101] In step S66, the i-th row in the target edge binary image is scanned.
[0102] In step S67, the continuous edge pixels scanned in the i-th row are grouped into a first cluster, and the multiple clusters are marked.
[0103] In the present disclosure, the content of the mark includes the starting edge pixel of the clique, the ending edge pixel of the clique, and the row number where the clique is located.
[0104] In step S68, it is determined whether the edge pixel in the first cluster has the same column coordinate as the edge pixel in the marked second cluster in the i-1th row.
[0105] In step S691, if there is overlap, the first cluster is marked with content consistent with the mark of the second cluster, or the first cluster is marked to match the mark of the first cluster, and multiple second clusters are marked as equivalent pairs.
[0106] In step S692, if there is no overlap, a new mark is used to mark the first group.
[0107] In step S610, the scanning of all rows of the target edge binary image is completed to obtain a plurality of clusters.
[0108] In step S611, all clusters are traversed, and each cluster in the target edge binary image is re-labeled based on equivalence.
[0109] In step S612, based on the number of continuous edge pixels included in each of the multiple connected domains, a target connected domain whose number of continuous edge pixels within the cluster exceeds a specified threshold is screened out by average.
[0110] In step S613, an edge image of the template pixel image is detected based on the target connected component.
[0111] Through the above real-time scenario, the edge length can be screened based on the target edge binary image obtained by Canny edge screening, which helps to eliminate the interference of false edges caused by noise or other reasons, improve the clarity and accuracy of the edge image, and thus help the length of each edge in the obtained edge image meet user needs, which is beneficial to improving the user experience.
[0112] Based on the same concept, an embodiment of the present disclosure also provides an edge detection device.
[0113] It is understandable that the edge detection device provided by the embodiment of the present disclosure includes hardware structures and / or software modules corresponding to the execution of each function in order to realize the above functions. In combination with the units and algorithm steps of each example disclosed in the embodiment of the present disclosure, the embodiment of the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present disclosure.
[0114] Figure 8 FIG. 1 is a block diagram of an edge detection device according to an exemplary embodiment. Figure 8 The edge detection device 100 includes an acquisition unit 101, a screening unit 102, a selection unit 103 and a detection unit 104.
[0115] The acquisition unit 101 is used to acquire a template pixel image and determine a strong edge binary image and a weak edge binary image of the template pixel image.
[0116] The screening unit 102 is used to screen the strong edge image based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image, and to screen out a target connected domain whose number of continuous edge pixels within the cluster exceeds a specified threshold from among multiple connected domains, wherein the target edge binary image and the weak edge binary image have the same size.
[0117] The selection unit 103 is used to select a connected domain from the target edge binary image to obtain a plurality of connected domains, wherein the connected domains include at least one cluster consisting of continuous edge pixels.
[0118] The detection unit 104 is used to detect an edge image of the template pixel image based on the target connected domain.
[0119] In one embodiment, the selection unit 103 selects connected domains from the target edge binary image in the following manner to obtain multiple connected domains: continuous edge pixels in the target edge binary image are scanned row by row. Based on the continuous edge pixels scanned in each row, multiple clusters are determined, and the multiple clusters are marked, wherein the marked content includes the starting edge pixel of the cluster, the ending edge pixel of the cluster, and the row number where the cluster is located. Multiple connected domains are determined based on the multiple clusters.
[0120] In another embodiment, the selection unit 103 determines multiple clusters based on the continuous edge pixels scanned in each row, and marks the multiple clusters in the following manner: for the i-th row in the target edge binary image, the scanned continuous edge pixels are grouped into a first cluster. After scanning all rows of the target edge binary image, multiple clusters are obtained, and the multiple clusters are marked. If the edge pixels in the first cluster have the same column coordinates as the edge pixels in a marked second cluster in the i-1th row, the first cluster is marked with the same marking content as the second cluster. If the edge pixels in the first cluster have the same column coordinates as the edge pixels in multiple marked second clusters in the i-1th row, the first cluster is marked to match the marking content of the first cluster, and the multiple second clusters are marked as equivalent pairs.
[0121] In another embodiment, the selection unit 103 determines multiple connected domains based on multiple clusters in the following manner: traverse the tag content of each cluster in the multiple clusters and search for equivalent pairs. Determine multiple connected domains based on the found equivalent pairs, wherein each equivalent pair corresponds to a connected domain.
[0122] In another embodiment, before screening out a target connected domain whose number of continuous edge pixels within a cluster exceeds a specified threshold among multiple connected domains, the edge detection device further includes: a determination unit for determining the specified threshold based on the number of continuous edge pixels included in each of the multiple connected domains.
[0123] In another embodiment, the screening unit 102 is further configured to: compare the connected domain whose number of continuous edge pixels within the cluster does not exceed a specified threshold with the target edge binary image, and if the connected domain has overlapping edge pixels with the target edge binary image, the connected domain is used as the target connected domain. If the connected domain does not have overlapping edge pixels with the target edge binary image, the connected domain is screened out.
[0124] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0125] Further, in an exemplary embodiment, the edge detection device may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method. For example, the edge detection device includes: a memory for storing instructions; and a processor for calling the instructions stored in the memory to perform the edge detection method provided in any of the above embodiments.
[0126] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the instructions can be executed by a processor of the edge detection device to complete the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0127] It is further understood that in the present disclosure, "plurality" refers to two or more than two, and other quantifiers are similar thereto. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. The singular forms "a", "the" and "the" are also intended to include plural forms, unless the context clearly indicates other meanings.
[0128] It is further understood that the terms "first", "second", etc. are used to describe various information, but such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other, and do not indicate a specific order or degree of importance. In fact, the expressions "first", "second", etc. can be used interchangeably. For example, without departing from the scope of the present disclosure, the first information can also be referred to as the second information, and similarly, the second information can also be referred to as the first information.
[0129] It can be further understood that, unless otherwise specified, “connection” includes a direct connection without other components between the two, and also includes an indirect connection with other components between the two.
[0130] It is further understood that, although the operations are described in a specific order in the drawings in the embodiments of the present disclosure, it should not be understood as requiring the operations to be performed in the specific order shown or in a serial order, or requiring the execution of all the operations shown to obtain the desired results. In certain environments, multitasking and parallel processing may be advantageous.
[0131] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0132] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An edge detection method, characterized in that: The edge detection method comprises: Acquire a template pixel image, and determine a strong edge binary image and a weak edge binary image of the template pixel image; Perform strong edge image screening based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image, wherein the target edge binary image has the same size as the weak edge binary image; Selecting a connected domain from the target edge binary image to obtain a plurality of connected domains, wherein the connected domains include at least one cluster consisting of continuous edge pixels; Among the multiple connected domains, select a target connected domain whose number of continuous edge pixels within the cluster exceeds a specified threshold; Compare the connected domain whose number of continuous edge pixels within the cluster does not exceed the specified threshold with the target edge binary image, and if the connected domain has overlapping edge pixels with the target edge binary image, take the connected domain as the target connected domain; An edge image of the template pixel image is detected based on the target connected domain.
2. The edge detection method according to claim 1, characterized in that: The connecting domain selection is performed on the target edge binary image to obtain multiple connecting domains, including: Scanning continuous edge pixels in the target edge binary image line by line; Based on the continuous edge pixels scanned in each row, a plurality of clusters are determined, and the plurality of clusters are marked, wherein the marking content includes the starting edge pixel of the cluster, the ending edge pixel of the cluster, and the row number where the cluster is located; The plurality of connected domains are determined based on the plurality of cliques.
3. The edge detection method according to claim 2, characterized in that: The determining a plurality of clusters based on the continuous edge pixels scanned in each row and marking the plurality of clusters comprises: For the i-th row in the target edge binary image, the scanned continuous edge pixels are grouped into a first cluster; Complete scanning of all rows of the target edge binary image to obtain a plurality of clusters, and mark the plurality of clusters; If the edge pixel in the first cluster has a column coordinate overlap with the edge pixel in a marked second cluster in the i-1th row, the first cluster is marked with the same marking content as the second cluster; If the edge pixels in the first cluster have overlapping column coordinates with the edge pixels in the multiple marked second clusters in the i-1th row, the first cluster is marked to match the marking content of the first cluster, and the multiple second clusters are marked as equivalent pairs.
4. The edge detection method according to claim 3, characterized in that: The determining the plurality of connected domains based on the plurality of clusters comprises: Traversing the tag content of each clique in the plurality of cliques and searching for equivalent pairs; A plurality of connected domains are determined based on the found equivalent pairs, wherein each equivalent pair corresponds to a connected domain.
5. The edge detection method according to claim 1 or 4, characterized in that: Before selecting a target connected domain whose number of continuous edge pixels within a cluster exceeds a specified threshold from among the multiple connected domains, the edge detection method further includes: The designated threshold is determined based on the number of continuous edge pixels included in each of the plurality of connected domains.
6. The edge detection method according to claim 1, characterized in that: The edge detection method further comprises: If there are no overlapping edge pixels between the connected domain and the target edge binary image, the connected domain is screened out.
7. An edge detection device, characterized in that: The edge detection device comprises: An acquisition unit, used for acquiring a template pixel image, and determining a strong edge binary image and a weak edge binary image of the template pixel image; A screening unit is used to screen strong edge images based on the strong edge binary image and the weak edge binary image to obtain a target edge binary image, and to screen out a target connected domain whose number of continuous edge pixels in a cluster exceeds a specified threshold value from multiple connected domains, wherein the target edge binary image and the weak edge binary image have the same size; a connected domain whose number of continuous edge pixels in a cluster does not exceed the specified threshold value is compared with the target edge binary image, and if there are overlapping edge pixels between the connected domain and the target edge binary image, the connected domain is used as the target connected domain; a selection unit is used to select connected domains from the target edge binary image to obtain the multiple connected domains, wherein the connected domain includes at least one cluster consisting of continuous edge pixels; A detection unit is used to detect an edge image of the template pixel image based on the target connected domain.
8. The edge detection device according to claim 7, characterized in that: The edge detection device also includes: The determining unit is configured to determine the specified threshold based on the number of continuous edge pixels included in each of the multiple connected domains.
9. The edge detection device according to claim 7, characterized in that: The screening unit is also used for: If there are no overlapping edge pixels between the connected domain and the target edge binary image, the connected domain is screened out.
10. An edge detection device, characterized in that: The edge detection device comprises: a memory for storing instructions; and A processor, configured to call the instructions stored in the memory to execute the edge detection method as described in any one of claims 1 to 6.
11. A computer-readable storage medium, characterized in that: Instructions are stored, and when the instructions are executed by the processor, the edge detection method according to any one of claims 1 to 6 is executed.
Citation Information
Patent Citations
An anti-starlight interference space relative navigation target rapid extraction method
CN109949308A
Multi-target detection tracking method of video image
CN111369570A
Cited By
Edge detection method, system and equipment based on improved loss function and medium
CN120852459A
Edge detection method, system, device and medium based on improved loss function
CN120852459B