Font generation method and device
By mapping and rolling deformation of Chinese characters, deformed fonts are generated, which solves the problem of large-scale engineering quantities of manual fonts of Chinese characters in different styles, and improves font generation efficiency and design diversity.
Patent Information
- Application Number
- CN202210333080.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-31
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2042-03-31
AI Technical Summary
The number of Chinese characters exceeds 7,000. The project volume of manual production of different styles of each Chinese character is very large, and it is difficult to improve the efficiency of font generation and design diversity.
By obtaining the relationship between all strokes and stroke positions of the target character, at least one stroke is mapped and transformed according to the preset rules to generate a deformed font. The method includes using preset mapping functions to deform strokes such as stretching, extruding, and twisting, and improving the artistic effect of the font through techniques such as rolling deformation and color value weighting.
It effectively improves the efficiency of font generation, increases the diversity of font design, and reduces the need for manual production.
Smart Images

Figure CN114693824B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of information processing, and particularly to a font generation method and apparatus. Background Art
[0002] In graphic design, in order to set off the theme atmosphere, artistic fonts are usually used to increase the artistic sense. The creation process of artistic fonts for Chinese characters usually involves manual writing and then using corresponding algorithms to extract the pixel map of the font. Summary of the Invention
[0003] The inventors noticed that the number of Chinese characters exceeds 7,000. If fonts of different styles for each Chinese character are to be made manually, the workload is extremely huge.
[0004] Accordingly, the present disclosure provides a font generation solution, which can effectively improve the font generation efficiency and effectively improve the diversity of font design.
[0005] According to a first aspect of an embodiment of the present disclosure, a font generation method is provided, including: obtaining all strokes of a target character and the stroke position relationship; in the case where the total number of all strokes is greater than 1, performing a mapping transformation on at least 1 stroke among all the strokes according to a preset rule to obtain a corresponding transformed stroke; generating a deformed font of the target character by using all the strokes and the transformed stroke according to the stroke position relationship.
[0006] In some embodiments, the generating a deformed font of the target character by using all the strokes and the transformed stroke includes: if n strokes among all the strokes are subjected to a mapping transformation, and n < M, where M is the total number of all the strokes, then assembling the M - n strokes that have not been subjected to the mapping transformation and the n transformed strokes among all the strokes according to the stroke position relationship to generate the deformed font of the target character.
[0007] In some embodiments, if all the strokes among all the strokes are subjected to a mapping transformation, then assembling the M transformed strokes according to the stroke position relationship to generate the deformed font of the target character.
[0008] In some embodiments, in the case where the total number of all strokes is equal to 1, performing a mapping transformation on the stroke of the target character to obtain a corresponding transformed stroke; generating the deformed font of the target character according to the stroke position relationship and the corresponding transformed stroke.
[0009] In some embodiments, the mapping transformation includes: performing a mapping transformation process on a stroke to be transformed by using a preset mapping function to obtain the transformed stroke.
[0010] In some embodiments, the mapping transformation processing of the strokes to be transformed using a preset mapping function includes: setting the strokes to be transformed in a first plane; using the preset mapping function located in a second plane, mapping the strokes to be transformed to a third plane, wherein the first plane, the second plane and the third plane are perpendicular to each other.
[0011] In some embodiments, the preset mapping function is a linear function.
[0012] In some embodiments, at least one of the slope and the intercept of the linear function corresponding to each pixel point in the stroke to be transformed is associated with the coordinate value of each pixel point on a predetermined coordinate axis, wherein the predetermined coordinate axis is located in the first plane and the third plane.
[0013] In some embodiments, the mapping transformation also includes: performing rolling deformation processing on the stroke to be transformed, wherein the coordinate value of the mapping point generated by each pixel in the stroke to be transformed after the rolling deformation processing is determined by the initial coordinate value of each pixel, the moving distance of the circle formed by the rolling of the stroke to be transformed, and the rotation angle of the circle.
[0014] In some embodiments, after the stroke to be transformed is subjected to rolling deformation processing, it is determined whether the mapping point falls on a preset coordinate point; if the mapping point does not fall on the preset coordinate point, the color value of the preset coordinate point is determined based on the weighted sum of the color values of all mapping points in the neighborhood of the preset coordinate point.
[0015] In some embodiments, the color value includes a red R value, a green G value, and a blue B value; and the weight of the color value of each mapping point is negatively correlated with the distance between each mapping point and the preset coordinate point.
[0016] In some embodiments, before mapping and transforming at least one of the total strokes according to preset rules, a trained stroke generation model is used to generate a stroke with a preset style corresponding to at least one of the total strokes to be updated, and the stroke with the preset style is used to replace the stroke to be updated.
[0017] In some embodiments, a machine learning model is trained to obtain the stroke generation model; wherein, the training of the machine learning model includes: inputting preset information into the machine learning model to obtain a first stroke; extracting a second stroke with a preset style from a training sample set; using a discriminator to determine which stroke among the first stroke and the second stroke comes from the training sample set; and training the discriminator and the machine learning model according to the determination result of the discriminator.
[0018] In some embodiments, the acquiring of all strokes and stroke position relationships of the target character includes: acquiring all strokes and stroke position relationships of the target character from a database.
[0019] In some embodiments, obtaining all strokes and stroke position relationships of the target character includes: performing connected region segmentation and recognition processing on the target character; performing stroke recognition in each connected region to obtain all strokes of the target character; and analyzing the structure of the target character to obtain the stroke position relationship of the target character.
[0020] According to a second aspect of an embodiment of the present disclosure, a font generation device is provided, comprising: a first processing module, configured to obtain all strokes and stroke position relationships of a target character; a second processing module, configured to map and transform at least one stroke of all strokes according to a preset rule when the total number of all strokes is greater than 1, so as to obtain a corresponding transformed stroke; and a third processing module, configured to generate a deformed font of the target character using all strokes and the transformed strokes according to the stroke position relationship.
[0021] According to a third aspect of an embodiment of the present disclosure, a font generation device is provided, comprising: a memory configured to store instructions; a processor coupled to the memory, the processor being configured to execute a method as described in any of the above embodiments based on the instructions stored in the memory.
[0022] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and when the instructions are executed by a processor, the method involved in any of the above embodiments is implemented.
[0023] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the embodiments of the present disclosure 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 some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0025] Figure 1 A flowchart of a font generation method according to an embodiment of the present disclosure;
[0026] Figure 2 A schematic diagram of segmenting a connected region of a target word according to an embodiment of the present disclosure;
[0027] Figure 3 A schematic diagram of the strokes of a target character according to an embodiment of the present disclosure;
[0028] Figure 4 A schematic diagram of a stroke format according to an embodiment of the present disclosure;
[0029] Figure 5A and Figure 5B A schematic diagram of intersection extraction for some embodiments of the present disclosure;
[0030] Figure 6 A schematic diagram of the relationship between strokes according to an embodiment of the present disclosure;
[0031] Figure 7 A schematic diagram of mapping transformation according to an embodiment of the present disclosure;
[0032] Figure 8 A schematic diagram of stroke deformation according to an embodiment of the present disclosure;
[0033] Fig. 9 A schematic diagram of stroke deformation according to another embodiment of the present disclosure;
[0034] Fig.10 A schematic diagram of rolling deformation according to an embodiment of the present disclosure;
[0035] Fig.11 A schematic diagram of a stroke rolling deformation according to an embodiment of the present disclosure;
[0036] Fig.12 A schematic diagram of pixel synthesis according to an embodiment of the present disclosure;
[0037] Fig.13 A flowchart of a font generation method according to another embodiment of the present disclosure;
[0038] Fig.14 A schematic diagram of a model training structure according to an embodiment of the present disclosure;
[0039] Fig.15 A schematic diagram of the structure of a font generation device according to an embodiment of the present disclosure;
[0040] Fig.16 It is a structural schematic diagram of a font generation device according to another embodiment of the present disclosure. DETAILED DESCRIPTION
[0041] Next, the technical solutions in the embodiments of the present disclosure will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and in no way limits the present disclosure and its application or use. Based on the embodiments in the present disclosure, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present disclosure.
[0042] Unless otherwise specifically stated, the relative arrangements, numerical expressions, and numerical values of the components and steps set forth in these embodiments do not limit the scope of the present disclosure.
[0043] At the same time, it should be understood that for the sake of description, the dimensions of the various parts shown in the drawings are not drawn in actual proportional relationships.
[0044] For technologies, methods, and devices known to those of ordinary skill in the relevant art, they may not be discussed in detail, but where appropriate, the technologies, methods, and devices should be regarded as part of the authorization specification.
[0045] In all the examples shown and discussed here, any specific value should be construed as merely exemplary and not as a limitation. Therefore, other examples of the exemplary embodiments may have different values.
[0046] It should be noted that similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further discussed in subsequent drawings.
[0047] Figure 1 It is a schematic flowchart of a font generation method according to an embodiment of the present disclosure. In some embodiments, the following font generation method is executed by a font generation device.
[0048] In step 101, all the strokes of the target character and the stroke position relationship are obtained.
[0049] In some embodiments, all the stroke and stroke position relationship information of the target character is preset in the database. Therefore, all the strokes of the target character and the stroke position relationship can be directly obtained from the database.
[0050] For example, if the target character is "王" (the Chinese character for "king"), then all the strokes of the character "王" and the stroke position relationship can be directly obtained from the database. It should be noted that the strokes obtained from the database can be the strokes of a preset font, such as Song typeface, etc.
[0051] In some other embodiments, the target character may also be directly analyzed to obtain all the strokes of the target character and the stroke position relationship. For example, the following method may be adopted for processing.
[0052] 1) Perform connected component segmentation and recognition processing on the target character.
[0053] For example, by performing connected component segmentation on the Chinese character "体", two partitions can be obtained, as Figure 2 shown.
[0054] 2) Perform stroke recognition in each connected component to obtain all the strokes of the target character.
[0055] For example, the strokes of the target character are recognized by using a trained FCN (Fully Convolutional Network).
[0056] As Figure 3 shown, by processing the Chinese character "王", four strokes, namely horizontal stroke 1, horizontal stroke 2, horizontal stroke 3, and vertical stroke, can be obtained.
[0057] 3) Analyze the structure of the target character to obtain the stroke position relationship of the target character.
[0058] For example, by analyzing the target character, distance parameters between regions where each stroke is located in the target character, and distance parameters between regions where each stroke is located and the border of the target character are obtained, thereby obtaining the layout information of the target character.
[0059] As Figure 4 shown, the Chinese character "六" has a total of four strokes.
[0060] The distance parameters related to the region 1 where stroke A is located are: the distance Rua between region 1 and the upper border U, the distance Rar between region 1 and the right border R, the distance Ral between region 1 and the left border L, and the distance Rab between region 1 and the region 2 where stroke B is located.
[0061] The distance parameters related to the region 2 where stroke B is located are: the distance Rab between region 2 and region 1, the distance Rbr between region 2 and the right border R, the distance Rbl between region 2 and the left border L, the distance Rbc between region 2 and the region 3 where stroke C is located, and the distance Rbe between region 2 and the region 4 where stroke E is located.
[0062] The distance parameters related to the region 3 where stroke C is located are: the distance Rbc between region 3 and region 2, the distance Rce between region 3 and region 4, the distance Rlc between region 3 and the left border L, and the distance Rcd between region 3 and the lower border D.
[0063] The distance parameters related to the area 4 where the stroke D is located are: the distance Rbe between area 4 and area 2, the distance Rer between area 4 and the right frame R, the distance Rce between area 4 and area 3, and the distance Red between area 4 and the bottom frame D.
[0064] Next, by identifying the intersection relationship of strokes, the intersection points of strokes are determined. For example, by using the K3M algorithm to erode the target character, the intersection points of strokes are obtained.
[0065] For example, the target character is the Chinese character "五" as Figure 5A shown. By using the K3M algorithm to erode the Figure 5A target character shown, 4 intersection points are obtained, as Figure 5B shown.
[0066] Next, the distances from the endpoints of each stroke to the intersection points are counted to obtain the stroke position relationship.
[0067] For example, as Figure 6 shown, the Chinese character "王" has 4 strokes A, B, C, and D, and these 4 strokes have 3 intersection points. It should be noted that for the intersection points of "horizontal" strokes, the distance relationship is calculated from left to right, and for the intersection points of "vertical" strokes, the distance relationship is calculated from top to bottom.
[0068] The distance from the left endpoint of stroke C to the first intersection point is Sca, and the distance from the left endpoint of stroke C to the right endpoint is Lc.
[0069] The distance from the left endpoint of stroke B to the second intersection point is Sba, and the distance from the left endpoint of stroke B to the right endpoint is Lb.
[0070] The distance from the left endpoint of stroke D to the third intersection point is Sda, and the distance from the left endpoint of stroke D to the right endpoint is Ld.
[0071] The distance from the upper end of stroke A to the first intersection point is Sac, the distance from the first intersection point to the second intersection point is Sab, the distance from the first intersection point to the third intersection point is Sad, and the distance from the upper end of stroke A to the lower segment of stroke A is La.
[0072] On this basis, the mutual intersection relationship between strokes can be obtained, as shown in Table 1.
[0073] A B C D A -1 Sab / La Sac / La Sad / La B Sba / Lb -1 -1 -1 C Sca / Lc -1 -1 -1 D Scd / Ld -1 -1 -1
[0074] Table 1
[0075] Return Figure 1 . In step 102, when the total number of all strokes is greater than 1, at least one stroke among all strokes is subjected to a mapping transformation according to a preset rule to obtain the corresponding transformed stroke.
[0076] It should be noted that, when the target character has multiple strokes, mapping transformation may be performed on some of the strokes in the target character as needed, or mapping transformation may be performed on all the strokes in the entire character.
[0077] In some embodiments, a preset mapping function is used to perform mapping transformation processing on the strokes to be transformed to obtain transformed strokes. Through mapping transformation, the strokes can be deformed by stretching, squeezing, twisting, etc.
[0078] In some embodiments, Figure 7 As shown, the stroke to be transformed is set in the XOZ plane, and the stroke to be transformed is mapped to the YOZ plane using a preset mapping function located in the XOY plane, wherein the XOZ plane, the XOY plane and the YOZ plane are perpendicular to each other.
[0079] In some embodiments, the preset mapping function is a linear function, for example, the linear function is y=kx+b.
[0080] In some embodiments, at least one of the slope k and the intercept b of the linear function corresponding to each pixel point in the stroke to be transformed is associated with the coordinate value of each pixel point on the z-axis.
[0081] That is, the linear function is y=k(z)x+b(z).
[0082] like Figure 8 As shown, if the stroke is a rectangle with a length of h and a width of w, the tail of the stroke can be optimized by using the slope k(z).
[0083] like Fig. 9 As shown, if the stroke is a rectangle with a length of h and a width of w, the stroke can be completely deformed by establishing an intercept transformation curve b(z).
[0084] In some embodiments, in order to increase the artistic effect of the strokes, the strokes to be transformed may also be subjected to rolling deformation processing, wherein the coordinate value of the mapping point generated by each pixel in the stroke to be transformed after the rolling deformation processing is determined by the initial coordinate value of each pixel, the moving distance of the circle formed by the rolling of the stroke to be transformed, and the rotation angle of the circle.
[0085] like Fig.10 As shown, let the stroke be "horizontal" and let all the pixels of the stroke be scrolled. Let the radius of the circle be R, the distance of advancement be S, then the angle of the circle rotation is:
[0086]
[0087] It should be noted that the radius R changes as S changes.
[0088] The original coordinates of the pixel are (x, y), and the position of the center of the circle is:
[0089] o x =x+S,o y =yR
[0090] The coordinates of the mapped points after the pixel rotation are calculated as:
[0091]
[0092] Where x0 is 0, y0 is R(s), and the coordinates (x, y) after rotation are (x′, y′):
[0093] x′=O x +x′0,y′=O y +y′0
[0094] Through the above rolling deformation, the resulting stroke is as follows Fig.11 shown.
[0095] In some embodiments, after the stroke to be transformed is subjected to rolling deformation processing, it is determined whether the mapping point falls on a preset coordinate point. If the mapping point does not fall on the preset coordinate point, the color value of the preset coordinate point is determined according to the weighted sum of the color values of all mapping points in the neighborhood of the preset coordinate point.
[0096] It should be noted that when the pixel point is rolled and deformed, the coordinate value of the corresponding mapping point may not be an integer. For example, the coordinate value of the mapping point is (3.1, 4.7), that is, the mapping point cannot fall on the coordinate point (3, 5) or (3, 4).
[0097] In this case, if Fig.12 As shown, if the mapping point does not fall on the preset coordinate point O, the color value of the preset coordinate point is determined according to the weighted sum of the color values of all mapping points (A1, A2, A3 and A4) in the neighborhood of the preset coordinate point O.
[0098] In some embodiments, the color values include a red value R, a green value G, and a blue value B. The weight of the color value of each mapping point is negatively correlated with the distance between each mapping point and the preset coordinate point.
[0099] For example, if the mapping point does not fall on the preset coordinate point O, the R value R of the preset coordinate point O is determined according to the weighted values of the R values, G values, and B values of the K mapping points in the neighborhood of the preset coordinate point O. o 、G value G o and B value B o . As shown in the following formula.
[0100]
[0101]
[0102]
[0103] wherein, R i is the R value of the i-th mapping point in the neighborhood, G i is the G value of the i-th mapping point in the neighborhood, B i is the B value of the i-th mapping point in the neighborhood, and W i (r) is the weight value of the i-th mapping point. W i (r) decreases as the distance between the weight value of the i-th mapping point and the preset coordinate point O increases.
[0104] In step 103, according to the stroke position relationship, a deformed font of the target character is generated by using all the strokes and the transformed strokes.
[0105] In some embodiments, if n strokes among all the strokes are subjected to mapping transformation, and n < M, where M is the total number of all the strokes, then the M - n strokes that have not been subjected to mapping transformation among all the strokes and the n transformed strokes are assembled according to the stroke position relationship to generate a deformed font of the target character.
[0106] For example, the Chinese character "王" has 4 strokes. Only one of the strokes can be subjected to mapping transformation as needed, and then the 3 strokes that have not been subjected to mapping transformation and the 1 transformed stroke are assembled according to the stroke position relationship to generate a deformed font of the Chinese character "王".
[0107] In some embodiments, if all the strokes among all the strokes are subjected to mapping transformation, then the M transformed strokes are assembled according to the stroke position relationship to generate a deformed font of the target character.
[0108] For example, if all 4 strokes of the Chinese character "王" are subjected to mapping transformation, then the 4 transformed strokes are assembled according to the stroke position relationship to generate a deformed font of the Chinese character "王".
[0109] In some embodiments, when the total number of all the strokes is equal to 1, the stroke of the target character is subjected to mapping transformation to obtain the corresponding transformed stroke. Furthermore, a deformed font of the target character is generated according to the stroke position relationship and the corresponding transformed stroke.
[0110] For example, the Chinese characters "一" and "乙" each have only one stroke. Therefore, the only stroke can be directly transformed. Next, according to the stroke position relationship, such as the distance of the only stroke relative to the character frame, a corresponding deformed font is generated.
[0111] In the font generation method provided in the above embodiment of the present disclosure, by mapping and converting the strokes of the target character, the font generation efficiency can be effectively improved, and the diversity of font design can be effectively improved.
[0112] Fig.13 FIG. 1 is a flowchart of a font generation method according to another embodiment of the present disclosure. In some embodiments, the following font generation method is executed by a font generation device.
[0113] It should be noted that Fig.13 and Figure 1 The difference is that in Fig.13 In the illustrated embodiment, before the strokes are mapped and transformed, the strokes of the target character are converted into strokes with a preset style, thereby facilitating the generalization of more fonts.
[0114] In step 1301, all strokes and stroke position relationships of the target character are obtained.
[0115] In step 1302, a stroke with a preset style corresponding to at least one stroke to be updated among all the strokes is generated using the trained stroke generation model, and the stroke to be updated is replaced with the stroke with the preset style.
[0116] For example, the preset style may be a style similar to human writing.
[0117] It should be noted that all the strokes of the target character obtained through the database are in Song style. Then, by using the trained stroke generation model, strokes with a preset style corresponding to the Song style strokes can be obtained, thereby effectively improving the diversity of font design.
[0118] In some embodiments, the stroke generation model is obtained by training the machine learning model. Fig.14 As shown, during the training process, the preset information is input into the machine learning model to obtain the first stroke X * . Extract a second stroke X with a preset style from the training sample set. Use a discriminator to determine which stroke of the first stroke and the second stroke comes from the machine learning model and which stroke comes from the training sample set. Train the discriminator and the machine learning model according to the judgment result of the discriminator, and use the trained machine learning model as a stroke generation model.
[0119] In step 1303, when the total number of all strokes is greater than 1, at least one stroke among all strokes is mapped and transformed according to a preset rule to obtain a corresponding transformed stroke.
[0120] It should be noted that in the case where the target character has multiple strokes, some of the strokes in the target character can be mapped and transformed as needed, or all the strokes in the entire character can be mapped and transformed.
[0121] In step 1304, according to the stroke position relationship, a deformed font of the target character is generated using all the strokes and the transformed strokes.
[0122] In some embodiments, if n strokes out of all the strokes are mapped and transformed, and n < M, where M is the total number of all the strokes, then the M - n strokes that have not been mapped and transformed among all the strokes and the n transformed strokes are assembled according to the stroke position relationship to generate a deformed font of the target character.
[0123] In some embodiments, if all the strokes among all the strokes are mapped and transformed, then the M transformed strokes are assembled according to the stroke position relationship to generate a deformed font of the target character.
[0124] In some embodiments, when the total number of all the strokes is equal to 1, the strokes of the target character are mapped and transformed to obtain the corresponding transformed strokes. Furthermore, a deformed font of the target character is generated according to the stroke position relationship and the corresponding transformed strokes.
[0125] Fig.15 The following is a schematic structural diagram of a font generation device according to an embodiment of the present disclosure. As Fig.15 shown, the font generation device includes a first processing module 151, a second processing module 152, and a third processing module 153.
[0126] The first processing module 151 is configured to obtain all the strokes of the target character and the stroke position relationship.
[0127] In some embodiments, all the strokes of the target character and the stroke position relationship information are preset in the database, so all the strokes of the target character and the stroke position relationship can be directly obtained from the database.
[0128] In some other embodiments, the target character can also be directly analyzed to obtain all the strokes of the target character and the stroke position relationship. For example, the first processing module 151 performs connected region segmentation and recognition processing on the target character, performs stroke recognition in each connected region to obtain all the strokes of the target character, and analyzes the structure of the target character to obtain the stroke position relationship.
[0129] The second processing module 152 is configured to, when the total number of all the strokes is greater than 1, map and transform at least 1 stroke among all the strokes according to a preset rule to obtain the corresponding transformed strokes.
[0130] It should be noted that, when the target character has multiple strokes, mapping transformation may be performed on some of the strokes in the target character as needed, or mapping transformation may be performed on all the strokes in the entire character.
[0131] In some embodiments, the second processing module 152 uses a preset mapping function to perform mapping transformation processing on the strokes to be transformed to obtain transformed strokes. Through mapping transformation, the strokes can be deformed by stretching, squeezing, twisting, etc.
[0132] In some embodiments, Figure 7 As shown, the stroke to be transformed is set in the XOZ plane, and the stroke to be transformed is mapped to the YOZ plane using a preset mapping function located in the XOY plane, wherein the XOZ plane, the XOY plane and the YOZ plane are perpendicular to each other.
[0133] In some embodiments, the preset mapping function is a linear function, for example, the linear function is y=kx+b.
[0134] In some embodiments, at least one of the slope k and the intercept b of the linear function corresponding to each pixel point in the stroke to be transformed is associated with the coordinate value of each pixel point on the z-axis.
[0135] In some embodiments, in order to increase the artistic effect of the strokes, the second processing module 152 performs rolling deformation processing on the strokes to be transformed, wherein the coordinate value of the mapping point generated by each pixel in the strokes to be transformed after the rolling deformation processing is determined by the initial coordinate value of each pixel, the moving distance of the circle formed by the rolling of the strokes to be transformed, and the rotation angle of the circle.
[0136] In some embodiments, after performing rolling deformation processing on the stroke to be transformed, the second processing module 152 determines whether the mapping point falls on a preset coordinate point. If the mapping point does not fall on the preset coordinate point, the color value of the preset coordinate point is determined according to the weighted sum of the color values of all mapping points in the neighborhood of the preset coordinate point.
[0137] In some embodiments, the color values include a red value R, a green value G, and a blue value B. The weight of the color value of each mapping point is negatively correlated with the distance between each mapping point and the preset coordinate point.
[0138] In some embodiments, the second processing module 152 generates a stroke with a preset style corresponding to at least one stroke to be updated among all the strokes using a trained stroke generation model, and replaces the stroke to be updated with the stroke with the preset style.
[0139] In some embodiments, the second processing module 152 trains the machine learning model to obtain a stroke generation model. The training process can be as follows: Fig.14 shown.
[0140] The third processing module 153 is configured to generate a deformed font of the target character according to the stroke position relationship by using all the strokes and the transformed strokes.
[0141] In some embodiments, if n strokes among all the strokes are subjected to mapping transformation, and n < M, where M is the total number of all the strokes, the third processing module 153 assembles the M - n strokes that have not been subjected to mapping transformation and the n transformed strokes among all the strokes according to the stroke position relationship to generate a deformed font of the target character.
[0142] In some embodiments, if all the strokes among all the strokes are subjected to mapping transformation, the third processing module 153 assembles the M transformed strokes according to the stroke position relationship to generate a deformed font of the target character.
[0143] In some embodiments, when the total number of all the strokes is equal to 1, the third processing module 153 performs mapping transformation on the strokes of the target character to obtain the corresponding transformed strokes. Furthermore, a deformed font of the target character is generated according to the stroke position relationship and the corresponding transformed strokes.
[0144] Fig.16 This is a schematic structural diagram of a font generation device according to another embodiment of the present disclosure. As Fig.16 shown, the font generation device includes a memory 161 and a processor 162.
[0145] The memory 161 is used to store instructions. The processor 162 is coupled to the memory 161, and the processor 162 is configured to execute the methods involved in any one of the embodiments as Figure 1 , 13 described.
[0146] As Fig.16 shown, the font generation device further includes a communication interface 163 for information interaction with other devices. At the same time, the font generation device further includes a bus 164, and the processor 162, the communication interface 163, and the memory 161 complete mutual communication through the bus 164.
[0147] The memory 161 may include a high - speed RAM memory, and may also include non - volatile memory, such as at least one disk memory. The memory 161 may also be a memory array. The memory 161 may also be partitioned, and the blocks may be combined into virtual volumes according to certain rules.
[0148] In addition, the processor 162 may be a central processing unit CPU, or may be an application - specific integrated circuit ASIC, or may be one or more integrated circuits configured to implement the embodiments of the present disclosure.
[0149] The present disclosure also relates to a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, which are executed by a processor to implement the following Figure 1 , 13 The method of any one of the embodiments.
[0150] In some embodiments, the functional unit module described above can be implemented as a general-purpose processor, a programmable logic controller (PLC), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components or any appropriate combination thereof for performing the functions described in the present disclosure.
[0151] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0152] The description of the present disclosure is given for the purpose of illustration and description, and is not intended to be exhaustive or to limit the present disclosure to the disclosed form. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiments are selected and described in order to better illustrate the principles and practical applications of the present disclosure, and to enable those of ordinary skill in the art to understand the present disclosure and thereby design various embodiments with various modifications suitable for specific uses.
Claims
1. A font generation method, comprising: Obtaining all the strokes of a target character and the stroke position relationship; When the total number of all the strokes is greater than 1, performing a mapping transformation on at least 1 stroke among all the strokes according to a preset rule to obtain corresponding transformed strokes; Generating a deformed font of the target character according to the stroke position relationship, using all the strokes and the transformed strokes; Wherein, the mapping transformation includes: Setting the stroke to be transformed in a first plane; Using a preset mapping function located in a second plane to map the stroke to be transformed into a third plane to obtain the transformed stroke, wherein the first plane, the second plane and the third plane are perpendicular to each other, the preset mapping function is a linear function, and at least one of the slope and intercept of the linear function corresponding to each pixel point in the stroke to be transformed is associated with the coordinate value of each pixel point on a predetermined coordinate axis, wherein the predetermined coordinate axis is located in the first plane and the third plane.
2. The method according to claim 1, wherein: The generating the deformed font of the target character using all the strokes and the transformed strokes includes: If n strokes among all the strokes are subjected to mapping transformation, and n < M, where M is the total number of all the strokes, then assembling the M - n strokes that are not subjected to mapping transformation and the n transformed strokes among all the strokes according to the stroke position relationship to generate the deformed font of the target character.
3. The method according to claim 2, further comprising: If all the strokes among all the strokes are subjected to mapping transformation, then assembling the M transformed strokes according to the stroke position relationship to generate the deformed font of the target character.
4. The method according to claim 1, further comprising: When the total number of all the strokes is equal to 1, performing a mapping transformation on the stroke of the target character to obtain a corresponding transformed stroke; Generating the deformed font of the target character according to the stroke position relationship and the corresponding transformed stroke.
5. The method according to any one of claims 1 to 4, wherein: The mapping transformation further includes: Performing a rolling deformation process on the stroke to be transformed, wherein the coordinate value of the mapping point generated after the rolling deformation process of each pixel in the stroke to be transformed is determined by the initial coordinate value of each pixel, the moving distance of the circle formed by the rolling of the stroke to be transformed, and the rotation angle of the circle.
6. The method according to claim 5, further comprising: After performing the rolling deformation process on the stroke to be transformed, determining whether the mapping point falls on a preset coordinate point; If the mapping point does not fall on the preset coordinate point, then determining the color value of the preset coordinate point according to the weighted sum of the color values of all the mapping points in the neighborhood of the preset coordinate point.
7. The method according to claim 6, wherein, The color value includes a red R value, a green G value, and a blue B value; The weight of the color value of each mapping point is negatively correlated with the distance between each mapping point and the preset coordinate point.
8. The method according to claim 1, further comprising: Before mapping and transforming at least one of all the strokes according to the preset rules, a trained stroke generation model is used to generate a stroke with a preset style corresponding to at least one of all the strokes to be updated, and the stroke with the preset style is used to replace the stroke to be updated.
9. The method according to claim 8, further comprising: Training the machine learning model to obtain the stroke generation model; The training of the machine learning model includes: Inputting preset information into the machine learning model to obtain a first stroke; Extracting a second stroke with a preset style from the training sample set; Using a discriminator to determine which stroke of the first stroke and the second stroke comes from the training sample set; The discriminator and the machine learning model are trained according to the judgment result of the discriminator.
10. The method according to claim 1, wherein: The method of obtaining all strokes and stroke position relationships of the target character includes: All strokes and stroke position relationships of the target character are obtained from a database.
11. The method according to claim 1, wherein: The method of obtaining all strokes and stroke position relationships of the target character includes: Performing connected region segmentation and recognition processing on the target word; Performing stroke recognition in each connected region to obtain all strokes of the target character; The structure of the target character is analyzed to obtain the stroke position relationship of the target character.
12. A font generation device, comprising: A first processing module is configured to obtain all strokes and stroke position relationships of a target character; The second processing module is configured to map and transform at least one stroke of the strokes according to a preset rule to obtain a corresponding transformed stroke when the total number of the strokes is greater than 1, wherein the mapping and transformation comprises: arranging the stroke to be transformed in a first plane, and mapping the stroke to be transformed to a third plane using a preset mapping function located in a second plane to obtain the transformed stroke, wherein the first plane, the second plane and the third plane are perpendicular to each other, the preset mapping function is a linear function, and at least one of a slope and an intercept of the linear function corresponding to each pixel point in the stroke to be transformed is associated with a coordinate value of each pixel point on a predetermined coordinate axis, wherein the predetermined coordinate axis is located in the first plane and the third plane; The third processing module is configured to generate a deformed font of the target character by using all the strokes and the transformed strokes according to the stroke position relationship.
13. A font generation device, comprising: a memory configured to store instructions; A processor is coupled to the memory, and the processor is configured to execute the method according to any one of claims 1 to 11 based on instructions stored in the memory.
14. A computer-readable storage medium, wherein: The computer-readable storage medium stores computer instructions, and when the instructions are executed by a processor, the method according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
Method and system for converting Chinese character fonts in image, computer equipment and medium
CN110135530A