Image generation method and device
By automatically determining the font size, position, and color of the text in the image, and combining it with a color matching knowledge base, the text information is automatically combined with the original image, solving the problem of high manual costs and improving generation efficiency and information transmission effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-18
- Publication Date
- 2026-03-31
AI Technical Summary
In existing technologies, combining text information with original images requires the involvement of professional designers, resulting in high labor costs and low generation efficiency.
By automatically determining the font size and position of the image text based on the text length and the main subject position of the original image, and using a color matching knowledge base to determine the text color, the automatic addition of image text is achieved.
While ensuring visual quality, it reduces labor costs, improves image generation efficiency, highlights important information, and enhances information delivery efficiency.
Smart Images

Figure CN121767480A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically, to an image generation method and apparatus. Background Technology
[0002] Combining text information with original images can improve the efficiency and effectiveness of information delivery and enhance user experience. However, to ensure the visual quality of the combined image, professional designers are needed to combine the images and text, which undoubtedly increases labor costs and reduces image generation efficiency. Summary of the Invention
[0003] In view of this, the present disclosure provides at least one image generation method and apparatus that can reduce the manual cost of image generation and improve the efficiency of image generation while ensuring the visual effect of the generated target image.
[0004] In a first aspect, embodiments of this disclosure provide an image generation method, including:
[0005] Determine the font size of the image text based on its length;
[0006] Determine the position information of the image text based on the position of the main subject in the original image;
[0007] Based on the font size and position information of the image text, the image text is added to the original image to obtain the target image.
[0008] Optionally, the font size of the image text is determined based on the text length of the image text, including:
[0009] Based on the order in which the text information in the image is obtained, the display priority of each text information is determined;
[0010] The font size of the image text is determined based on the display priority and text length of each text message; among them, the font size of text messages with higher display priority is larger than the font size of text messages with lower display priority.
[0011] Optionally, the method further includes:
[0012] Based on the location of the subject in the original image, determine the maximum usable area in the original image for adding image text; the maximum usable area does not overlap with the subject;
[0013] Based on the maximum available area, determine the arrangement of each text information in the image text; wherein, the length and width of the text box obtained after arranging each text information according to the arrangement method are less than the length and width corresponding to the maximum available area;
[0014] Based on the font size, arrangement, and position information of the image text, the image text is added to the original image to obtain the target image.
[0015] Optionally, based on the position of the subject in the original image, the positional information of the image text is determined, including:
[0016] Define the text box for the image text;
[0017] Based on the position of the subject in the original image, the position information of the text in the image is obtained by taking the following as objective functions: minimizing the overlap rate between the text box and the subject, minimizing the difference between the distance between the text box and the edge of the original image and the distance between the text box and the subject, and ensuring that the distance between the text box and the edge of the original image is greater than a preset threshold. The preset threshold is determined based on the size of the original image.
[0018] Optionally, the method further includes:
[0019] Based on the location information of the image text and the color information of the original image, determine the background color within a preset range around the image text;
[0020] Based on the background color within a preset range around the image text and a pre-generated color matching knowledge base, determine the text color corresponding to the background color, and use the text color corresponding to the background color as the text color of the image text.
[0021] Based on the font size, position information, and text color of the image text, the image text is added to the original image to obtain the target image.
[0022] Optionally, the color scheme knowledge base is generated through the following steps:
[0023] Based on the collected historical images, determine the text regions within the historical images;
[0024] Generate a mapping relationship between the background color and the text color within the text area, and generate a color matching knowledge base based on the mapping relationship.
[0025] Secondly, embodiments of this disclosure provide an image generation apparatus, comprising:
[0026] The font determination module is used to determine the font size of the image text based on its text length.
[0027] The location determination module is used to determine the location information of the text in the image based on the location of the main subject in the original image;
[0028] The add module is used to add image text to the original image to obtain the target image based on the font size and position information of the image text.
[0029] Thirdly, embodiments of this disclosure also provide an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the first aspect or any optional implementation of the first aspect are performed.
[0030] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the first aspect or any optional implementation thereof.
[0031] Fifthly, embodiments of this disclosure also provide a computer program product, including a computer program that, when executed by a processor, implements the methods of any of the above embodiments.
[0032] In any of the above aspects or any implementation thereof, the font size of the image text is determined based on the text length of the image text, and the position of the image text is determined based on the position of the subject in the original image. This allows the font size and position of the image text to adapt to the original image, ensuring the visual effect of the final generated target image. Furthermore, since the font size is determined based on the image text and the position is determined based on the subject position, no professional designers are required to design the layout, thereby improving image generation efficiency while saving labor costs.
[0033] In a further embodiment of this disclosure, when determining the font size of the image text, the priority of different text information in the image text can also be considered. By designing the font of high-priority text information to be larger and the font of low-priority text information to be smaller, the text information that is to be displayed first can be highlighted, thereby further improving the visual effect and information transmission efficiency of the target image.
[0034] In a further embodiment of this disclosure, when determining the position of the image text, the objective functions are: minimizing the overlap rate between the text box and the subject, minimizing the difference between the distance between the text box and the edge of the original image and the distance between the image text and the subject, and ensuring that the distance between the text box and the edge of the original image is greater than a preset threshold. In addition, a pre-generated color matching knowledge base is used to determine the text color of the image text, and the arrangement of the image text is determined according to the available area size in the original image. This can further improve the visual effect of the final generated target image, reduce labor costs, and improve image generation efficiency.
[0035] The effects of the aforementioned image generation apparatus, electronic device, and storage medium are described in the description of the image generation method above, and will not be repeated here. Attached Figure Description
[0036] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.
[0037] Figure 1 A flowchart of an image generation method provided by an embodiment of this disclosure is shown;
[0038] Figure 2 This illustration shows a schematic diagram of a generated binary image in the image generation method provided in this embodiment of the present disclosure;
[0039] Figure 3 The illustration shows a schematic diagram of a method for determining the text position in an image generation method provided in this embodiment of the present disclosure;
[0040] Figure 4 The diagram illustrates a flowchart of the image generation method provided in this embodiment, in which a genetic algorithm is used to determine the text position in an image.
[0041] Figure 5 The illustration shows a schematic diagram of a method for determining the color of text in an image generation method provided in an embodiment of this disclosure;
[0042] Figure 6 A schematic diagram of an image generation apparatus provided in an embodiment of this disclosure is shown;
[0043] Figure 7 An exemplary system architecture in which embodiments of this disclosure can be applied is shown;
[0044] Figure 8 A schematic diagram of the structure of a computer system used to implement the embodiments of the present disclosure is shown. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0046] It should be noted that the collection, use, storage, sharing and transfer of user personal information involved in the technical solution of the present invention all comply with the provisions of relevant laws and regulations, and require notification to users and obtaining their consent or authorization. When applicable, user personal information is subjected to de-identification and / or anonymization and / or encryption technical processing.
[0047] The aforementioned problems and solutions are the result of the inventor's practice and careful research. The discovery process of the aforementioned problems and the solutions proposed for the aforementioned problems should be considered as the inventor's contribution to this disclosure.
[0048] The technical solutions of this disclosure will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely to illustrate selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0049] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0050] To facilitate understanding of this embodiment, a detailed description of the image generation method disclosed in this disclosure is provided first. The execution entity of the image generation method provided in this disclosure is generally a computer device with certain computing capabilities. This computer device may include, for example, a terminal device, a server, or other processing devices. The terminal device may be a user equipment (UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (PDA), handheld device, computing device, in-vehicle device, wearable device, etc. In some possible implementations, the image generation method can be implemented by a processor calling computer-readable instructions stored in memory.
[0051] See Figure 1 The diagram shows a flowchart of an image generation method provided in an embodiment of this disclosure. The method includes steps S101 to S103, wherein:
[0052] S101: Determine the font size of the image text based on its text length.
[0053] In this step, the font size of the image text can be determined based on its length. Specifically, the text length and font size can be linearly related. Given the text length, the font size can be calculated using y = kx + b; where y represents the font size, x represents the text length, and k and b are preset parameters that can be set according to visual requirements. It should be noted that when determining the font size, the predetermined size of the final target image can also be taken into account to ensure that the font is not too large (exceeding the image edges) or too small (resulting in poor display).
[0054] For example, assuming the target image has a predetermined size of 800 pixels * 800 pixels, then in the above y = kx + b, b can be set to 100 and k to -10. Assuming the text length of the image text is 6, the calculated font size would be 40 points. Setting a linear relationship is to maintain coordination between the image text and the target image. Setting k and b ensures that the text occupies a certain proportion of the image area.
[0055] In one possible implementation, the font size of the image text can also be determined based on the text length of the image text and a predefined rule. For example, when the text length is less than 6, the font size of the image text can be set to size 4, while when the text length exceeds 6, the font size of the image text can be set to small size 4. Similarly, the font size of the image text can be determined in a step-by-step manner based on the text length, etc., and this disclosure does not limit this aspect.
[0056] In this embodiment of the disclosure, when the image text includes more than one piece of text information, different font sizes can be determined for different pieces of text information. Specifically, determining the font size of the image text based on its text length includes: determining the display priority of each piece of text information based on the order in which they are obtained; and determining the font size of the image text based on the display priority and text length of each piece of text information; wherein the font size of text information with higher display priority is greater than the font size of text information with lower display priority.
[0057] In specific implementations, the image text can be user-inputted or actively acquired by the execution entity of this disclosure embodiment. The display priority of each text message can be determined based on the order in which they are acquired. For example, the display priority of text messages can decrease with the acquisition order, so the first acquired text message has the highest display priority, and the last acquired text message has the lowest display priority. Alternatively, the display priority of each text message can be determined based on both the quantity and acquisition order. For instance, if the image text includes four text messages, the first two acquired text messages can be set to the same high priority, while the last two acquired text messages can be set to the same low priority. Alternatively, the first acquired text message can be set to a high priority, while the remaining three can be set to the same low priority. This disclosure embodiment does not impose specific limitations on this approach; the actual application should be based on specific needs. It should be noted that the above method of determining font size based on the quantity and acquisition order of text messages is only one possible implementation method in this disclosure embodiment and does not constitute an improper limitation of the present invention.
[0058] In a specific implementation, another possible approach is that the display priority of each text message can be specified by the user. In a specific implementation, the user can set a display priority for each text message when inputting it, or specify which text messages in the current image should be enlarged and displayed first. Alternatively, when the execution entity of this embodiment actively retrieves each text message, it can display it to the user on a display device associated with the execution entity of this embodiment, allowing the user to set its display priority. Then, the font size of the image text can be determined based on the user-specified display priority and text length.
[0059] In this embodiment, a standard font size can be determined first based on the text length. Then, it can be adjusted based on the display priority of different text information, for example, increasing the font size of higher-priority text information. The increase can be related to the specific priority level of the text information. Alternatively, display priority can be used as a coefficient in the formula for determining font size, thereby directly determining the font size of the image text based on the text length and display priority. By controlling the display priority of different text information in the image text, the text information that should be prioritized for display to the user can be highlighted, further improving the information delivery effect and efficiency of the final target image.
[0060] In this embodiment, the arrangement of the image text can also be determined. When the image text includes only one piece of text information, the arrangement can include whether the text in that text information is arranged horizontally or vertically, etc. When the image text includes at least two pieces of text information, in addition to determining the arrangement of the text in each piece of text information, the arrangement between different pieces of text information can also be determined, such as whether four pieces of text information are arranged in one column and four rows or two columns and two rows, etc. Specifically, the maximum available area in the original image for adding image text can be determined based on the position of the main subject in the original image; the maximum available area does not overlap with the main subject; based on the maximum available area, the arrangement of each piece of text information in the image text is determined; wherein, the length and width of the text box obtained after arranging each piece of text information according to the arrangement method are less than the length and width corresponding to the maximum available area; based on the font size, arrangement method, and position information of the image text, the image text is added to the original image to obtain the target image.
[0061] In specific implementation, the area in the original image that can be used to add image text can be calculated based on the subject's position. Then, based on the determined font size, text boxes corresponding to the image text can be generated according to different arrangement methods. To ensure the display effect of the final generated target image, the size of the text box corresponding to the final selected arrangement method should be smaller than the size of the maximum usable area. When multiple arrangement methods meet the above requirements, a final arrangement method can be randomly determined, or the user can select the final arrangement method. This disclosure does not specifically limit this. Alternatively, the arrangement method can also be determined based on the number of text information. For example, when the image text includes four pieces of text information, a two-column, two-row arrangement method is used. This disclosure does not specifically limit the method for determining the image text arrangement method.
[0062] S102: Determine the position information of the image text based on the position of the main subject in the original image.
[0063] In this embodiment, the positional information of the subject in the original image can be determined first. In specific implementations, techniques such as foreground detection can be used to cut out the original image, distinguishing the subject from the background, and then a binary image can be generated based on the main image. Figure 2 A schematic diagram of a binary image generated according to an embodiment of this disclosure, as shown below. Figure 2 As shown, the white portion represents the main subject, and the black portion represents the background. The generated binary image can be the same size as the preset size of the target image. When the generated binary image differs from the original image, the main subject's coordinates in the original image can be used as a basis to proportionally transform the main subject in the binary image, thereby ensuring that the display effect in the binary image is the same as that in the original image. It should be noted that the above method for determining the position of the main subject in the original image is only illustrative of one possible implementation in this disclosure and does not constitute an improper limitation of the present invention. In practical applications, any method can be used to determine the position in the original image, and this disclosure does not impose specific limitations on this, as long as its function can be achieved. After determining the position information of the main subject in the original image, the position information of the image text can be determined. For example, the area that does not overlap with the position of the main subject can be directly used as the center as the position of the image text.
[0064] In this embodiment of the disclosure, in order to ensure that the display effect of the image text can achieve high information transmission efficiency and aesthetic appeal, the position information of the image text can be calculated. Specifically, the position information of the image text is determined based on the position of the subject in the original image, including: determining the text box of the image text; and obtaining the position information of the image text based on the position of the subject in the original image, with the objective function being the minimum overlap rate between the text box and the subject, the minimum difference between the distance between the text box and the edge of the original image and the distance between the image text and the subject, and the distance between the text box and the edge of the original image being greater than a preset threshold; wherein, the preset threshold is determined based on the size of the original image.
[0065] In practice, swarm intelligence optimization algorithms such as genetic algorithms and particle swarm optimization can be used to calculate the location information of image text. The following explanation uses the genetic algorithm to determine the location information of image text as an example.
[0066] In practical implementation, after generating a binary image corresponding to the original image, the subject edges can be detected based on the binary image to obtain, as shown below. Figure 3 The outline diagram is shown, and the set of outline coordinates of the main outline is recorded. Then, the text box T of the image text can be determined according to the font size and arrangement determined in the above steps, and the initial parameters of the genetic algorithm are set, including the initial population size N, the maximum number of iterations G, the crossover probability α, and the mutation probability β.
[0067] Figure 4This is a schematic diagram illustrating the process of determining the text position in an image using a genetic algorithm in an image generation method provided in this embodiment. Figure 4 As shown, N initial positions of text boxes can be randomly generated as the initial population, and a fitness function is defined for each text box position to evaluate its display effect. This fitness function can consider various factors, such as the overlap rate between the text box and the subject, the distance between the text box and the edge of the original image, the difference between the distances between the text box and the subject, and whether the distance between the text box and the edge of the original image is greater than a preset threshold, etc. Figure 3 As shown, the text box T has a length of a, a width of b, a body of L, and the area of the intersection of T and L is S, where S = T∩L. and The centroids of T and L are respectively connected. and And extend it to the edge of the image, intersecting the image edge at A, intersecting T at B and E, and intersecting L at F. Let the distance between the text box and the edge of the original image be . =AB, the distance between the text box and the main image is =EF. Taking into account both the distance between the text box T and the subject L, and the distance between T and the image edge, taking an image resolution of 800*800 as an example, the fitness function can be set as follows:
[0068]
[0069]
[0070] Since the image resolution is 800*800, the range of individuals generated by the genetic algorithm is 0 to 800. Considering the overall aesthetics of the image, the distance from T to the edge of the image must be greater than d.
[0071] Then, based on the fitness function value, text box positions with higher performance are selected. These better text box positions have a greater chance of being retained and passed on in the next iteration. New text box positions can then be generated through crossover and mutation operations. Specifically, the crossover probability refers to the proportion of individuals that will generate new individuals through crossover when generating a new generation of the population. Crossover involves swapping some parameters of two text box positions to generate a new text box position. The mutation probability refers to the proportion of individuals that will generate new individuals through mutation in each generation of the population. Mutation involves randomly changing the parameters of a text box. In practice, the crossover probability is generally set to a higher value (e.g., 0.7 to 0.9) to ensure that most individuals participate in crossover, thus producing diverse offspring; while the mutation probability is generally set to a lower value (e.g., 0.01 to 0.1) to avoid excessive mutation leading to a decrease in population fitness. Figure 4As shown, after the crossover and mutation operations, out-of-bounds processing may be performed. Out-of-bounds processing refers to the need for appropriate processing to adjust the function value of an individual function back to the valid range when it exceeds a preset allowable range. Specifically, out-of-bounds processing can be performed by directly cropping the out-of-bounds function value to the boundary of the preset range, or by resetting the out-of-bounds function value to a random value within the preset range. This disclosure does not specifically limit the specific methods, but only requires that the function can be implemented.
[0072] After generating a new generation of the population, i.e., generating new text box positions, the selection, crossover, and mutation operations described above can be repeated until the fitness function value reaches the value required by the objective function. At this point, iteration can stop, and the currently indicated text box position can be determined as the final image text position. Alternatively, iteration can stop when the number of iterations reaches a preset maximum, and the currently indicated text box position can be determined as the final image text position. When there are multiple currently indicated text box positions, the text box position with the fitness function value closest to the objective value can be selected as the final image text position.
[0073] S103: Based on the font size and position information of the image text, add the image text to the original image to obtain the target image.
[0074] In this step, after determining the font size and position information of the image text, the text image can be added to the original image to obtain the final target image.
[0075] As mentioned above, once the arrangement of the image text is determined, the image text can be added to the original image based on its arrangement, font size, and position. It should be noted that if the preset size of the target image differs from the original image, background transformations can be applied to the background and subject areas of the original image to adapt the image text to the subject.
[0076] In this embodiment of the disclosure, before adding image text to the original image to obtain the target image, the text color of the image text can be determined, thereby further improving the display effect of the image text. Specifically, based on the position information of the image text and the color information of the original image, the background color within a preset range around the image text is determined; based on the background color within the preset range around the image text and a pre-generated color matching knowledge base, the text color corresponding to the background color is determined, and the text color corresponding to the background color is used as the text color of the image text; based on the font size, position information, and text color of the image text, the image text is added to the original image to obtain the target image.
[0077] In practice, after determining the location information of the image text, the background color within a certain range of the original image's background can be determined. Then, the text color corresponding to that background color can be found in a pre-generated color matching knowledge base. If multiple text colors correspond to the background color, the text color with the highest occurrence rate can be used as the final text color of the image text, or the user can choose the final text color from among them.
[0078] In this embodiment of the disclosure, the color matching knowledge base can be generated through the following steps: determining the text region in the historical image based on the collected historical image; generating the mapping relationship between the background color and the text color within the text region; and generating the color matching knowledge base based on the mapping relationship.
[0079] In specific implementation, historical images used to build the color matching knowledge base can be collected first. This embodiment does not specifically limit the source of these historical images. Then, text positions in the historical images can be identified. Specifically, OCR (Optical Character Recognition) technology can be used to identify text positions. After identifying the text positions, the corresponding image can be cropped from the text box, and the background color and text color in the cropped image can be identified to establish a mapping relationship between them. Then, abnormal samples can be removed. For example, some color pairs may appear disharmonious, such as a combination of blue-black and black, making it difficult to clearly identify the background and text. These can be removed to ensure the quality of the sample set data. The removal operation can be performed manually or pre-configured with removal conditions. When the execution entity of this embodiment identifies a background color and text color with a mapping relationship that meets the removal conditions, it can automatically remove them from the sample set used to build the color matching knowledge base. The removal conditions can be set manually, such as the difference between the background color and text color in the three color channels being less than a preset threshold.
[0080] After removing outliers, the remaining color pairs (i.e., background and text colors with a mapping relationship) can be categorized. Specifically, assuming the background color has RGB values of (253, 220, 170) and the text color has RGB values of (200, 114, 14), the text color's R, G, and B channels can be divided into 20 color values per category, and then the classification result for each text color can be labeled. For example, given the color combination RGB=[(253, 220, 170), (200, 114, 14)], the corresponding category result is labeled "10-6-1", thus constructing a color matching knowledge base.
[0081] For example, such as Figure 5As shown, when the background color corresponding to the image text is recognized... When the value is (217, 232, 244), the K-Nearest Neighbors of the background color can be retrieved from the color matching knowledge base: .like Figure 5 As shown, distance The most recent k samples are The category identifier "12-11-10" appeared twice, and it was the most frequent identifier. Therefore, it can be... The category is set as 12-11-10, and the corresponding color value is (240, 220, 200).
[0082] In another possible implementation, the text color can be set by the user, or it can be set to a contrasting color of the main color of the original image, thereby highlighting the text in the image, enhancing the visual effect of the text in the image, and thus improving the efficiency and effectiveness of the information transmission of the target image.
[0083] Once the text color of the image text is determined, the final target image can be generated based on the text color, font size, and position information of the image text.
[0084] According to a second aspect of the embodiments of this disclosure, such as Figure 6 As shown, an image generation apparatus 600 is provided, comprising:
[0085] The font determination module 601 is used to determine the font size of the image text based on the text length of the image text;
[0086] The position determination module 602 is used to determine the position information of the image text based on the position of the main subject in the original image;
[0087] Add module 603 to add image text to the original image to obtain the target image based on the font size and position information of the image text.
[0088] Optionally, the font determination module 601 is specifically used for:
[0089] Based on the order in which the text information in the image is obtained, the display priority of each text information is determined;
[0090] The font size of the image text is determined based on the display priority and text length of each text message; among them, the font size of text messages with higher display priority is larger than the font size of text messages with lower display priority.
[0091] Optionally, the font determination module 601 is also used for:
[0092] Based on the location of the subject in the original image, determine the maximum usable area in the original image for adding image text; the maximum usable area does not overlap with the subject;
[0093] Based on the maximum available area, determine the arrangement of each text information in the image text; wherein, the length and width of the text box obtained after arranging each text information according to the arrangement method are less than the length and width corresponding to the maximum available area;
[0094] Based on the font size, arrangement, and position information of the image text, the image text is added to the original image to obtain the target image.
[0095] Optionally, the position determination module 602 is specifically used for:
[0096] Define the text box for the image text;
[0097] Based on the position of the subject in the original image, the position information of the text in the image is obtained by taking the following as objective functions: minimizing the overlap rate between the text box and the subject, minimizing the difference between the distance between the text box and the edge of the original image and the distance between the text box and the subject, and ensuring that the distance between the text box and the edge of the original image is greater than a preset threshold. The preset threshold is determined based on the size of the original image.
[0098] Optionally, the device further includes a color matching module 604; the color matching module 604 is specifically used for:
[0099] Based on the location information of the image text and the color information of the original image, determine the background color within a preset range around the image text;
[0100] Based on the background color within a preset range around the image text and a pre-generated color matching knowledge base, determine the text color corresponding to the background color, and use the text color corresponding to the background color as the text color of the image text.
[0101] Based on the font size, position information, and text color of the image text, the image text is added to the original image to obtain the target image.
[0102] Optionally, the color matching module 604 is also used for:
[0103] Based on the collected historical images, determine the text regions within the historical images;
[0104] Generate a mapping relationship between the background color and the text color within the text area, and generate a color matching knowledge base based on the mapping relationship.
[0105] According to a third aspect of the present disclosure, an electronic device for image generation is provided, comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the present invention.
[0106] According to a fourth aspect of the present disclosure, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method provided in the first aspect of the present invention.
[0107] According to a fifth aspect of the present invention, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method of any of the above embodiments.
[0108] Figure 7 An exemplary system architecture 700 is shown that can be applied to the image generation method or image generation apparatus implemented in this disclosure.
[0109] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, and 703, a network 704, and a server 705. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0110] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0111] Terminal devices 701, 702, and 703 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0112] Server 705 can be a server providing various services, such as a backend management server supporting shopping websites browsed by users using terminal devices 701, 702, and 703 (for example only). The backend management server can process received image generation requests and return the processing results (for example only) to the terminal devices.
[0113] It should be noted that the image generation method provided in the embodiments of the present invention is generally executed by server 705, and correspondingly, the image generation device is generally disposed in server 705. The image generation method provided in the embodiments of the present invention can also be executed by terminal devices 701, 702, and 703, and correspondingly, the image generation device can be disposed in terminal devices 701, 702, and 703.
[0114] It should be understood that Figure 7 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0115] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing a terminal device of the present invention. Figure 8 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0116] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0117] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.
[0118] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.
[0119] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0120] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0121] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor. For example, a processor may include a font determination module, a position determination module, and an adding module. The names of these modules do not necessarily limit the module itself; for example, the font determination module may also be described as "a module for determining the font size of image text based on the text length of the image text."
[0122] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the device implements the following method: determining the font size of the image text based on the text length of the image text; determining the position information of the image text based on the position of the subject in the original image; and adding the image text to the original image based on the font size and position information of the image text to obtain a target image.
[0123] Finally, it should be noted that the above embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.
Claims
1. An image generation method characterized by, The method comprises: determining the font size of the image text according to the text length of the image text; determining the position information of the image text according to the position of the subject in the original image; adding the image text in the original image according to the font size and the position information of the image text to obtain a target image.
2. The method of claim 1, wherein, The method comprises: determining the font size of the image text according to the text length of the image text, comprising: determining the display priority of each text information based on the sequence of obtaining the image text; 3. The method of claim 1, wherein, determining the font size of the image text according to the display priority and the text length of the text information; wherein the font size of the text information with high display priority is larger than the font size of the text information with low display priority. The method further comprises: determining the maximum available area for adding the image text in the original image according to the position of the subject in the original image; the maximum available area does not overlap with the subject; determining the arrangement mode of each text information in the image text based on the maximum available area; wherein the length and width of the text box obtained after arranging each text information according to the arrangement mode are smaller than the length and width corresponding to the maximum available area; 4. The method of claim 1, wherein, adding the image text in the original image according to the font size, the arrangement mode and the position information of the image text to obtain a target image. The method further comprises: determining the position information of the image text according to the position of the subject in the original image, comprising:
5. The method of claim 1, wherein, determining the text box of the image text; obtaining the position information of the image text based on the position of the subject in the original image, with the minimum overlap rate of the text box and the subject, the minimum difference between the distance of the text box and the edge of the original image and the distance of the text box and the subject, and the distance of the text box and the edge of the original image being greater than a preset threshold; wherein the preset threshold is determined based on the size of the original image. The method further comprises: determining the background color within a preset range around the image text based on the position information of the image text and the color information of the original image; 6. The method of claim 5, wherein, determining the text color corresponding to the background color based on the background color within the preset range around the image text and the pre-generated color matching knowledge base, and taking the text color corresponding to the background color as the text color of the image text; adding the image text in the original image according to the font size, the position information and the text color of the image text to obtain a target image. The color matching knowledge base is generated by the following steps:
7. An image generation apparatus characterized by comprising: determining the text area in the historical image according to the collected historical image; generating the mapping relationship between the background color and the text color in the text area, and generating the color matching knowledge base based on the mapping relationship. The method comprises: a font determining module for determining the font size of the image text according to the text length of the image text; 8. An electronic device, comprising: a position determining module for determining the position information of the image text according to the position of the subject in the original image; an adding module for adding the image text in the original image according to the font size and the position information of the image text to obtain a target image. The method comprises: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, cause the one or more processors to carry out the method of any one of claims 1-6.
9. A computer readable medium having stored thereon a computer program, characterized in that the program, when executed by the processor, carries out the method of any one of claims 1-6.
10. A computer program product comprising a computer program which, when executed by a processor, carries out the method according to any one of claims 1-6.