Chinese vector font generation method and system
Through the component affine transformation regressor model and detailed classification of font component data sets, the problems of low efficiency, low quality and limited scalability of Chinese vector font design in the prior art are solved, and high-efficiency and high-quality large-scale Chinese is achieved Vector font generation improves design efficiency and visual quality.
Patent Information
- Application Number
- CN202411175096.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2024-12-10
AI Technical Summary
The existing Chinese vector font design method is inefficient, low quality and limited scalability when processing large-scale Chinese characters. It is unable to effectively deal with large-scale Chinese character sets with complex structures, and it is also difficult to effectively deal with subtle aesthetic differences, character overlap and center of mass equalization layout. There are limitations in terms of aspects and it is difficult to meet professional standards.
Using the component affine transformation regressor model, the affine transformation matrix is calculated through feature extraction, fusion and regression, combined with the detailed classification of font component data sets, generate efficient and high-quality large-scale Chinese vector fonts, and use the Glyphs plug-in to achieve automated font synthesis , allowing designers to adjust and optimize.
It realizes efficient and high-quality large-scale Chinese vector font generation, significantly improving design efficiency and visual quality, and reducing hand-made time and cost.
Smart Images

Figure CN119106656A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Chinese vector font design, and in particular to a Chinese vector font generation method and system. Background Art
[0002] The design of Chinese vector fonts involves many characters and has a complex structure, so the design process is time-consuming and costly. Figure 1 As shown in the figure, the traditional font design process often relies on manual drawing by designers, which is particularly cumbersome when faced with more than 90,000 Chinese characters. In addition, although existing automatic font generation methods have made certain progress in simplifying the design process and reducing costs, most methods focus on font style transfer and the generation of a small number of characters, and cannot effectively handle large-scale Chinese character sets with complex structures. For example, although image-based methods can simulate specific font styles at the pixel level, the results they generate are often limited to bitmap formats and cannot be directly applied to vector font design. In addition, they often fail to meet commercial requirements in terms of font details and style consistency. On the other hand, although existing vector-based methods can directly generate fonts in vector format, these methods are often limited to processing simple characters and face great challenges in learning complex character structures, making it difficult to expand to large-scale Chinese character generation.
[0003] In addition, existing technologies also show limitations in dealing with subtle aesthetic differences in fonts, overlapping issues between characters, and balanced layout of character centroids. These technical limitations make it difficult for the generated fonts to meet professional standards in terms of visual quality, and for designers, there is a lack of sufficient editing space for later adjustments and optimizations.
[0004] In summary, the existing methods for automatic generation of Chinese vector fonts have deficiencies in efficiency, quality and scalability. A new solution is urgently needed to support efficient, high-quality and large-scale generation of Chinese vector fonts. Summary of the invention
[0005] The object of the present invention is to provide a method and system for generating Chinese vector fonts to solve at least one technical problem existing in the above-mentioned background technology.
[0006] In order to achieve the above object, the present invention adopts the following technical solutions:
[0007] In a first aspect, the present invention provides a method for generating a Chinese vector font, comprising:
[0008] Get the character's component and layout type information;
[0009] The obtained character components and layout type information are processed using a pre-trained component affine transformation regressor model to obtain the corresponding character; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract the component features of the character; the feature fusion module is used to fuse the features of the character components as the input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
[0010] Further, training the component affine transformation regressor model includes: using the affine transformation matrix of the component affine transformation regressor, applying the affine transformation matrix to the corresponding component to generate a transformed version with appropriate scale and position; the transformed components are merged to generate the final Chinese character; wherein the entire training process is trained in the image space, and in the inference stage, the affine transformation can be directly applied to the vector font;
[0011] During the training process, specific training and adjustment strategies are used for different layout types to ensure that the component affine transformation regressor can effectively handle various complex character structures; the component images are randomly flipped and input into the component affine transformation regressor for training.
[0012] Furthermore, for the left-right layout type, the component affine transformation regressor is trained from scratch, but the feature extractor is initialized with pre-trained parameters; for the top-down layout type, the characters of the upper and lower structures distribute the components in the vertical direction, which requires the model to be able to flexibly adjust the vertical alignment of the components; first, the model parameters obtained from the left-right structure training are used as the pre-training basis; then the conversion module is introduced, which exchanges the parameters in the affine transformation matrix that control horizontal and vertical scaling and translation, so that the transformation originally for the left-right layout is applicable to the upper and lower layout; for the fully enclosed structure, additional weights for the center of mass and inertia loss are added to enable CAR to converge faster; for the left-center-right structure and the top-center-bottom structure, an iterative calling strategy is adopted, that is, first synthesizing two components to form an intermediate product, and then synthesizing the third component into it.
[0013] Furthermore, the loss function L used in model training is:
[0014] L=αL pixel +βL overlap +γL cent +θL inertia
[0015] Among them, L pixel represents pixel loss, α represents the weight of pixel loss; L overlaprepresents the overlap loss, β represents the weight of the overlap loss; L cent represents the centroid loss, γ represents the weight of the centroid loss; L inertia represents the inertia loss, and θ represents the weight of the inertia loss.
[0016] Furthermore, the pixel loss is calculated to measure the difference between the synthesized character S and the real character C:
[0017] L pixel =D(S,C)
[0018] Where D represents the L1 distance.
[0019] Furthermore, the overlap loss is:
[0020]
[0021] Where S(x,y) represents the pixel value of S. In the case of two components being synthesized, a pixel value greater than 1 indicates that the two components overlap at that position.
[0022] Furthermore, the center of gravity loss is:
[0023]
[0024] Where Φ represents the original moment:
[0025] Φ(I,i,j)=∑ x,y I(x,y)x i y j .
[0026] Furthermore, the inertia loss is: L inertia =D(Ψ(S),Ψ(C)); where Ψ represents inertia, which is calculated as follows:
[0027]
[0028] The inertial loss regulates the shape and bounding box of the synthesized characters.
[0029] In a second aspect, the present invention provides a Chinese vector font generation system, comprising:
[0030] The acquisition module is used to obtain the component and layout type information of the character;
[0031] A processing module is used to process the acquired character component and layout type information using a pre-trained component affine transformation regressor model to obtain the corresponding character; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract the component features of the character; the feature fusion module is used to fuse the features of the character components as the input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
[0032] In a third aspect, the present invention provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium is used to store computer instructions, and when the computer instructions are executed by a processor, the Chinese vector font generation method as described in the first aspect is implemented.
[0033] In a fourth aspect, the present invention provides a computer device comprising a memory and a processor, wherein the processor and the memory communicate with each other, the memory stores program instructions executable by the processor, and the processor calls the program instructions to execute the Chinese vector font generation method as described in the first aspect.
[0034] In a fifth aspect, the present invention provides an electronic device, comprising: a processor, a memory and a computer program; wherein the processor is connected to the memory, the computer program is stored in the memory, and when the electronic device is running, the processor executes the computer program stored in the memory so that the electronic device executes instructions for implementing the Chinese vector font generation method as described in the first aspect.
[0035] The beneficial effects of the present invention are as follows: by learning affine transformation parameters and performing affine transformation on the Bezier curve of a vector font component, vector Chinese characters can be directly generated; the generated Chinese characters can meet the requirements of font design tasks; by combining character components based on a large-scale Chinese font component data set, complex vector Chinese characters can be synthesized, efficient and large-scale Chinese vector font generation can be achieved, and the speed of Chinese font design is improved.
[0036] Additional advantages of the present invention will be more clearly given in the following description or learned through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0038] Figure 1 Design a flow chart for traditional Chinese vector font.
[0039] Figure 2 This is a flow chart of a method for generating a Chinese vector font according to an embodiment of the present invention.
[0040] Figure 3 Schematic diagram of the structure of the Chinese character data set described in an embodiment of the present invention.
[0041] Figure 4 Schematic diagram of six main Chinese character layout types described in an embodiment of the present invention.
[0042] Figure 5 Schematic diagram of the overall architecture of the affine transformation regressor model described in an embodiment of the present invention. DETAILED DESCRIPTION
[0043] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements with the same or similar functions. The embodiments described below by the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be interpreted as limiting the present invention.
[0044] It should be understood by those skilled in the art that unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those skilled in the art to which this invention belongs.
[0045] It should also be understood that terms, such as those defined in commonly used dictionaries, should be understood to have a meaning consistent with that in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless as defined herein.
[0046] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements and / or groups thereof.
[0047] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. Different embodiments or examples described in this specification and features of different embodiments or examples may be combined and combined by those skilled in the art without contradiction.
[0048] To facilitate understanding of the present invention, the present invention is further explained below with reference to specific embodiments in conjunction with the accompanying drawings, and the specific embodiments do not constitute a limitation on the embodiments of the present invention.
[0049] Those skilled in the art should understand that the drawings are merely schematic diagrams of embodiments, and the components in the drawings are not necessarily necessary for implementing the present invention.
[0050] The present invention aims to solve many technical problems in the existing Chinese vector font design. First, the Chinese vector font design involves a large number of characters and a complex structure. The traditional manual drawing method is time-consuming and costly. In the face of more than 90,000 Chinese characters, this process is particularly cumbersome. In addition, although the existing automatic font generation methods have made certain progress in simplifying the design process and reducing costs, most methods are mainly focused on font style migration and the generation of a small number of characters, and cannot effectively handle large-scale Chinese character sets with complex structures. For example, although image-based methods can simulate specific font styles at the pixel level, the generated results are often limited to bitmap formats and cannot be directly applied to vector font design, and often cannot meet commercial requirements in terms of font details and style consistency. On the other hand, although existing vector-based methods can directly generate fonts in vector format, these methods are usually limited to processing simple characters, and face greater challenges in learning complex character structures, and are difficult to expand to large-scale Chinese character generation. In addition, the existing technology also shows limitations in dealing with subtle aesthetic differences in fonts, overlapping problems between characters, and balanced layout of character centroids. These technical limitations make it difficult for the generated fonts to meet professional standards in terms of visual quality, and for designers, there is a lack of sufficient editing space for later adjustment and optimization.
[0051] In order to solve the above problems, the present invention constructs a Chinese vector font generation method based on component combination. Through the component affine transformation regressor and the detailed classified font component data set, the problems of low efficiency, low generation quality and limited scalability in the existing methods when generating large-scale complex Chinese characters are solved. The font component data set covers more than 90,000 Chinese characters and their constituent components and layout information, so that characters of each layout type can be accurately synthesized. The component affine transformation regressor (CAR) performs affine transformation on font components through deep learning, and outputs transformation parameters for character synthesis to ensure the consistency and aesthetics of the generated characters. The Glyphs plug-in integrates CAR and font component data sets into the Glyphs font design software to realize automatic font synthesis, significantly improve the efficiency and quality of font design, and allow designers to further adjust and optimize the synthesized characters, thereby greatly reducing the time and cost of manual production.
[0052] Example 1
[0053] In this embodiment 1, a Chinese vector font generation system is first provided, including: an acquisition module for acquiring component and layout type information of characters. A processing module for processing the acquired component and layout type information of characters using a pre-trained component affine transformation regressor model to obtain corresponding characters; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract component features of characters; the feature fusion module is used to fuse the features of character components as input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
[0054] In this embodiment, the above-mentioned system is used to implement a Chinese vector font generation method, including: obtaining component and layout type information of characters; using a pre-trained component affine transformation regressor model to process the obtained component and layout type information of characters to obtain corresponding characters; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract component features of characters; the feature fusion module is used to fuse the features of character components as input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which is superimposed to create the final character.
[0055] Wherein, training the component affine transformation regressor model includes: using the affine transformation matrix of the component affine transformation regressor, applying the affine transformation matrix to the corresponding component to generate a transformed version with appropriate scale and position; the transformed components are merged to generate the final Chinese character; wherein the entire training process is trained in the image space, and in the inference stage, the affine transformation can be directly applied to the vector font;
[0056] During the training process, specific training and adjustment strategies are used for different layout types to ensure that the component affine transformation regressor can effectively handle various complex character structures; the component images are randomly flipped and input into the component affine transformation regressor for training.
[0057] For the left-right layout type, the component affine transformation regressor is trained from scratch, but the feature extractor is initialized with pre-trained parameters;
[0058] For the top-down layout type, the characters of the top-bottom structure distribute the components in the vertical direction, which requires the model to be able to flexibly adjust the vertical alignment of the components. First, the model parameters obtained by left-right structure training are used as the pre-training basis. Then, the conversion module is introduced. This module exchanges the parameters controlling horizontal and vertical scaling and translation in the affine transformation matrix, so that the transformation originally for the left-right layout is applicable to the top-bottom layout.
[0059] For the fully enclosed structure, additional weights of the center of mass and inertia loss are added to enable CAR to converge faster;
[0060] For the left-middle-right structure and the top-middle-bottom structure, an iterative calling strategy is adopted, that is, first synthesizing two components to form an intermediate product, and then synthesizing the third component into it.
[0061] The loss function L used in model training is:
[0062] L=αL pixel +βL overlap +γL cent +θL inertia
[0063] Among them, L pixel represents pixel loss, α represents the weight of pixel loss; L overlap represents the overlap loss, β represents the weight of the overlap loss; L cent represents the centroid loss, γ represents the weight of the centroid loss; L inertia represents the inertia loss, and θ represents the weight of the inertia loss.
[0064] Among them, the pixel loss is calculated to measure the difference between the synthesized character S and the real character C:
[0065] L pixel=D(S,C)
[0066] Where D represents the L1 distance.
[0067] The overlap loss is:
[0068]
[0069] Where S(x,y) represents the pixel value of S. In the case of two components being synthesized, a pixel value greater than 1 indicates that the two components overlap at that position.
[0070] The center of gravity loss is:
[0071]
[0072] Where Φ represents the original moment:
[0073] Φ(I,i,j)=Σ x,y I(x,y)x i y j .
[0074] The inertia loss is: L inertia =D(Ψ(S),Ψ(C)); where Ψ represents inertia, which is calculated as follows:
[0075]
[0076] The inertial loss regulates the shape and bounding box of the synthesized characters.
[0077] Example 2
[0078] like Figures 2 to 5 As shown, this embodiment provides a Chinese vector Chinese character generation method based on component combination, which is used to solve the problems of low efficiency, low generation quality and limited scalability in the existing methods when generating large-scale complex Chinese characters, and promote the development of Chinese font design.
[0079] In this embodiment, a large-scale Chinese vector font generation method based on component combination includes: a font component data set, which contains more than 90,000 Chinese characters and their constituent components and layout information, and each character stores and annotates the basic components that constitute the character and its corresponding layout structure; a component affine transformation regressor, which is a deep learning network model that can perform regression learning of affine transformation on input font components and output affine transformation parameters for character components; a Glyphs plug-in, which integrates a component affine transformation regressor (CAR) and a font component data set into the font design software Glyphs, thereby enabling users to directly call the CAR model combination and generate vector fonts through a software interface.
[0080] The font component dataset classifies and annotates the six basic layouts of Chinese characters in detail, including independent (single character), left-right structure (components distributed left and right), top-bottom structure (components arranged top-bottom), surrounding structure (such as the shape of a circle), left-center-right structure (three components arranged horizontally), and top-center-bottom structure (three components arranged vertically), to ensure that characters of each layout type can be accurately synthesized through the corresponding components.
[0081] The component affine transformation regressor (CAR) includes a feature extractor, a feature fusion module, and a regressor module, wherein the feature fusion module can fuse features of different components for use by the regressor to improve the consistency and accuracy of the generated font.
[0082] The feature fusion module can adopt a variety of feature fusion strategies, including but not limited to stacking, adaptive instance normalization (AdaIN), cross attention and spatial position adaptive denormalization (SPADE), to adapt to different font design requirements.
[0083] The component affine transformation regressor (CAR) includes a parameter adjustment mechanism specific to different character layouts (such as left-right structure, top-bottom structure). For example, for top-bottom structure characters, a switcher module is applied to adapt the affine transformation learning from the left-right structure pre-training model to the top-bottom structure characters. The component affine transformation regressor (CAR) includes multiple loss functions for optimizing the learning process of affine transformation, including pixel-level loss, overlap loss, center of mass loss and inertia loss to ensure the visual quality of generated characters. The Glyphs plug-in can integrate the component affine transformation regressor (CAR) and the font component dataset into the Glyphs font design software to achieve automatic font synthesis.
[0084] In this embodiment, a generation device for generating large-scale Chinese vector fonts is also provided, which is implemented by a Glyphs plug-in. The following steps are included: selecting a target character; retrieving the component components and layout information of the target character from a font component data set; using a component affine transformation regressor (CAR) to generate affine transformation parameters of the target character according to the retrieved components and layout information; applying the generated affine transformation parameters to the corresponding font components to synthesize the target character; and further editing and optimizing the synthesized character through the Glyphs software to meet the specific requirements of the designer.
[0085] Component-based Chinese Vector Font Generation Method, including the construction of a Chinese character dataset, the training of a component affine transformation regressor, and a Glyphs plugin. Compared with conventional manual font design, this method can generate large-scale Chinese vector fonts more automatically for font design. The process of the Chinese vector font generation method based on component combination is as Figure 2 shown, including:
[0086] S1: Construction of the Chinese character dataset.
[0087] Figure 3 is the structure of the Chinese character dataset. The dataset covers more than 90,000 Chinese characters encoded in Unicode, including common and rare characters. This dataset is used to support the automatic generation of Chinese vector fonts, especially for efficient font design through component reuse.
[0088] S11: Annotation of components and layouts
[0089] Define components and layouts: For each character, label its basic components and their layout types in the character. Chinese characters are usually composed of multiple components, which are reused in different characters, and radicals belong to a subset of components. For example, for example, 女 (the left half) and 夭 (the right half) are both regarded as components of 妖. The layout types are divided into six main categories: isolated (NL00), left-right structure (NL01), up-down structure (NL02), fully enclosed structure (NL03), left-middle-right structure (NL04), and up-middle-down structure (NL05). NL03 includes eight different sub-layouts. The layout types are as Figure 4 shown.
[0090] Extract all Chinese characters from the Unicode standard and arrange them in Unicode encoding order, a total of 92,560 characters. The Chinese characters encoded in Unicode are arranged in their Unicode order in sequence, with a total of 92,560 characters. Combining Figure 3 shown, the first column of the dataset represents the character ID; the second column shows the character itself; the third column lists the Unicode of the character; the fourth column provides component information; the fifth column describes the layout of the character; and the sixth to eighth columns show the decomposed components. Note that some Chinese characters use more than two components. When a character needs to combine more components, different structures are nested together and labeled as "nested". As Figure 3 shown, the character with ID = 2 nests a left-right layout in a top-bottom layout. The information of the dataset is annotated with component and layout information through crowdsourcing, and all participants need to receive training on how to identify components and layouts. Random spot checks and expert reviews are used to ensure the accuracy and consistency of the annotation.
[0091] S12: Application of the dataset
[0092] This dataset provides detailed component and layout information, allowing the component affine transformation regressor (CAR) to generate corresponding affine transformation parameters and control the Bezier curves of the components to facilitate character synthesis.
[0093] S2: Development and training of component affine transformation regressor model (CAR)
[0094] This step details the design, training, and application of the component-radio regressor (CAR), which can automatically synthesize high-quality Chinese vector characters by learning the affine transformation relationship between components based on pre-defined components and layout information.
[0095] S21: Construction of model architecture
[0096] For a character C with components R1, R2, CAR generates a composite character S by merging the transformed components. This model is similar to the spatial transformer network, which is used to regress the component affine transformation matrix. Figure 5 The model architecture is shown. The model consists of three modules: feature extractor, fusion module, and regressor. The feature extractor is used to extract component features, which can be any backbone structure. For simplicity, the classic model VGG19-bn pre-trained on ImageNet is chosen here. Different components share parameters. The feature fusion module fuses the features of the components as input to the regressor. The intuition behind the fusion module is that the regressor needs to know the information of all components in order to provide a suitable transformation prediction for the current component. Regarding the fusion strategy, Stack, AdaIN, and CrossAttention are all supported. The performance of these fusion strategies varies slightly for different layouts. The regressor takes the fused component features as input and calculates the affine transformation matrix. The regressor is an n-layer multi-layer perceptron network with a special initialization for the last linear layer. The weights are set to zero and the bias term receives a standard affine transformation. This initialization ensures that our model initially performs the same transformation and gradually improves as training progresses. The resulting affine transformation matrix is applied to the component images to obtain the transformed images, which are superimposed to create the final character.
[0097] S22: Training details
[0098] First, the affine transformation matrix of the component affine transformation regressor (CAR) is used, and then the affine transformation matrix is applied to the corresponding components to produce a transformed version with appropriate scale and position. Finally, these transformed components are merged to generate the final Chinese character. The entire training process is trained in image space, and in the inference stage, the affine transformation can be directly applied to the vector font.
[0099] During the training process, specific training and adjustment strategies are designed and implemented for different layout types (NL01 to NL05) to ensure that the component affine transformation regressor (CAR) can effectively handle various complex character structures. For component images, randomly flip them and input them into CAR for training. The following describes the processing details of these layouts in detail:
[0100] For NL01 (left-right architecture), CAR is trained from scratch, but the feature extractor is initialized with pre-trained parameters.
[0101] For NL02 (top-down), the characters of the top-bottom structure distribute the components in the vertical direction, which requires the model to be able to flexibly adjust the vertical alignment of the components. First, the model parameters obtained by training the left-right structure (NL01) are used as the pre-training basis. Then the switcher module is introduced, which makes the transformation originally for the left-right layout applicable to the top-bottom layout by exchanging the parameters that control the horizontal and vertical scaling and translation in the affine transformation matrix.
[0102] For NL03 (fully enclosed structure), additional weights of center of mass and inertia loss are added to enable CAR to converge faster.
[0103] For three-component structures such as NL04 (left-middle-right structure) and NL05 (upper-middle-lower structure), an iterative calling strategy is adopted, that is, two components are synthesized to form an intermediate product, and then the third component is synthesized. This strategy helps to gradually and accurately adjust the position and size of each component. Using the already trained CAR models of the left-right structure (NL01) and the upper-lower structure (NL02), through iterative calling, the need for training from scratch is reduced, and the training efficiency and the generalization ability of the model are improved.
[0104] S23: Design of loss function
[0105] In order to ensure the quality of synthesized Chinese characters, several corresponding loss functions are designed
[0106] First, the pixel loss is calculated to measure the difference between the synthesized character S and the real character:
[0107] L pixel =D(S,C)
[0108] Where D represents the L1 distance.
[0109] The affine transformation matrix is initialized with the identity matrix so that the components may have a large overlap at the beginning of the training cycle. Therefore, the pixel loss L pixelcontribute a lot in the beginning. However, as the network converges, the overlap area becomes smaller and the pixel loss decreases accordingly, causing the components to no longer move away from each other. To solve this problem and make each component move in the right direction, an overlap loss is added:
[0110]
[0111] Where S(x,y) represents the pixel value of S. In the case of two components being synthesized, a pixel value greater than 1 indicates that the two components overlap at that position. In addition, the ideal synthesized character S should share the same center of gravity position with the actual character C to ensure the balance of the synthesized character. To this end, the center of gravity loss is introduced:
[0112]
[0113] Where Φ represents the original moment:
[0114] Φ(I,i,j)=Σ x,y I(x,y)x i y j
[0115] In order to ensure that the distance from each pixel of the synthesized character S to the center of mass is the same as the actual value C, the second-order central moment, i.e., inertia loss, is introduced:
[0116] L inertia =D(Ψ(S),Ψ(C))
[0117] Among them, Ψ represents inertia, which is calculated as follows:
[0118]
[0119] In actual training, the inertial loss regulates the shape and bounding box of the synthesized characters.
[0120] Then, the final loss function is defined as follows:
[0121]
[0122] Among them, lowercase Greek letters represent the weight of the loss.
[0123] S3: Glyphs plugin for automated font generation.
[0124] In this embodiment, the function of the Glyphs plug-in is to integrate the Chinese character dataset and the component affine transformation regressor (CAR) into the font design software, allowing designers to directly use the trained component affine transformation regressor (CAR) to generate characters in Glyphs, greatly improving the efficiency of font design. The pseudo code of the Glyphs plug-in is in Figure 5 The specific steps are as follows:
[0125] S31: Create an empty glyph object
[0126] S311: Use the Glyphs API to create a new GSGlyph object, which represents a character to be generated.
[0127] S312: Access the first layer of the GSGlyph object, because the glyphs in Glyphs may contain multiple layers, each layer can be used for different designs or glyph states. :
[0128] S32: For each component and the corresponding affine transformation matrix
[0129] S321: Use Python's zip function to combine each component name and its corresponding affine transformation matrix.
[0130] S322: Convert the PyTorch-style affine transformation matrix into a format that Glyphs can understand through the custom conversion function translate(affineT).
[0131] S33: Transformation of application components
[0132] S331: Create a GSComponent object as a part of the character and specify its name.
[0133] S332: Add the GSComponent object to the corresponding layer of the GSGlyph object.
[0134] S333: If necessary, split the single-step affine transformation into two steps: translation and scaling.
[0135] S34: Applying position transformation and scaling
[0136] S341: Call comp.applyTransform() method to apply translation transformation and adjust component position.
[0137] S342: Use calcOffset(comp) to calculate the offset to the correct position.
[0138] S343: Apply scaling transformation and correct position offset.
[0139] S35: Complete glyph construction
[0140] S551: For the transformed component, call the applyTransform() method to move the component to its correct position to complete the synthesis of the character.
[0141] In summary, the character generation method described in this embodiment can generate complex Chinese characters using font components and layout data sets. The component affine transformation regressor is used to operate the Bezier curve of the component to directly generate a Chinese vector font. Compared with bitmaps, vector fonts can be better applied to font design. Using the developed Glyphs plug-in, the method can be applied to the professional process of Chinese font design, which speeds up the speed of Chinese font design.
[0142] Example 3
[0143] This embodiment 3 provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium is used to store computer instructions. When the computer instructions are executed by a processor, the method for generating a Chinese vector font as described above is implemented. The method includes:
[0144] Get the character's component and layout type information;
[0145] The obtained character components and layout type information are processed using a pre-trained component affine transformation regressor model to obtain the corresponding character; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract the component features of the character; the feature fusion module is used to fuse the features of the character components as the input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
[0146] Example 4
[0147] This embodiment 4 provides a computer device, including a memory and a processor, the processor and the memory communicate with each other, the memory stores program instructions executable by the processor, the processor calls the program instructions to execute the above-mentioned Chinese vector font generation method, the method comprising:
[0148] Get the character's component and layout type information;
[0149] The obtained character components and layout type information are processed using a pre-trained component affine transformation regressor model to obtain the corresponding character; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract the component features of the character; the feature fusion module is used to fuse the features of the character components as the input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
[0150] Example 5
[0151] This embodiment 5 provides an electronic device, including: a processor, a memory, and a computer program; wherein the processor is connected to the memory, the computer program is stored in the memory, and when the electronic device is running, the processor executes the computer program stored in the memory to enable the electronic device to execute instructions for implementing the above-mentioned Chinese vector font generation method, the method comprising:
[0152] Get the character's component and layout type information;
[0153] The obtained character components and layout type information are processed using a pre-trained component affine transformation regressor model to obtain the corresponding character; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract the component features of the character; the feature fusion module is used to fuse the features of the character components as the input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
[0154] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0155] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0156] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0157] These computer program instructions can also be loaded onto a computer or other programmable data processing device, and a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0158] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art without creative work on the basis of the technical solution disclosed in the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for generating a Chinese vector font, characterized in that: include: Get the character's component and layout type information; The obtained character components and layout type information are processed using a pre-trained component affine transformation regressor model to obtain the corresponding character; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract the component features of the character; the feature fusion module is used to fuse the features of the character components as the input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
2. The Chinese vector font generation method according to claim 1, characterized in that: Training the component affine transformation regressor model includes: using the affine transformation matrix of the component affine transformation regressor, applying the affine transformation matrix to the corresponding component to generate a transformed version with appropriate scale and position; the transformed components are merged to generate the final Chinese character; wherein the entire training process is trained in the image space, and in the inference stage, the affine transformation can be directly applied to the vector font; During the training process, specific training and adjustment strategies are used for different layout types to ensure that the component affine transformation regressor can effectively handle various complex character structures; the component images are randomly flipped and input into the component affine transformation regressor for training.
3. The Chinese vector font generation method according to claim 2, characterized in that: For the left-right layout type, the component affine transformation regressor is trained from scratch, but the feature extractor is initialized with pre-trained parameters; For the top-down layout type, the characters of the top-bottom structure distribute the components in the vertical direction, which requires the model to be able to flexibly adjust the vertical alignment of the components. First, the model parameters obtained by left-right structure training are used as the pre-training basis. Then, the conversion module is introduced. This module exchanges the parameters controlling horizontal and vertical scaling and translation in the affine transformation matrix, so that the transformation originally for the left-right layout is applicable to the top-bottom layout. For the fully enclosed structure, additional weights of the center of mass and inertia loss are added to enable CAR to converge faster; For the left-middle-right structure and the top-middle-bottom structure, an iterative calling strategy is adopted, that is, first synthesizing two components to form an intermediate product, and then synthesizing the third component into it.
4. The Chinese vector font generation method according to claim 2, characterized in that: The loss function L used in model training is: Among them, L pixel represents pixel loss, α represents the weight of pixel loss; L overlap represents the overlap loss, β represents the weight of the overlap loss; L cent represents the centroid loss, γ represents the weight of the centroid loss; L inertia represents the inertia loss, and θ represents the weight of the inertia loss.
5. The Chinese vector font generation method according to claim 4, characterized in that: The pixel loss is calculated to measure the difference between the synthesized character S and the real character C: L pixel =D(S,C) Where D represents the L1 distance.
6. The Chinese vector font generation method according to claim 4, characterized in that: The overlap loss is: Where S(x,y) represents the pixel value of S. In the case of two components being synthesized, a pixel value greater than 1 indicates that the two components overlap at that position.
7. The Chinese vector font generation method according to claim 4, characterized in that: The center of gravity loss is: Where Φ represents the original moment: Φ(I,i,j)=Σ x,y I(x,y)x i y j 。 8. The method for generating Chinese vector fonts according to claim 4, characterized in that: The inertia loss is: L inertia =D(Ψ(S),Ψ(C)); where Ψ represents inertia, which is calculated as follows: The inertial loss regulates the shape and bounding box of the synthesized characters.
9. A Chinese vector font generation system, characterized in that: include: The acquisition module is used to obtain the component and layout type information of the character; A processing module is used to process the acquired character component and layout type information using a pre-trained component affine transformation regressor model to obtain the corresponding character; wherein the component affine transformation regressor model includes a feature extractor, a feature fusion module and a regressor; the feature extractor is used to extract the component features of the character; the feature fusion module is used to fuse the features of the character components as the input of the regressor; the regressor takes the fused component features as input, calculates the affine transformation matrix, and applies the obtained affine transformation matrix to the component image to obtain the transformed image, which are superimposed to create the final character.
10. An electronic device, characterized in that: include: A processor, a memory and a computer program; wherein the processor is connected to the memory, the computer program is stored in the memory, and when the electronic device is running, the processor executes the computer program stored in the memory so that the electronic device executes instructions for implementing the Chinese vector font generation method as described in any one of claims 1-8.
Citation Information
Cited By
Hierarchical layout driven random shape scene text image generation method, system and device and medium
CN120070666A
