Sub-pixel edge detection method and device and electronic equipment
By using gradient information to determine subpixel points in image processing and calculating feature difference matching degrees in local subgraphs, the problems of sparse edge points and non-smooth contours in the prior art are solved, and high-precision subpixel edge detection is achieved.
Patent Information
- Application Number
- CN202411820871.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-04-18
AI Technical Summary
The existing subpixel edge detection methods have problems such as sparse edge points and insufficient smooth contours when extracting edge profiles, which are difficult to meet the needs of high-precision detection.
By determining the subpixel points of each edge point based on the gradient of the neighboring pixel points of each edge point in the image to be detected, and the matching degree is calculated based on the feature difference in the local sub-map, thereby linking the subpixel points of each edge point to obtain a relatively smooth subpixel edge profile.
It realizes smoother subpixel edge contour extraction, enhances noise resistance, and is suitable for high-precision detection.
Smart Images

Figure CN119850660A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of image processing technology, and in particular relates to a sub-pixel edge detection method, device and electronic equipment. Background Art
[0002] In some image processing fields with high precision requirements (such as medical imaging, remote sensing image analysis, high-precision industrial quality inspection, etc.), pixel-level edge positioning can no longer meet the needs, and the development of sub-pixel edge detection can achieve higher accuracy.
[0003] Related solutions use the Sobel operator and the Canny operator to perform sub-pixel edge detection. When performing sub-pixel edge extraction, the Sobel operator and the Canny operator usually perform a simple difference between two adjacent pixels, which easily results in "step-like" or discontinuous edges. The extracted sub-pixel edges are not precise and smooth enough. Summary of the invention
[0004] The present application aims to solve at least one of the technical problems existing in the related art. To this end, the present application proposes a sub-pixel edge detection method, device and electronic device, which can obtain a relatively smooth sub-pixel edge contour.
[0005] In a first aspect, the present application provides a sub-pixel edge detection method, the method comprising:
[0006] Determine the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected;
[0007] For each edge point, when the local sub-map of the edge point includes at least two neighboring edge points, the matching degree between the edge point and each neighboring edge point is obtained according to the feature differences between the sub-pixel point of the edge point and the sub-pixel points of each neighboring edge point; the local sub-map takes the edge point as the pixel center;
[0008] Determine a target neighborhood edge point of an edge point from at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points;
[0009] The sub-pixel points of each edge point are linked with the sub-pixel points of the corresponding target neighborhood edge points to obtain the sub-pixel edge contour of the image to be detected.
[0010] According to the sub-pixel edge detection method of the present application, the sub-pixel points of each edge point are determined according to the gradient of the neighborhood pixel points of each edge point in the image to be detected; for each edge point, when the local sub-image of the edge point includes at least two neighborhood edge points, the matching degree between the edge point and each neighborhood edge point is obtained according to the feature differences between the sub-pixel point of the edge point and the sub-pixel points of each neighborhood edge point; the target neighborhood edge point of the edge point is determined from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and the other neighborhood edge points; the sub-pixel points of each edge point and the sub-pixel points of the corresponding target neighborhood edge point are linked to obtain the sub-pixel edge contour of the image to be detected, which solves the problems of sparse edge points and insufficiently smooth edge contours in the existing sub-pixel contour extraction methods, can obtain a relatively smooth sub-pixel edge contour, and also has good noise resistance, which can better adapt to the field of high-precision detection.
[0011] According to one embodiment of the present application, determining the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected includes:
[0012] According to the gradient of edge points and neighboring pixels, the local curvature information of edge points is obtained;
[0013] According to the local curvature information of the edge point, the vertical offset and the horizontal offset of the edge point are determined;
[0014] The coordinates of the sub-pixel point corresponding to the edge point are determined according to the coordinates of the edge point, the vertical offset, and the horizontal offset.
[0015] According to an embodiment of the present application, obtaining local curvature information of an edge point according to the gradient of the edge point and the neighboring pixel point includes:
[0016] According to the gradients of the edge points and the neighboring pixel points, the gradient values of the edge points and the neighboring pixel points are determined;
[0017] According to the gradient values of edge points and neighboring pixels, a target second-order polynomial model is constructed to describe the image intensity changes around the edge points;
[0018] According to the coefficients of the target second-order polynomial model, the target second-order derivative matrix at the edge point is obtained; the target second-order derivative matrix is used to describe the local curvature information.
[0019] According to an embodiment of the present application, determining the vertical offset and the horizontal offset of the edge point according to the local curvature information of the edge point includes:
[0020] Perform eigendecomposition on the target second-order derivative matrix at the edge points to obtain the eigenvalues and eigenvectors of the target second-order derivative matrix;
[0021] According to the eigenvalue and eigenvector, the vertical offset and horizontal offset of the edge point are obtained.
[0022] According to an embodiment of the present application, determining the coordinates of the sub-pixel point corresponding to the edge point according to the coordinates, the vertical offset, and the horizontal offset of the edge point includes:
[0023] According to the horizontal coordinate and horizontal offset of the edge point, the horizontal coordinate of the sub-pixel point corresponding to the edge point is obtained;
[0024] According to the vertical coordinate and the vertical offset of the edge point, the vertical coordinate of the sub-pixel point corresponding to the edge point is obtained.
[0025] According to an embodiment of the present application, obtaining the matching degree between the edge point and each neighboring edge point according to each feature difference between the sub-pixel point of the edge point and the sub-pixel points of each neighboring edge point includes:
[0026] Determine the one-way matching degree corresponding to each feature difference; the feature difference includes at least one of a distance difference, a gradient angle and a grayscale difference;
[0027] Get the weights corresponding to each feature difference;
[0028] According to the weights corresponding to the feature differences, the one-way matching degrees corresponding to the feature differences are weighted summed to obtain the matching degrees between the edge points and the edge points in each neighborhood.
[0029] According to one embodiment of the present application, before determining the sub-pixel point of each edge point according to the gradient of the neighborhood pixel points of each edge point in the image to be detected, the method further includes:
[0030] Traverse each pixel in the image to be detected, and perform the following operations during the traversal process:
[0031] For each pixel, according to the gradient of the pixel and the corresponding neighboring pixel, the gradient value of the pixel and the neighboring pixel is obtained;
[0032] When it is determined that the gradient value of the pixel point is greater than the gradient values of each neighboring pixel point, the pixel point is determined to be an edge point.
[0033] In a second aspect, the present application provides a sub-pixel edge detection device, the device comprising:
[0034] The first processing module is used to determine the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected;
[0035] The second processing module is used for obtaining, for each edge point, a matching degree between the edge point and each neighboring edge point according to each feature difference between a sub-pixel point of the edge point and the sub-pixel points of each neighboring edge point when the local sub-map of the edge point includes at least two neighboring edge points; the local sub-map takes the edge point as the pixel center;
[0036] The third processing module is used to determine a target neighborhood edge point of the edge point from at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points;
[0037] The fourth processing module is used to link the sub-pixel points of each edge point with the sub-pixel points of the corresponding target neighborhood edge point to obtain the sub-pixel edge contour of the image to be detected.
[0038] According to the sub-pixel edge detection device of the present application, the sub-pixel points of each edge point are determined according to the gradient of the neighborhood pixel points of each edge point in the image to be detected; for each edge point, when the local sub-image of the edge point includes at least two neighborhood edge points, the matching degree between the edge point and each neighborhood edge point is obtained according to the feature differences between the sub-pixel point of the edge point and the sub-pixel points of each neighborhood edge point; the target neighborhood edge point of the edge point is determined from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and the other neighborhood edge points; the sub-pixel points of each edge point and the sub-pixel points of the corresponding target neighborhood edge point are linked to obtain the sub-pixel edge contour of the image to be detected, which solves the problems of sparse edge points and insufficiently smooth edge contours in the existing sub-pixel contour extraction methods, can obtain a relatively smooth sub-pixel edge contour, and also has good noise resistance, which can better adapt to the field of high-precision detection.
[0039] In a third aspect, the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the sub-pixel edge detection method provided in the first aspect above is implemented.
[0040] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the sub-pixel edge detection method provided in the first aspect above.
[0041] In a fifth aspect, the present application provides a chip, the chip comprising a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a program or instruction to implement the sub-pixel edge detection method provided in the first aspect.
[0042] In a sixth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the sub-pixel edge detection method provided in the first aspect above.
[0043] The above one or more technical solutions in the embodiments of the present application have at least one of the following technical effects:
[0044] The sub-pixel points of each edge point are determined according to the gradient of the neighborhood pixel points of each edge point in the image to be detected; for each edge point, when the local sub-image of the edge point includes at least two neighborhood edge points, the matching degree between the edge point and each neighborhood edge point is obtained according to the feature differences between the sub-pixel point of the edge point and the sub-pixel points of each neighborhood edge point; the target neighborhood edge point of the edge point is determined from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points; the sub-pixel points of each edge point are linked with the sub-pixel points of the corresponding target neighborhood edge point to obtain the sub-pixel edge contour of the image to be detected, which solves the problems of sparse edge points and insufficiently smooth edge contour in the existing sub-pixel contour extraction method, can obtain a relatively smooth sub-pixel edge contour, and also has good noise resistance, which can better adapt to the field of high-precision detection.
[0045] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0047] Figure 1 This is one of the flow charts of the sub-pixel edge detection method provided in the embodiment of the present application;
[0048] Figure 2 It is a horizontal gradient map and a vertical gradient map of a certain pixel point and neighboring pixel points around the pixel point provided in an embodiment of the present application;
[0049] Figure 3 is a schematic diagram of a local subgraph corresponding to a certain edge point provided in an embodiment of the present application;
[0050] Figure 4 This is the second flow chart of the sub-pixel edge detection method provided in the embodiment of the present application;
[0051] Figure 5 is a schematic structural diagram of a sub-pixel edge detection device provided in an embodiment of the present application;
[0052] Figure 6 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0054] The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0055] In conjunction with the accompanying drawings, the sub-pixel edge detection method, sub-pixel edge detection device, electronic device and readable storage medium provided in the embodiments of the present application are described in detail through specific embodiments and their application scenarios.
[0056] The sub-pixel edge detection method may be applied to a terminal, and may be specifically executed by hardware or software in the terminal.
[0057] The sub-pixel edge detection method provided in the embodiment of the present application may be executed by an electronic device or a functional module or functional entity in the electronic device that can implement the sub-pixel edge detection method. The electronic devices mentioned in the embodiment of the present application include but are not limited to mobile phones, tablet computers, computers, cameras, and wearable devices. The sub-pixel edge detection method provided in the embodiment of the present application is described below using an electronic device as an example of the execution subject.
[0058] like Figure 1 As shown, the sub-pixel edge detection method includes: step 110, step 120, step 130 and step 140.
[0059] Step 110: Determine the sub-pixel points of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected.
[0060] The gradient of a pixel usually refers to the rate of change of the intensity of an image at a certain pixel position. For a two-dimensional image, the gradient is the result of differential calculation of the brightness value (grayscale value) of the image pixel.
[0061] Edge points, also called edge pixels, are usually defined as points in an image where the grayscale (or color) value changes greatly. Specifically, edge points are places where the image gradient (or derivative) is large, and edges usually correspond to local maximum values of the gradient.
[0062] In some embodiments, before determining the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected, the method further includes:
[0063] Traverse each pixel in the image to be detected, and perform the following operations during the traversal process:
[0064] For each pixel, according to the gradient of the pixel and the corresponding neighboring pixel, the gradient value of the pixel and the neighboring pixel is obtained;
[0065] When it is determined that the gradient value of the pixel point is greater than the gradient values of each neighboring pixel point, the pixel point is determined to be an edge point.
[0066] Gradients are usually divided into horizontal gradients and vertical gradients.
[0067] Horizontal gradient (Gx): describes the change in image brightness along the horizontal direction (x-axis).
[0068] Vertical gradient (Gy): describes the change in image brightness along the vertical direction (y-axis).
[0069] The gradient value (also called gradient amplitude) of a pixel is the rate at which the grayscale of the pixel in the image changes, usually expressed as the magnitude of the gradient. The gradient value is used to describe the intensity or speed of grayscale change at a certain point in the image, and it reflects the change in image brightness. The gradient value G can be obtained by the following formula (1):
[0070]
[0071] Among them, G represents the gradient value of the pixel point, Gx represents the horizontal gradient, and Gy represents the vertical gradient.
[0072] like Figure 2As shown, an embodiment of the present application provides a horizontal gradient map and a vertical gradient map of a certain pixel point and the neighboring pixel points around the pixel point, the pixel point is pixel point A, the horizontal gradient map and the vertical gradient map are both 3*3, the horizontal gradient map includes the horizontal gradient and the horizontal gradient direction of each pixel point, the horizontal gradients of the pixel points in each row are [-1,0,+1], [-2,0,+2], [-1,0,+1] respectively, the vertical gradient map includes the vertical gradient and the vertical gradient direction, the vertical gradients of the pixel points in each column are [-1,0,+1], [-2,0,+2], [-1,0,+1] respectively, the horizontal gradient and the vertical gradient of the pixel point A are both 0, and when it is determined that the gradient value of the pixel point is greater than the gradient values of each neighboring pixel point, the pixel point is determined to be an edge point, and the gradient value of the pixel point A is not greater than the gradient values of each neighboring pixel point, therefore, the pixel point A is not an edge point.
[0073] In the embodiment of the present application, the edge points in the image to be detected may be edge points of the target object, and the target object may be a person or an object, such as a product, a product component, etc., without limitation.
[0074] In the embodiment of the present application, the edge points in the image to be detected can be determined by any one or more of the following methods, without limitation, including a threshold method (Edge Detection with Thresholding), a gradient-based algorithm (such as Sobel, Canny, Prewitt, Roberts operator), a second-order derivative-based algorithm (such as LoG, Marr-Hildreth), and some graph theory-based or optimization methods (such as graph cuts, Hough transform, etc.).
[0075] The neighborhood pixels of an edge point are the pixels that are closely adjacent to the current pixel in the image, usually including pixels in the up, down, left, right and diagonal directions. Common neighborhood pixels include 4-neighborhood and 8-neighborhood. Among them, 4-neighborhood refers to the four pixels directly adjacent to the current pixel, which are located in the up, down, left and right directions of the current pixel respectively; 8-neighborhood includes the four pixels above, below, left, right and four diagonal directions of the current pixel.
[0076] For each edge point in the image to be detected, the sub-pixel point of each edge point can be determined according to the gradient of the neighboring pixel points of each edge point.
[0077] Specifically, the local curvature information of the edge point can be obtained according to the gradient values of the edge point and the neighboring pixel points.
[0078] The local curvature information of edge points indicates the degree of curvature or the direction of curvature around the edge points. Curvature is usually a measure of the curvature of a curve or surface at a certain point in mathematics. For edge points in an image, it helps to describe the shape characteristics of the edge and can be represented by a second-order derivative matrix. The detailed determination process is shown in the subsequent content.
[0079] Further, according to the local curvature information of the edge point, the vertical offset and the horizontal offset of the edge point are determined; according to the coordinates of the edge point, the vertical offset and the horizontal offset, the coordinates of the sub-pixel point corresponding to the edge point are determined.
[0080] Step 120: For each edge point, when the local sub-graph of the edge point includes at least two neighboring edge points, the matching degree between the edge point and each neighboring edge point is obtained according to the feature differences between the sub-pixel point of the edge point and the sub-pixel points of each neighboring edge point; the local sub-graph takes the edge point as the pixel center.
[0081] In the embodiment of the present application, each edge point has a corresponding local sub-graph, which takes the edge point as the pixel center, and the local sub-graph generally includes at least one neighborhood edge point, which refers to other edge points existing around the edge point of a certain edge point (in the local sub-graph). In simple terms, the neighborhood edge points of a certain edge point are other edge points located in the local sub-graph of the edge point.
[0082] The size of the local sub-image can be set according to actual needs, and can be set to 3*3, 5*5, 7*7, etc., and 5*5 is usually selected.
[0083] When an edge contour map needs to be generated, if a local submap of a certain edge point includes a neighborhood edge point, then the sub-pixel point corresponding to the edge point and the sub-pixel point corresponding to the neighborhood edge point are linked.
[0084] When a local sub-map of an edge point includes at least two neighborhood edge points, in order to improve the smoothness of the edge contour, an embodiment of the present application obtains a matching degree between the edge point and each neighborhood edge point based on each feature difference between a sub-pixel point of the edge point and each neighborhood edge point, and determines a target neighborhood edge point from at least two neighborhood edge points based on the matching degree between the edge point and each neighborhood edge point.
[0085] The feature difference includes at least one of a distance difference, a gradient angle, and a grayscale difference.
[0086] Among them, the smaller the distance difference, the higher the matching degree; the smaller the gradient angle, the higher the matching degree; the smaller the grayscale difference, the higher the matching degree.
[0087] Specifically, the one-way matching degree corresponding to each feature difference can be determined, that is, the distance difference, gradient angle and grayscale difference all have corresponding one-way matching degrees, and the weight corresponding to each feature difference can be obtained; according to the weight corresponding to each feature difference, the one-way matching degree corresponding to each feature difference is weighted and summed to obtain the matching degree between the edge point and each neighborhood edge point.
[0088] like Figure 3 As shown, an embodiment of the present application provides a schematic diagram of a local sub-graph corresponding to a certain edge point, the size of the local sub-graph is 5*5, including pixel 1, pixel 2, pixel 3, ..., pixel 24 and pixel 25, pixel 13 is an edge point, pixels 7, 10, 19 are neighborhood edge points of pixel 13, and at least one of the distance difference, gradient angle difference and grayscale difference between these three neighborhood edge points and pixel point 13 can be determined, and the matching degree between the edge point and each neighborhood edge point can be determined in combination with the one-way matching degree corresponding to each feature difference.
[0089] Step 130: Determine a target neighborhood edge point of the edge point from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points.
[0090] It can be understood that the higher the matching degree between two edge points, the more similar the sub-pixel points of the two edge points are, and the smoother the two are. Therefore, the neighborhood edge point with the highest matching degree between the edge points can be determined from at least two neighborhood edge points as the target neighborhood edge point.
[0091] Step 140: Link the sub-pixel points of each edge point with the sub-pixel points of the corresponding target neighborhood edge points to obtain the sub-pixel edge contour of the image to be detected.
[0092] After obtaining the target neighborhood edge points of each edge point, the embodiment of the present application can link the sub-pixel points of each edge point with the sub-pixel points of the corresponding target neighborhood edge point, and continue Figure 3 Assuming that pixel 19 is the target neighborhood edge point of edge point 13, pixel 13 and pixel 19 can be linked. After all edge points are linked into a chain in this way, a relatively smooth sub-pixel edge contour of the image to be detected is obtained.
[0093] The embodiment of the present application determines the sub-pixel points of each edge point according to the gradient of the neighborhood pixel points of each edge point in the image to be detected; for each edge point, when the local sub-image of the edge point includes at least two neighborhood edge points, the matching degree between the edge point and each neighborhood edge point is obtained according to the feature differences between the sub-pixel points of the edge point and the sub-pixel points of each neighborhood edge point; the target neighborhood edge point of the edge point is determined from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and the other neighborhood edge points; the sub-pixel points of each edge point are linked to the sub-pixel points of the corresponding target neighborhood edge point to obtain the sub-pixel edge contour of the image to be detected, which solves the problems of sparse edge points and unclear edge contour in the existing sub-pixel contour extraction method, can obtain a relatively smooth sub-pixel edge contour, and also has good noise resistance, which can better adapt to the field of high-precision detection.
[0094] In some embodiments, determining the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected includes:
[0095] According to the gradient of edge points and neighboring pixels, the local curvature information of edge points is obtained;
[0096] According to the local curvature information of the edge point, the vertical offset and the horizontal offset of the edge point are determined;
[0097] The coordinates of the sub-pixel point corresponding to the edge point are determined according to the coordinates of the edge point, the vertical offset, and the horizontal offset.
[0098] The embodiment of the present application can obtain local curvature information of the edge point according to the gradient of the edge point and the neighboring pixel points. Specifically, the gradient value of the edge point and the neighboring pixel points can be determined according to the gradient of the edge point and the neighboring pixel points.
[0099] Based on the above formula (1), the gradient value of the edge point and the gradient value of the neighboring pixel point can be obtained, and then the local curvature information of the edge point can be obtained according to the gradient value of the edge point and the neighboring pixel point. In the field of image processing, the local curvature information of the edge point is used to describe the change and curvature of the edge shape in the image.
[0100] The vertical offset and horizontal offset of the edge point can be determined according to the local curvature information of the edge point. In order to determine the vertical and horizontal offsets of the edge point, the normal direction of the point (i.e., the direction perpendicular to the edge tangent direction) can be determined based on the local curvature information of the edge point, and then the vertical offset and horizontal offset of the edge point can be inferred through the changes in the normal direction.
[0101] Specifically, the horizontal coordinate of the sub-pixel point corresponding to the edge point can be obtained according to the horizontal coordinate and horizontal offset of the edge point; the vertical coordinate of the sub-pixel point corresponding to the edge point can be obtained according to the vertical coordinate and vertical offset of the edge point.
[0102] Compared to determining the sub-pixel edge points of edge points by interpolation, the embodiments of the present application obtain local curvature information of edge points based on the gradients of edge points and neighboring pixel points; determine the vertical offset and horizontal offset of the edge points based on the local curvature information of the edge points; and determine the coordinates of the sub-pixel points corresponding to the edge points based on the coordinates, vertical offset and horizontal offset of the edge points, thereby more accurately determining the coordinates of the sub-pixel points corresponding to the edge points.
[0103] In some embodiments, obtaining local curvature information of an edge point according to the gradient of the edge point and the neighboring pixel point includes:
[0104] According to the gradients of the edge points and the neighboring pixel points, the gradient values of the edge points and the neighboring pixel points are determined;
[0105] According to the gradient values of edge points and neighboring pixels, a target second-order polynomial model is constructed to describe the image intensity changes around the edge points;
[0106] According to the coefficients of the target second-order polynomial model, the target second-order derivative matrix at the edge point is obtained; the target second-order derivative matrix is used to describe the local curvature information.
[0107] The embodiment of the present application can construct a target second-order polynomial model for describing the change of image intensity around the edge point according to the gradient values of the edge point and the neighboring pixel points. Specifically, an initial second-order polynomial model can be constructed first, and the initial second-order polynomial model can be fitted according to the gradient values of the edge point and the neighboring pixel points to obtain a target second-order polynomial model, see formula (2), and the target polynomial model can be characterized as:
[0108] I=Ax 2 +By 2 +Cxy+Dx+Ey+F (2),
[0109] Among them, I represents the gradient value, x and y represent the horizontal coordinate and vertical coordinate respectively, and A, B, C, D, E and F are the coefficients of the target second-order polynomial model.
[0110] The coefficients of the polynomial can be calculated based on the gradient values of edge points and neighborhood pixels.
[0111] Furthermore, the target second-order derivative matrix at the edge point can be obtained according to the coefficients of the target second-order polynomial model; the target second-order derivative matrix is used to describe the local curvature information. In practical applications, the target second-order derivative matrix can be a Hession matrix, which is used to describe the local curvature information.
[0112] In some embodiments, determining the vertical offset and the horizontal offset of the edge point according to the local curvature information of the edge point includes:
[0113] Perform eigendecomposition on the target second-order derivative matrix at the edge points to obtain the eigenvalues and eigenvectors of the target second-order derivative matrix;
[0114] According to the eigenvalue and eigenvector, the vertical offset and horizontal offset of the edge point are obtained.
[0115] The above embodiments have shown that the local curvature information at the edge point can be represented by the Hession matrix, so the Hession matrix can be characteristically solved. Specifically, a characteristic equation can be constructed, Hv-λv=0. In order to have a non-zero solution v, the following formula (3) must be satisfied:
[0116] det(H-λI)=0
[0117] Where I is the identity matrix, det represents the determinant, and this equation is called the characteristic equation. It is a polynomial equation about λ, usually an nth-order equation (if the matrix HH is an n×n matrix), and solving this formula (3) obtains all eigenvalues λ1, λ2, …, λn.
[0118] After obtaining the eigenvalue, the corresponding eigenvector v can be solved by substituting λi into (H-λiI)v=0.
[0119] Furthermore, the vertical offset and horizontal offset of the edge point can be obtained according to the eigenvalue and eigenvector. Specifically, the size of the offset is usually proportional to the eigenvalue, and the eigenvalue in the direction of the main curvature can be determined from multiple eigenvalues. If λ1 is the eigenvalue in the direction of the main curvature, the horizontal offset Δx can be expressed by formula (4), and the vertical offset Δy can be expressed by formula (5):
[0120] Δx=λ1·v 1x (4)
[0121] Δy=λ1·v 1y (5)
[0122] Among them, v 1x and v 1y are the components of the eigenvector v in the horizontal and vertical directions, respectively.
[0123] In some embodiments, determining the coordinates of the sub-pixel point corresponding to the edge point according to the coordinates, the vertical offset, and the horizontal offset of the edge point includes:
[0124] According to the horizontal coordinate and horizontal offset of the edge point, the horizontal coordinate of the sub-pixel point corresponding to the edge point is obtained;
[0125] According to the vertical coordinate and the vertical offset of the edge point, the vertical coordinate of the sub-pixel point corresponding to the edge point is obtained.
[0126] Specifically, assuming that the coordinates of the edge point are expressed as (x, y), the vertical coordinates of the sub-pixel point can be expressed as (x+Δx, y+Δy).
[0127] Compared with determining the sub-pixel edge points of edge points by interpolation, the coordinates of the sub-pixel points corresponding to the edge points can be determined more accurately based on the above process.
[0128] In some embodiments, obtaining the matching degree between the edge point and each neighboring edge point according to each feature difference between the sub-pixel point of the edge point and the sub-pixel points of each neighboring edge point includes:
[0129] Determine the one-way matching degree corresponding to each feature difference; the feature difference includes at least one of a distance difference, a gradient angle and a grayscale difference;
[0130] Get the weights corresponding to each feature difference;
[0131] According to the weights corresponding to the feature differences, the one-way matching degrees corresponding to the feature differences are weighted summed to obtain the matching degrees between the edge points and the edge points in each neighborhood.
[0132] The embodiment of the present application can combine various feature differences to determine the matching degree between edge points and neighborhood edge points. The feature difference is at least one of distance difference, gradient angle and grayscale difference. Each feature difference has a corresponding one-way matching degree. The linear relationship or nonlinear relationship between each feature difference and the corresponding one-way matching degree can be determined, thereby determining the one-way matching degree corresponding to each feature difference.
[0133] Next, according to the weights corresponding to the feature differences, the one-way matching degrees corresponding to the feature differences can be weighted summed to obtain the matching degrees between the edge point and each neighborhood edge point.
[0134] like Figure 4 As shown, the present embodiment provides a second flow chart of a sub-pixel edge detection method, comprising the following steps:
[0135] Step 401, traverse each pixel point in the image to be detected, for each pixel point, obtain the gradient value of the pixel point and its neighboring pixel points according to the gradient of the pixel point and the corresponding neighboring pixel points; when it is determined that the gradient value of the pixel point is greater than the gradient values of each neighboring pixel point, determine that the pixel point is an edge point.
[0136] Step 402, for each edge point, obtain local curvature information of the edge point according to the gradient of the edge point and the neighboring pixel points;
[0137] Step 403, for each edge point, determine the vertical offset and horizontal offset of the edge point according to the local curvature information of the edge point;
[0138] Step 404: for each edge point, determine the coordinates of the sub-pixel point corresponding to the edge point according to the coordinates, vertical offset and horizontal offset of the edge point.
[0139] Step 405, for each edge point, when the local sub-graph of the edge point includes at least two neighboring edge points, the matching degree between the edge point and each neighboring edge point is obtained according to each feature difference between the sub-pixel point of the edge point and the sub-pixel points of each neighboring edge point; the local sub-graph takes the edge point as the pixel center;
[0140] Step 406, determining a target neighborhood edge point of the edge point from at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points;
[0141] Step 407 , linking the sub-pixel points of each edge point with the sub-pixel points of the corresponding target neighborhood edge point to obtain the sub-pixel edge contour of the image to be detected.
[0142] The detailed implementation process of step 401 to step 407 is shown in the above embodiment and will not be described again here.
[0143] The sub-pixel edge detection method provided in the embodiment of the present application can be executed by a sub-pixel edge detection device. In the embodiment of the present application, the sub-pixel edge detection method performed by the sub-pixel edge detection device is taken as an example to illustrate the sub-pixel edge detection device provided in the embodiment of the present application.
[0144] The embodiment of the present application also provides a sub-pixel edge detection device.
[0145] like Figure 5 As shown, the sub-pixel edge detection device includes: a first processing module 510 , a second processing module 520 , a third processing module 530 and a fourth processing module 540 .
[0146] The first processing module 510 is used to determine the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected;
[0147] The second processing module 520 is used for obtaining, for each edge point, a matching degree between the edge point and each neighboring edge point according to each feature difference between a sub-pixel point of the edge point and a sub-pixel point of each neighboring edge point when the local sub-map of the edge point includes at least two neighboring edge points; the local sub-map takes the edge point as a pixel center;
[0148] The third processing module 530 is used to determine a target neighborhood edge point of the edge point from at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points;
[0149] The fourth processing module 540 is used to link the sub-pixel points of each edge point with the sub-pixel points of the corresponding target neighborhood edge point to obtain the sub-pixel edge contour of the image to be detected.
[0150] According to the sub-pixel edge detection device provided by the embodiment of the present application, the sub-pixel points of each edge point are determined according to the gradient of the neighborhood pixel points of each edge point in the image to be detected; for each edge point, when the local sub-image of the edge point includes at least two neighborhood edge points, the matching degree between the edge point and each neighborhood edge point is obtained according to the feature differences between the sub-pixel point of the edge point and the sub-pixel points of each neighborhood edge point; the target neighborhood edge point of the edge point is determined from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and the other neighborhood edge points; the sub-pixel points of each edge point and the sub-pixel points of the corresponding target neighborhood edge point are linked to obtain the sub-pixel edge contour of the image to be detected, which solves the problems of sparse edge points and insufficiently smooth edge contours in the existing sub-pixel contour extraction methods, can obtain a relatively smooth sub-pixel edge contour, and also has good noise resistance, which can better adapt to the field of high-precision detection.
[0151] In some embodiments, the first processing module 510 includes:
[0152] The first processing submodule is used to obtain local curvature information of the edge point according to the gradient of the edge point and the neighboring pixel points;
[0153] The second processing submodule is used to determine the vertical offset and the horizontal offset of the edge point according to the local curvature information of the edge point;
[0154] The third processing submodule is used to determine the coordinates of the sub-pixel point corresponding to the edge point according to the coordinates of the edge point, the vertical offset and the horizontal offset.
[0155] In some embodiments, the first processing submodule specifically includes:
[0156] A first processing unit, configured to determine the gradient values of the edge point and the neighboring pixel points according to the gradients of the edge point and the neighboring pixel points;
[0157] A second processing unit is used to construct a target second-order polynomial model for describing the change of image intensity around the edge point according to the gradient values of the edge point and the neighboring pixel points;
[0158] The third processing unit is used to obtain a target second-order derivative matrix at the edge point according to the coefficients of the target second-order polynomial model; the target second-order derivative matrix is used to describe local curvature information.
[0159] In some embodiments, the second processing submodule is specifically used for:
[0160] Perform eigendecomposition on the target second-order derivative matrix at the edge points to obtain the eigenvalues and eigenvectors of the target second-order derivative matrix;
[0161] According to the eigenvalue and eigenvector, the vertical offset and horizontal offset of the edge point are obtained.
[0162] In some embodiments, the third processing submodule is specifically used for:
[0163] According to the horizontal coordinate and horizontal offset of the edge point, the horizontal coordinate of the sub-pixel point corresponding to the edge point is obtained;
[0164] According to the vertical coordinate and the vertical offset of the edge point, the vertical coordinate of the sub-pixel point corresponding to the edge point is obtained.
[0165] In some embodiments, the second processing module 520 is specifically used to:
[0166] Determine the one-way matching degree corresponding to each feature difference; the feature difference includes at least one of a distance difference, a gradient angle and a grayscale difference;
[0167] Get the weights corresponding to each feature difference;
[0168] According to the weights corresponding to the feature differences, the one-way matching degrees corresponding to the feature differences are weighted summed to obtain the matching degrees between the edge points and the edge points in each neighborhood.
[0169] In some embodiments, the sub-pixel edge detection device further includes:
[0170] The fifth processing module is used to traverse each pixel in the image to be detected, and perform the following operations during the traversal process:
[0171] For each pixel, according to the gradient of the pixel and the corresponding neighboring pixel, the gradient value of the pixel and the neighboring pixel is obtained;
[0172] When it is determined that the gradient value of the pixel point is greater than the gradient values of each neighboring pixel point, the pixel point is determined to be an edge point.
[0173] The sub-pixel edge detection device in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0174] The sub-pixel edge detection device in the embodiment of the present application may be a device having an operating system. The operating system may be a Microsoft (Windows) operating system, an Android (Android) operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0175] The sub-pixel edge detection device provided in the embodiment of the present application can achieve Figures 1 to 4 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0176] In some embodiments, Figure 6 As shown, the embodiment of the present application also provides an electronic device 600, including a processor 601, a memory 602, and a computer program stored in the memory 602 and executable on the processor 601. When the program is executed by the processor 601, each process of the above-mentioned sub-pixel edge detection method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0177] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0178] The embodiment of the present application also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned sub-pixel edge detection method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0179] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0180] An embodiment of the present application further provides a computer program product, including a computer program, which implements the above-mentioned sub-pixel edge detection method when executed by a processor.
[0181] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0182] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned sub-pixel edge detection method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0183] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0184] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises one..." does not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the method and device in the embodiment of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0185] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0186] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
[0187] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples" or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0188] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present application, and that the scope of the present application is defined by the claims and their equivalents.
Claims
1. A sub-pixel edge detection method, characterized in that: include: Determine the sub-pixel point of each edge point in the image to be detected according to the gradient of the neighboring pixel points of each edge point; For each edge point, when the local sub-map of the edge point includes at least two neighboring edge points, obtaining a matching degree between the edge point and each neighboring edge point according to each feature difference between a sub-pixel point of the edge point and sub-pixel points of each neighboring edge point; The local sub-image takes the edge point as a pixel center; Determine a target neighborhood edge point of the edge point from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points; The sub-pixel points of each edge point are linked to the sub-pixel points of the corresponding target neighborhood edge points to obtain the sub-pixel edge contour of the image to be detected.
2. The sub-pixel edge detection method according to claim 1, characterized in that: The step of determining the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected comprises: Obtaining local curvature information of the edge point according to the gradient of the edge point and the neighboring pixel points; Determining a vertical offset and a horizontal offset of the edge point according to local curvature information of the edge point; The coordinates of the sub-pixel point corresponding to the edge point are determined according to the coordinates of the edge point, the vertical offset, and the horizontal offset.
3. The sub-pixel edge detection method according to claim 2, characterized in that: The obtaining of local curvature information of the edge point according to the gradient of the edge point and the neighboring pixel point includes: Determine the gradient values of the edge point and the neighborhood pixel point according to the gradients of the edge point and the neighborhood pixel point; According to the gradient values of the edge point and the neighboring pixel points, a target second-order polynomial model for describing the change of image intensity around the edge point is constructed; According to the coefficients of the target second-order polynomial model, a target second-order derivative matrix at the edge point is obtained; the target second-order derivative matrix is used to describe the local curvature information.
4. The sub-pixel edge detection method according to claim 3, characterized in that: Determining the vertical offset and the horizontal offset of the edge point according to the local curvature information of the edge point includes: Performing eigendecomposition processing on the target second-order derivative matrix at the edge point to obtain eigenvalues and eigenvectors of the target second-order derivative matrix; The vertical offset and the horizontal offset of the edge point are obtained according to the eigenvalue and the eigenvector.
5. The sub-pixel edge detection method according to claim 2, characterized in that: The determining, according to the coordinates of the edge point, the vertical offset, and the horizontal offset, the coordinates of the sub-pixel point corresponding to the edge point includes: Obtaining, according to the horizontal coordinate of the edge point and the horizontal offset, the horizontal coordinate of the sub-pixel point corresponding to the edge point; The vertical coordinate of the sub-pixel point corresponding to the edge point is obtained according to the vertical coordinate of the edge point and the vertical offset.
6. The sub-pixel edge detection method according to claim 1, characterized in that: The obtaining the matching degree between the edge point and each neighboring edge point according to each feature difference between the sub-pixel point of the edge point and the sub-pixel points of each neighboring edge point includes: Determine the one-way matching degree corresponding to each feature difference; the feature difference includes at least one of a distance difference, a gradient angle and a grayscale difference; Get the weights corresponding to each feature difference; According to the weights corresponding to the feature differences, the one-way matching degrees corresponding to the feature differences are weighted summed to obtain the matching degrees between the edge point and each neighborhood edge point.
7. The sub-pixel edge detection method according to any one of claims 1 to 6, characterized in that: Before determining the sub-pixel point of each edge point according to the gradient of the neighboring pixel points of each edge point in the image to be detected, the method further includes: Traverse each pixel in the image to be detected, and perform the following operations during the traversal process: For each pixel point, according to the gradient of the pixel point and the corresponding neighboring pixel points, the gradient value of the pixel point and the neighboring pixel points of the pixel point is obtained; When it is determined that the gradient value of the pixel point is greater than the gradient values of each neighboring pixel point, the pixel point is determined to be an edge point.
8. A sub-pixel edge detection device, characterized in that: include: A first processing module, used for determining the sub-pixel point of each edge point in the image to be detected according to the gradient of the neighboring pixel points of each edge point; A second processing module is used for obtaining, for each edge point, a matching degree between the edge point and each neighboring edge point according to each feature difference between a sub-pixel point of the edge point and sub-pixel points of each neighboring edge point when the local sub-map of the edge point includes at least two neighboring edge points; The local sub-image takes the edge point as a pixel center; A third processing module is used to determine a target neighborhood edge point of the edge point from the at least two neighborhood edge points; the matching degree between the edge point and the target neighborhood edge point is not less than the matching degree between the edge point and other neighborhood edge points; The fourth processing module is used to link the sub-pixel points of each edge point with the sub-pixel points of the corresponding target neighborhood edge points to obtain the sub-pixel edge contour of the image to be detected.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the sub-pixel edge detection method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the sub-pixel edge detection method according to any one of claims 1 to 7 is implemented.