Text beautification method, device, readable storage medium and electronic device
Through text recognition and image processing technology, the text in the image is decomposed and beautified, which solves the problem of poor handwriting beautification effect in the existing technology and achieves a more aesthetic text beautification effect.
Patent Information
- Application Number
- CN202110815639.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-19
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-07-19
AI Technical Summary
When the existing technology processes text in images, it cannot effectively beautify the handwriting, resulting in poor processing effects.
Through text recognition, image processing and font beautification, the text in the image is decomposed into single character images, and the font structure and style are processed, and the beautified single character image and the original background image are synthesized to form a beautified image.
The text processing effect in the image is improved, making the adjusted single-character image handwriting more beautiful and enhancing the beautification effect of the text.
Smart Images

Figure CN113689525B
Abstract
Description
Technical Field
[0001] The present application belongs to the field of communication technology, and specifically relates to a text beautification method, device, readable storage medium and electronic device. Background Art
[0002] With the development of electronic devices, the functions of electronic devices are becoming more and more abundant. For example, electronic devices can process text in an image (specifically text in image format, hereinafter referred to as text image) through a text processing tool. Specifically, electronic devices can adjust the size of the text image and the position of the text image in the image through the text processing tool.
[0003] However, since the electronic device processes the text in the image by adjusting the size and / or position of the text image, the processing effect of the text image in the image is poor. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a text beautification method, device, readable storage medium and electronic device, which can solve the problem of poor processing effect on text images in images.
[0005] In a first aspect, an embodiment of the present application provides a text beautification method, the method comprising: performing text recognition on a first image to determine M image areas, each image area including a character; performing image processing on the first image based on the M image areas to obtain M first single-character images, each first single-character image corresponding to an image area; performing font beautification processing on the M first single-character images to obtain M second single-character images, the font beautification processing comprising at least one of the following: font structure processing, font style processing; synthesizing the M second single-character images with the original background image of the first image to obtain a second image.
[0006] In a second aspect, an embodiment of the present application provides a text beautification device, which may include: a recognition module, a processing module and a synthesis module; the recognition module is used to perform text recognition on a first image; the processing module is used to determine M image areas in the first image according to the recognition result of the recognition module, each image area includes a character; the processing module is also used to perform image processing on the first image according to the M image areas to obtain M first single-character images, each first single-character image corresponds to an image area; the processing module is also used to perform font beautification processing on the M first single-character images to obtain M second single-character images, and the font beautification processing includes at least one of the following: font structure processing, font style processing; the synthesis module is used to synthesize the M second single-character images obtained by the processing module with the original background image of the first image to obtain a second image.
[0007] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, and the program or instruction, when executed by the processor, implements the steps of the method of the first aspect.
[0008] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method of the first aspect are implemented.
[0009] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the method of the first aspect.
[0010] In an embodiment of the present application, text recognition can be performed on the first image to determine M image areas, each of which includes a character; based on the M image areas, image processing is performed on the first image to obtain M first single-character images, each of which corresponds to an image area; font beautification processing is performed on the M first single-character images to obtain M second single-character images, and the font beautification processing includes at least one of the following: font structure processing, font style processing; the M second single-character images are synthesized with the original background image of the first image to obtain a second image. Through this scheme, since font beautification processing (specifically at least one of font structure processing and font style processing) can be performed on single-character images in an image (such as the first image), it can be ensured that the handwriting of the adjusted single-character image is more aesthetically pleasing, thereby improving the beautification processing effect on the text image in the image. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 A schematic diagram of a text beautification method is provided for an embodiment of the present application;
[0012] Figure 2 One of the flow charts of processing a single word image using the text beautification method provided in the embodiment of the present application;
[0013] Figure 3 The second flow chart of processing a single word image by using the text beautification method provided in the embodiment of the present application;
[0014] Figure 4 A schematic diagram of processing a reference image to obtain an original background image in an embodiment of the present application;
[0015] Figure 5 A schematic diagram for determining the fitting straight line in units of text lines;
[0016] Figure 6A schematic diagram of the effect of processing a single word image using the text beautification method provided in an embodiment of the present application;
[0017] Figure 7 The third flow chart of processing a single word image by using the text beautification method provided in the embodiment of the present application;
[0018] Figure 8 A schematic diagram of a text beautification device provided in an embodiment of the present application;
[0019] Fig. 9 A schematic diagram of an electronic device provided in an embodiment of the present application;
[0020] Fig.10 A hardware schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0022] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here. In addition, the "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally represents that the objects associated with each other are in an "or" relationship.
[0023] First, some nouns or terms involved in the claims and description of this application are explained below.
[0024] The text beautification method, device and electronic device provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.
[0025] The text beautification method provided in the embodiment of the present application can be applied to the scenario of beautifying handwritten text.
[0026] With the development of computer vision technology, documents in image format have been widely used due to their features of being easy to carry, copy, transmit, manage, and view. At the same time, a large number of image processing tools have been launched, providing users with many convenient and effective image editing tools, such as word processing tools that can process text in image format. Specifically, you can use word processing tools to add text to an image or erase text in an image. As a result, since current word processing tools cannot beautify the text in an image, the processing effect of the text in the image is poor.
[0027] In the text beautification method provided in the embodiment of the present application, text recognition can be performed on the first image to determine M image areas, each of which includes a character; based on the M image areas, image processing is performed on the first image to obtain M first single-character images, each of which corresponds to an image area; font beautification processing is performed on the M first single-character images to obtain M second single-character images, and the font beautification processing includes at least one of the following: font structure processing, font style processing; the M second single-character images are synthesized with the original background image of the first image to obtain a second image. Through this scheme, since font beautification processing (specifically at least one of font structure processing and font style processing) can be performed on single-character images in an image (such as the first image), it can be ensured that the handwriting of the adjusted single-character image is more aesthetically pleasing, thereby improving the beautification processing effect of the text image in the image.
[0028] The present application embodiment provides a text beautification method. Figure 1 FIG. 1 is a flowchart of a font beautification method provided in an embodiment of the present application. Figure 1 As shown, the text beautification method provided in the embodiment of the present application may include the following step 101. The following is an exemplary description taking an electronic device executing the method as an example.
[0029] Step 101: An electronic device performs text recognition on a first image to determine M image regions in the first image.
[0030] Each of the M image regions includes a character, which may be a Chinese character, a letter or a symbol.
[0031] Optionally, in the embodiment of the present application, the characters may be handwritten characters or printed characters, which may be determined based on actual usage requirements and are not limited in the embodiment of the present application.
[0032] Optionally, in an embodiment of the present application, the electronic device may perform text recognition on the first image based on text recognition technology to determine M image regions in the first image.
[0033] Optionally, in the embodiment of the present application, the electronic device imports the first image (such as Figure 2 After obtaining the image shown in (a) in the figure, the electronic device may first perform text detection on the first image to determine the positions (or position information, such as coordinate information) of the M image regions in the first image.
[0034] For example, Figure 2 As shown in (b) of FIG. 1 , the electronic device may first use a text line detection technology to detect character lines (eg, Figure 2 Then, the character row 20 shown in (b) in FIG. 1 is detected by using the single word detection technology to detect the area of each character in each row area (such as Figure 2 The area 21 where the word "wine" is located as shown in (c).
[0035] Step 102: The electronic device performs image processing on the first image according to the M image areas to obtain M first single-word images.
[0036] Each of the M first single-word images corresponds to one image region among the M image regions, that is, the M image regions correspond to the M first single-word images one by one.
[0037] In an embodiment of the present application, the electronic device may crop the first image according to the M image regions to obtain M first single-word images.
[0038] Optionally, in the embodiment of the present application, the electronic device may copy a first image as a reference image before cropping the first image.
[0039] Step 103: The electronic device performs font beautification processing on the M first single-character images to obtain M second single-character images.
[0040] The above-mentioned font beautification may include at least one of the following: (i) font structure processing, (ii) font style processing.
[0041] Optionally, in the embodiment of the present application, the above step 103 can be specifically implemented by the following step 103a.
[0042] Step 103a: The electronic device performs font beautification processing on each of the M first single-character images based on the font beautification parameters to obtain a second single-character image corresponding to each first single-character image.
[0043] The above-mentioned font beautification parameters are parameters obtained by training a neural network model using a large number of single-word images, and each single-word image pair includes a single-word image to be beautified and a beautified single-word image.
[0044] It can be understood that in the embodiment of the present application, there are differences in the font style and / or stroke structure between the above-mentioned single-word image to be beautified and the above-mentioned single-word image after beautification.
[0045] For example, taking the difference in stroke structure between the single-word image to be beautified and the single-word image after beautification as an example, the stroke structure of the single-word image after beautification is more compact and coordinated than the stroke structure of the single-word image to be beautified.
[0046] Optionally, in the embodiment of the present application, the above-mentioned font beautification parameters may be parameters of a font beautification model. The font beautification model is obtained by training a convolutional neural network model using the above-mentioned large number of single-word image pairs; the font beautification model may be used to beautify at least one of the stroke structure and font style of a single-word image.
[0047] In order to more clearly explain the font beautification method provided in the embodiment of the present application, the method of training a neural network model using the above-mentioned large number of images is first exemplarily described below.
[0048] 1) Prepare the training set:
[0049] A large number of single-word image pairs are collected as training data sets. Each single-word image pair includes a single-word image to be beautified and a single-word image after the stroke structure and / or font style of the single-word image is adjusted (i.e., the beautified single-word image). The beautified single-word image in each single-word image pair is used as the label of the single-word image pair.
[0050] 2) Font beautification model training:
[0051] i) Randomly initialize the parameters (weights and biases) of each layer of the neural network model; and divide the single-word image pairs in the training set into batches, each batch including N single-word image pairs, where N is a positive integer.
[0052] ii) Input the first batch of single-word image pairs in the training set into the initialized neural network model.
[0053] After the first batch of single-word image pairs are input into the first layer of the neural network model, the N single-word images to be beautified in the first batch of single-word image pairs are weighted with the weights of the first layer, and a bias term is added and activated by the ReLu function to obtain N first result images; the N first result images are used as inputs of the second layer of the neural network model, and the N first result images are weighted with the weights of the second layer, and a bias term is added and activated by the ReLu function to obtain N second result images; then the N second result images are used as inputs of the third layer of the neural network model, and this is repeated until N j-th result images processed by the last layer of the neural network model are obtained, where j (indicating that the neural network model includes j layers) is a positive integer.
[0054] iii) The Euclidean distance between the N j-th result images and the corresponding label images (corresponding beautified single word images) is used to obtain N Euclidean distances, and then the average value of the N Euclidean distances is used as the error to calculate the gradient of the error to each network parameter in the neural network model; then the stochastic gradient descent algorithm is used to update the network parameters of the neural network model. In this way, the training of the neural network model is completed.
[0055] Then the second batch of single word image pairs are input into the neural network model to train the neural network model for the second time. This is repeated until the error drops to a suitable range and tends to be stable, and the entire training of the neural network model is completed. In the embodiment of the present application, the neural network model that has completed the above training is the font beautification model in the present application. The above font beautification parameters are the parameters of each layer in the trained neural network model.
[0056] Optionally, in an embodiment of the present application, the above-mentioned neural network model can be a convolutional neural network model, or it can be any other neural network model with learning ability, which can be determined according to actual usage requirements and is not limited in the embodiment of the present application.
[0057] Optionally, in an embodiment of the present application, the single-word image to be beautified in the above-mentioned training set can be handwritten, or the single-word image to be beautified in the above-mentioned training set can be obtained by randomly perturbing (i.e., "uglifying") a beautified single-word image by an electronic device.
[0058] It should be noted that in actual implementation, the electronic device performs font beautification processing on the i-th first single-word image among the M first single-word images based on the font beautification parameters to obtain the i-th second single-word image corresponding to the i-th first single-word image. Then, the electronic device can perform font beautification processing on the i+1-th first single-word image among the M first single-word images based on the font beautification parameters to obtain the i+1-th second single-word image corresponding to the i+1-th first single-word image. By analogy, after the electronic device performs font beautification processing on the M-th first single-word image among the M first single-word images based on the font beautification parameters, the M-th second single-word image corresponding to the M-th first single-word image can be obtained. That is, after the electronic device performs the above step 103a M times, M second single-word images can be obtained.
[0059] In an embodiment of the present application, the electronic device performs font beautification processing on each of the M first single-word images based on the font beautification parameters to obtain a second single-word image corresponding to each first single-word image. Specifically, each first single-word image is input into the font beautification model in turn for processing to obtain a second single-word image corresponding to each first single-word image.
[0060] For example, taking the example of beautifying one of the M first single-word images by using the font beautification model, the electronic device may be configured to be a first single-word image (eg Figure 3 The single word image 30 in the font beautification model is input, and the first single word image is compared with the font beautification model (for example Figure 3 The weight and bias value (i.e., font beautification parameter) of each layer of the font beautification model 22 in the image are calculated, and activation calculation is performed, and then the font beautification model can output a font beautification image corresponding to the first single word image, i.e., a second single word image corresponding to the first single word image (e.g., Figure 3 It can be understood that in the embodiment of the present application, inputting a single word image into the font beautification model for processing is essentially processing the single word image using the network parameters of each layer of the font beautification model (ie, the font beautification parameters).
[0061] In an embodiment of the present application, since the font beautification processing can be performed on the first single word image based on the font beautification parameters obtained by training the neural network model with a large number of single word image pairs, it is possible to achieve handwriting beautification while retaining the author's original writing style and personal characteristics.
[0062] Furthermore, since the stroke structure and / or font style of a single character image (i.e., the first single word image) can be adjusted, it can be ensured that the handwriting of the adjusted single word image is more aesthetically pleasing, thereby improving the processing effect of the text image in the image.
[0063] Step 104: The electronic device synthesizes the M second single-word images with the original background image of the first image to obtain a second image.
[0064] Optionally, in the embodiments of the present application, in the embodiments of the present application, as Figure 4 As shown, the electronic device can erase the characters in the reference image 40 by using a text erasing technique to obtain a Figure 4 The original background image 41 is shown. Alternatively, the electronic device can use the image other than the M image regions in the first image as the original background image, which can be determined according to actual use requirements and is not limited in the embodiment of the present application.
[0065] In the embodiment of the present application, the synthesis positions of the M second single-word images in the background image are determined according to the positions of the M image areas in the first image.
[0066] Optionally, in the embodiment of the present application, the above step 104 can be specifically implemented by the following steps 104a and 104b.
[0067] Step 104a: The electronic device determines second position information according to first position information of the M image areas in the first image, where the second position information is used to indicate synthesis positions of the M second single-word images in the original background image.
[0068] Step 104b: The electronic device synthesizes the M second single-word images with the background image according to the second position information to obtain a third image.
[0069] Among them, the similarity between the first arrangement method and the second arrangement method is greater than or equal to a preset threshold, the first arrangement method is the arrangement method of M second single word images in the third image, and the second arrangement method is the arrangement method of M image areas in the first image.
[0070] In the embodiment of the present application, the first position information is used to indicate the positions of the M image areas in the first image.
[0071] In the embodiment of the present application, it is assumed that the first image and the original background image are in the same coordinate system, and the position information (e.g., coordinate information) of the first image and the original background image in the coordinate system are the same. For example, it is assumed that the coordinate information of the first image is: (x1, y1), (x2, y2), (x3, y3), (x4, y4), and the coordinate information of the original background image is also: (x1, y1), (x2, y2), (x3, y3), (x4, y4); then:
[0072] In one method, the electronic device can use the first position information as the second position information. In this case, the synthesized positions of the M second single-character images in the original background image are the same as the positions of the M image areas in the first image area, that is, the positions of the characters in the image remain unchanged before and after the beautification processing.
[0073] In another way, in order to achieve a neat typesetting effect, during synthesis, the electronic device can divide the M image areas into at least one unit according to the distribution of the M image areas in the first image, where each unit is a character row or character column, and fine-tune the position information (i.e., the first position information) of the M image areas in units, and use the fine-tuned position information as the second position information, so that the synthesis positions of the second single-character images corresponding to the single image area group in the original background image can be arranged in a straight line as much as possible.
[0074] The following is an illustrative description of a method for an electronic device to fine-tune position information of M image regions, taking a character line as an example.
[0075] i) The electronic device calculates the position information of the center points of the M image areas in the first image (such as Figure 5The position information 50 shown in the figure) is used to obtain M position information (ie, the first position information).
[0076] ii) The electronic device divides the M image areas into at least one character line according to the distribution of the M image areas in the first image, and fits the position information of the image areas in each character line into a straight line (such as Figure 5 It should be noted that, in the embodiment of the present application, the number of straight lines determined by the electronic device is the same as the number of character rows.
[0077] iii) For each character row, assuming that a character row (hereinafter referred to as character row o) includes u (u is an integer greater than 1) image areas (i.e., u characters), and the straight line determined according to the position information of the u characters is the first straight line, then: the electronic device can use the projection position of the center point of the leftmost image area of the character row o on the first straight line as the synthesis starting point; use the projection position of the center point of the rightmost image area of the character row o on the first straight line as the synthesis end point; and calculate the gap d between two adjacent second single word images based on the distance L between the synthesis starting point and the synthesis end point, and the width values w1, w2, w3...wu of the u second single word images corresponding to the u image areas. Specifically, the gap d can be calculated by the following formula 1, Formula 1: d=[L-(w1+w2+w3...+wu-w1*0.5-wu*0.5)]÷(u-1). It can be understood that the position information of the synthesis positions of the u second single-character images in the original background image includes: the position information of the synthesis starting point, the position information of the synthesis end point, and the position information of u-2 positions located between the synthesis starting point and the synthesis end point and with an interval of d. It should be noted that in the embodiment of the present application, the electronic device can obtain the second position information after performing the above step iii on the image area in each character row.
[0078] For the description of determining the second position information in units of character columns, please refer to the relevant description of determining the second position information in units of character lines. In order to avoid repetition, it will not be repeated here.
[0079] It can be understood that in the embodiments of the present application, the above i~iii are illustrated by taking the example of fine-tuning the row coordinates (i.e., X-axis coordinates) and column coordinates (i.e., Y-axis coordinates) of the position information of the image area in each character row. In actual implementation, at least one of the row coordinates and column coordinates of the position information of the image area can be adjusted.
[0080] Exemplarily, taking the character line as the unit, assume that the first image completely coincides with the original background image. Then: The electronic device can use the original position of the leftmost image area in a character line of the first image as the synthesis starting point, and paste the second single-character images corresponding to the image areas in this character line to the second image in sequence from left to right, and these single-character images maintain the same gap in the horizontal direction (i.e., the average paste gap d). That is, only the row coordinates are adjusted.
[0081] Also exemplarily, in combination with Figure 5 , as Figure 6 shows, taking the character line as the unit, if the distance between the position information of an image area in M image areas and the fitting straight line is less than or equal to the first threshold, for example Figure 5 ("small", "garden", "fragrant", "path", "alone", "wander", "徘徊") in Figure 5 , then the electronic device vertically moves the column coordinate (Y-axis coordinate) of the second single-character image corresponding to this image area to the fitting straight line; if the distance between the position information of an image area in the first image and the fitting straight line is greater than the first threshold, for example Figure 5 "." in Figure 5 ; then the electronic device keeps the column coordinate of the second single-character image corresponding to this image area the same as the column coordinate of this image area. As Figure 6 shows, Figure 6 is a schematic diagram of the second image. The column coordinates of the second single-character images "small", "garden", "fragrant", "path", "alone", "wander", and "徘徊" are vertically adjusted to the fitting straight line, while the row coordinate of the second single-character image "." is not moved.
[0082] The embodiments of the present application provide a method for beautifying the handwriting (font structure and font style) of characters in an image. Using the text beautification method provided by the embodiments of the present application can not only beautify the handwritten handwriting in the image, but also standardize the typesetting effect of the text in the image, so as to improve the visual perception of the (handwritten) text in the image.
[0083] In the embodiments of the present application, since the electronic device can finely adjust the typesetting of M second single-character images, it can ensure that the typesetting of M second single-character images in the second image is more neat and beautiful.
[0084] In the font beautification method provided by the embodiments of the present application, since the single-character images in an image (such as the first image) can be subjected to font beautification processing (specifically at least one of font structure processing and font style processing), it can ensure that the handwriting of the adjusted single-character images is more aesthetically pleasing, thus improving the beautification processing effect of the text images in the image.
[0085] Optionally, in an embodiment of the present application, after obtaining M second single-word images, the electronic device may adjust the sizes of the M second single-word images to reduce the size difference between words, thereby making the layout of the M second single-word images more visually neat.
[0086] Optionally, in an embodiment of the present application, before the above step 104, the font beautification method provided in the embodiment of the present application further includes the following steps 105 and 106.
[0087] Step 105: The electronic device divides the M second single-word images into at least one image group according to the distribution of the M image regions in the first image.
[0088] In the embodiment of the present application, each image group in the at least one image group includes at least one second single-word image.
[0089] In the embodiment of the present application, since the M image areas, M first single-word images, and M second single-word images in the first image correspond one to one, the M second single-word images can be grouped according to the areas where the M image areas are located in the first image, and H groups are obtained, where H is a positive integer. Specifically, assuming that Q single-word images in the M image areas are in area 1 in the first image, and K images in the M image areas are in area 2 in the first image, and area 1 is different from area 2, the sum of Q and K is equal to M, and Q and K are both positive integers; then: the Q second single-word images corresponding to the Q single-word images are one group, and the K second single-word images corresponding to the K single-word images are another group.
[0090] It can be understood that in actual implementation, the second single-character images can also be grouped according to the size. For example, if the size of 2 second single-character images among M second single-character images is greater than 2 square centimeters, and the size of 3 second single-character images among M second single-character images is less than or equal to 2 square centimeters, then: the 2 second single-character images are one group, and the 3 second single-character images are another group.
[0091] Step 106: The electronic device performs size normalization processing on the second single-word images in at least one image group in units of image groups to obtain M normalized second single-word images.
[0092] Optionally, in the embodiment of the present application, the above step 106 can be specifically implemented by the following steps 106a and 106b, or by the following steps 106a and 106c.
[0093] Step 106a: for each of the M second single-character images, determine a first difference between the size of the second single-character image and the target size.
[0094] The target size may be a median value of sizes of all second single-word images in a first image group, and the first image group is the image group to which the above-mentioned second single-word image belongs.
[0095] In an embodiment of the present application, the electronic device can calculate the median of the width values of the second single-word images in the first image group (hereinafter referred to as the width median), and calculate the median of the height values of all second single-word images in a group (hereinafter referred to as the height median), and use the width median and height median as the target size.
[0096] In the embodiment of the present application, for each of the M second single-word images, the electronic device can first determine a first difference between the size of a second single-word image and the target size; if the first difference is less than or equal to the preset difference, the electronic device can perform the following step 106b; if the first difference is greater than the preset difference, the electronic device can perform the following step 106c. It should be noted that in the embodiment of the present application, after the electronic device performs this process M times, it can obtain M second single-word images after normalization.
[0097] Step 106b: The electronic device adjusts the size of a second single-word image to the first size.
[0098] The difference between the first size and the target size is smaller than the first difference. For example, the second difference may be 0.
[0099] Step 106c: The electronic device keeps the size of a second single word image unchanged.
[0100] Optionally, in the embodiment of the present application, assuming that the first dimension is: width*height=a1*b1, and the second dimension is: width*height=a2*b2, then a2=(1±k)*a1, b2=(1±w)*b1, where a1, a2, b1, and b2 are numbers greater than 0, k is greater than 0 and less than the median of the width, and w is greater than 0 and less than or equal to the median of the height. For example, the median of the width can be 0.2, and the median of the height can be 0.2. Of course, the first preset value and the second preset value can also be different.
[0101] It can be understood that in the embodiment of the present application, for each single-word image in the M second single-word images, assuming that the size of a second single-word image is the first size, then: if the difference between the first size and the target size (i.e., the above-mentioned first difference) is less than or equal to the target preset value, the electronic device can adjust the size of the second single-word image from the first size to the second size, so that the size of the second single-word image is closer to the target size. If the difference between the first size and the target size (i.e., the above-mentioned first difference) is greater than the target preset value, the electronic device keeps the size of the second single-word image unchanged to maintain the size characteristics of the second single-word image.
[0102] In the embodiment of the present application, since the sizes of the M second single-word images can be brought closer to the target size, the size difference between different second single-word images can be reduced, so that the layout of the M second single-word images can be more visually neat.
[0103] Optionally, in an embodiment of the present application, in order to ensure that the sizes of the M first single-word images meet the size requirements of image processing, the sizes of the M first single-word images may be adjusted before font beautification processing is performed on the above-mentioned M first single-word images.
[0104] Optionally, in the embodiment of the present application, before the above step 103, the font beautification method provided in the embodiment of the present application may further include the following step 107.
[0105] Step 107: The electronic device performs normalization processing on the M first single-word images.
[0106] The size of each first single word image after normalization is within a preset size range. The preset size range is to meet the image processing size requirements.
[0107] Optionally, in the embodiment of the present application, the size of a single-word image may be the side length and / or area of the single-word image.
[0108] In an embodiment of the present application, if the size of a single-character image is within a preset size range, it means that the size of the single-character image meets the image processing size requirement; if the size of a single-character image is outside the preset size range, it means that the size does not meet the image processing size requirement.
[0109] It can be understood that in the embodiments of the present application, Figure 7 As shown, the electronic device will normalize the single word images detected from the character row one by one (for example, in the order from "small" to "diameter") within a preset size range, and then input them into the font beautification model for processing to obtain the processed "Wandering alone in the fragrant path of the small garden".
[0110] It should be noted that, in the embodiment of the present application, in order to make the typesetting more neat, after the normalization processing is performed on the above-mentioned M first single-word images and the font beautification processing is performed to obtain M second single-word images, the size of the M second single-word images can be restored to the original size.
[0111] In the embodiment of the present application, since the size of the single word image to be beautified can be normalized before processing the single word image to be beautified, the success rate of processing the single word image to be beautified can be ensured.
[0112] Combination Figure 8As shown, an embodiment of the present application provides a text beautification device 80, which may include: a recognition module 81, a processing module 82 and a synthesis module 83; the recognition module 81 is used to perform text recognition on a first image; the processing module 82 is used to determine M image areas in the first image according to the recognition result of the recognition module 81, each image area includes a character; the processing module 82 is also used to perform image processing on the first image according to the M image areas to obtain M first single-character images, each first single-character image corresponds to an image area; the processing module 82 is also used to perform font beautification processing on the M first single-character images to obtain M second single-character images, and the font beautification processing includes at least one of the following: font structure processing, font style processing; the synthesis module 83 is used to synthesize the M second single-character images processed by the processing module 82 with the original background image of the first image to obtain a second image.
[0113] In a possible implementation, the processing module 82 is specifically configured to perform font beautification processing on each first single-character image based on the font beautification parameters to obtain a second single-character image corresponding to each first single-character image.
[0114] The font beautification parameters are parameters obtained by training a neural network model using a large number of single-word images, and each single-word image pair includes a single-word image to be beautified and a beautified single-word image.
[0115] In a possible implementation, the processing module 82 is also used to divide the M second single word images into at least one image group according to the distribution of the M image areas in the first image before the synthesis module 83 synthesizes the M second single word images with the original background image of the first image to obtain the second image; and perform size normalization processing on the second single word images in at least one image group in units of image groups to obtain M second single word images after normalization.
[0116] In one possible implementation, the processing module 82 is specifically used to, for each of the M second single-character images, adjust the size of a second single-character image to a first size, and the difference between the first size and the target size is less than the first difference, when a first difference between the size of a second single-character image and a target size is less than a preset difference; or, the processing module 82 is specifically used to, for each of the M second single-character images, keep the size of a second single-character image unchanged when a first difference between the size of a second single-character image and the target size is greater than a preset difference.
[0117] The target size is the median of the sizes of all second single-word images in the first image group, and the first image group is an image group to which a second single-word image belongs.
[0118] In a possible implementation, the synthesis module 83 includes a determination submodule and a synthesis submodule;
[0119] A determination submodule is used to determine second position information based on first position information of the M image areas in the first image, wherein the second position information is used to indicate the synthesis position of the M second single-word images in the original background image; and a synthesis submodule is used to synthesize the M second single-word images with the background image according to the second position information determined by the determination submodule to obtain a third image.
[0120] Among them, the similarity between the first arrangement method and the second arrangement method is greater than or equal to a preset threshold, the first arrangement method is the arrangement method of M second single word images in the third image, and the second arrangement method is the arrangement method of M image areas in the first image.
[0121] In the text beautification device provided in the embodiment of the present application, since the single-word image in an image (for example, the first image) can be subjected to font beautification processing (specifically at least one of font structure processing and font style processing), it can be ensured that the handwriting of the adjusted single-word image is more aesthetically pleasing, thereby improving the beautification processing effect of the text image in the image.
[0122] The beneficial effects of various implementations in this embodiment can be specifically referred to the beneficial effects of the corresponding implementations in the above method embodiment. To avoid repetition, they will not be described again here.
[0123] The text beautification in the embodiments of the present application may be a device, or a component, integrated circuit, or chip in a terminal. The device may be a mobile electronic device or a non-mobile electronic device. For example, the mobile electronic device may be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc. The non-mobile electronic device may be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc., which is not specifically limited in the embodiments of the present application.
[0124] The text beautification device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0125] The text beautification device provided in the embodiment of the present application can achieve Figures 1 to 6 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0126] like Fig. 9 As shown, an embodiment of the present application also provides an electronic device 200, including a processor 202, a memory 201, and a program or instruction stored in the memory 201 and executable on the processor 202. When the program or instruction is executed by the processor 202, each process of the above-mentioned text beautification method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0127] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0128] Fig.10 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application.
[0129] The electronic device 1000 includes but is not limited to: a radio frequency unit 1001, a network module 1002, an audio output unit 1003, an input unit 1004, a sensor 1005, a display unit 1006, a user input unit 1007, an interface unit 1008, a memory 1009, and a processor 1010 and other components.
[0130] Those skilled in the art will appreciate that the electronic device 1000 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1010 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Fig.10 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0131] Among them, the processor 1010 is used to perform text recognition on the first image; and determine M image areas in the first image, each image area includes a character; and perform image processing on the first image to obtain M first single-character images, each first single-character image corresponds to an image area; and perform font beautification processing on the M first single-character images to obtain M second single-character images, and the font beautification processing includes at least one of the following: font structure processing, font style processing; the processor 1010 is used to synthesize the M second single-character images processed by the processor 1010 with the original background image of the first image to obtain a second image.
[0132] In a possible implementation, the processor 1010 is specifically configured to perform font beautification processing on each first single-character image based on the font beautification parameter to obtain a second single-character image corresponding to each first single-character image.
[0133] The font beautification parameters are parameters obtained by training a neural network model using a large number of single-word images, and each single-word image pair includes a single-word image to be beautified and a beautified single-word image.
[0134] In a possible implementation, the processor 1010 is further used to divide the M second single word images into at least one image group according to the distribution of the M image areas in the first image before synthesizing the M second single word images with the original background image of the first image to obtain the second image; and to perform size normalization processing on the second single word images in at least one image group in units of image groups to obtain M second single word images after normalization.
[0135] In one possible implementation, the processor 1010 is specifically used to, for each of the M second single-character images, adjust the size of a second single-character image to a first size, and the difference between the first size and the target size is less than the first difference, when a first difference between the size of the second single-character image and the target size is less than a preset difference; or, the processor 1010 is specifically used to, for each of the M second single-character images, keep the size of a second single-character image unchanged when a first difference between the size of the second single-character image and the target size is greater than a preset difference.
[0136] The target size is the median of the sizes of all second single-word images in the first image group, and the first image group is an image group to which a second single-word image belongs.
[0137] In one possible implementation, the processor 1010 is used to determine second position information based on first position information of the M image areas in the first image, where the second position information is used to indicate the synthesis position of the M second single-word images in the original background image; and synthesize the M second single-word images with the background image according to the determined second position information to obtain a third image.
[0138] Among them, the similarity between the first arrangement method and the second arrangement method is greater than or equal to a preset threshold, the first arrangement method is the arrangement method of M second single word images in the third image, and the second arrangement method is the arrangement method of M image areas in the first image.
[0139] In the text beautification device provided in the embodiment of the present application, since the single-word image in an image (for example, the first image) can be subjected to font beautification processing (specifically at least one of font structure processing and font style processing), it can be ensured that the handwriting of the adjusted single-word image is more aesthetically pleasing, thereby improving the beautification processing effect of the text image in the image.
[0140] The beneficial effects of various implementations in this embodiment can be specifically referred to the beneficial effects of the corresponding implementations in the above method embodiment. To avoid repetition, they will not be described again here.
[0141] It should be understood that in the embodiment of the present application, the input unit 1004 may include a graphics processor (Graphics Processing Unit, GPU) 10041 and a microphone 10042, and the graphics processor 10041 processes the image data of the static picture or video obtained by the image capture device (such as a camera) in the video capture mode or the image capture mode. The display unit 1006 may include a display panel 10061, and the display panel 10061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1007 includes a touch panel 10071 and other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include two parts: a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, a physical keyboard, a function key (such as a volume control button, a switch button, etc.), a trackball, a mouse, and a joystick, which will not be repeated here. The memory 1009 can be used to store software programs and various data, including but not limited to applications and operating systems. The processor 1010 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 1010.
[0142] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned text beautification method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0143] Among them, the above-mentioned processor is the processor in the electronic device in the above-mentioned embodiment. The above-mentioned readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc. The embodiment of the present application further provides a chip, which includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a program or instruction to implement each process of the above-mentioned text beautification method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0144] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0145] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0146] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0147] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A text beautification method, characterized in that: The method comprises: Performing text recognition on the first image to determine M image regions in the first image, each image region including a character; According to the M image regions, performing image processing on the first image to obtain M first single-word images, each first single-word image corresponding to an image region; Performing font beautification processing on the M first single-character images to obtain M second single-character images, wherein the font beautification processing includes at least one of the following: font structure processing and font style processing; Dividing the M second single-word images into at least one image group according to the distribution of the M image areas in the first image; Taking image groups as units, performing size normalization processing on the second single-word images in the at least one image group to obtain M second single-word images after normalization processing; The normalized M second single-word images are synthesized with the original background image of the first image to obtain a second image.
2. The method according to claim 1, characterized in that The method of performing font beautification processing on the M first single word images to obtain M second single word images includes: Based on the font beautification parameter, performing font beautification processing on each of the first single-character images to obtain a second single-character image corresponding to each of the first single-character images; The font beautification parameters are parameters obtained by training a neural network model using a large number of single-word image pairs, and each single-word image pair includes a single-word image to be beautified and a beautified single-word image.
3. The method according to claim 1, characterized in that: The step of performing size normalization processing on the second single word images in the at least one image group in units of image groups to obtain M second single word images after normalization processing comprises: For each of the M second single-character images, when a first difference between a size of a second single-character image and a target size is less than or equal to a preset difference, adjusting the size of the second single-character image to a first size, wherein the difference between the first size and the target size is less than the first difference; or, When a first difference between a size of a second single-character image and a target size is greater than a preset difference, maintaining the size of the second single-character image unchanged; The target size is the median of the sizes of all second single-word images in the first image group, and the first image group is the image group to which the second single-word image belongs.
4. The method according to claim 1, characterized in that: The step of synthesizing the normalized M second single-word images with the original background image of the first image to obtain a second image comprises: Determine second position information according to first position information of the M image areas in the first image, wherein the second position information is used to indicate a synthesis position of the normalized M second single-word images in the original background image; According to the second position information, the normalized M second single word images are synthesized with the background image to obtain a third image; Among them, the similarity between the first arrangement method and the second arrangement method is greater than or equal to a preset threshold, the first arrangement method is the arrangement method of the M second single-word images after the normalization processing in the third image, and the second arrangement method is the arrangement method of the M image areas in the first image.
5. A text beautification device, characterized in that: The device comprises: an identification module, a processing module and a synthesis module; The recognition module is used to perform text recognition on the first image; The processing module is used to determine M image regions in the first image according to the recognition result of the recognition module, each image region includes a character; The processing module is further used to perform image processing on the first image according to the M image regions to obtain M first single-word images, each first single-word image corresponding to an image region; The processing module is further used to perform font beautification processing on the M first single-character images to obtain M second single-character images, wherein the font beautification processing includes at least one of the following: font structure processing and font style processing; The processing module is further used to divide the M second single-word images into at least one image group according to the distribution of the M image areas in the first image; and perform size normalization processing on the second single-word images in the at least one image group in units of image groups to obtain the normalized M second single-word images; The synthesis module is used to synthesize the normalized M second single-word images obtained by the processing module with the original background image of the first image to obtain a second image.
6. The device according to claim 5, characterized in that The processing module is specifically used to perform font beautification processing on each of the first single-character images based on the font beautification parameters to obtain a second single-character image corresponding to each of the first single-character images; The font beautification parameters are parameters obtained by training a neural network model using a large number of single-word image pairs, and each single-word image pair includes a single-word image to be beautified and a beautified single-word image.
7. The device according to claim 5, characterized in that The processing module is specifically configured to adjust the size of each second single-character image in the M second single-character images to a first size when a first difference between the size of the second single-character image and the target size is less than or equal to a preset difference, and the difference between the first size and the target size is less than the first difference; or The processing module is specifically configured to keep the size of each second single-character image in the M second single-character images unchanged when a first difference between the size of the second single-character image and the target size is greater than a preset difference; The target size is the median of the sizes of all second single-word images in the first image group, and the first image group is the image group to which the second single-word image belongs.
8. The device according to claim 5, characterized in that The synthesis module includes a determination submodule and a synthesis submodule; The determination submodule is used to determine second position information according to first position information of the M image areas in the first image, wherein the second position information is used to indicate the synthesis position of the M second single-word images after the normalization process in the original background image; The synthesis submodule is used to synthesize the normalized M second single word images with the background image according to the second position information determined by the determination submodule to obtain a third image; Among them, the similarity between the first arrangement method and the second arrangement method is greater than or equal to a preset threshold, the first arrangement method is the arrangement method of the M second single-word images after the normalization processing in the third image, and the second arrangement method is the arrangement method of the M image areas in the first image.
9. An electronic device, characterized in that: The method comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the text beautification method as claimed in any one of claims 1 to 4.
10. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the text beautification method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Font addition method and device
CN105335198A
Method and device for beautifying handwritten fonts by utilizing AI technology
CN110111243A
A method and device for processing image
CN111783508A
Chinese character calligraphy style recognition method and scoring method based on convolutional neural network
CN113128442A
