Font style sampling method, electronic device, storage medium and system

By performing weighted random sampling on font image data and generating multiple image areas as data for model training, the problem of poor font image generation in the existing technology is solved, and better font style distinction and generation quality are achieved.

CN115512163BActive Publication Date: 2025-09-09BEIJING HANYI KEYIN INFORMATION TECH +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211232565.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-10
Publication Date
2025-09-09
Estimated Expiration
2042-10-10

AI Technical Summary

Technical Problem

Existing data augmentation methods cannot effectively consider the particularity of text image data and the consistency of character meaning in font image data generation tasks, resulting in poor generation results.

Method used

By rendering the character data in the font file into a single-channel text image, determining the center position, obtaining the non-zero pixel point at the center position, performing weighted random sampling, generating a sampling set, and setting the sampling area with the sampling point as the center of the circle, multiple image areas are obtained as data for model training.

Benefits of technology

The quality of font image generation has been improved, and it can effectively distinguish between two sets of fonts with similar styles, which improves the generation effect of deep neural networks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115512163B_ABST
    Figure CN115512163B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a font style sampling method, electronic device, storage medium and system, the method comprising the following steps: rendering character data in a font file into a single-channel text image; determining the center position of the text image; obtaining all non-zero pixel points with the same distance to the center position from the text image, and forming the obtained non-zero pixel points into a set L; performing weighted random sampling on the set L to obtain a first sampling set; randomly sampling the first sampling set to obtain a second sampling set, obtaining sampling points from the second sampling set, taking the sampling points as the center of a circle, setting a radius of a sampling area, obtaining multiple image areas through multiple sampling, and using the obtained multiple image areas as negative samples to train a model, so that the model can generate font images with better effect and a style closer to the target style. The sampling method disclosed in the present disclosure can express the style information of the font and improve the generation quality of the text image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data augmentation of text image data, and particularly to a sampling method for font styles, an electronic device, a storage medium, and a system. Background Art

[0002] The production of font libraries requires a large amount of manual work and takes a particularly long time. Therefore, a font library production method based on deep neural network technology has emerged, which can reduce a large amount of workload and greatly shorten the time for producing font libraries. However, the generation effect of this font library production method is related to the size of the dataset. In theory, the larger the dataset, the better the generation effect. However, due to the particularity of font data, there is only one character of the same style, and the data volume is very limited. Therefore, data augmentation technology is often needed to expand the dataset during training, thereby improving the generation quality.

[0003] Common data augmentation methods include: randomly changing colors, randomly inverting, randomly affine transformation, Cut Up, Mixup, etc. However, most of these methods are applied to various tasks of natural images and face images. For example, the augmentation method of randomly changing colors is only applicable to natural images with multiple colors and is not applicable to text image data with only black and white colors; when the random flipping augmentation method is applied to natural images, the viewing angle is changed, but when applied to text image data, the content expressed by the text is changed (except for text that is symmetric left and right); CutUp is to randomly select an image area for masking operation, which is meaningless for text image data composed of components and will also have a negative effect on the generation effect. For example, when trying to generate the character "three", due to the random sampling masking using CutUp, the deep neural network generates "two", destroying the character meaning information. The above data augmentation methods do not consider the particularity of text picture data and the consistency of character meanings, so they cannot play a good role in the generation task using font image data and cannot be applied to the generation task of font data. Summary of the Invention

[0004] To solve the above technical problems, the present disclosure provides the following technical solutions: The present disclosure provides a sampling method for font styles, an electronic device, a storage medium, and a system to at least solve at least one of the technical problems in the above background art.

[0005] In a preferred embodiment of the present disclosure, an embodiment of the present application provides a sampling method for font styles, and the method includes:

[0006] Render the character data in the font library file into single-channel text pictures;

[0007] Determine the central position of the text picture;

[0008] Obtain all non-zero pixel points with the same distance from the center position from the text image, and form a set L of the obtained non-zero pixel points, wherein the set L is composed of a set L_di, where L_di represents the set of pixel points with a distance di from the center position;

[0009] Perform weighted random sampling on the set L to obtain a first sampling set;

[0010] The first sampling set is randomly sampled to obtain a second sampling set, and sampling points are obtained from the second sampling set.

[0011] Furthermore, after obtaining the sampling point, the method further includes: setting different sampling radii with the sampling point as the center of the circle, thereby obtaining a sampling area of ​​the text image.

[0012] Furthermore, determining the center position of the text image specifically includes calculating the width and height of the text image to determine the center position of the text image.

