Interpolation method and system of curves in images, readable storage medium
By using spline interpolation, image edge points are obtained and nodes and control points are calculated. Gradient or derivative constraints are applied to solve the problems of jagged edges and blurred edges when the image is magnified, achieving a smoother interpolation effect and reducing computational complexity.
Patent Information
- Application Number
- CN202211251518.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-13
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2042-10-13
AI Technical Summary
Existing technologies struggle to mitigate jagged edges or blurred edges when images are magnified, while remaining easily implementable in hardware.
The spline interpolation method is adopted. By obtaining the edge points of the image, the nodes and control points of the spline curve are calculated. The edge points are interpolated using the k-th order spline curve. Gradient or derivative constraints are applied to the first and last control points or nodes of the spline curve to achieve a smoother interpolation effect.
It effectively reduces jagged edges and blurred edges when images are enlarged, improves interpolation results, and reduces computational complexity, making the image closer to vectorization.
Smart Images

Figure CN115511712B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to a method and system for interpolating curves in an image, and a readable storage medium. Background Technology
[0002] With the emergence and widespread application of digital images, people have increasingly higher requirements for image quality. When enlarging images, jagged edges or blurred edges often occur, resulting in unclear edges of characters and patterns in the enlarged image. Image enlargement is the process of converting an image from low resolution to high resolution. Its core issue is how to reconstruct the pixels of the target image at the new resolution based on the pixel distribution and various features of the source image; it can be understood as image reconstruction. With the hardware capabilities of image acquisition devices approaching their limits, using software techniques to improve the resolution of existing images has gradually become one of the hot topics in the field of digital image processing.
[0003] Image interpolation is a traditional method for improving image resolution, including zero-order interpolation and linear interpolation. However, while zero-order and linear interpolation are simple and efficient, their results are unsatisfactory, often exhibiting noticeable jagged edges or blurred edges. Another method for improving image resolution is super-resolution reconstruction, which uses computers to process a low-resolution image or image sequence to reconstruct a high-resolution image. Although this method is more effective than the first, it has higher computational complexity and requires strong continuity between previous and subsequent frames.
[0004] Therefore, existing technologies struggle to mitigate jagged edges or blurred edges when images are magnified, while ensuring ease of hardware implementation. Summary of the Invention
[0005] This invention provides a method and system for interpolating curves in an image, as well as a readable storage medium, aimed at mitigating jagged edges or blurred edges when an image is magnified.
[0006] According to a first aspect, one embodiment provides an interpolation method for curves in an image, comprising:
[0007] Obtain the image to be processed;
[0008] Obtain the edge points of the image to be processed;
[0009] The coordinates of the nodes of the spline curve are obtained based on the coordinates of the edge points. The control points of the spline curve of the preset order k are calculated based on the coordinates of the nodes and the spline curve formula. The gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, respectively, or the derivatives of the spline curve of the preset order k at the first and last nodes are the same.
[0010] Determine the k-th order spline curve based on the nodes and the control points;
[0011] Obtain the interpolation point position, and use the k-order spline curve to perform spline interpolation on the edge point.
[0012] In one embodiment, the spline curve formula is:
[0013]
[0014] in
[0015] Among them, P i Let u be the coordinate of the i-th control point, and u be the coordinate of the independent variable. i Let N be the coordinates of the i-th node, p be the order of the spline curve, and N be the number of nodes. i,p (u) is the basis function of the i-th control point of the p-order spline curve, n is the integer obtained by subtracting 1 from the number of control points, and C(u) is the coordinate of the interpolation point;
[0016] The process involves obtaining the coordinates of the nodes of the spline curve based on the coordinates of the edge points, and calculating the control points of the spline curve of a preset order k based on the coordinates of the nodes and the spline curve formula. The derivative of the spline curve of the preset order k is the same at both the beginning and end nodes. This includes:
[0017] Obtain the sub-pixel coordinates of the edge points;
[0018] The coordinates u of the spline curve nodes are obtained based on the sub-pixel coordinates of the edge points. j , where 1≤j≤N+k-1, and j is an integer, N is the number of edge points, and the last k-1 nodes coincide with the Nth node;
[0019] Based on the coordinates of the nodes and the spline curve formula, calculate the basis function value N of the k-th order spline curve at each node. i,k (u j );
[0020] Let n = N-1, and solve the following equations to obtain the coordinates of the control points P0, P1, ... P2. n :
[0021]
[0022] [C u i (u1)-C u i (u N+k-1 )]×Y c =0,
[0023] Where Y1, Y2, ... Y N Y represents the sub-pixel coordinates of the edge point. c =[P0 P1 … P n ] T C u i (u j ) indicates that the spline curve at node u j The i-th derivative at point i, where i = 1, 2, ..., k-1.
[0024] In one embodiment, the coordinates u of the spline curve nodes are obtained based on the sub-pixel coordinates of the edge points. j ,include:
[0025] The intermediate coordinate L is calculated using the following formula. l :
[0026]
[0027] Where L l Let Q represent the l-th intermediate coordinate, 1≤l≤N. i Let X be the sub-pixel coordinate of the i-th edge point;
[0028] The coordinates u of the node are calculated using the following formula. j :
[0029]
[0030] For the part where i < 0, take L. i|i<0 =L i+N -1; for the part where i > N, take L. i|i>N =L i-N +1.
[0031] In one embodiment, obtaining the interpolation point position and performing spline interpolation on the edge point using the k-order spline curve includes:
[0032] Calculate the X coordinates of all interpolation points based on the preset interpolation step size and number of points;
[0033] The intermediate coordinate L is calculated using the following formula. l :
[0034]
[0035] Where 1 ≤ l ≤ M, M is the number of interpolation points, and R i Let X be the X coordinate of the i-th interpolation point;
[0036] The smoothed X-coordinate Rx of the interpolation point is calculated using the following formula. l :
[0037]
[0038] For the part where i < 0, take L. i|i<0 =L i+N -1; for the part where i > N, take L. i|i>N =L i-N +1;
[0039] The smoothed X-coordinate Rx of the interpolation point l Substitute these coordinates into the formula for the k-th order spline curve to obtain the complete coordinates of the interpolation points.
[0040] In one embodiment, the spline curve formula is:
[0041]
[0042] in
[0043] Among them, P i Let u be the coordinate of the i-th control point, and u be the coordinate of the independent variable. i Let N be the coordinates of the i-th node, p be the order of the spline curve, and N be the number of nodes. i,p (u) is the basis function of the i-th control point of the p-order spline curve, n is the integer obtained by subtracting 1 from the number of control points, and C(u) is the coordinate of the interpolation point;
[0044] The process involves obtaining the coordinates of the nodes of the spline curve based on the coordinates of the edge points, and calculating the control points of the spline curve of a preset order k based on the coordinates of the nodes and the spline curve formula. The gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, respectively.
[0045] Obtain the sub-pixel coordinates of the edge points;
[0046] The coordinates u of the spline curve nodes are obtained based on the sub-pixel coordinates of the edge points. j , where 1≤j≤N+k-1, and j is an integer, N is the number of edge points, and the last k-1 nodes coincide with the Nth node;
[0047] Based on the coordinates of the nodes and the spline curve formula, calculate the basis function value N of the k-th order spline curve at each node. i,k (u j );
[0048] Let n = N-1, and calculate the coordinates of the control points P0, P1, ... P using the following formula. n :
[0049]
[0050] Where Y1, Y2, ... Y N Let C0 be the sub-pixel coordinates of the edge point, and C0 be the gradient of the first edge point. n The gradient of the last edge point.
[0051] In one embodiment, the coordinates u of the spline curve nodes are obtained based on the sub-pixel coordinates of the edge points. j ,include:
[0052] The intermediate coordinate L is calculated using the following formula. l :
[0053]
[0054] Where L l Let Q represent the l-th intermediate coordinate, 1≤l≤N. i Let X be the sub-pixel coordinate of the i-th edge point;
[0055] The coordinates u of the node are calculated using the following formula. j :
[0056]
[0057] In one embodiment, obtaining the interpolation point position and performing spline interpolation on the edge point using the k-order spline curve includes:
[0058] Calculate the X coordinates of all interpolation points based on the preset interpolation step size and number of points;
[0059] The intermediate coordinate L is calculated using the following formula. l :
[0060]
[0061] Where 1 ≤ l ≤ M, M is the number of interpolation points, and R i Let X be the X coordinate of the i-th interpolation point;
[0062] The smoothed X-coordinate Rx of the interpolation point is calculated using the following formula. l :
[0063]
[0064] The smoothed X-coordinate Rx of the interpolation point l Substitute these coordinates into the formula for the k-th order spline curve to obtain the complete coordinates of the interpolation points.
[0065] In one embodiment, obtaining the sub-pixel coordinates of the edge point includes:
[0066] Obtain the grayscale gradient value n along the X-axis of the image at the edge point. x and the gray-level gradient value n along the Y-axis of the image y ;
[0067] The offset parameter t is calculated using the following formula:
[0068]
[0069] Where g x and g y Let g be the first derivative at the edge point. xx g xy and g yy Let be the second derivative at the edge point, and
[0070]
[0071]
[0072] in Let g(x,y) represent the Kronecker product, (x,y) be the coordinates of the edge point, g(x,y) be the gray value of the edge point, and k be the gray value of the edge point. x k y k xx k xy and k yy The pre-defined convolution kernel;
[0073] The sub-pixel coordinates of the edge point are (x′, y′) = (x + tn) x ,y+tn y ).
[0074] According to a second aspect, one embodiment provides an interpolation system for curves in an image, comprising:
[0075] The image acquisition module is used to acquire the image to be processed.
[0076] An edge point acquisition module is used to acquire the edge points of the image to be processed;
[0077] The control point calculation module is used to obtain the coordinates of the nodes of the spline curve based on the coordinates of the edge points, and to calculate the control points of the spline curve of a preset order k based on the coordinates of the nodes and the spline curve formula. The gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, respectively, or the derivatives of the spline curve of the preset order k at the first and last nodes are the same.
[0078] The k-order spline curve determination module is used to determine the k-order spline curve based on the nodes and the control points.
[0079] The spline interpolation module is used to obtain the interpolation point positions and perform spline interpolation on the edge points using the k-order spline curve.
[0080] According to a third aspect, one embodiment provides a computer-readable storage medium storing a program that can be executed by a processor to implement the interpolation method as described in the first aspect above.
[0081] According to the image curve interpolation method and system and readable storage medium of the above embodiments, the edge points of the image to be processed are first obtained, and the coordinates of the nodes of the spline curve are obtained according to the coordinates of the edge points. The control points of the spline curve of the preset order k are calculated according to the coordinates of the nodes and the spline curve formula. The gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, respectively, or the derivatives of the spline curve of the preset order k at the first and last nodes are the same. Then, the k-order spline curve is determined according to the nodes and control points. Finally, the interpolation point positions are obtained, and spline interpolation is performed on the edge points using the k-order spline curve. Because using spline curves to interpolate edge points in an image is smoother than zero-order interpolation or linear interpolation, it is better able to adapt to the distribution of image edges, resulting in better interpolation effects. Furthermore, the gradients of the first and last control points or the derivatives of the first and last nodes of the spline curve are restricted, ensuring that the gradients of the first and last control points are the same as the gradients of the first and last edge points, or that the derivatives of the spline curve are the same at the first and last nodes. This makes the spline curve smoother. Using the technical solution of this invention, an effect similar to image vectorization can be achieved, effectively mitigating the jagged edges or edge blurring during image magnification. Moreover, it is less complex and easier to implement than image super-resolution reconstruction methods. Attached Figure Description
[0082] Figure 1 A flowchart illustrating an example of a curve interpolation method in an image;
[0083] Figure 2 A flowchart illustrating the calculation of control point coordinates in one embodiment;
[0084] Figure 3 A flowchart illustrating the calculation of control point coordinates in another embodiment;
[0085] Figure 4 This is a schematic diagram of an edge point in one embodiment;
[0086] Figure 5 To utilize the interpolation method according to the present invention Figure 4 A schematic diagram of the spline curve generated from the edge points;
[0087] Figure 6 This is a schematic diagram of the structure of an interpolation system for curves in an image, according to one embodiment. Detailed Implementation
[0088] The present invention will now be described in further detail with reference to specific embodiments and accompanying drawings. Similar elements in different embodiments are referred to by associated similar element reference numerals. In the following embodiments, many details are described to facilitate a better understanding of this application. However, those skilled in the art will readily recognize that some features may be omitted in different situations, or may be replaced by other elements, materials, or methods. In some cases, certain operations related to this application are not shown or described in the specification. This is to avoid obscuring the core parts of this application with excessive description. For those skilled in the art, detailed description of these related operations is not necessary; they can fully understand the related operations based on the description in the specification and general technical knowledge in the art.
[0089] Furthermore, the features, operations, or characteristics described in the specification can be combined in any suitable manner to form various embodiments. At the same time, the steps or actions in the method description can be rearranged or adjusted in a manner obvious to those skilled in the art. Therefore, the various orders in the specification and drawings are only for the clear description of a particular embodiment and do not imply a necessary order, unless otherwise stated that a particular order must be followed.
[0090] The serial numbers assigned to components in this document, such as "first" and "second," are used only to distinguish the described objects and have no sequential or technical meaning. The terms "connection" and "linkage" used in this application, unless otherwise specified, include both direct and indirect connections (linkages).
[0091] This invention primarily targets image edges, employing spline interpolation for image reconstruction to achieve vectorization and resolve jagged edges or blurred edges during image magnification. To improve interpolation performance, constraints are imposed on the start and end control points or nodes of the spline curve, resulting in a smoother curve. The task of spline curve interpolation is to find a continuous, smooth spline curve passing through all given points; this problem does not have a unique solution. Research on spline curve interpolation has a long history, with interpolation of closed curves being a particularly challenging technical aspect.
[0092] To better understand the technical solution of this invention, a brief introduction to spline curves will be given below.
[0093] Define a B-spline curve: Curve C(u) is a p-order curve whose shape is controlled by n+1 control points, and curve C(u) is a piecewise curve, defined by the node vector U = {u0, u1, ... u}. m Define a segmented interval, where P iLet u be the coordinate of the i-th control point, and u be the coordinate of the independent variable. i Let m be the coordinates of the i-th node, m be a natural number, 0 ≤ i ≤ m, and N be the coordinates of the i-th node. i,p (u) is the basis function of the i-th control point of the p-order spline curve, n is the integer obtained by subtracting 1 from the number of control points, and C(u) is the coordinate of the interpolation point. The following is an introduction to each part.
[0094] (1) Control Point: The coordinates of data points used to control the shape of the curve, denoted by P. i express;
[0095] (2) Degree: Characterizes the continuity of the curve, denoted by p, where p is an integer greater than 0;
[0096] (3) Knot Vector: Represented by U, where the node vector U = {u0, u1, ... u} m The vector U consists of m+1 nodes and is a non-decreasing sequence representing the domain and interval range of the piecewise curve. In some embodiments, some nodes in the node vector U may overlap. The curve C(u) passes through each node u. i ;
[0097] (4) B-spline basis functions: using N i,p (u) represents each control point P i Corresponding to a basis function N i,p (u); the basis functions are defined as follows:
[0098]
[0099]
[0100] The following describes the curve interpolation method in images provided by this invention. Please refer to [link / reference]. Figure 1 In one embodiment, the method includes steps 110 to 150, which are described in detail below.
[0101] Step 110: Obtain the image to be processed.
[0102] The image to be processed can be a computer-generated or computer-drawn image, or an image captured by a camera. The image may contain various characters, patterns, etc., forming curves. Some characters or patterns may form a closed curve, such as the character "0".
[0103] Step 120: Obtain the edge points of the image to be processed.
[0104] Edge points in the image to be processed can be extracted using operators such as Sobel and Canny.
[0105] Step 130: Obtain the coordinates of the nodes of the spline curve based on the coordinates of the edge points. Calculate the control points of the spline curve of the preset order k based on the coordinates of the nodes and the spline curve formula. The gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, respectively, or the derivatives of the spline curve of the preset order k at the first and last nodes are the same.
[0106] In this invention, to alleviate jagged edges or blurred edges, spline curves are used to interpolate the edge points of the image to be processed. Therefore, the spline curve must pass through the edge points, and the coordinates of the spline curve nodes are obtained from the coordinates of the edge points. The node coordinates can be obtained directly from the edge point coordinates, or more refined sub-pixel coordinates can be used. In addition, control point coordinates need to be calculated to ultimately determine the spline curve. Since the nodes are located on the spline curve, the control point coordinates can be treated as unknown parameters. The node coordinates are substituted into the spline curve formula to construct an equation to solve for the control point coordinates. Before calculation, the order of the spline curve needs to be preset. In this embodiment, the order is set to k. The specific value of the order k can be set according to actual needs and is not limited here.
[0107] To improve interpolation performance, this invention imposes constraints on the beginning and end portions of the spline curve when calculating the control point coordinates. In one embodiment, the gradients of the beginning and end control points of the spline curve are constrained, ensuring that the gradients of the beginning and end control points are the same as the gradients of the first and last edge points (i.e., the beginning and end endpoints of the original sample points), resulting in a smoother spline curve and mitigating jagged edges or blurred edges during image magnification. Those skilled in the art will understand that the first and last edge points here are ordered along the curve containing the edge points.
[0108] Please refer to Figure 2 In this embodiment, step 130 may include steps 1311 to 1314, which will be described in detail below.
[0109] Step 1311: Obtain the sub-pixel coordinates of the edge points.
[0110] The sub-pixel coordinates of edge points can be obtained using existing sub-pixel coordinate calculation methods. Furthermore, this invention also provides a novel sub-pixel coordinate calculation method, which is described below.
[0111] For any point in the image, the gray value can be estimated using a second-order approximation, as follows:
[0112]
[0113] Where (x,y) represents the image coordinates, g(x,y) is the gray value of point (x,y), g0 is a constant, and g x and g y Let g be the first derivative at the point (x,y). xx g xy and g yy Let be the second derivative at the point (x, y).
[0114] Therefore, the second-order approximate estimate of the sub-pixel grayscale value can be expressed as:
[0115]
[0116] Where t is the offset parameter, n x and n y These are the grayscale gradient values along the X and Y axes of the image at point (x, y), respectively.
[0117] Setting its partial derivative to 0, we get:
[0118]
[0119] We can obtain: Then the sub-pixel coordinates of the point (x, y) are (x′, y′) = (x + tn) x ,y+tn y ).
[0120] Therefore, for an edge point with image coordinates (x, y), we can first obtain the gray-level gradient value n along the X-axis of the image at the edge point (x, y). x and the gray-level gradient value n along the Y-axis of the image y grayscale gradient value n along the X-axis of the image x and the gray-level gradient value n along the Y-axis of the image y It can be achieved by solving the second derivative matrix. The eigenvector corresponding to the smallest eigenvalue is obtained; then the offset parameter t is calculated according to the following formula:
[0121]
[0122] Where g x and g y Let g be the first derivative at the edge point. xx g xy and g yy Let be the second derivative at the edge point, and
[0123]
[0124]
[0125] in This represents the Kronecker product, where g(x,y) is the gray value of the edge point, and k... x k y k xx k xy and k yy The kernel is a preset convolution kernel, which can be set according to actual needs. In one embodiment, it can be set as follows:
[0126] Then the sub-pixel coordinates of the edge point (x, y) are (x′, y′) = (x + tn) x ,y+tn y ).
[0127] Step 1312: Obtain the coordinates u of the spline curve nodes based on the sub-pixel coordinates of the edge points. j , where 1≤j≤N+k-1, and j is an integer, N is the number of edge points, and the last k-1 nodes coincide with the Nth node.
[0128] In this embodiment, the number of control points is N, so there must be N+k-1 nodes. Therefore, the last node is reused k times, so the last k-1 nodes coincide with the Nth node.
[0129] For image interpolation, it is necessary to obtain the image coordinates of the interpolation point, i.e., the X and Y coordinates of the interpolation point. Therefore, the X coordinate of the interpolation point can be used as the independent variable coordinate u, and the complete interpolation point coordinates (x, y, y) can be obtained through a spline curve. I ,y I Accordingly, the coordinates u of the spline curve nodes can be obtained from the X-coordinate of the sub-pixel coordinates of the edge points. j In one embodiment of the present invention, the coordinates u of the nodes of the spline curve are calculated based on the centripetal parameter method and the moving average method. j Specifically, the intermediate coordinates are first calculated using the centripetal parameter method, i.e., the intermediate coordinates L are calculated using the following formula. l :
[0130]
[0131] Where L l Let Q represent the l-th intermediate coordinate, 1≤l≤N. i Let be the X-coordinate of the i-th edge point in the sub-pixel coordinates. Then, the coordinate u of the node is calculated using the moving average method. j The coordinates u of the node are calculated using the following formula. j :
[0132]
[0133] The method for calculating the coordinates of the nodes involves transforming the coordinates using the centripetal parameter method, and then using the moving average method to introduce the moving average term to calculate the coordinates of the nodes. This makes the spline curve smoother near the control points and the constructed spline curve more stable.
[0134] Step 1313: Based on the node coordinates and the spline curve formula, calculate the basis function value N of the k-th order spline curve at each node. i,k (u j ).
[0135] As can be seen from the definition of the basis function above, once the coordinates and order of the node are determined, the corresponding basis function value N can be calculated from the coordinates u of the independent variable. i,k (u), since it is necessary to calculate the basis function value corresponding to each control point, a basis function value vector N = [N] can be obtained. 0,k (u),N 1,k (u),…N n,k (u)].
[0136] Set the coordinates of the node u j Substituting the coordinate u, the independent variable, into the definition of the basis function yields the basis function value N. i,k (u j Each node can obtain a basis function value vector N. j =[N 0,k (u j ),N 1,k (u j ),…N n,k (u j )).
[0137] Step 1314: Construct equations based on basis function values and gradient values, and calculate the coordinates of control points P0, P1, ... P1. n .
[0138] Based on the basis function value vector N j Each node can provide an equation N j ×Y c =Y j , where Y c =[P0 P1…P n ] T Y j Let J be the sub-pixel coordinates of the j-th edge point. N distinct nodes can provide N equations.
[0139] Furthermore, two additional equations can be contributed based on the constraint that the gradients of the first and last control points are the same as the gradients of the first and last edge points, respectively:
[0140] P1-P0=C0,
[0141] P n -P n-1 =C n ,
[0142] Where C0 is the gradient of the first edge point, C n This represents the gradient at the last edge point.
[0143] Solving the above N+2 equations simultaneously, we can obtain:
[0144]
[0145] Since the number of control points set in this embodiment is N, we can let n = N-1, and use the least squares method or conjugate gradient descent method to iteratively calculate the coordinates P0, P1, ... P of the control points according to the above formula (1). n .
[0146] In another embodiment, for the closed curve, the derivative of the k-th order spline curve at the first and last nodes is restricted to ensure that the derivative of the k-th order spline curve is the same at the first and last nodes, thus guaranteeing the continuity of the spline curve. This makes the interpolated closed curve smoother and alleviates the jagged edges or blurred edges when the image is enlarged. Those skilled in the art will understand that the first and last edge points here are ordered along the closed curve where the edge points are located.
[0147] Please refer to Figure 3 In this embodiment, step 130 may include steps 1321 to 1324, which will be described in detail below.
[0148] Step 1321: Obtain the sub-pixel coordinates of the edge points.
[0149] For the calculation method of sub-pixel coordinates, please refer to step 1311 above, which will not be repeated here.
[0150] Step 1322: Obtain the coordinates u of the spline curve nodes based on the sub-pixel coordinates of the edge points. j , where 1≤j≤N+k-1, and j is an integer, N is the number of edge points, and the last k-1 nodes coincide with the Nth node.
[0151] In this embodiment, the number of control points is N, so there must be N+k-1 nodes. Therefore, the last node is reused k times, so the last k-1 nodes coincide with the Nth node.
[0152] In this embodiment, the coordinates u of the spline curve nodes can also be obtained from the X-coordinate of the sub-pixel coordinates of the edge points. j In one embodiment, the coordinates u of the nodes of the spline curve are calculated based on the centripetal parameter method and the moving average method.j Specifically, the intermediate coordinates are first calculated using the centripetal parameter method, i.e., the intermediate coordinates L are calculated using the following formula. l :
[0153]
[0154] Where L l Let Q represent the l-th intermediate coordinate, 1≤l≤N. i Let be the X-coordinate of the i-th edge point in the sub-pixel coordinates. Then, the coordinate u of the node is calculated using the moving average method. j The coordinates u of the node are calculated using the following formula. j :
[0155]
[0156] For the part where i < 0, take L. i|i<0 =L i+N -1; for the part where i > N, take L. i|i>N =L i-N +1.
[0157] The method for calculating the coordinates of the nodes involves transforming the coordinates using the centripetal parameter method, and then using the moving average method to introduce the moving average term to calculate the coordinates of the nodes. This makes the spline curve smoother near the control points and the constructed spline curve more stable.
[0158] Step 1323: Based on the node coordinates and the spline curve formula, calculate the basis function value N of the k-th order spline curve at each node. i,k (u j ).
[0159] Similarly, for each node, a basis function value vector N can be obtained. j =[N 0,k (u j ),N 1,k (u j ),…N n,k (u j )).
[0160] Step 1324: Construct equations based on the basis function values and the derivative constraints of the first and last nodes, and calculate the coordinates of the control points P0, P1, ... P2. n .
[0161] Based on the basis function value vector N j Each node can provide an equation N j ×Y c =Y j , where Y c =[P0 P1 …P n] T Y j Let J be the sub-pixel coordinates of the j-th edge point. N distinct nodes can provide N equations.
[0162] Furthermore, the solution to curve C(u) lies at the first node u1 and the last node u N+k-1 Let the first node u1 and the last node u1 be derivatives of order 1 to k-1. N+k-1 Since the derivatives from order 1 to (k-1) are all equal at any point, we can obtain an additional (k-1) equations:
[0163] [C u i (u1)-C u i (u N+k-1 )]×Y c =0,
[0164] Where C u i (u j ) indicates that the spline curve at node u j The i-th derivative at point i, where i = 1, 2, ..., k-1.
[0165] Solving the above N+k-1 equations simultaneously, we get:
[0166]
[0167] [C u i (u1)-C u i (u N+k-1 )]×Y c =0, (3)
[0168] Since the number of control points set in this embodiment is N, we can let n = N-1, and use the least squares method or conjugate gradient descent method to iteratively calculate the coordinates P0, P1, ... P of the control points according to the above formulas (2) and (3). n .
[0169] Step 140: Determine the k-th order spline curve based on the nodes and control points.
[0170] The nodes and control points of the k-th order spline curve have been determined through the above steps, and the k-th order spline curve can also be determined accordingly.
[0171] Figure 4 and Figure 5 A schematic diagram of edge points and spline curves generated according to the method of the present invention, wherein the cross symbol × indicates an edge point. For example... Figure 4As shown, these edge points form a closed set of points. Connecting these edge points sequentially forms a closed curve. Performing steps 130-140 on these edge points yields a third-order closed spline curve, as shown below. Figure 5 As shown, it is a continuous smooth curve.
[0172] Step 150: Obtain the interpolation point positions and use the k-order spline curve to perform spline interpolation on the edge points.
[0173] Specifically, the location of an interpolation point can be represented by its X-coordinate. Based on the X-coordinate of the interpolation point, the complete coordinates (x, y) of the interpolation point can be obtained through a k-order spline curve. I ,y I This completes the spline interpolation of the edge points. Before interpolation, the interpolation step size and number of points need to be set in advance. The X coordinate of the interpolation point can be determined by the interpolation step size and number of points.
[0174] If the gradients of the first and last control points of the spline curve are constrained to be the same as the gradients of the first and last edge points, and the coordinates u of the spline curve nodes are calculated based on the centripetal parameter method and the moving average method... j First, calculate the X-coordinates of all interpolation points based on the preset interpolation step size and number of points. For example, if the interpolation step size is 0.5 and the number of points is 200, then the X-coordinates of the interpolation points are 0, 0.5, 1...99. Then, calculate the intermediate coordinate L using the following formula. l :
[0175]
[0176] Where 1 ≤ l ≤ M, M is the number of interpolation points, and R i Let X be the X coordinate of the i-th interpolation point;
[0177] The smoothed X-coordinate Rx of the interpolation point is then calculated using the following formula. l :
[0178]
[0179] The smoothed X-coordinate Rx of the interpolation point l Substitute these values into the formula for the k-th order spline curve to obtain the complete coordinates (x, y) of the interpolation point. I ,y I This allows for spline interpolation of edge points, thus enabling the interpolation of curves in the image.
[0180] If the derivatives of the k-th order spline curve at the first and last nodes are restricted to be the same, and the coordinates u of the spline curve nodes are calculated based on the centripetal parameter method and the moving average method... jSimilarly, firstly, the X coordinates of all interpolation points are calculated based on the preset interpolation step size and number of points; then, the intermediate coordinates L are calculated according to the following formula. l :
[0181]
[0182] Where 1 ≤ l ≤ M, M is the number of interpolation points, and R i Let X be the X coordinate of the i-th interpolation point;
[0183] The smoothed X-coordinate Rx of the interpolation point is then calculated using the following formula. l :
[0184]
[0185] For the part where i < 0, take L. i|i<0 =L i+N -1; for the part where i > N, take L. i|i>N =L i-N +1;
[0186] The smoothed X-coordinate Rx of the interpolation point l Substitute these values into the formula for the k-th order spline curve to obtain the complete coordinates (x, y) of the interpolation point. I ,y I This allows for spline interpolation of edge points, thus enabling interpolation of closed curves in the image.
[0187] Based on the curve interpolation method described above, this invention also provides a curve interpolation system for images. Please refer to [reference needed]. Figure 6 In one embodiment, the system includes an image acquisition module 1, an edge point acquisition module 2, a control point calculation module 3, a k-order spline curve determination module 4, and a spline interpolation module 5, which are described below.
[0188] The image acquisition module 1 is used to acquire the image to be processed. For details on acquiring the image to be processed, please refer to step 110; it will not be repeated here.
[0189] Edge point acquisition module 2 is used to acquire edge points of the image to be processed.
[0190] The control point calculation module 3 is used to obtain the coordinates of the nodes of the spline curve based on the coordinates of the edge points, and to calculate the control points of the spline curve of the preset order k based on the coordinates of the nodes and the spline curve formula. The gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, respectively, or the derivatives of the spline curve of the preset order k are the same at the first and last nodes.
[0191] If the derivatives of a spline curve of the preset order k are the same at the beginning and end nodes, then the control point calculation module 3 is specifically used for:
[0192] Obtain the sub-pixel coordinates of the edge points;
[0193] The coordinates u of the spline curve nodes are obtained from the sub-pixel coordinates of the edge points. j , where 1≤j≤N+k-1, and j is an integer, N is the number of edge points, and the last k-1 nodes coincide with the Nth node;
[0194] Based on the node coordinates and the spline curve formula, calculate the basis function value N of the k-th order spline curve at each node. i,k (u j );
[0195] Let n = N-1, and solve the following equations to obtain the coordinates of the control points P0, P1, ... P2. n :
[0196]
[0197] [C u i (u1)-C u i (u N+k-1 )]×Y c =0,
[0198] Where Y1, Y2, ... Y N Y represents the sub-pixel coordinates of the edge point. c =[P0 P1 … P n ] T C u i (u j ) indicates that the spline curve at node u j The i-th derivative at point i, where i = 1, 2, ..., k-1.
[0199] In one embodiment, the control point calculation module 3 calculates the coordinates u of the spline curve nodes based on the centripetal parameter method and the moving average method. j Specifically, the control point calculation module 3 obtains the coordinates u of the spline curve nodes based on the sub-pixel coordinates of the edge points in the following manner. j The intermediate coordinate L is calculated using the following formula. l :
[0200]
[0201] Where L l Let Q represent the l-th intermediate coordinate, 1≤l≤N. i Let X be the sub-pixel coordinate of the i-th edge point;
[0202] The coordinates u of the node are calculated using the following formula. j :
[0203]
[0204] For the part where i < 0, take L. i|i<0 =L i+N -1; for the part where i > N, take L. i|i>N =L i-N +1.
[0205] The smoothed X-coordinate Rx of the interpolation point l Substituting these coordinates into the formula for the k-th order spline curve yields the complete coordinates of the interpolation points, thus completing the spline interpolation of the edge points and achieving the interpolation of closed curves in the image.
[0206] If the gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, then control point calculation module 3 is specifically used for:
[0207] Obtain the sub-pixel coordinates of the edge points;
[0208] The coordinates u of the spline curve nodes are obtained from the sub-pixel coordinates of the edge points. j , where 1≤j≤N+k-1, and j is an integer, N is the number of edge points, and the last k-1 nodes coincide with the Nth node;
[0209] Based on the node coordinates and the spline curve formula, calculate the basis function value N of the k-th order spline curve at each node. i,k (u j );
[0210] Let n = N-1, and calculate the coordinates of the control points P0, P1, ... P using the following formula. n :
[0211]
[0212] Where Y1, Y2, ... Y N Let C be the sub-pixel coordinates of the edge point, C0 be the gradient of the first edge point, and C... n This represents the gradient at the last edge point.
[0213] In one embodiment, the control point calculation module 3 calculates the coordinates u of the spline curve nodes based on the centripetal parameter method and the moving average method. j Specifically, the control point calculation module 3 obtains the coordinates u of the spline curve nodes based on the sub-pixel coordinates of the edge points in the following manner. j The intermediate coordinate L is calculated using the following formula. l :
[0214]
[0215] Where L l Let Q represent the l-th intermediate coordinate, 1≤l≤N. i Let X be the sub-pixel coordinate of the i-th edge point;
[0216] The coordinates u of the node are calculated using the following formula. j :
[0217]
[0218] The k-order spline curve determination module 4 is used to determine the k-order spline curve based on nodes and control points.
[0219] The spline interpolation module 5 is used to obtain the position of the interpolation point and to perform spline interpolation on the edge point using the k-order spline curve.
[0220] Specifically, if the derivatives of a spline curve of a predetermined order k are the same at the beginning and end nodes, and the coordinates u of the nodes of the spline curve are calculated based on the centripetal parameter method and the moving average method... j The spline interpolation module 5 is specifically used for: calculating the X coordinates of all interpolation points based on the preset interpolation step size and number of points; and calculating the intermediate coordinates L according to the following formula. l :
[0221]
[0222] Where 1 ≤ l ≤ M, M is the number of interpolation points, and R i Let X be the X coordinate of the i-th interpolation point;
[0223] The smoothed X-coordinate Rx of the interpolation point is calculated using the following formula. l :
[0224]
[0225] For the part where i < 0, take L. i|i<0 =L i+N -1; for the part where i > N, take L. i|i>N =L i-N +1;
[0226] The smoothed X-coordinate Rx of the interpolation point l Substituting these coordinates into the formula for the k-th order spline curve yields the complete coordinates of the interpolation points, thus completing the spline interpolation of the edge points and achieving the interpolation of closed curves in the image.
[0227] If the gradients of the first and last control points of the spline curve are the same as the gradients of the first and last edge points, and the coordinates u of the nodes of the spline curve are calculated based on the centripetal parameter method and the moving average method... jThe spline interpolation module 5 is specifically used to: calculate the X coordinates of all resampling points based on the preset resampling step size and number of points; and calculate the intermediate coordinates L according to the following formula. l :
[0228]
[0229] Where 1 ≤ l ≤ M, M is the number of interpolation points, and R i Let X be the X coordinate of the i-th interpolation point;
[0230] The smoothed X-coordinate Rx of the interpolation point is calculated using the following formula. l :
[0231]
[0232] The smoothed X-coordinate Rx of the interpolation point l Substituting these coordinates into the formula for the k-th order spline curve yields the complete coordinates of the interpolation points, thus completing the spline interpolation of the edge points and achieving the interpolation of the curve in the image.
[0233] The image curve interpolation method and system according to the above embodiments, because it uses spline curves to interpolate edge points in the image, is smoother than zero-order interpolation and linear interpolation, and can better adapt to the distribution of image edges, resulting in better interpolation effect; and it restricts the gradient of the first and last control points of the spline curve or the derivative of the first and last nodes, so that the gradient of the first and last control points is the same as the gradient of the first and last endpoints of the original sample points, or the derivative of the spline curve at the first and last nodes is the same, thereby making the spline curve smoother. Using the technical solution of the present invention, an effect similar to image vectorization can be achieved, effectively reducing the jaggedness or edge blurring phenomenon when the image is enlarged, and it is less complex and easier to implement than the image super-resolution reconstruction method.
[0234] For closed curves, this invention restricts the derivatives of the spline curve at the first and last nodes, ensuring that the derivatives at the first and last nodes are the same. This guarantees the continuity of the spline curve, making the interpolated closed curve smoother and helping to alleviate jagged edges or blurred edges during image magnification. In one embodiment, for a k-th order spline curve, the derivatives from order 1 to k-1 are made equal at both the first and last nodes, thus ensuring the continuity of order k-1.
[0235] The subpixel coordinate calculation method provided by this invention is beneficial for improving the accuracy and stability of curve interpolation in images.
[0236] Those skilled in the art will understand that all or part of the functions of the various methods in the above embodiments can be implemented by hardware or by computer programs. When all or part of the functions in the above embodiments are implemented by computer programs, the program can be stored in a computer-readable storage medium, which may include: read-only memory, random access memory, disk, optical disk, hard disk, etc., and the program is executed by a computer to achieve the above functions. For example, the program can be stored in the memory of a device, and when the program in the memory is executed by the processor, all or part of the above functions can be achieved. In addition, when all or part of the functions in the above embodiments are implemented by computer programs, the program can also be stored in a server, another computer, disk, optical disk, flash drive, or external hard drive, etc., and can be downloaded or copied to the memory of a local device, or the system of the local device can be updated. When the program in the memory is executed by the processor, all or part of the functions in the above embodiments can be achieved.
[0237] The above examples illustrate the present invention only to aid in understanding it and are not intended to limit the scope of the invention. Those skilled in the art can make various simple deductions, modifications, or substitutions based on the principles of this invention.
Claims
1. A method of interpolation of a curve in an image, characterized in that, The method comprises: acquiring an image to be processed; acquiring edge points of the image to be processed; acquiring sub-pixel coordinates of the edge points; obtaining coordinates of nodes of a spline curve according to the sub-pixel coordinates of the edge points, and calculating control points of a spline curve of a preset order k according to the coordinates of the nodes and a spline curve formula, wherein gradients of first and last control points of the spline curve are respectively the same as gradients of first and last edge points, or derivatives of the spline curve of the preset order k at the first and last nodes are the same; determining a k-order spline curve according to the nodes and the control points; acquiring positions of interpolation points, and performing spline interpolation on the edge points by using the k-order spline curve. The method further comprises: obtaining a gray scale gradient value n along the image X axis at the edge point x and a gray scale gradient value n along the image Y axis y ; calculating an offset parameter t according to the following formula: where g x and g y is the first derivative at the edge point, g xx , g xy and g yy are the second derivatives at the edge point, and wherein denotes a Kronecker product, (x, y) is a coordinate of the edge point, g(x, y) is a gray value of the edge point, k x , k y , k xx , k xy , and k yy are preset convolution kernels; The sub-pixel coordinates of the edge point are (x', y') = (x + tn x ,y + tn y ).
2. The interpolation method of claim 1, wherein, The spline curve formula is: wherein where P i is the coordinate of the i-th control point, u is the coordinate of the independent variable, u i is the coordinate of the i-th node, p is the order of the spline curve, N i,p (u) is the base function of the i-th control point of the p-order spline curve, n is an integer obtained by reducing the number of control points by 1, and C(u) is the coordinate of the interpolation point. The method further comprises: obtaining the coordinates u of the nodes of the spline curve according to the sub-pixel coordinates of the edge points j wherein 1≤j≤N+k-1, j is an integer, N is the number of the edge points, and the last k-1 nodes coincide with the Nth node; calculating, according to the coordinates of the nodes and the spline curve formula, a basis function value N of a k-order spline curve at each of the nodes i,k (u j ); Let n=N-1, the coordinates of the control points P0, P1, …P n : [C u i (u1)-C u i (u N+k-1 )]×Y c =0, where Y1, Y2,... Y N are subpixel coordinates of the edge points, Y c = [P0 P1... P n ] T , C u i (u j ) denotes the i-th derivative of the spline curve at the node u j , where i = 1, 2,... k - 1.
3. The interpolation method of claim 2, wherein, the coordinates u of the nodes of the spline curve are obtained according to the subpixel coordinates of the edge points j comprising: The intermediate coordinates L are calculated according to the following formula l : where L l represents the lth intermediate coordinate, 1≤l≤N, Q i is the X coordinate in the subpixel coordinate of the ith edge point; The coordinates u of the nodes are calculated according to the following formula j : where for the part of i < 0, take L i|i<0 = L i+N -1; for the part of i > N, take L i|i>N = L i-N +1.
4. The interpolation method of claim 3, wherein, The method further comprises: calculating X coordinates of all interpolation points according to a preset interpolation step and a point number. The intermediate coordinates L are calculated according to the following formula l : where 1 < l < M, M is the number of interpolation points, R i is the X coordinate of the i-th interpolation point; The smoothed X coordinate Rx of the interpolation point is calculated according to the following equation l : where for the part of i < 0, take L i|i<0 = L i+N -1 ; for the part of i > N, take L i|i>N = L i-N +1 ; The smoothed X coordinate Rx of the interpolation point is calculated as follows: l The complete coordinates of the interpolation point are obtained by substituting the kth order spline curve formula.
5. The interpolation method of claim 1, wherein, The spline curve formula is: wherein where P i is the coordinate of the i-th control point, u is the coordinate of the independent variable, u i is the coordinate of the i-th node, p is the order of the spline curve, N i,p (u) is the base function of the i-th control point of the p-order spline curve, n is an integer obtained by reducing the number of control points by 1, and C(u) is the coordinate of the interpolation point. The method further comprises: obtaining the coordinates u of the nodes of the spline curve according to the sub-pixel coordinates of the edge points j wherein 1≤j≤N+k-1, j is an integer, N is the number of the edge points, and the last k-1 nodes coincide with the Nth node; calculating, according to the coordinates of the nodes and the spline curve formula, a basis function value N of a k-order spline curve at each of the nodes i,k (u j ); Let n=N-1, the coordinates of the control points P0, P1, …Pn are calculated according to the following formula n : where Y1, Y2,... Y N is the subpixel coordinate of the edge point, Co is the gradient of the first edge point, C n is the gradient of the last edge point.
6. The interpolation method of claim 5, wherein, the coordinates u of the nodes of the spline curve are obtained according to the sub-pixel coordinates of the edge points j comprising: The intermediate coordinates L are calculated according to the following formula l : where L l represents the lth intermediate coordinate, 1≤l≤N, Q i is the X coordinate in the subpixel coordinate of the ith edge point; The coordinates u of the nodes are calculated according to the following formula j :
7. The interpolation method of claim 6, wherein, The method further comprises: calculating X coordinates of all interpolation points according to a preset interpolation step and a point number. The intermediate coordinates L are calculated according to the following formula l : where 1 < l < M, M is the number of interpolation points, R i is the X coordinate of the i-th interpolation point; The smoothed X coordinate Rx of the interpolation point is calculated according to the following equation l : The smoothed X coordinate Rx of the interpolation point is calculated as follows: l The complete coordinates of the interpolation point are obtained by substituting the k-th order spline curve formula.
8. An interpolation system for curves in images, characterized in that The method comprises: An image to be processed is acquired. Edge points of the image to be processed are acquired. Sub-pixel coordinates of the edge points are acquired. Coordinates of nodes of a spline curve are obtained according to the sub-pixel coordinates of the edge points, and control points of a spline curve of a preset order k are calculated according to the coordinates of the nodes and a spline curve formula, wherein gradients of first and last control points of the spline curve are respectively the same as gradients of first and last edge points, or derivatives of the spline curve of the preset order k at the first and last nodes are the same. A k-order spline curve is determined according to the nodes and the control points. Interpolation points are acquired, and spline interpolation is performed on the edge points by using the k-order spline curve. obtaining a gray scale gradient value n along the image X axis at the edge point x and a gray scale gradient value n along the image Y axis y ; The control point calculation module acquires the sub-pixel coordinates of the edge points, and comprises: where g x and g y is a first derivative at the edge point, g xx , g xy and g yy are second derivatives at the edge point, and wherein represents a Kronecker product, (x, y) is a coordinate of the edge point, g(x, y) is a gray value of the edge point, k x , k y , k xx , k xy and k yy is a preset convolution kernel; The subpixel coordinates of the edge point are (x', y') = (x + tn x ,y + tn y ).
9. A computer-readable storage medium, characterized in that, An offset parameter t is calculated according to the following formula: The medium has a program stored thereon, and the program can be executed by a processor to implement the interpolation method according to any one of claims 1-7.