Chinese character image deformation method and device
By selecting multiple deformation control points in the Chinese character image, calculating the weight and weighting center points, generating a transformation matrix for affine transformation, the problem of poor deformation effect of Chinese character image in the prior art is solved, and higher diversity, fine control and natural and realistic deformation effect are achieved.
Patent Information
- Application Number
- CN202411715272.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-18
AI Technical Summary
The existing Chinese character image deformation technology has poor results, limited diversity, lack of fine control, damaged image integrity, incomplete deformation, long deformation, and artifacts and incoherent deformation may occur at the boundaries.
By obtaining the original text image to be deformed, multiple coordinates are randomly selected as deformation control points, and the corresponding target point is selected for each control point, the weight is calculated based on the Euclidean distance, the weighted center point is calculated, the transformation matrix is generated, and affine transformation is performed to achieve image deformation.
It improves the diversity and fine control ability of Chinese character image deformation, maintains the integrity and coherence of the image, reduces artifacts and time-consuming during deformation, and achieves a natural and realistic distortion effect.
Smart Images

Figure CN119648519A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method and device for deforming a Chinese character image. Background Art
[0002] Chinese character recognition is a key area in optical character recognition (OCR) research and is an integral part of applications such as document scanning, text processing, and language translation. Due to the large number of Chinese characters and the variety of writing styles, the accuracy and generalization of Chinese character recognition still need to be improved. The accuracy and generalization of Chinese character recognition models depend on the quality and diversity of training datasets. Existing Chinese character datasets have very limited diversity in writing styles and fonts, and usually contain standardized or printed Chinese characters, which cannot fully represent the various variations of Chinese fonts in handwriting or artistic creations. It is very difficult to build large datasets by manually collecting, annotating, and organizing Chinese character data, and automated or semi-automated methods are needed to effectively enhance and diversify Chinese character datasets.
[0003] Existing Chinese character image deformation technologies include: affine transformation: affine transformation is a type of linear transformation, including translation, rotation, scaling and shearing, which can be combined and applied to images to achieve geometric distortion; Thin-Plate Splines (TPS): a spline function used for nonlinear deformation of images, which distorts images based on control points; Free-Form Deformations (FFD): a nonlinear deformation technology that places a lattice or grid on the image and adjusts the control points to locally distort the image; Adding noise: adding random noise to the image to simulate defects in the writing or shooting process; Gaussian blur: reducing the level of image details to produce a blurring effect; Brightness and contrast adjustment: changing the brightness and contrast of the Chinese character image to simulate changes in lighting and Chinese character color intensity; Flipping and mirroring: flipping the Chinese character image horizontally, vertically and mirroring.
[0004] The deformation effect of Chinese character images in the prior art is poor, which is mainly manifested in: limited deformation diversity, lack of fine control, damaged image integrity, incomplete deformation, long deformation time, artifacts may appear at the boundaries and deformation is incoherent. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method and device for deforming a Chinese character image, so as to achieve the purpose of improving the deformation effect of the Chinese character image.
[0006] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0007] A first aspect of an embodiment of the present invention discloses a method for deforming a Chinese character image, the method comprising:
[0008] Obtaining the original text image to be deformed;
[0009] Randomly selecting a plurality of coordinates in the original text image as deformation control points, and selecting corresponding coordinates for each deformation control point as a deformation target point;
[0010] For each of the deformation control points, a weight corresponding to the deformation control point is calculated based on the Euclidean distance between each pixel point in the original text image and the deformation control point;
[0011] Based on the coordinates of each of the deformation control points and the corresponding weights, a first weighted center point is calculated, and based on the coordinates of each of the deformation target points and the corresponding weights of each of the deformation control points, a second weighted center point is calculated;
[0012] Based on the weight corresponding to each deformation control point and the first weighted center point, a transformation matrix corresponding to each pixel point in the original text image is calculated;
[0013] Based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point, the original text image is deformed to obtain a new text image.
[0014] Preferably, the step of calculating the transformation matrix corresponding to each pixel point in the original text image based on the weight corresponding to each deformation control point and the corresponding first weighted center point includes:
[0015] For each of the deformation control points, calculate the difference between the coordinates of the deformation control point and the coordinates of the corresponding first weighted center point to obtain a weighted offset value;
[0016] For each pixel in the original text image, a second-order matrix is calculated based on each weighted offset value and a weight corresponding to each deformation control point;
[0017] For each pixel in the original text image, a transformation matrix is calculated based on the inverse matrix of the corresponding second-order matrix, the coordinates of each of the first weighted center points and each of the weighted offset values.
[0018] Preferably, the method further comprises:
[0019] If the second-order matrix corresponding to any of the pixel points does not have an inverse matrix, calculating the adjoint matrix of the second-order matrix;
[0020] For each pixel point in the original text image, a transformation matrix is calculated based on the companion matrix, the coordinates of each of the first weighted center points and each of the weighted offset values.
[0021] Preferably, the deforming operation is performed on the original text image based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point to obtain a new text image, including:
[0022] Creating a blank new text image based on the background color value and size of the original text image;
[0023] Calculate the target coordinates of each pixel point after deformation based on the transformation matrix corresponding to each pixel point, the coordinates of each deformed target point and the second weighted center point;
[0024] For each of the target coordinates, if the horizontal coordinate of the target coordinate is less than 0, the horizontal coordinate is set to 0, and if the vertical coordinate of the target coordinate is less than 0, the vertical coordinate is set to 0;
[0025] For each of the target coordinates, if the target coordinate exceeds the boundary of the blank new text image, the target coordinate is discarded;
[0026] Based on the remaining target coordinates and the blank new text image, a new text image after the original text image is deformed is obtained.
[0027] Preferably, after obtaining the blank new text image, the method further comprises:
[0028] Convert the coordinates of each pixel in the blank new text image into homogeneous coordinates.
[0029] Preferably, after obtaining the weights corresponding to the deformation control points, the method further comprises:
[0030] The weights corresponding to the deformation control points are standardized so that the sum of the weights corresponding to the deformation control points is equal to 1.
[0031] A second aspect of an embodiment of the present invention discloses a Chinese character image deformation device, the device comprising:
[0032] An acquisition unit, used for acquiring an original text image to be deformed;
[0033] A selection unit, used for randomly selecting a plurality of coordinates in the original text image as deformation control points, and selecting corresponding coordinates for each deformation control point as a deformation target point;
[0034] A weight calculation unit, configured to calculate, for each of the deformation control points, a weight corresponding to the deformation control point based on a Euclidean distance between each pixel point in the original text image and the deformation control point;
[0035] A weighting unit, configured to calculate a first weighted center point based on the coordinates of each of the deformation control points and the corresponding weights, and to calculate a second weighted center point based on the coordinates of each of the deformation target points and the corresponding weights of each of the deformation control points;
[0036] A matrix calculation unit, configured to calculate a transformation matrix corresponding to each pixel point in the original text image based on a weight corresponding to each deformation control point and the first weighted center point;
[0037] The deformation unit is used to perform a deformation operation on the original text image based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point to obtain a new text image.
[0038] Preferably, the matrix calculation unit comprises:
[0039] an offset calculation unit, configured to calculate, for each of the deformation control points, a difference between the coordinates of the deformation control point and the coordinates of the corresponding first weighted center point, to obtain a weighted offset value;
[0040] A second-order matrix calculation unit, configured to calculate a second-order matrix for each pixel in the original text image based on each weighted offset value and a weight corresponding to each deformation control point;
[0041] The transformation matrix calculation unit is used to calculate the transformation matrix for each pixel point in the original text image based on the inverse matrix of the corresponding second-order matrix, the coordinates of each first weighted center point and each weighted offset value.
[0042] Preferably, the transformation matrix calculation unit is further used for:
[0043] If the second-order matrix corresponding to any of the pixel points does not have an inverse matrix, calculating the adjoint matrix of the second-order matrix;
[0044] For each pixel point in the original text image, a transformation matrix is calculated based on the companion matrix, the coordinates of each of the first weighted center points and each of the weighted offset values.
[0045] Preferably, a blank new text image is created based on the background color value and size of the original text image;
[0046] Calculate the target coordinates of each pixel point after deformation based on the transformation matrix corresponding to each pixel point, the coordinates of each deformed target point and the second weighted center point;
[0047] For each of the target coordinates, if the horizontal coordinate of the target coordinate is less than 0, the horizontal coordinate is set to 0, and if the vertical coordinate of the target coordinate is less than 0, the vertical coordinate is set to 0;
[0048] For each of the target coordinates, if the target coordinate exceeds the boundary of the blank new text image, the target coordinate is discarded;
[0049] Based on the remaining target coordinates and the blank new text image, a new text image after the original text image is deformed is obtained.
[0050] Based on a deformation method and device for a Chinese character image provided by the above-mentioned embodiment of the present invention, an original character image to be deformed is obtained; a plurality of coordinates are randomly selected in the original character image as deformation control points, and corresponding coordinates are selected for each deformation control point as a deformation target point; for each deformation control point, a weight corresponding to the deformation control point is calculated based on the Euclidean distance between each pixel point in the original character image and the deformation control point; a first weighted center point is calculated based on the coordinates of each deformation control point and the corresponding weight, and a second weighted center point is calculated based on the coordinates of each deformation target point and the weight corresponding to each deformation control point; a transformation matrix corresponding to each pixel point in the original character image is calculated based on the weight corresponding to each deformation control point and the first weighted center point; based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point, the original character image is deformed to obtain a new character image. In this scheme, weighted multiple control points are used to produce different influences on the pixels in different areas of the image. This influence is used to calculate the affine transformation required for the distortion and deformation of the pixels, ensuring a smooth transition between the deformed and undeformed areas of the image, thereby achieving the purpose of improving the deformation effect of the Chinese character image. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0052] Figure 1 A flowchart of a method for deforming a Chinese character image disclosed in an embodiment of the present invention;
[0053] Figure 2 An example diagram of an original text image disclosed in an embodiment of the present invention;
[0054] Figure 3 An example diagram of selecting a deformation control point disclosed in an embodiment of the present invention;
[0055] Figure 4 This is an example diagram of selecting a deformation target point disclosed in the present invention;
[0056] Figure 5 An example diagram of a new text image disclosed in an embodiment of the present invention;
[0057] Figure 6 The present invention is a structural diagram of a Chinese character image deformation device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising 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 "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0060] First, the technical terms appearing in this application are explained as follows:
[0061] Chinese character dataset: A collection of samples consisting of Chinese character images used to train and test computer algorithms (such as convolutional neural networks).
[0062] Data augmentation: A technique that increases the size and diversity of a dataset by creating new samples from existing samples. Data augmentation is used to deform Chinese character images while maintaining the integrity and correctness of the Chinese character structure. Chinese character image data augmentation refers to the process of improving the quality, diversity, and quantity of Chinese character images for training recognition models. It plays a key role in solving the problem of accuracy and generalization of Chinese character recognition models. The application of data augmentation techniques can create variants of existing Chinese character images, including operations such as rotation, scaling, shearing, and adding noise to simulate different writing styles and conditions. The innovation of Chinese character image data augmentation lies in the effective generation of Chinese character images of different styles and fonts, while maintaining the integrity and visual beauty of the Chinese character structure. For example, by locally deforming different areas of the Chinese character image, the diversity of the dataset is expanded. The focus of the technology is to create changes that are both realistic and consistent with the original Chinese characters, ensuring that the enhanced data remains relevant and useful for training.
[0063] Image Warping: Apply translation, rotation, scaling, shearing, and more to images.
[0064] Transformation matrix: A matrix is used to represent the transformation. For example, in Euclidean space, a point p = [x, y, z] is transformed into p' after translation transformation t and rotation transformation R, that is, p' = Rp + t, which can be represented by a matrix:
[0065]
[0066] In the above formula, let the matrix is the transformation matrix.
[0067] Inverse matrix: Let A be an n-order matrix. If there exists another n-order matrix B such that: AB = BA = E, then the matrix A is called invertible, and the matrix B is called the inverse matrix of A. Where E is the unit matrix, and all its elements are 1.
[0068] Singular matrix: A matrix for which there is no inverse.
[0069] Adjoint matrix: A matrix related to the original matrix. When the original matrix is a singular matrix, it is used to approximate its inverse matrix.
[0070] Interpolation: used to estimate the value between two known values or to smooth the transition between data points. In image deformation, interpolation is used to ensure that deformations applied to different triangular image patches blend smoothly together to create a visually coherent result. Interpolation can be understood as filling in the gaps between known data points, and the pixel values between them can be estimated based on the surrounding pixels.
[0071] As can be seen from the background technology, the deformation effect of Chinese character images in the prior art is poor, which is mainly manifested in: limited deformation diversity, lack of fine control, damaged image integrity, incomplete deformation, long deformation time, artifacts may appear at the boundaries and deformation is incoherent.
[0072] The specific analysis is as follows:
[0073] Limited deformation diversity: Existing Chinese character image deformation techniques usually cannot capture all the variations of Chinese character strokes and the deformation diversity is limited.
[0074] Lack of fine control: The deformation is applied to individual Chinese characters, lacking fine control over the details of the Chinese characters.
[0075] Image integrity is damaged: After the Chinese character image is cropped, the content of the enhanced Chinese character image is no longer complete and becomes a fragment that cannot express the meaning of the same Chinese character.
[0076] Incomplete deformation: Compared with rigid body transformation (rotation and translation), affine transformation not only changes the position of the target, but also changes the shape of the target, but still maintains "straightness (such as two parallel lines in the image remain parallel after transformation)".
[0077] Excessive computation: Some nonlinear deformation techniques (such as thin plate splines and free-form deformation) require a lot of computation and are very time-consuming.
[0078] Boundary artifacts: Artifacts may appear at image boundaries, where the deformation extends beyond the original image.
[0079] Deformation discontinuity: Local distortion and deformation will cause unnatural visual effects such as "breaks" at the junction of the deformed area and the undeformed area.
[0080] Therefore, an embodiment of the present invention discloses a method and device for deforming a Chinese character image. By weighting multiple control points to produce different influences on pixel points in different areas of the image, such influences are used to calculate the affine transformation required for the distortion and deformation of the pixel points. This can ensure a smooth transition between the deformed area and the undeformed area of the image, maintain the visual continuity of the Chinese characters in the image, produce a natural and realistic distortion effect, and thus achieve the purpose of improving the deformation effect of the Chinese character image.
[0081] like Figure 1 FIG. 1 is a flow chart of a method for deforming a Chinese character image disclosed in an embodiment of the present invention, comprising the following steps:
[0082] Step S101: obtaining an original text image to be deformed.
[0083] like Figure 2 , which is an example diagram of an original text image disclosed in an embodiment of the present invention.
[0084] In step S101 , the background color value of the original text image is C, the width of the original text image is W, and the height is H.
[0085] Step S102: randomly selecting a plurality of coordinates in the original text image as deformation control points, and selecting corresponding coordinates for each deformation control point as a deformation target point.
[0086] like Figure 3 , which is an example diagram of selecting deformation control points disclosed in an embodiment of the present invention.
[0087] In step S103, deformation control points are defined, that is, a number of coordinate points are selected as control points for image distortion and deformation. These deformation control points will be used as anchor points for deformation.
[0088] Specifically, several coordinate points are randomly selected as deformation control points for image distortion, and the coordinates of each deformation control point are represented by (x, y). The set of these coordinates is recorded as the deformation control point set P.
[0089] When the original text image is distorted, each deformation control point P in the deformation control point set P will also be distorted accordingly. The control point after distortion is recorded as P', which represents the deformation target point set.
[0090] like Figure 4 FIG. 1 is an example diagram of selecting a deformation target point disclosed in the present invention.
[0091] Among them, P and P′ are paired (x, y) coordinates. Assuming that the number of deformation control points and the number of deformation target points are both N, they define the correspondence between the pixel points in the original text image and the new text image obtained after deformation.
[0092] It should be noted that it is assumed that the mapping relationship between P and P' is determined by the function f. Since the image distortion problem can essentially be regarded as a pixel interpolation problem, for each pixel v, according to the mapping function f, it can be transformed into v'=f(v).
[0093] The mapping function f is defined as: f(x) = Mx + T, where M represents the linear transformation matrix and T represents the translation transformation matrix. M and T may be different for different pixels. However, the mapping function f always satisfies the smoothness property, that is, the positions of points close in space after deformation should also be close: lim vi→vj f(v i )=f(v j ).
[0094] The main purpose of the subsequent steps is to determine the position v′ after deformation based on the given pixel point v and the mapping relationship f between P and P′. That is, after solving f, substituting v into f(v) can obtain the position coordinates of the pixel point after deformation.
[0095] Step S103: for each deformation control point, based on the Euclidean distance between each pixel point in the original text image and the deformation control point, a weight corresponding to the deformation control point is calculated.
[0096] In step S103, a weighting function is defined for each deformation control point. The weighting function indicates the degree to which the deformation control point affects the distortion of surrounding pixels. By affecting the deformation effect of each area of the image based on the control points at different positions, a new text image with varied and controllable styles can be generated.
[0097] In the specific implementation process of step S103, the weight of each control point is ω i , the weight is based on the Euclidean distance between each pixel v and the deformation control point, and the calculation formula is as follows:
[0098]
[0099] Among them, the α parameter is used to control the influence of the weight on the deformation control point; ε is infinitesimal to prevent the denominator from being 0; p i Represents each control point in the deformation control point set.
[0100] Preferably, after obtaining the weights corresponding to the deformation control points, the weights corresponding to the deformation control points are normalized so that the sum of the weights corresponding to the deformation control points is equal to 1. The specific normalization formula is as follows:
[0101]
[0102] It should be noted that a weight is calculated for each control point, which in turn affects the deformation of the pixels around the control point. The deformation of each pixel is determined by the weighted average of the nearby control points (ie, the weighted average).
[0103] Step S104: based on the coordinates of each deformation control point and the corresponding weight, a first weighted center point is calculated, and based on the coordinates of each deformation target point and the corresponding weight of each deformation control point, a second weighted center point is calculated.
[0104] In step S104, the deformation of each pixel is determined by the weighted average of nearby deformation control points, so the weighted center point needs to be calculated.
[0105] In the specific implementation process of step S104, the weighted center point of each deformation control point is calculated: Similarly, calculate the weighted center point of the deformation target point set P′
[0106] It can be understood that since the weights are standardized, the sum of the weights is 1, so the denominator in the calculation formula of the weighted center point is 1.
[0107] It should be noted that each pixel point will be affected by the deformation control point, but due to different distances, the influence of each deformation control point on the pixel point is different. Therefore, the weighted center point is calculated, and the influence of each deformation control point on the pixel point is calculated using this weighted center point, and then the accumulation is the influence of each deformation control point on the pixel point.
[0108] Step S105: Based on the weight corresponding to each deformation control point and the first weighted center point, a transformation matrix corresponding to each pixel point in the original text image is calculated.
[0109] In step S105, for each pixel in the image, its transformation matrix is calculated according to the influence area of the deformation control point. The deformation of each pixel is determined by the weighted center point of the nearby deformation control points. The deformation control points that are closer have stronger influence.
[0110] In the specific implementation process of step S105, first, for each deformation control point, the difference between the coordinates of the deformation control point and the coordinates of the corresponding first weighted center point is calculated to obtain a weighted offset value, that is, i Subtract the weighted center point pstar from i To calculate the weighted offset value phat i =p i -pstar i .
[0111] Then, for each pixel in the original text image, based on each weighted offset value and the weight corresponding to each deformation control point, a second-order matrix is calculated, as follows:
[0112] According to each deformation control point p i , the weight of each deformation control point ω i and the weighted offset phat for each deformation control point i Calculate the matrix pTwp for each pixel i .pT i is a 2×2 matrix calculated for each pixel in the image. i Store the information needed for subsequent calculation of the affine transformation matrix A to perform image distortion. Iterate the control point set P, and according to each control point p i calculate:
[0113]
[0114] Finally, for each pixel in the original text image, the transformation matrix is calculated based on the inverse matrix of the corresponding second-order matrix, the coordinates of each first weighted center point and each weighted offset value. The transformation matrix calculation formula for each pixel is as follows:
[0115]
[0116] In the process of calculating the transformation matrix in the above formula, the influence of each deformation control point is calculated using the weighted center point, and the total influence on the pixel point after summing is the same.
[0117] It should be noted that if there is no inverse matrix for the second-order matrix corresponding to any pixel point, the adjoint matrix of the second-order matrix is calculated; for each pixel point in the original text image, the transformation matrix is calculated based on the adjoint matrix, the coordinates of each first weighted center point and each weighted offset value.
[0118] Specifically, if the matrix pTwp is singular, it means that pTwp is a square matrix without an inverse matrix. It is impossible to directly calculate the inverse matrix of a singular matrix because it does not exist. Therefore, we first try to calculate the inverse of pTwp, assuming that:
[0119]
[0120] Calculate the determinant of pTwp det(pTwp) = ad-bc. If the determinant is close to zero, it means that the matrix is singular. Then find the adjoint matrix of pTwp adjoint(pTwp) instead of the inverse process.
[0121] The calculation formula of adjoint(pTwp) is as follows:
[0122]
[0123] When calculating the inverse matrix inv(pTwp) of pTwp, a threshold value θ is used to avoid the situation where the denominator is 0 when calculating the division.
[0124] If det(pTwp)<θ then otherwise
[0125] In the embodiment of the present invention, weighted control points are used to achieve a smooth transition between the deformed area and the undeformed area of the image, maintain the visual continuity of the Chinese characters in the image, and produce a natural and realistic distortion effect.
[0126] Step S106: Based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point, the original text image is deformed to obtain a new text image.
[0127] like Figure 5 , which is an example diagram of a new text image disclosed in an embodiment of the present invention.
[0128] The specific implementation process of step S106 includes the following steps:
[0129] Step S1061: Create a blank new text image based on the background color value and size of the original text image.
[0130] In step S1061 , the size of the new text image is the same as that of the original text image, and the color value of each pixel of the new text image is set to the background color value of the original text image.
[0131] Preferably, the coordinates of each pixel in the blank new text image are converted into homogeneous coordinates.
[0132] Homogeneous coordinates make image deformation processing simpler, more unified, and more accurate, and support more complex transformation methods, making it more flexible and efficient when generating new text images.
[0133] It should be noted that, after step S101 , that is, after the original text image is acquired, a new text image may be created for standby use.
[0134] Step S1062: based on the transformation matrix corresponding to each pixel point, the coordinates of each deformed target point and the second weighted center point, the target coordinates of each pixel point after deformation are calculated.
[0135] In the specific implementation process of step S1062, the position of the pixel after deformation is calculated:
[0136]
[0137] Step S1063: For each target coordinate, if the horizontal coordinate of the target coordinate is less than 0, the horizontal coordinate is set to 0; if the vertical coordinate of the target coordinate is less than 0, the vertical coordinate is set to 0.
[0138] Step S1064: For each target coordinate, if the target coordinate exceeds the boundary of the blank new text image, the target coordinate is discarded.
[0139] In step S1064, in order to ensure that the deformed pixel points remain within the effective range of the image, correction processing is required. For each transformed pixel point v', check whether it is outside the image boundary. If it is outside the boundary, set the coordinates of v' to the boundary value, which is equivalent to discarding the pixel points beyond the image boundary.
[0140] Assume that the coordinates of the transformed pixel point v′ are (x′, y′), check whether x′ is greater than or equal to W. If so, set x′ to W; check whether y′ is greater than or equal to H. If so, set y′ to H.
[0141] Step S1065: Based on the remaining target coordinates and the blank new text image, a new text image after the original text image is deformed is obtained.
[0142] Based on the above-mentioned embodiment of the present invention, a deformation method of a Chinese character image is disclosed. By weighting multiple control points to produce different influences on pixel points in different areas of the image, and using this influence to calculate the affine transformation required for the distortion and deformation of the pixel points, a smooth transition between the deformed area and the undeformed area of the image can be ensured, the visual continuity of the Chinese characters in the image can be maintained, and a natural and realistic distortion effect can be produced, thereby achieving the purpose of improving the deformation effect of the Chinese character image.
[0143] Corresponding to the deformation method of a Chinese character image disclosed in the above embodiment of the present invention, as Figure 6 As shown, it is a structural diagram of a Chinese character image deformation device disclosed in an embodiment of the present invention, including: an acquisition unit 601, a selection unit 602, a weight calculation unit 603, a weighting unit 604, a matrix calculation unit 605 and a deformation unit 606.
[0144] The acquisition unit 601 is used to acquire the original text image to be deformed.
[0145] The selection unit 602 is used to randomly select a plurality of coordinates in the original text image as deformation control points, and select corresponding coordinates for each deformation control point as a deformation target point.
[0146] The weight calculation unit 603 is used to calculate the weight corresponding to each deformation control point based on the Euclidean distance between each pixel point in the original text image and the deformation control point.
[0147] The weighting unit 604 is used to calculate a first weighted center point based on the coordinates of each deformation control point and the corresponding weight, and to calculate a second weighted center point based on the coordinates of each deformation target point and the corresponding weight of each deformation control point.
[0148] The matrix calculation unit 605 is used to calculate the transformation matrix corresponding to each pixel point in the original text image based on the weight corresponding to each deformation control point and the first weighted center point.
[0149] The deformation unit 606 is used to perform a deformation operation on the original text image based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point to obtain a new text image.
[0150] In one embodiment, the matrix calculation unit 605 includes:
[0151] The offset calculation unit is used to calculate, for each deformation control point, the difference between the coordinates of the deformation control point and the coordinates of the corresponding first weighted center point to obtain a weighted offset value.
[0152] The second-order matrix calculation unit is used to calculate the second-order matrix for each pixel point in the original text image based on each weighted offset value and the weight corresponding to each deformation control point.
[0153] The transformation matrix calculation unit is used to calculate the transformation matrix for each pixel point in the original text image based on the inverse matrix of the corresponding second-order matrix, the coordinates of each first weighted center point and each weighted offset value.
[0154] In one embodiment, the transformation matrix calculation unit is further used for:
[0155] If the second-order matrix corresponding to any pixel point does not have an inverse matrix, calculate the adjoint matrix of the second-order matrix;
[0156] For each pixel in the original text image, a transformation matrix is calculated based on the adjoint matrix, the coordinates of each first weighted center point and each weighted offset value.
[0157] In one embodiment, the deformation unit 606 is specifically configured to:
[0158] Based on the background color value and size of the original text image, a blank new text image is created; based on the transformation matrix corresponding to each pixel point, the coordinates of each deformed target point and the second weighted center point, the target coordinates of each pixel point after deformation are calculated; for each target coordinate, if the horizontal coordinate of the target coordinate is less than 0, the horizontal coordinate is set to 0, and if the vertical coordinate of the target coordinate is less than 0, the vertical coordinate is set to 0; for each target coordinate, if the target coordinate exceeds the boundary of the blank new text image, the target coordinate is discarded; based on the remaining target coordinates and the blank new text image, a new text image after deformation of the original text image is obtained.
[0159] In one embodiment, the device further comprises:
[0160] The conversion unit is used to convert the coordinates of each pixel point in the blank new text image into homogeneous coordinates after obtaining the blank new text image.
[0161] In one embodiment, the device further comprises:
[0162] The processing unit is used to, after obtaining the weights corresponding to the deformation control points, perform normalization processing on the weights corresponding to the deformation control points so that the sum of the weights corresponding to the deformation control points is equal to 1.
[0163] Based on the above-mentioned embodiment of the present invention, a deformation device for a Chinese character image is disclosed. By weighting multiple control points to produce different influences on pixel points in different areas of the image, and using such influences to calculate the affine transformation required for the distortion and deformation of the pixel points, a smooth transition between the deformed area and the undeformed area of the image can be ensured, the visual continuity of the Chinese characters in the image can be maintained, and a natural and realistic distortion effect can be produced, thereby achieving the purpose of improving the deformation effect of the Chinese character image.
[0164] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0165] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0166] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for deforming a Chinese character image, characterized in that: The method comprises: Obtaining the original text image to be deformed; Randomly selecting a plurality of coordinates in the original text image as deformation control points, and selecting corresponding coordinates for each deformation control point as a deformation target point; For each of the deformation control points, a weight corresponding to the deformation control point is calculated based on the Euclidean distance between each pixel point in the original text image and the deformation control point; Based on the coordinates of each of the deformation control points and the corresponding weights, a first weighted center point is calculated, and based on the coordinates of each of the deformation target points and the corresponding weights of each of the deformation control points, a second weighted center point is calculated; Based on the weight corresponding to each deformation control point and the first weighted center point, a transformation matrix corresponding to each pixel point in the original text image is calculated; Based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point, the original text image is deformed to obtain a new text image.
2. The method according to claim 1, characterized in that The step of calculating the transformation matrix corresponding to each pixel point in the original text image based on the weight corresponding to each deformation control point and the corresponding first weighted center point includes: For each of the deformation control points, calculate the difference between the coordinates of the deformation control point and the coordinates of the corresponding first weighted center point to obtain a weighted offset value; For each pixel in the original text image, a second-order matrix is calculated based on each weighted offset value and a weight corresponding to each deformation control point; For each pixel in the original text image, a transformation matrix is calculated based on the inverse matrix of the corresponding second-order matrix, the coordinates of each of the first weighted center points and each of the weighted offset values.
3. The method according to claim 2, characterized in that The method further comprises: If the second-order matrix corresponding to any of the pixel points does not have an inverse matrix, calculating the adjoint matrix of the second-order matrix; For each pixel point in the original text image, a transformation matrix is calculated based on the companion matrix, the coordinates of each of the first weighted center points and each of the weighted offset values.
4. The method according to claim 1, characterized in that: The step of performing a deformation operation on the original text image based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point to obtain a new text image includes: Creating a blank new text image based on the background color value and size of the original text image; Calculate the target coordinates of each pixel point after deformation based on the transformation matrix corresponding to each pixel point, the coordinates of each deformed target point and the second weighted center point; For each of the target coordinates, if the horizontal coordinate of the target coordinate is less than 0, the horizontal coordinate is set to 0, and if the vertical coordinate of the target coordinate is less than 0, the vertical coordinate is set to 0; For each of the target coordinates, if the target coordinate exceeds the boundary of the blank new text image, the target coordinate is discarded; Based on the remaining target coordinates and the blank new text image, a new text image after the original text image is deformed is obtained.
5. The method according to claim 4, characterized in that After obtaining the blank new text image, the method further includes: Convert the coordinates of each pixel in the blank new text image into homogeneous coordinates.
6. The method according to any one of claims 1 to 5, characterized in that: After obtaining the weights corresponding to the deformation control points, the method further includes: The weights corresponding to the deformation control points are standardized so that the sum of the weights corresponding to the deformation control points is equal to 1.
7. A Chinese character image deformation device, characterized in that: The device comprises: An acquisition unit, used for acquiring an original text image to be deformed; A selection unit, used for randomly selecting a plurality of coordinates in the original text image as deformation control points, and selecting corresponding coordinates for each deformation control point as a deformation target point; A weight calculation unit, configured to calculate, for each of the deformation control points, a weight corresponding to the deformation control point based on a Euclidean distance between each pixel point in the original text image and the deformation control point; A weighting unit, configured to calculate a first weighted center point based on the coordinates of each of the deformation control points and the corresponding weights, and to calculate a second weighted center point based on the coordinates of each of the deformation target points and the corresponding weights of each of the deformation control points; A matrix calculation unit, configured to calculate a transformation matrix corresponding to each pixel point in the original text image based on a weight corresponding to each deformation control point and the first weighted center point; The deformation unit is used to perform a deformation operation on the original text image based on the transformation matrix corresponding to each pixel point, the coordinates of each deformation target point and the second weighted center point to obtain a new text image.
8. The device according to claim 7, characterized in that The matrix calculation unit comprises: an offset calculation unit, configured to calculate, for each of the deformation control points, a difference between the coordinates of the deformation control point and the coordinates of the corresponding first weighted center point, to obtain a weighted offset value; A second-order matrix calculation unit, configured to calculate a second-order matrix for each pixel in the original text image based on each weighted offset value and a weight corresponding to each deformation control point; The transformation matrix calculation unit is used to calculate the transformation matrix for each pixel point in the original text image based on the inverse matrix of the corresponding second-order matrix, the coordinates of each first weighted center point and each weighted offset value.
9. The device according to claim 8, characterized in that The transformation matrix calculation unit is further used for: If the second-order matrix corresponding to any of the pixel points does not have an inverse matrix, calculating the adjoint matrix of the second-order matrix; For each pixel point in the original text image, a transformation matrix is calculated based on the companion matrix, the coordinates of each of the first weighted center points and each of the weighted offset values.
10. The device according to claim 7, characterized in that The matrix calculation unit is specifically used for: Creating a blank new text image based on the background color value and size of the original text image; Calculate the target coordinates of each pixel point after deformation based on the transformation matrix corresponding to each pixel point, the coordinates of each deformed target point and the second weighted center point; For each of the target coordinates, if the horizontal coordinate of the target coordinate is less than 0, the horizontal coordinate is set to 0, and if the vertical coordinate of the target coordinate is less than 0, the vertical coordinate is set to 0; For each of the target coordinates, if the target coordinate exceeds the boundary of the blank new text image, the target coordinate is discarded; Based on the remaining target coordinates and the blank new text image, a new text image after the original text image is deformed is obtained.
Citation Information
Cited By
Deformed character dynamic typesetting rendering method and system based on parameterized shape
CN120931477A