[0013] Furthermore, before determining the center position of the text image, the method further includes obtaining the positions and pixel values ​​of pixels with pixel values ​​between 5 and 250 in the single-channel text image.

[0014] Furthermore, the step of acquiring all non-zero pixel points having the same distance from the center position in the text image and forming the acquired non-zero pixel points into a set L includes the following steps:

[0015] Calculate the distance from each non-zero pixel in the text image to the center position one by one, and record the position and pixel value of each non-zero pixel;

[0016] The non-zero pixel points with the same distance from the center position are grouped into a list set L, wherein the set L is composed of a set L_di, and L_di represents a set of pixel points with a distance from the center position being di.

[0017] Furthermore, the weighted random sampling of the set L to obtain the first sampling set includes the following:

[0018] The distance between each non-zero pixel and the center position is randomly weighted to obtain the weighted distance, where the distance between the non-zero pixel and the center position is proportional to the weight;

[0019] A set of non-zero pixel points having a weighted distance from the center position is obtained to obtain a first sampling set.

[0020] In a preferred embodiment of the present disclosure, the present application also provides a font style sampling system, including:

[0021] The rendering module is used to render the character data in the font file into a single-channel text image;

[0022] A center position determination module is used to determine the center position of the text image;

[0023] A pixel point set generation module is used to obtain all non-zero pixel points with the same distance to the center position from the text image, and form the obtained non-zero pixel points into a set L;

[0024] A weighting module, configured to perform weighted random sampling on the set L to obtain a first sampling set;

[0025] The sampling point generation module is configured to randomly sample the first sampling set to obtain a second sampling set, and obtain sampling points from the second sampling set.

[0026] Furthermore, the font style sampling system further includes:

[0027] The sampling area generation module is used to set different sampling radii with the sampling point as the center of the circle, so as to obtain the sampling area of ​​the text image.

[0028] In a preferred embodiment of the present disclosure, an embodiment of the present disclosure further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned font style sampling method when executing the computer program.

[0029] In a preferred embodiment of the present disclosure, the present disclosure also provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the above-mentioned font style sampling method when executed by a processor.

[0030] The beneficial effects of the present disclosure are: in the font style task, for two sets of fonts with similar styles and only slight differences, the existing methods cannot improve the model's ability to distinguish between style fonts. The present disclosure, based on the uniqueness of text image data and considering the uniformity of character meaning, proposes a sampling method that focuses on font style. The sampling method can express the style information of the font and improve the quality of text data generation; after using the method of the present disclosure, the sampled point is used as the center point of a region, and then an area radius is set, such as 8. Through multiple sampling, multiple image regions with a diameter of 16 can be obtained. After this image region is used as data for model training, the model can distinguish between two sets of fonts with similar styles. At the same time, the multiple image regions obtained are used as negative samples to train the model, which can make the model generate font images better and the style closer to the target style. In addition, the present disclosure is fast and, compared with the existing methods, can improve the algorithm effect of the technical solution based on deep neural networks. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1Flowchart of the font style sampling method;

[0032] Figure 2 This is a diagram showing the components of the font style sampling system.

[0033] Figure 3 is a schematic diagram of the center distance;

[0034] Figure 4 This is a comparison chart of sampling effects. DETAILED DESCRIPTION

[0035] The following will be combined with the accompanying drawings in the embodiments of the present disclosure to clearly and completely describe the technical solutions in the embodiments of the present disclosure. Obviously, the embodiments described are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of the present disclosure.

[0036] Example 1

[0037] Please see the attached Figure 1 According to the font style sampling method proposed in the exemplary embodiment of the present disclosure, the technical problems mentioned in the background technology are addressed. By sampling more points on the edge through weighted random sampling, the generation effect of the font image is greatly improved.

[0038] The implementation process of the font style sampling method as an example includes the following steps:

[0039] Render the character data in the font file into a single-channel text image;

[0040] Get the position information and pixel value of the pixel points with pixel values ​​between 5 and 250 in the single-channel text image, recorded as I_edge;

[0041] Calculate the width W and height H of the text image and determine the center position of the text image as (H / 2, W / 2), recorded as P_center;

[0042] Calculate the distance from each pixel in I_edge to the center position P_center one by one, record it as D_center, and record the position information (x, y) and pixel value of each pixel in I_edge, where D_center = max(xH / 2, yW / 2);

[0043] The pixels in I_edge with the same D_center are organized into a list set, denoted as L, and the elements in the list set are denoted as L_di, where L_di is also a set, representing the set of pixels with a distance di from the center. For example, L_0 represents the set of all pixels with a distance 0 from the center, L_1 represents the set of all pixels with a distance 1 from the center, ..., L_max represents the set of all pixels with a maximum distance max from the center, max = max(H / 2, W / 2). Thus, the set L can be represented as {L_0, L_1, L_2, L_3, ..., L_max}, and the value range of di is [0, max].

