Font generation method and device, computer equipment and storage medium
By building training data sets and training font generation models, extracting and optimizing the structure and stroke characteristics of fonts, the problems of low efficiency, single style and insufficient intelligence in traditional font design are solved, and efficient, diversified and innovative font generation is achieved.
Patent Information
- Application Number
- CN202411841706.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-04-29
AI Technical Summary
There are problems in the traditional font design process of inefficient, single style and insufficient intelligence. Especially when designing fonts with unique cultural characteristics, it is difficult to achieve efficient, diversified and innovative font generation.
By constructing a training data set, including multiple font images of the same style, structure and stroke analysis are performed, structural features and stroke features are extracted as font labels, the initial model is trained and the font generation model is optimized, and the target font image corresponding to the target text is output.
It realizes the accuracy and efficiency of the font generation process, can highly restore different historical font styles, improves font creation efficiency, ensures the diversity and innovation of generated fonts, and is suitable for a variety of application scenarios.
Smart Images

Figure CN119904542A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to a font generation method, device, computer equipment and storage medium. Background Art
[0002] In the traditional font design process, font designers need to manually draw and digitize the font style and make complex visual adjustments to ensure that the font has good visual effects and readability in various application scenarios. However, this process often requires a lot of manpower, time and expertise, especially for fonts with unique cultural characteristics (such as ancient Chinese characters), the design and re-creation is even more difficult. The main shortcomings of the existing technology in the field of font design are manifested in the following aspects:
[0003] Font design is inefficient. The traditional manual design process involves a lot of repetitive labor. Designers need to draw and adjust the shape of each character one by one, which greatly limits the speed of font development.
[0004] The diversity of font styles is difficult to maintain. Currently, a large number of digital fonts or standardized templates on the market tend to be single in form and lack innovation and culture.
[0005] Existing technologies are deficient in intelligent design and automatic adjustment. Although computer-aided design and font generation tools have alleviated the need for manual adjustment to a certain extent in recent years, these tools still rely on designers to manually input a large number of parameters and lack the ability to intelligently recognize and learn different font features, resulting in the need for repeated adjustments of fonts in different application scenarios. Summary of the invention
[0006] In view of this, the present disclosure proposes a font generation method, device, computer equipment and storage medium to solve the problems of low font efficiency, single style and lack of intelligence in the traditional font design process.
[0007] The first aspect of the present disclosure provides a font generation method, the method comprising:
[0008] Constructing a training data set, wherein the training data set includes a plurality of font images of the same style;
[0009] For any one of the multiple font images, perform structural analysis on the font image to obtain structural features of the font image; the structural features include characters, components, strokes and pen shapes of the font;
[0010] Performing a stroke analysis on the font image to obtain stroke features of the font image; the stroke features are used to characterize the thickness, straightness, density, and wetness of the font lines;
[0011] Using the structural features and the stroke features as font labels of the font image;
[0012] The initial model is trained and optimized through multiple font images and the font label of each font image to obtain a font generation model;
[0013] The target font image corresponding to the target text is outputted through the font generation model.
[0014] The disclosed implementation uses the structural features and stroke features of the font as the font labels of the font image, and trains and optimizes the initial model through multiple font images and the font label of each font image to obtain a font generation model, which can make the font generation process more accurate and efficient, and highly restore different historical font styles in terms of structure and stroke details.
[0015] In the disclosed embodiment, the initial model is trained and optimized through multiple font images and the font label of each font image to obtain a font generation model, including:
[0016] Identifying an original weight matrix to be fine-tuned in the initial model;
[0017] Superimposing the low-rank matrix onto the original weight matrix to obtain a fine-tuned initial model;
[0018] The fine-tuned initial model is trained and optimized using multiple font images and the font label of each font image to obtain a font generation model; during the model optimization process, the parameters of the low-rank matrix are updated, and the parameters of the original weight matrix are kept unchanged.
[0019] In the embodiment of the present disclosure, outputting a target font image corresponding to the target text through the font generation model includes:
[0020] In the process of the font generation model generating the target font image, calling the edge control model to generate a depth map corresponding to the first font image; the font pixels in the depth map are associated with a first depth value, and other pixels in the depth map are associated with a second depth value; the first depth value is different from the second depth value;
[0021] According to the depth relationship between the font pixel and other pixel points in the depth map, the font structure in the first font image is controlled to obtain the target font image.
[0022] In the embodiment of the present disclosure, constructing a training data set includes:
[0023] Acquire multiple original images of the same style; the original images include images of stone tablets and images of oracle bones;
[0024] For any one of the multiple original images, binarization processing is performed on the original image to obtain a binary image;
[0025] Performing vectorization processing on the binary image, and performing image segmentation on the vectorized image according to fonts to obtain a plurality of font images, each font image corresponding to a font in the vectorized image;
[0026] The training data set is constructed according to a plurality of font images corresponding to the plurality of original images.
[0027] In the embodiment of the present disclosure, after constructing the training data set, the method further includes:
[0028] For any one of the multiple font images, performing a font structure integrity analysis on the font image to obtain a font structure integrity analysis result, and performing a font clarity analysis on the font image to obtain a font clarity analysis result;
[0029] If the font structure integrity analysis result does not meet the first preset requirement, the font image is removed from the training data set;
[0030] If the font clarity analysis result does not meet the second preset requirement, the font image is removed from the training data set.
[0031] In the embodiment of the present disclosure, after outputting the target font image corresponding to the target text through the font generation model, the method further includes:
[0032] Performing a structural comparison between the target font image and the reference font image, judging whether there is a stroke error in the target font image according to the structural comparison result, and if so, re-outputting a second font image corresponding to the target text through the font generation model;
[0033] The target font image is compared with the reference font image in style, and whether the font styles of the target font image and the reference font image are consistent is determined based on the style comparison result; if they are inconsistent, a second font image corresponding to the target text is re-output through the font generation model.
[0034] In the disclosed embodiment, the initial model is trained and optimized through multiple font images and the font label of each font image to obtain a font generation model, including:
[0035] According to the multiple font images and the structural features of each font image, the initial model is trained to obtain a first model;
[0036] Superimposing the low-rank matrix onto the original weight matrix of the first model to obtain a second model;
[0037] According to multiple font images and the stroke features of each font image, the second model is optimized to obtain the font generation model; during the model optimization process, the parameters of the low-rank matrix are updated and the parameters of the original weight matrix are kept unchanged.
[0038] The second aspect of the present disclosure provides a font generation device, including:
[0039] A training data set construction module, used to construct a training data set, wherein the training data set includes a plurality of font images of the same style;
[0040] A structural analysis module, for performing structural analysis on any one of the multiple font images to obtain structural features of the font image; the structural features include characters, components, strokes and pen shapes of the font;
[0041] A stroke analysis module, used to perform stroke analysis on the font image to obtain stroke features of the font image; the stroke features are used to characterize the thickness, straightness, density, and dryness of the font lines;
[0042] A font label determination module, used for using the structural features and the stroke features as font labels of the font image;
[0043] A model training module is used to train and optimize the initial model through multiple font images and the font label of each font image to obtain a font generation model;
[0044] The font image output module is used to output a target font image corresponding to the target text through the font generation model.
[0045] An embodiment of the third aspect of the present disclosure provides a computer device, which includes a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the font generation method described in the first aspect by executing the computer instructions.
[0046] An embodiment of a fourth aspect of the present disclosure provides a computer-readable storage medium, on which computer instructions are stored, and the computer instructions are used to enable a computer to execute the font generation method described in the first aspect.
[0047] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will become apparent from the following description or be learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] By reading the detailed description of the preferred embodiment below, various other advantages and benefits will become clear to those of ordinary skill in the art. The accompanying drawings are only used for the purpose of illustrating the preferred embodiment and are not considered to be limitations of the present disclosure. In addition, the same reference symbols are used to represent the same components throughout the accompanying drawings.
[0049] In the attached picture:
[0050] Figure 1 A schematic diagram showing a flow chart of a font generation method provided by an embodiment of the present disclosure;
[0051] Figure 2 A schematic diagram showing an original image provided by an embodiment of the present disclosure is shown;
[0052] Figure 3 A schematic diagram showing a vectorization result provided by an embodiment of the present disclosure is shown;
[0053] Figure 4 A schematic diagram of image segmentation provided by an embodiment of the present disclosure is shown;
[0054] Figure 5 A schematic diagram showing an incomplete font structure provided by an embodiment of the present disclosure;
[0055] Figure 6 A schematic diagram showing a brush stroke feature provided by an embodiment of the present disclosure is shown;
[0056] Figure 7 shows a depth map corresponding to a font image provided by an embodiment of the present disclosure;
[0057] Figure 8 A schematic diagram showing the model input results with and without Depth control provided by an embodiment of the present disclosure;
[0058] Fig. 9 A schematic diagram showing image processing of a font image provided by an embodiment of the present disclosure is shown;
[0059] Fig.10 A schematic diagram showing a stroke effect of a font image provided by an embodiment of the present disclosure is shown;
[0060] Fig.11 A schematic diagram of generating a font test provided by an embodiment of the present disclosure is shown;
[0061] Fig.12 A schematic diagram of the structure of a font generation device provided by an embodiment of the present disclosure is shown;
[0062] Fig.13A schematic diagram of the structure of a computer device provided by an embodiment of the present disclosure is shown;
[0063] Fig.14 A schematic diagram of a storage medium provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0064] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0065] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in the present disclosure should have the common meanings understood by those skilled in the art to which the present disclosure belongs.
[0066] The following describes the technical scenarios involved in the embodiments of the present disclosure.
[0067] In the traditional font design process, font designers need to manually draw and digitize the font style and make complex visual adjustments to ensure that the font has good visual effects and readability in various application scenarios. However, this process often requires a lot of manpower, time and expertise, especially for fonts with unique cultural characteristics (such as ancient Chinese characters), the design and re-creation is even more difficult. The main shortcomings of the existing technology in the field of font design are manifested in the following aspects:
[0068] First, the design efficiency is low. The traditional manual design process involves a lot of repetitive work. Designers need to draw and adjust the shape of each character one by one, which greatly limits the speed of font development. Especially when designing for Chinese characters, designers not only need to understand the structural characteristics of the font, but also need to take into account the cultural attributes of the font. This makes it challenging to mass-produce high-quality, unique fonts in a short period of time. Although there have been software tools and font template libraries in recent years, these tools often lack creativity and automation, resulting in long font design time and high costs.
[0069] Secondly, it is difficult to maintain the diversity of font styles. Currently, a large number of digital fonts or standardized templates on the market tend to be single in form and lack innovation and culture. Especially in the field of brush calligraphy, it is difficult for existing technology to fully reproduce the diverse font styles in history, and even some subtle stroke features and structural styles may deviate, resulting in the designed fonts being inconsistent with historical prototypes. Traditional digital methods are limited by standardized procedures and lack the ability to express details, and it is often difficult to accurately reproduce and innovatively express historical styles.
[0070] Third, the existing technology is insufficient in intelligent design and automatic adjustment. Although computer-aided design and font generation tools have alleviated the need for manual adjustment to a certain extent in recent years, these tools still rely on designers to manually input a large number of parameters and lack the ability to intelligently identify and learn different font features, resulting in the need for repeated adjustments of fonts in different application scenarios. In particular, in the generation of non-standard characters, brush fonts or innovative fonts, it is difficult for existing technologies to provide an effective auxiliary generation mechanism, which limits the widespread use of fonts and their adaptation to multiple scenarios.
[0071] In response to the above problems and challenges, the present invention proposes a Chinese character font generation method based on generative artificial intelligence technology, which aims to solve the problems of low efficiency, single style and lack of intelligence in the traditional font design process. It is particularly suitable for the automatic generation and innovative creation of various types of brush fonts.
[0072] The present invention combines generative artificial intelligence with a large-scale historical Chinese font database, which can not only analyze the structural characteristics and style changes of historical Chinese fonts, but also realize automatic generation through model learning, thereby improving the efficiency of Chinese font creation. In view of the low efficiency of traditional manual design, the generative artificial intelligence system of the present invention can automatically extract and analyze the characteristics of historical Chinese fonts, automate the complex Chinese font design process, and realize the efficient production of diversified Chinese fonts in a short time. This method greatly reduces the repetitive workload of Chinese font design and reduces the design cost, so that both professional designers and non-professional users can participate in the design of personalized fonts.
[0073] In terms of maintaining the diversity of font styles, the present invention generates a Chinese character font model through training, so that it can generate fonts with unique styles based on learning historical Chinese character fonts. Compared with traditional technologies, the present invention no longer relies on template libraries and manual drawing, but is based on the algorithm advantages of large models, which can automatically reproduce and innovate the style characteristics of Chinese characters, making the generated fonts closer to historical prototypes in details and style, realizing the reproduction and innovation of diversified styles, and meeting the needs of modern application scenarios for high-quality fonts.
[0074] According to an embodiment of the present disclosure, a font generation method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0075] In this embodiment, a font generation method is provided. Figure 1 is a flowchart of a font generation method according to an embodiment of the present disclosure, such as Figure 1 As shown, the process includes the following steps:
[0076] Step S101, constructing a training data set.
[0077] The training data set includes multiple font images of the same style, and the styles include but are not limited to Songti, Kaiti and Caoti.
[0078] In some specific embodiments, the above step S101 includes steps S1011 to S1014:
[0079] Step S1011, obtaining multiple original images of the same style.
[0080] The original images include but are not limited to images of stone tablets and oracle bone inscriptions; each original image contains multiple fonts, such as Figure 2 shown.
[0081] Step S1012: For any one of the multiple original images, binarization processing is performed on the original image to obtain a binary image.
[0082] In the embodiment of the present disclosure, binarization processing can be performed by setting a pixel threshold, for example: a pixel threshold is pre-determined, and each pixel value in the original image is compared with the pixel threshold. If the pixel value is higher than the pixel threshold, its pixel value is set to white; if the pixel value is lower than or equal to the pixel threshold, its pixel value is set to black.
[0083] Step S1013, vectorizing the binary image, and segmenting the vectorized image according to fonts to obtain a plurality of font images, each of which corresponds to a font in the vectorized image.
[0084] In the embodiment of the present disclosure, the process of vectorizing the binary image is mainly divided into the following steps:
[0085] Image preprocessing, including: preprocessing the binary image to remove noise and compensate for the damaged characteristic curve to ensure the quality of the image;
[0086] Thinning processing includes: gradually removing the points on the edge of the outline of the binary image pixel array to make it a skeleton image with a line width of only one pixel. The thinned skeleton image not only retains most of the features of the original image, but also facilitates the next step of tracking processing;
[0087] Tracking processing includes: the thinned binary image forms a skeleton image, and tracking is to convert the skeleton into a coordinate sequence of vector graphics. The basic steps include searching for the starting point of the line from left to right and from top to bottom, and recording the coordinates, and then tracking the point in the eight directions of the point. If there is no point, the tracking of this line ends and the next line is tracked; otherwise, the coordinates are recorded.
[0088] Topology, including finding the endpoints, nodes, and isolated points of lines. This step helps to maintain the topological structure of the image during the vectorization process.
[0089] In the embodiment of the present disclosure, the vectorization result of the binary image is as follows: Figure 3 As shown, multiple font images are obtained by segmenting the vectorized image according to the fonts, for example Figure 4 shown.
[0090] Step S1014: construct the training data set according to the multiple font images corresponding to the multiple original images.
[0091] In some specific embodiments, after step S1014, the method further includes:
[0092] Step S1015, for any one of the multiple font images, performing a font structure integrity analysis on the font image to obtain a font structure integrity analysis result, and performing a font clarity analysis on the font image to obtain a font clarity analysis result.
[0093] Step S1016: if the font structure integrity analysis result does not meet the first preset requirement, the font image is removed from the training data set.
[0094] The font structure integrity analysis result may be understood as the first difference in font structure between the font image and the corresponding reference image, and the first preset requirement may be understood as whether the numerical representation of the first difference is greater than a first preset threshold.
[0095] Step S1017: if the font clarity analysis result does not meet the second preset requirement, the font image is removed from the training data set.
[0096] The font clarity analysis result is understood as the second difference in font clarity between the font image and the corresponding reference image, and the second preset requirement can be understood as whether the numerical representation of the second difference is greater than a second preset threshold.
[0097] In the above steps S1015 to S1017, after constructing a training data set using multiple font images corresponding to multiple original images, it is also necessary to perform data analysis on the font structure integrity and font clarity in each font image to eliminate fonts with incomplete structures (e.g. Figure 5 As shown in the figure), font images with blurred edges can be used to improve the image quality of the training dataset.
[0098] Step S102: for any one of the multiple font images, perform structural analysis on the font image to obtain structural features of the font image.
[0099] Specifically, the specific implementation method of the structural analysis is not specifically limited in the present invention, and it can be achieved by extracting structural features from the font image.
[0100] In the disclosed embodiment, the structural features of each font image include the characters, components, strokes and pen shapes of the font. After the structural features are obtained, an association relationship is established between the structural features and the corresponding font image, thereby facilitating the font generation model's ability to learn the font morphology.
[0101] Step S103: performing a stroke analysis on the font image to obtain the stroke features of the font image.
[0102] Specifically, the specific implementation method of the stroke analysis is not specifically limited in the present invention, and the stroke analysis can be extracted from the font image.
[0103] In the disclosed embodiment, the stroke features are used to characterize the thickness, straightness, density, and wetness of the font lines. For example, Figure 6 shown.
[0104] More specifically, brushstrokes can be understood as the brushwork and style of calligraphy, painting, and articles. In painting, brushstrokes often refer to the traces of brushstrokes in oil and gouache paintings. It is the painter's ability to depict the texture, volume, and light and shadow of the object by using the thickness contrast of the pigment, the changes in the thickness of the blending agent, the weight of the brush, the speed and rhythm of the brushstrokes, and the artistic feeling of the dotting. The brushstrokes are closely matched with the surface of the object, which can create a strong sense of reality. At the same time, brushstrokes are also the natural expression of the painter's personality, interest, and artistic endowment, which are manifested as the painter's artistic style and personality characteristics. Take the calligraphy written with a beautiful brush as an example. The calligraphy has the characteristics of straight and tough pen tips and capable brushstrokes.
[0105] Step S104: using the structural features and the stroke features as font labels of the font image.
[0106] In the disclosed embodiment, an association relationship is established between each font image and the structural features and stroke features of the font image, and the structural features and stroke features are used as font tags of the font image.
[0107] Step S105, training and optimizing the initial model using multiple font images and the font label of each font image to obtain a font generation model.
[0108] In some specific embodiments, the above step S105 further includes steps S1051 to S1053:
[0109] Step S1051, identifying the original weight matrix to be fine-tuned in the initial model.
[0110] Among them, the initial model is a pre-trained model used to output font images; the original weight matrix is the parameter in the initial model used to calculate the mapping relationship between input data and output data. The original weight matrix can be located in each layer in the initial model, or in the layer that has a greater impact on the model performance, such as: the fully connected layer in the ransformer architecture or the linear transformation layer in the self-attention mechanism.
[0111] Step S1052, superimposing the low-rank matrix onto the original weight matrix to obtain a fine-tuned initial model.
[0112] In the embodiment of the present disclosure, the low-rank matrix includes a first low-rank matrix and a second low-rank matrix. The low-rank matrix is superimposed on the original weight matrix, which can be expressed by the following formula:
[0113] W=Woriginal+A×B
[0114] Woriginal represents the original weight matrix, A represents the first low-rank matrix, and B represents the second low-rank matrix.
[0115] Step S1053, training and optimizing the fine-tuned initial model using multiple font images and the font label of each font image to obtain a font generation model.
[0116] In the disclosed embodiment, during the training optimization process, only the parameters of the low-rank matrix are updated, and the parameters of the original weight matrix are kept unchanged.
[0117] The disclosed embodiment uses multiple font images and font labels for each font image to train a low-rank matrix in a fine-tuned initial model, so that the font generation model can capture changes in font styles and significantly improve the performance of the font generation model on specific font style tasks.
[0118] In some specific embodiments, the font generation model mainly includes the following steps during the model training process:
[0119] After all the data sets are prepared, you can start preparing for training. First, you need to set the training material path parameters to determine the trained data set for the model to access. Secondly, you need to set the basic model used for training according to the different training materials. pretrained_model indicates the basic model path, and train_data_dir indicates the training material path.
[0120] After the path is set, the training parameters need to be set. Different parameter settings will affect the training speed of the model and the final learning results. Different parameters need to be set according to different training materials. Resolution refers to the width and height of the image. Non-square is supported, but it must be a multiple of 64; Batch_size refers to the number of samples fed into the model at one time during neural network training. (In layman's terms, Batch_size determines how many samples are fed into the model at one time. A larger Batch_size can speed up training, but it will take up more memory resources);
[0121] max_train_epoches indicates the maximum number of training epochs, that is, the model will be trained so many times on the entire training data set (assuming that the maximum training epoch is 10, that is, 10 complete training set cycles will be performed during the training process. This parameter can be adjusted according to actual conditions to achieve better model effects) Network_dim refers to the dimension of the neural network, especially when using the LoRA model. It affects the width of the model, that is, the amount of information that the model can learn. The common setting range of Network_dim is 4 to 128. The wider the width, the more information LoRA can learn, but it also requires more data for training. Therefore, when setting the Network_dim parameter, it is necessary to decide based on your personal learning goals and the amount of data.
[0122] After the training parameters are set, the learning rate parameters need to be set. The learning rate is a very important hyperparameter when training neural networks, which controls the update speed of the weights. The larger this parameter is, the greater the amplitude of the weight update; conversely, the smaller the parameter is, the smaller the update amplitude is. Lr represents the learning rate, which is used to control the step size each time the model updates the parameters; unet_lr represents the learning rate of the unet network, which can be the same as the lr value; text_encoder_lr represents the learning rate of the text encoder. Changes need to be tested through specific practical situations; lr_scheduler represents the learning rate scheduling strategy, which is used to control the way the model learning rate changes. Five optional scheduling strategies are provided here, namely: linear, "cosine", "cosine_with_restarts", "polynomial", "constant", "constant_with_warmup", and basically only "constant_with_warmup" is used;
[0123] lr_warmup_steps indicates the number of warm-up steps. It is only required to be set when the learning rate scheduling policy is "constant_with_warmup". It is used to control the number of steps that the model gradually increases the learning rate before training. lr_restart_cycles indicates the number of cosine annealing restarts. It is only required to be set when the learning rate scheduling policy is "cosine_with_restarts". It is used to control the number of cosine annealing restarts. (The learning rate can be compared to the speed at which humans learn a skill. If the learning speed is too fast, some details may be missed or the understanding may not be deep. Similarly, if the learning speed is too slow, time may be wasted or patience may be lost. Therefore, the size of the learning rate needs to be adjusted according to the specific situation to obtain the best learning effect.
[0124] After the settings are completed, you need to set the training output and optimizer. After all the settings are completed, you can start model training. After the training is completed, you can find the file with the suffix safetensors in the specified location, that is, the model file, which can be used in Comfyui, Webui and other image generation systems.
[0125] Step S106: outputting a target font image corresponding to the target text through the font generation model.
[0126] In some specific embodiments, the above step S106 includes step S1061-step S1062:
[0127] Step S1061 : in the process of the font generation model generating the target font image, calling the edge control model to generate a depth map corresponding to the first font image.
[0128] In the embodiment of the present disclosure, the font pixel points in the depth map are associated with a first depth value, and the other pixel points in the depth map are associated with a second depth value; the first depth value is different from the second depth value, for example Figure 7 shown.
[0129] Step S1062: Control the font structure in the first font image according to the depth relationship between the font pixel and other pixel points in the depth map to obtain the target font image.
[0130] In the disclosed embodiment, considering that the font generation model cannot effectively control the structural details of the font, which often leads to font collapse, graphic spreading and other problems, the present invention inserts the Depth Anything edge control model into the process of the font generation model generating the font image, and uses the edge control model to automatically calculate the depth relationship of the font image and generate a depth map, thereby controlling the structure of the font according to the depth map, thereby achieving the effect of controlling the font structure stability. Among them, the model input results with and without Depth control are as follows: Figure 8 shown.
[0131] In some specific embodiments, after the above step S106, the method further includes:
[0132] Step 107, performing a structural comparison between the target font image and the reference font image, and judging whether there are any stroke errors in the target font image according to the structural comparison result, and if so, re-outputting a second font image corresponding to the target text through the font generation model.
[0133] Step 108, performing a style comparison between the target font image and the reference font image, and determining whether the font styles of the target font image and the reference font image are consistent based on the style comparison result; if not, re-outputting a second font image corresponding to the target text through the font generation model.
[0134] In the embodiments of the present disclosure, for example Fig. 9 As shown in the figure: After a single font image is generated, image processing, accuracy matching and similarity analysis are required. Image processing means that during the generation process, some font images may have defects such as blur, and such images need to be deleted and the correct font image needs to be regenerated; accuracy matching means comparing the generated font with the correct Chinese character to check whether there are any stroke errors, etc., and deleting the incorrect font and regenerating it; similarity analysis means that after training a font of a specific style, the generated font needs to be compared with the original style font to determine whether the generated font is highly consistent with the original font in style.
[0135] In some specific embodiments, the above step S105 further includes steps a1 to a3:
[0136] Step a1, training the initial model according to the plurality of font images and the structural features of each font image to obtain a first model;
[0137] Step a2, superimposing the low-rank matrix onto the original weight matrix of the first model to obtain a second model;
[0138] Step a3, optimizing the second model according to a plurality of font images and the stroke features of each font image to obtain the font generation model;
[0139] In the process of model optimization, the parameters of the low-rank matrix are updated, and the parameters of the original weight matrix are kept unchanged.
[0140] In the disclosed embodiment, the first model is obtained by training the initial model through the font image and the structural features of the font image, so that the first model can learn the structural features of the font image, so that the first model can output the corresponding font image according to the structural features in actual use. The second model is optimized through multiple font images and the stroke features of each font image to obtain the font generation model, which can greatly optimize the stroke effect of the font image output by the model to ensure that the generated brush font has a real and natural stroke effect in various application scenarios, improve the artistry and practicality of the font, and effectively reduce the design's dependence on professional skills.
[0141] The disclosed implementation optimizes the second model through multiple font images and the stroke features of each font image to obtain the font generation model, so that the generated font shows significant improvement in various aspects. For example, in terms of stroke details, the fine-tuning model can accurately reproduce the changes in line thickness and the natural transition of starting and ending strokes of the brush font, making the font more in line with the fluency of brush writing. At the texture level, the fine-tuned model can accurately simulate the changes in ink thickness, wet and dry effects, and brushstroke texture, presenting a richer sense of hierarchy and delicate visual expression. In addition, in terms of glyph structure and layout balance, the fine-tuning model optimizes the stroke spacing and shape so that the generated font maintains the consistency and beauty of the glyph, avoiding the imbalance and incoordination of the font structure that may occur in the traditional generation model. On the whole, the fine-tuning model significantly improves the visual restoration and artistic expression of the brush font, provides higher aesthetic quality and practicality for the generated font, and its font stroke effect, for example Fig.10 shown.
[0142] In some specific embodiments, in order to fully test the effect of the final generated font, for example Fig.11As shown: The present invention selects four brush fonts with different style characteristics as benchmarks, and conducts detailed conditional diffusion training on the structural characteristics, stroke performance and overall style of these four brush fonts, so as to construct a font generation model with diverse styles. By conditionally controlling the key features of each font during the training process, the present invention ensures that the model can generate font performance that conforms to a specific style. In addition, in order to further improve the detail fidelity and style consistency of the generated fonts, the present invention extracts the basic stroke features of each brush font, and applies a fine-tuning model for fine control, so that the generated results can retain the detailed features and unique stroke performance of the target font, thereby achieving a highly stylized and detail-rich generation effect. The final experimental results show that the generated fonts have a high degree of similarity in maintaining the unique features of the four target brush fonts, while also achieving excellent performance in visual effects. For example Fig.11 As shown: During the test, the present invention selected a total of 6 Chinese characters representing different font complexities for generation. From the generated results, it can be seen that the font generated by the font generation method of the present invention has a very high degree of consistency in font structure and strokes with the original font, verifying the reliability and feasibility of the font generation system.
[0143] The font generation method provided by the present invention makes the font generation process more accurate and efficient. With the support of font database and pre-training set, it can not only highly restore different historical font styles in structure and stroke details, but also realize diversified innovative expressions. The method has excellent detail fidelity and style consistency in the generated results, while improving the automation and flexibility of font generation, meeting the needs of different font styles in various scenarios.
[0144] Corresponding to the implementation of the above font generation method, the embodiment of the present disclosure also provides a font generation device for executing the above Figures 1 to 11 The font generation method described in any of the embodiments shown in the figure. Fig.12 As shown, the font generation device includes:
[0145] A training data set construction module, used to construct a training data set, wherein the training data set includes a plurality of font images of the same style;
[0146] A structural analysis module, for performing structural analysis on any one of the multiple font images to obtain structural features of the font image; the structural features include characters, components, strokes and pen shapes of the font;
[0147] A stroke analysis module, used to perform stroke analysis on the font image to obtain stroke features of the font image; the stroke features are used to characterize the thickness, straightness, density, and dryness of the font lines;
[0148] A font label determination module, used for using the structural features and the stroke features as font labels of the font image;
[0149] A model training module is used to train and optimize the initial model through multiple font images and the font label of each font image to obtain a font generation model;
[0150] The font image output module is used to output a target font image corresponding to the target text through the font generation model.
[0151] Optionally, the model training module is also used to identify the original weight matrix to be fine-tuned in the initial model; superimpose the low-rank matrix on the original weight matrix to obtain the fine-tuned initial model; train and optimize the fine-tuned initial model through multiple font images and the font label of each font image to obtain a font generation model; during the model optimization process, update the parameters of the low-rank matrix and keep the parameters of the original weight matrix unchanged.
[0152] Optionally, the font image output module is also used to call the edge control model to generate a depth map corresponding to the first font image during the process of the font generation model generating the target font image; the font pixels in the depth map are associated with a first depth value, and other pixels in the depth map are associated with a second depth value; the first depth value is different from the second depth value; and according to the depth relationship between the font pixels and other pixels in the depth map, the font structure in the first font image is controlled to obtain the target font image.
[0153] Optionally, the training data set construction module is also used to obtain multiple original images of the same style; the original images include stele images and oracle bone inscriptions images; for any one of the multiple original images, the original image is binarized to obtain a binary image; the binary image is vectorized, and the vectorized image is segmented according to fonts to obtain multiple font images, each font image corresponds to a font in the vectorized image; the training data set is constructed based on the multiple font images corresponding to the multiple original images.
[0154] Optionally, the device also includes: a font analysis module, used to perform a font structure integrity analysis on any one of the multiple font images to obtain a font structure integrity analysis result, and to perform a font clarity analysis on the font image to obtain a font clarity analysis result; if the font structure integrity analysis result does not meet a first preset requirement, the font image is removed from the training data set; if the font clarity analysis result does not meet a second preset requirement, the font image is removed from the training data set.
[0155] Optionally, the device further comprises:
[0156] A structure comparison module, used for performing a structure comparison between the target font image and the reference font image, and judging whether there is a stroke error in the target font image according to the structure comparison result, and if so, re-outputting a second font image corresponding to the target text through the font generation model;
[0157] The style comparison module is used to compare the styles of the target font image with the reference font image, and determine whether the font styles of the target font image and the reference font image are consistent according to the style comparison result. If they are inconsistent, the font generation model is used to re-output a second font image corresponding to the target text.
[0158] Optionally, the model training module is also used to: perform model training on the initial model to obtain a first model based on multiple font images and structural features of each font image; superimpose the low-rank matrix on the original weight matrix of the first model to obtain a second model; optimize the second model to obtain the font generation model based on multiple font images and stroke features of each font image; during the model optimization process, update the parameters of the low-rank matrix and keep the parameters of the original weight matrix unchanged.
[0159] The font generation device provided in the above-mentioned embodiment of the present disclosure and the font generation method provided in the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the method adopted, run or implemented by the application program stored therein.
[0160] The present disclosure also provides a computer device to execute the above-mentioned font generation method. Fig.13 , which shows a schematic diagram of a computer device provided by some embodiments of the present disclosure. Fig.13As shown, the computer device 13 includes: a processor 1300, a memory 1301, a bus 1302 and a communication interface 1303, wherein the processor 1300, the communication interface 1303 and the memory 1301 are connected via the bus 1302; the memory 1301 stores a computer program that can be run on the processor 1300, and the processor 1300 executes the aforementioned Figures 1 to 11 A font generation method is provided in any of the illustrated embodiments.
[0161] The memory 1301 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 1303 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0162] The bus 1302 may be an ISA bus, a PCI bus, or an EISA bus. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 1301 is used to store programs. After receiving the execution instruction, the processor 1300 executes the program. Figures 1 to 11 The font generation method disclosed in any of the illustrated embodiments may be applied to the processor 1300 , or implemented by the processor 1300 .
[0163] The processor 1300 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 1300. The above processor 1300 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 1301, and the processor 1300 reads the information in the memory 1301 and completes the steps of the above method in combination with its hardware.
[0164] The computer device provided by the embodiment of the present disclosure and the font generation method provided by the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by them.
[0165] The present disclosure also provides a computer-readable storage medium corresponding to the font generation method provided in the above embodiment. Fig.14 The computer-readable storage medium shown is a CD 30 on which a computer program (ie, a program product) is stored. When the computer program is run by a processor, the font generation method provided by any of the aforementioned embodiments will be executed.
[0166] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0167] The computer-readable storage medium provided by the above-mentioned embodiment of the present disclosure and the font generation method provided by the embodiment of the present disclosure are based on the same inventive concept, and have the same beneficial effects as the method adopted, run or implemented by the application program stored therein.
[0168] It should be noted that:
[0169] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present disclosure can be practiced without these specific details. In some instances, well-known structures and technologies are not shown in detail so as not to obscure the understanding of this description.
[0170] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present disclosure, the various features of the present disclosure are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following schematic diagram: the claimed disclosure requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, the inventive aspects lie in less than all the features of the single embodiment disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present disclosure.
[0171] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of this disclosure and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0172] The above is only a preferred specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed in the present disclosure should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A font generation method, characterized in that: The method comprises: Constructing a training data set, wherein the training data set includes a plurality of font images of the same style; For any one of the multiple font images, perform structural analysis on the font image to obtain structural features of the font image; the structural features include characters, components, strokes and pen shapes of the font; Performing a stroke analysis on the font image to obtain stroke features of the font image; the stroke features are used to characterize the thickness, straightness, density, and wetness of the font lines; Using the structural features and the stroke features as font labels of the font image; The initial model is trained and optimized through multiple font images and the font label of each font image to obtain a font generation model; The target font image corresponding to the target text is outputted through the font generation model.
2. The method according to claim 1, characterized in that The initial model is trained and optimized through multiple font images and the font labels of each font image to obtain a font generation model, including: Identifying an original weight matrix to be fine-tuned in the initial model; Superimposing the low-rank matrix onto the original weight matrix to obtain a fine-tuned initial model; The fine-tuned initial model is trained and optimized using multiple font images and the font label of each font image to obtain a font generation model; during the model optimization process, the parameters of the low-rank matrix are updated, and the parameters of the original weight matrix are kept unchanged.
3. The method according to claim 1 or 2, characterized in that: Outputting a target font image corresponding to the target text through the font generation model includes: In the process of the font generation model generating the target font image, calling the edge control model to generate a depth map corresponding to the first font image; the font pixels in the depth map are associated with a first depth value, and other pixels in the depth map are associated with a second depth value; the first depth value is different from the second depth value; According to the depth relationship between the font pixel and other pixel points in the depth map, the font structure in the first font image is controlled to obtain the target font image.
4. The method according to claim 1 or 2, characterized in that: Construct a training dataset, including: Acquire multiple original images of the same style; the original images include images of stone tablets and images of oracle bones; For any one of the multiple original images, binarization processing is performed on the original image to obtain a binary image; Performing vectorization processing on the binary image, and performing image segmentation on the vectorized image according to fonts to obtain a plurality of font images, each font image corresponding to a font in the vectorized image; The training data set is constructed according to a plurality of font images corresponding to the plurality of original images.
5. The method according to claim 4, characterized in that After constructing the training data set, the method further includes: For any one of the multiple font images, performing a font structure integrity analysis on the font image to obtain a font structure integrity analysis result, and performing a font clarity analysis on the font image to obtain a font clarity analysis result; If the font structure integrity analysis result does not meet the first preset requirement, the font image is removed from the training data set; If the font clarity analysis result does not meet the second preset requirement, the font image is removed from the training data set.
6. The method according to claim 1 or 2, characterized in that: After outputting the target font image corresponding to the target text through the font generation model, the method further includes: Performing a structural comparison between the target font image and the reference font image, judging whether there is a stroke error in the target font image according to the structural comparison result, and if so, re-outputting a second font image corresponding to the target text through the font generation model; The target font image is compared with the reference font image in style, and whether the font styles of the target font image and the reference font image are consistent is determined based on the style comparison result; if they are inconsistent, a second font image corresponding to the target text is re-output through the font generation model.
7. The method according to claim 1, characterized in that The initial model is trained and optimized through multiple font images and the font labels of each font image to obtain a font generation model, including: According to the multiple font images and the structural features of each font image, the initial model is trained to obtain a first model; Superimposing the low-rank matrix onto the original weight matrix of the first model to obtain a second model; According to multiple font images and the stroke features of each font image, the second model is optimized to obtain the font generation model; during the model optimization process, the parameters of the low-rank matrix are updated and the parameters of the original weight matrix are kept unchanged.
8. A font generation device, characterized in that: The device comprises: A training data set construction module, used to construct a training data set, wherein the training data set includes a plurality of font images of the same style; A structural analysis module, for performing structural analysis on any one of the multiple font images to obtain structural features of the font image; the structural features include characters, components, strokes and pen shapes of the font; A stroke analysis module, used to perform stroke analysis on the font image to obtain stroke features of the font image; the stroke features are used to characterize the thickness, straightness, density, and dryness of the font lines; A font label determination module, used for using the structural features and the stroke features as font labels of the font image; A model training module is used to train and optimize the initial model through multiple font images and the font label of each font image to obtain a font generation model; The font image output module is used to output a target font image corresponding to the target text through the font generation model.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the font generation method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the font generation method according to any one of claims 1 to 7.