[0044] Calculate the weight of weighted random sampling. The weight calculation formula is: The weight calculation formula is: , where W i Represents the weight of L_di, max represents the maximum value from the center position, i represents the i-th element of the set L_di, and j represents the j-th element of the set L; after obtaining the weight, the distance D_center from each non-zero pixel to the center position is randomly weighted to obtain the weighted distance d_sample; obtain the first sampling set L_d_sample in the set L, that is, obtain the set of pixels with the same d_sample in the set L; for example, after calculation, the value range of D_center is [0,10], then the set L={L_0, L_1, L_2, ..., L_10}, and the set L is weighted randomly sampled. The sampling result is 4, then d_sample=4, L_d_sample= L_4; by giving a greater weight to the larger the distance from the center position, more pixels on the edge can be sampled, and the positions of these pixels are exactly where the font style is more obvious;

[0045] Random sampling is performed in the first sampling set L_d_sample to obtain a second sampling set, and sampling points are obtained from the second sampling set. Because the first sampling set L_d_sample is a set of pixel points that are d_sample away from the center position, and multiple pixel points have the same distance from the center position, a specific second sampling set can be determined through the second random sampling, and the sampling points of the present disclosure can be obtained from the second sampling set.

[0046] Using the obtained sampling point as the center of the circle, different sampling radii are set according to the sampling task to obtain the sampling area of ​​the text image. For example, the point obtained in the second sampling set is used as the sampling point of a sampling area, and the sampling area radius is set to 8. Through multiple sampling, multiple image areas with a diameter of 16 can be obtained. After using this image area as data for model training, the model can distinguish between two sets of fonts with similar styles. At the same time, using multiple image areas as negative samples for model training can enable the model to generate font images with better results and styles closer to the target style.

[0047] Example 2

[0048] like Figure 2 As shown, the sampling system of font styles as an example includes:

[0049] The rendering module is used to render the character data in the font file into a single-channel text image;

[0050] A center position determination module is used to determine the center position of the text image;

[0051] A pixel point set generation module is used to obtain all non-zero pixel points with the same distance from the center position from the text image, and form the obtained non-zero pixel points into a set L, where the set L is composed of the set L_di, where L_di represents the set of pixel points with a distance di from the center position;

[0052] A weighting module, configured to perform weighted random sampling on the set L to obtain a first sampling set;

[0053] The sampling point generation module is configured to randomly sample the first sampling set to obtain a second sampling set, and obtain sampling points from the second sampling set.

[0054] Furthermore, the font style sampling system further includes a sampling area generating module for setting different sampling radii with the sampling point as the center of the circle, thereby obtaining a sampling area of ​​the text image.

[0055] Furthermore, the center position determination module is used to calculate the width W and height H of the text image, and determine the center position P_center of the text image as (H / 2, W / 2).

[0056] Furthermore, the pixel point set generation module is used to calculate the distance D_center from each pixel point in the text image to the center position P_center one by one, and record the position information (x, y) and pixel value of each pixel point in the text image, where D_center=max(xH / 2, yW / 2); the pixel points with the same D_center in the text image are organized into a list set, denoted as L, and the elements in the list are denoted as L_di, where L_di is also a set, representing the set of pixel points with a distance di from the center position, for example, L_0 represents the set of all pixel points with a distance from the center position of 0, ..., L_max represents the set of all pixel points with a distance from the center position of the maximum value max, max=max(H / 2, W / 2), so that the set L can be expressed as {L_0, L_1, L_2, L_3, ..., L_max}, and the value range of di is [0, max].

[0057] Furthermore, the weighting module is used to calculate the weight of weighted random sampling, and the weight calculation formula is: , where W i represents the weight of L_di, max represents the maximum value from the center position, i represents the i-th element of the set L_di, and j represents the j-th element of the set L. After obtaining the weight, the distance D_center from each non-zero pixel point to the center position is randomly weighted to obtain the weighted distance d_sample. Obtain the first sampling set L_d_sample in the set L, that is, obtain the set of pixel points with the same d_sample in the set L.

[0058] Example 3

[0059] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the font style sampling method in Example 1 is implemented.

[0060] Embodiment 3 of the present disclosure is merely an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0061] The electronic device may be a general-purpose computing device, such as a server device. Components of the electronic device may include, but are not limited to, at least one processor, at least one memory, and a bus connecting different system components (including the memory and the processor).

[0062] The bus includes data bus, address bus and control bus.

[0063] The memory may include volatile memory, such as random access memory (RAM) and / or cache memory, and may further include read-only memory (ROM).

[0064] The memory may also include a program tool having a set (at least one) of program modules, such program modules including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include an implementation of a network environment.

[0065] The processor executes computer programs stored in the memory to perform various functional applications and process data.

[0066] The electronic device may also communicate with one or more external devices (e.g., a keyboard, pointing device, etc.). This communication may occur via an input / output (I / O) interface. Furthermore, the electronic device may communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter. The network adapter communicates with other modules of the electronic device via a bus. It should be understood that, although not shown in the figures, other hardware and / or software modules may be used in conjunction with the electronic device, including but not limited to microcode, device drivers, redundant processors, external disk drive arrays, RAID (RAID) systems, tape drives, and data backup storage systems.

[0067] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, depending on the embodiment of the present application, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided and embodied by multiple units / modules.

[0068] Example 4

[0069] A computer-readable storage medium stores a computer program, wherein the program, when executed by a processor, implements the steps of the font style sampling method in embodiment 1.

[0070] The readable storage medium may include, but is not limited to, a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0071] In a possible implementation, the present disclosure may also be implemented in the form of a program product, which includes program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps of the font style sampling method described in Example 1.

[0072] The program code for executing the present disclosure may be written in any combination of one or more programming languages, and may be executed entirely on the user device, partially on the user device, as a standalone software package, partially on the user device and partially on a remote device, or entirely on the remote device.

[0073] Although the embodiments of the present disclosure have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and alterations may be made to the embodiments without departing from the principles and spirit of the present disclosure, and the scope of the present disclosure is defined by the appended claims and their equivalents.

Claims

1. A font style sampling method, characterized in that: The steps include: Render the character data in the font file into a single-channel text image; Determine the center position of the text image; Obtain all non-zero pixel points with the same distance from the center position from the text image, and form a set L of the obtained non-zero pixel points, wherein the set L is composed of a set L_di, where L_di represents the set of pixel points with a distance di from the center position; Perform weighted random sampling on the set L to obtain a first sampling set; Randomly sampling the first sampling set to obtain a second sampling set, and obtaining sampling points from the second sampling set; Taking the sampling point as the center of the circle, different sampling radii are set to obtain the sampling area of ​​the text image; The weighted random sampling of the set L to obtain the first sampling set comprises the following steps: The distance between each non-zero pixel and the center position is randomly weighted to obtain the weighted distance, where the distance between the non-zero pixel and the center position is proportional to the weight; A set of non-zero pixel points having a weighted distance from the center position is obtained to obtain a first sampling set.

2. The font style sampling method according to claim 1, wherein: The step of acquiring all non-zero pixel points having the same distance from the center position to the text image and forming the acquired non-zero pixel points into a set L comprises the following steps: Calculate the distance from each non-zero pixel in the text image to the center position one by one, and record the position and pixel value of each non-zero pixel; The non-zero pixel points with the same distance from the center position are grouped into a list set L, wherein the set L is composed of a set L_di, and L_di represents a set of pixel points with a distance from the center position being di.

3. The font style sampling method according to claim 1, wherein: Determining the center position of the text image specifically includes: calculating the width and height of the text image, and determining the center position of the text image.

4. The font style sampling method according to claim 1, wherein: Before determining the center position of the text image, the following steps are also included: Get the positions and pixel values ​​of pixels between 5 and 250 in a single-channel text image.

5. A font style sampling system implemented by the font style sampling method according to any one of claims 1 to 4, characterized in that: include: The rendering module is used to render the character data in the font file into a single-channel text image; A center position determination module is used to determine the center position of the text image; A pixel point set generation module is used to obtain all non-zero pixel points with the same distance from the center position from the text image, and form the obtained non-zero pixel points into a set L, where the set L is composed of the set L_di, where L_di represents the set of pixel points with a distance di from the center position; A weighting module, configured to perform weighted random sampling on the set L to obtain a first sampling set; a sampling point generation module, configured to randomly sample the first sampling set to obtain a second sampling set, and obtain sampling points from the second sampling set; The sampling area generation module is used to set different sampling radii with the sampling point as the center of the circle, so as to obtain the sampling area of ​​the text image.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the font style sampling method according to any one of claims 1 to 4 is implemented.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the font style sampling method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Machine learning-based universal OCR training data generation system and method

    CN112418224A

  • Font data processing method and device based on generative adversarial network

    CN112861806A