Image and text typesetting method and related apparatus thereof
11790584 · 2023-10-17
Assignee
Inventors
Cpc classification
G06V10/462
PHYSICS
International classification
G06F40/131
PHYSICS
G06V10/44
PHYSICS
G06V10/46
PHYSICS
G06V20/56
PHYSICS
G06V20/62
PHYSICS
H04N5/45
ELECTRICITY
Abstract
A method includes determining a first importance measurement value of a pixel in an image, obtaining at least one text box area stacked on the image, obtaining, based on first importance measurement value of a pixel in a background image corresponding to each text box area a second importance measurement value of a background image corresponding to each text box area, obtaining an importance measurement value gravity center or an importance measurement value mass center of the image based on the first importance measurement value, determining, based on a preset principle and a location relationship between the importance measurement value gravity center and a central area of the image or a location relationship between the importance measurement value mass center and a central area of the image, information about a balance degree value of each text box area relative to the image, and selecting, from the at least one text box area, one text box area to typeset a word.
Claims
1. An image and text typesetting method implemented by a processor, comprising: determining a first importance measurement value of a pixel in an image; obtaining at least one text box area formed by at least one text box stacked on the image, wherein the at least one text box area is an area range of a background image, and wherein the background image comprises the pixel; obtaining, based on the first importance measurement value, a second importance measurement value of the background image corresponding to the at least one text box area; obtaining an importance measurement value gravity center or an importance measurement value mass center of the image based on the first importance measurement value, wherein the importance measurement value gravity center or the importance measurement value mass center represents a gravity center or a mass center of the image respectively, and wherein the gravity center or the mass center represents a focal point of the image based on a saliency value of the pixel; determining, based on a preset principle and either based on a location relationship between the importance measurement value gravity center and a central area of the image or a location relationship between the importance measurement value mass center and the central area of the image, information about a first balance degree value of each text box area relative to the image, wherein the preset principle comprises a vector balancing principle, and wherein the first balance degree value is set to one when the importance measurement value gravity center or the importance measurement value mass center is located in a central area range of the image; and selecting, from the at least one text box area based on the second importance measurement value and the information about the first balance degree value, a first text box area to typeset a word.
2. The image and text typesetting method of claim 1, wherein the second importance measurement value of the background image comprises a sum of importance measurement values of pixels in the background image, a sum of importance measurement values of pixels in the background image divided by a quantity of the pixels in the background image, or a maximum value in importance measurement values of pixels in the background image.
3. The image and text typesetting method of claim 1, further comprising: setting a second balance degree value of a second text box area located on a central axis of the image to 1, and setting a third balance degree value of a third text box area that is not located on the central axis to 0 when the importance measurement value gravity center is located in a central area range of the image or the importance measurement value mass center is located in the central area range, wherein the second text box area and the third text box area belong to the at least one text box area; and obtaining the first balance degree value of each text box area based on the vector balancing principle when the importance measurement value gravity center is not located in the central area range or the importance measurement value mass center is not located in the central area range.
4. The image and text typesetting method of claim 1, further comprising: weighting the second importance measurement value of the background image and the first balance degree value to obtain a weighting result of the at least one text box area; and selecting, from the at least one text box area based on the weighting result, the first text box area to typeset the word.
5. The image and text typesetting method of claim 1, further comprising: obtaining the second importance measurement value by weighting the saliency value and one or more of a facial recognition result and an object recognition result; or obtaining the second importance measurement value by weighting a saliency segmentation result and one or more of a facial recognition result and an object recognition result.
6. The image and text typesetting method of claim 1, further comprising: determining a color feature of a target background image based on an image feature, an information entropy, the saliency value, or a color distribution of the target background image corresponding to the first text box area comprising the word; and adding a mask to a background of the word when the color feature belongs to a preset mottled color feature set, wherein a mask area is preset based on the first text box area.
7. The image and text typesetting method of claim 6, further comprising: determining a dominant color of the target background image; obtaining a highlight color and a shadow color using a dark-level calculation method and the dominant color; determining lightness of the target background image; setting the mask area to the highlight color or the shadow color based on the lightness; and setting, based on the lightness, a text in the first text box area to the highlight color or the shadow color.
8. A terminal comprising: a memory configured to store instructions; and a processor coupled to the memory, wherein the instructions cause the processor to be configured to: determine a first importance measurement value of a pixel in an image; obtain at least one text box area formed by at least one text box stacked on the image, wherein the at least one text box area is an area range of a background image, and wherein the background image comprises the pixel; obtain, based on the first importance measurement value, a second importance measurement value of the background image corresponding to each of the at least one text box area; obtain an importance measurement value gravity center or an importance measurement value mass center of the image based on the first importance measurement value, wherein the importance measurement value gravity center or the importance measurement value mass center represents a gravity center or a mass center of the image respectively, and wherein the gravity center or the mass center represents a focal point of the image based on a saliency value of the pixel; determine, based on a preset principle and either based on a location relationship between the importance measurement value gravity center and a central area of the image or a location relationship between the importance measurement value mass center and the central area of the image, information about a first balance degree value of each text box area relative to the image, wherein the preset principle comprises a vector balancing principle, and wherein the first balance degree value is set to one when the importance measurement value gravity center or the importance measurement value mass center is located in a central area range of the image; and select, from the at least one text box area based on the second importance measurement value and the information about the first balance degree value, a first text box area to typeset a word.
9. The terminal of claim 8, wherein the second importance measurement value of the background image comprises a sum of importance measurement values of pixels in the background image, a sum of importance measurement values of pixels in the background image divided by a quantity of the pixels in the background image, or a maximum value in importance measurement values of pixels in the background image.
10. The terminal of claim 8, wherein the instructions further cause the processor to be configured to: set a second balance degree value of a second text box area located on a central axis of the image to 1, and set a third balance degree value of a third text box area that is not located on the central axis to 0 when the importance measurement value gravity center is located in a central area range of the image or the importance measurement value mass center is located in the central area range, wherein the second text box area and the third text box area belong to the at least one text box area; and obtain the first balance degree value of each text box area based on the vector balancing principle when the importance measurement value gravity center is not located in the central area range or the importance measurement value mass center is not located in the central area range.
11. The terminal of claim 8, wherein the instructions further cause the processor to be configured to: weight the second importance measurement value of the background image and the first balance degree value to obtain a weighting result of the at least one text box area; and select, from the at least one text box area based on the weighting result, the first text box area to typeset the word.
12. The terminal of claim 8, wherein the instructions further cause the processor to be configured to: obtain the second importance measurement value by weighting the saliency value and one or more of a facial recognition result and an object recognition result; or obtain the second importance measurement value by weighting a saliency segmentation result and one or more of a facial recognition result and an object recognition result.
13. The terminal of claim 8, wherein the instructions further cause the processor to be configured to: determine a color feature of a target background image based on an image feature, an information entropy, the saliency value, or a color distribution of the target background image corresponding to the first text box area comprising the word; and add a mask to a background of the word when the color feature belongs to a preset mottled color feature set, wherein a mask area is preset based on the first text box area.
14. The terminal of claim 13, wherein the instructions further cause the processor to be configured to: determine a dominant color of the target background image; obtain a highlight color and a shadow color using a dark-level calculation method and the dominant color; determine lightness of the target background image; set the mask area to the highlight color or the shadow color based on the lightness; and set, based on the lightness, a text in the first text box area to the highlight color or the shadow color.
15. A computer program product comprising computer-executable instructions stored on a non-transitory computer-readable medium that, when executed by a processor, cause a terminal to: determine a first importance measurement value of a pixel in an image; obtain at least one text box area formed by at least one text box stacked on the image, wherein the at least one text box area is an area range of a background image of the image, and wherein the background image corresponds to the at least one text box area comprising the pixel; obtain, based on the first importance measurement value, a second importance measurement value of the background image corresponding to the at least one text box area; obtain an importance measurement value gravity center or an importance measurement value mass center of the image based on the first importance measurement value, wherein the importance measurement value gravity center or the importance measurement value mass center of the image represents a gravity center or a mass center of the image respectively, and wherein the gravity center or the mass center represents a focal point of the image based on a saliency value of the pixel; determine, based on a preset principle and either based on a location relationship between the importance measurement value gravity center and a central area of the image or a location relationship between the importance measurement value mass center and the central area, information about a first balance degree value of each text box area relative to the image, wherein the preset principle comprises a vector balancing principle, and wherein the first balance degree value is set to one when the importance measurement value gravity center or the importance measurement value mass center is located in a central area range of the image; and select, from the at least one text box area based on the second importance measurement value and the information about the first balance degree value, a first text box area to typeset a word.
16. The computer program product of claim 15, wherein the computer-executable instructions further cause the terminal to: set a second balance degree value of a second text box area located on a central axis of the image to 1, and set a third balance degree value of a third text box area that is not located on the central axis to 0 when the importance measurement value gravity center is located in a central area range of the image or the importance measurement value mass center is located in the central area range, wherein the second text box area and the third text box area belong to the at least one text box area; and obtain the first balance degree value of each text box area based on the vector balancing principle when the importance measurement value gravity center is not located in the central area range or the importance measurement value mass center is not located in the central area range.
17. The computer program product of claim 15, wherein the computer-executable instructions further cause the terminal to: weight the second importance measurement value of the background image and the first balance degree value to obtain a weighting result of the at least one text box area; and select, from the at least one text box area based on the weighting result, the first text box area to typeset the word.
18. The computer program product of claim 15, wherein the computer-executable instructions further cause the terminal to: obtain the second importance measurement value by weighting the saliency value and one or more of a facial recognition result and an object recognition result; or obtain the second importance measurement value by weighting a saliency segmentation result and one or more of a facial recognition result and an object recognition result.
19. The computer program product of claim 15, wherein the computer-executable instructions further cause the terminal to: determine a color feature of a target background image based on an image feature, an information entropy, the saliency value, or a color distribution of the target background image corresponding to the first text box area comprising the word; and add a mask to a background of the word when the color feature belongs to a preset mottled color feature set, wherein a mask area is preset based on the first text box area.
20. The computer program product of claim 19, wherein the computer-executable instructions further cause the terminal to: determine a dominant color of the target background image; obtain a highlight color and a shadow color using a dark-level calculation method and the dominant color; determine lightness of the target background image; set the mask area to the highlight color or the shadow color based on the lightness; and set, based on the lightness, a text in the first text box area to the highlight color or the shadow color.
Description
BRIEF DESCRIPTION OF DRAWINGS
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
DESCRIPTION OF EMBODIMENTS
(9) This application may be applied to image and text typesetting of a magazine lock screen, or may be applied to image and text typesetting of a poster advertisement and the like that have a relatively high visual effect requirement, or may be applied to image and text typesetting of a sharing card such as a book list, a playlist, or an album contact. More applicable scenarios are not limited herein.
(10) In the specification, claims, and accompanying drawings of this application, the terms “first”, “second”, “third”, “fourth”, and the like (if existent) are intended to distinguish between similar objects but do not necessarily indicate a specific order or sequence. It should be understood that the data termed in such a way are interchangeable in proper circumstances so that the embodiments of this application described herein can be implemented in orders except the order illustrated or described herein. Moreover, the terms “include”, “have” and any other variants mean to cover the non-exclusive inclusion, for example, a process, method, system, product, or device that includes a list of steps or units is not necessarily limited to those expressly listed steps and units, but may include other steps or units not expressly listed or inherent to such a process, method, system, product, or device.
(11) In a scenario in which image content such as a lock screen of a terminal changes continuously, if a single image and text typesetting manner is set on the terminal, when the image content changes, it is definitely inappropriate if a location of a word is fixed. Currently, there is a solution for performing image and text typesetting based on saliency (saliency) of an image, so that the word may be typeset in an area with relatively low saliency in the image, to avoid covering the image content by the word. However, in this typesetting manner, a visual effect is not very good, and user experience is poor. Based on this, this application discloses an image and text typesetting method, and a problem of balance between the image content and the word is considered. Referring to
(12) 101: Determine an importance measurement value of each pixel in an image.
(13) An image has a plurality of pixels. After obtaining the image, a terminal determines an importance measurement value of each pixel in the image. The importance measurement value is used to measure importance of the pixel. The importance measurement value may be specifically a saliency value. Generally, a higher saliency value of a pixel indicates that the pixel is more salient and is more easily observed by a user. The saliency value may be a coherent saliency value or a saliency segmentation result. For example, a grayscale value of the pixel in the image is set to 0 or 255. A pixel whose grayscale value is larger has a larger saliency value and is more easily observed. The importance measurement value may alternatively be obtained by weighting the saliency value and any one or more of a facial recognition result and a final result. The final result is obtained after an object recognition result is sorted based on a specific object label or a semantic label. For example, weighting calculation is performed on a saliency map (saliency map) of the image and semantic information, facial information, and the like of the image to obtain the importance measurement value of each pixel.
(14)
(15) 102: Obtain at least one text box area formed by at least one text box stacked on the image.
(16) The text box area in this application refers to a text box stacked on an image interface. There may be a plurality of text boxes. Each text box has one text box area, and the text box area may be considered as an area range corresponding to a partial image obtained after the image is captured by using coordinate axes of the text box as four boundaries. It can be learned that the area range is smaller than an area range corresponding to the entire image. The obtained partial image is referred to as a background image corresponding to the text box area in this application. The background image corresponding to the text box area includes M pixels, and M is a positive integer greater than 0, Because the text boxes are stacked, background images corresponding to text box areas may partially overlap.
(17) 103: Obtain, based on an importance measurement value of a pixel in a background image corresponding to each text box area, an importance measurement value of the background image corresponding to each text box area.
(18) The importance measurement value of the background image corresponding to each text box area may be obtained through calculation based on the importance measurement value of the pixel in the background image. Specifically, there are the following several possible cases.
(19) The importance measurement value of the background image corresponding to the text box area may be equal to a sum of the importance measurement values of the pixels in the background image, or the importance measurement value of the background image corresponding to the text box area is equal to a sum of the importance measurement values of the pixels in the background image/a quantity of the pixels in the background image, or an importance measurement value of the text box area is equal to a maximum value in the importance measurement values of all the pixels in the background image, or an importance measurement value of the text box area is equal to a mode in the importance measurement values of the pixels in the background image. More possible cases are not listed herein one by one.
(20) A text box area with an importance measurement value as small as possible is selected. A smaller importance measurement value indicates a smaller saliency value, and the smaller saliency value indicates lower saliency and that image content is more difficult to be covered. For example, a saliency value of the jellyfish in
(21) 104: Obtain an importance measurement value gravity center or an importance measurement value mass center of the image based on the importance measurement value of the pixel in the image.
(22) The importance measurement value gravity center or the importance measurement value mass center of the entire image is determined. The importance measurement value gravity center represents a gravity center, of the image, that is obtained through calculation based on the importance measurement value of each pixel in the entire image. The importance measurement value mass center represents a mass center, of the image, that is obtained through calculation based on the importance measurement value of each pixel in the entire image.
(23) 105: Determine, based on a preset principle and a location relationship between the importance measurement value gravity center and a central area of the image or a location relationship between the importance measurement value mass center and a central area of the image, information about a balance degree of each text box area relative to the image.
(24) A central area range of the image is first determined, and the central area range may be a circle or ellipse whose center is a central point of the image.
(25) In this embodiment, a balance degree of a text box area is used to indicate a balance degree of the text box area relative to the image. When the importance measurement value gravity center of the image is located in the central area range of the image, or the importance measurement value mass center is located in the central area range of the image, it indicates that the image is self-balanced. In this case, balance degree values of text boxes located on a horizontal central axis and a longitudinal central axis of the image are set to 1, and a balance degree value of a text box at another location is set to 0. A schematic diagram of the central axes of the image and the central area of the image is shown in
(26) If the importance measurement value gravity center of the image is located outside the central area range of the image or even deviates greatly from the central area range of the image, or the importance measurement value mass center of the image is located outside the central area range of the image or even deviates greatly from the central area range of the image, to form visual balance between the image and the word, a balance degree value of the text box area needs to be obtained through calculation based on the importance measurement value gravity center of the image and a vector balancing principle or a lever balancing principle, or a balance degree value of the text box area needs to be obtained through calculation based on the importance measurement value mass center of the image and a vector balancing principle or a lever balancing principle. A specific calculation manner of obtaining the balance degree value of the text box area through calculation based on the vector balancing principle or the lever balancing principle is as follows:
(27) The vector balancing principle is specifically as follows: A first vector is formed from coordinates of a geometric center of a text box to coordinates of a central point of an image. A second vector is formed from coordinates of an importance measurement value mass center of the image to the coordinates of the central point of the image (or a second vector is formed from coordinates of an importance measurement value gravity center of the image to the coordinates of the central point of the image). A balance degree value of the text box is determined based on values and directions of the two vectors. When the two vectors are equal in value and opposite in direction, a maximum balance degree of the text box is 1, and in another case, the balance degree ranges from 0 to 1. It may be understood that a value range 0 to 1 herein is merely an example, the value may alternatively range from 0 to 100, and more value ranges are not limited herein.
(28) The lever balancing principle is specifically as follows: A distance from a geometric center of a text box to a central point of an image is a first arm of force. A distance from an importance measurement value mass center of the image to the central point of the image is a second arm of force (or a distance from an importance measurement value gravity center of the image to the central point of the image is a second arm of force). Text box mass=preset text box density×a text area. Image mass is obtained through calculation by using image saliency segmentation. When the first arm of force×the text box mass=the second arm of force×the image mass, a maximum balance degree of the text box is 1, and in another case, the balance degree ranges from 0 to 1. It may be understood that a value range 0 to 1 herein is merely an example, and more value ranges are not limited herein.
(29) Herein, the balance degree of the text box area may be determined based on another image balancing principle in addition to the vector balancing principle and the lever balancing principle. This is not limited in this application.
(30) It is found, after the balance degree value of the text box is determined based on the lever balancing principle or the vector balancing principle, that when the importance measurement value gravity center (or the importance measurement value mass center) of the image is located at an upper left part of the image, a balance degree value of a text box area at a lower right part of the image is relatively large; when the importance measurement value gravity center (or the importance measurement value mass center) of the image is located at an upper right part of the image, a balance degree value of a text box area at a lower left part of the image is relatively large; and similarly, when the importance measurement value gravity center or the importance measurement value mass center of the image is located in another direction, a balance degree value of a text box area in a direction opposite to the importance measurement value gravity center or the importance measurement value mass center of the image is relatively large. Referring to
(31) In this embodiment, a text box area balanced with the image is preferentially selected to typeset the word, so that typesetting of the image and the word may generate visual balance, thereby improving user experience.
(32) 106: Select, from the at least one text box area based on the importance measurement value of the background image corresponding to each text box area and the information about the balance degree of each text box area, one text box area to typeset the word.
(33) Weighting calculation is performed on a balance degree priority of the text box area and the importance measurement value of the text box area to obtain a calculation result, and then the text box area is selected based on the calculation result to typeset the word. For example:
(34) a weighting calculation result of the text box=
(35) A×an importance measurement value of the text box +, where values of A and B are
(36) B×the balance degree value of the text box
(37) preset by the terminal based on an actual situation.
(38) It can be learned that the importance measurement value of the text box area is considered when the text box area is selected to typeset the word in this application. Therefore, a text box area with a relatively small saliency value may be selected to avoid covering the image content. In addition, a balance degree between the text box area and the image is considered, so that the visual balance can be ensured. A best visual effect of the text box area is obtained by combining the importance measurement value and the balance degree, and user experience is improved.
(39) Further, in this application, whether a mask needs to be added to a background of the word may be further determined. Details are as follows.
(40) A color feature of a background image corresponding to a text box area in which the word is located is determined based on an image feature, an information entropy, a saliency value, or a color distribution of the background image corresponding to the text box area in which the word is located. The image feature is specifically a color feature of the image. When the color feature of the background image corresponding to the text box area is a preset color feature of a mottled type, the mask is added to the background of the word. It should be noted that a size of an area to which the mask is added is determined by a size of the text box area. Generally, a mask area is larger than the text box area but smaller than an area in which the entire image is located. For example, as shown in
(41) Further, in this application, a dominant color of the background image corresponding to the text box area in which the word is located may further be determined, and a shadow color and a highlight color are derived from the determined dominant color in a dark-level calculation manner in HSV (Hue, Saturation, Value) or LCH (lightness, chroma, hue) space.
(42) Lightness of the background image corresponding to the text box area in which the word is located is determined. Then, a text in the text box is set to the highlight color or the shadow color based on the lightness. If the mask is added, the mask area may further be set to the highlight color or the shadow color. Specifically, when the lightness of the background image corresponding to the text box area in which the word is located belongs to a preset lighter chroma set, whether the mask is added to the background of the word is further determined. If the mask is added to the background of the word, the text in the text box is set to the shadow color, and the mask area is set to the highlight color. If the mask is not added to the background of the word, the text in the text box area is set to the shadow color. When the lightness of the background image corresponding to the text box area in which the word is located belongs to a preset darker chroma set, whether the mask is added to the background of the word is further determined. If the mask is added to the background of the word, the text in the text box is set to the highlight color, and the mask area is set to the shadow color, if the mask is not added to the background of the word, the text in the text box area is set to the highlight color. A better visual effect can be achieved in the foregoing setting manner.
(43)
(44) The image and text typesetting method in this application is described above. Referring to
(45) a receiver 701, a transmitter 702, a processor 703, and a memory 704 (there may be one or more processors 703 in the terminal 700, and one processor is used as an example in
(46) The memory 704 may include a read-only memory and a random access memory, and provide instructions and data to the processor 703. A part of the memory 704 may further include a non-volatile random access memory (English full name: non-volatile random access memory, NVRAM for short). The memory 704 stores an operating system and operation instructions, an executable module or a data structure, a subset thereof, or an extended set thereof. The operation instructions may include various operation instructions, used to implement various operations. The operating system may include various system programs, to implement various basic services and process hardware-based tasks.
(47) The processor 703 controls an operation of a network device, and the processor 703 may also be referred to as a central processing unit (English full name: central processing unit, CPU for short). In a specific application, components of the network device are coupled together through a bus system. In addition to a data bus, the bus system may further include a power bus, a control bus, a status signal bus, and the like. However, for clear description, various types of buses in the figure are referred to as the bus system.
(48) The method disclosed in the foregoing embodiment of this application may be applied to the processor 703, or may be implemented by the processor 703. The processor 703 may be an integrated circuit chip and has a signal processing capability. In an implementation process, steps in the foregoing method can be implemented by using a hardware integrated logical circuit in the processor 703, or by using instructions in a form of software. The processor 703 may be a general-purpose processor, a digital signal processor (English full name: digital signal processing, DSP for short), an application-specific integrated circuit (English full name: application specific integrated circuit, ASIC tar short), a field programmable gate array (English full name: field-programmable gate array, FPGA for short) or another programmable logical component, a discrete gate or transistor logic device, or a discrete hardware component. The processor 703 may implement or perform the method, the steps, and logical block diagrams that are disclosed in the embodiments of this application. The general-purpose processor may be a microprocessor, or the processor may be any conventional processor or the like. Steps of the method disclosed with reference to the embodiments of this application may be directly executed and accomplished by a hardware decoding processor, or may be executed and accomplished by using a combination of hardware and software modules in a decoding processor. The software module may be located in a mature storage medium in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, or a register. The storage medium is located in the memory 704, and the processor 703 reads information in the memory 704 and completes the steps in the foregoing method in combination with hardware of the processor.
(49) The receiver 701 may be configured to receive input digit or character information, and generate signal input related to a related setting and function control of the network device. The transmitter 702 may include a display device such as a display. The transmitter 702 may be configured to output digit or character information through an external interface.
(50) In this embodiment of this application, the processor 703 is configured to perform the foregoing method.
(51) Referring to
(52) a processing unit 801, configured to determine an importance measurement value of a pixel in an image;
(53) an obtaining unit 802, configured to obtain at least one text box area formed by at least one text box stacked on the image, where the text box area is an area range of a background image obtained after the image is captured by using a coordinate axis of the text box as a boundary, and a background image corresponding, to each of the at least one text box area includes at least one pixel, where
(54) the processing unit 801 is further configured to obtain, based on an importance measurement value of the pixel in the background image corresponding to each text box area, an importance measurement value of the background image corresponding to each text box area,
(55) the processing unit 801 is configured to obtain an importance measurement value gravity center or an importance measurement value mass center of the image based on the importance measurement value of the pixel in the image, and
(56) the processing unit 801 is further configured to determine, based on a preset principle and a location relationship between the importance measurement value gravity center and a central area of the image or a location relationship between the importance measurement value mass center and a central area of the image, information about a balance degree of each text box area relative to the image; and
(57) a text box selecting unit 803, configured to select, from the at least one text box area based on the importance measurement value of the background image corresponding to each text box area and the information about the balance degree of each text box area, one text box area to typeset a word.
(58) Optionally, the importance measurement value of the background image corresponding to the text box area a sum of the importance measurement values of the pixels in the background image.
(59) Alternatively,
(60) the importance measurement value of the background image corresponding to the text box area=a sum of the importance measurement values of the pixels in the background image/a quantity of the pixels in the background image.
(61) Alternatively,
(62) the importance measurement value of the background image corresponding to the text box area=a maximum value or a mode in the importance measurement values of the pixels in the background image.
(63) Optionally, the processing unit 801 is specifically configured to: when the importance measurement value gravity center is located in a central area range of the image, or the importance measurement value mass center is located in a central area range of the image, set a balance degree value of a text box area located on a central axis of the image to 1, and set a balance degree value of a text box area that is not located on the central axis of the image to 0, where the text box area located on the central axis of the image and the text box area that is not located on the central axis of the image belong to the at least one text box area; and
(64) when the importance measurement value gravity center is not located in the central area range of the image, or the importance measurement value mass center is not located in the central area range of the image, obtain the balance degree value of each text box area based on a vector balancing principle or a lever balancing principle.
(65) Optionally, the text box selecting unit 803 is specifically configured to:
(66) weight the importance measurement value of the background image corresponding to the text box area and the balance degree value of the text box area to obtain a weighting result, and repeatedly performing the operation until a weighting result of each text box area is obtained; and select, from the at least one text box area based on the weighting result of each text box area, one text box area to typeset the word.
(67) Optionally, the importance measurement value is obtained by weighting a saliency value and any one or more of a facial recognition result, an object recognition result, and semantic information. Alternatively, the importance measurement value is obtained by weighting a saliency segmentation result and any one or more of a facial recognition result, an object recognition result, and semantic information. Alternatively, the importance measurement value is specifically a saliency value.
(68) Optionally, the terminal further includes:
(69) a color feature determining unit 804, configured to determine, based on an image feature, an information entropy, a saliency value, or a color distribution of a target background image corresponding to the text box area in which the word is located, a color feature of the target background image; and
(70) a mask adding unit 805, configured to: when the color feature belongs to a preset mottled color feature set, add a mask to a background of the word, where a mask area is preset based on the text box area.
(71) Optionally, the processing unit 801 is further configured to: determine a dominant color of the target background image;
(72) obtain a highlight color and a shadow color by using a dark-level calculation method and the dominant color; and
(73) determine lightness of the target background image.
(74) The terminal further includes:
(75) a setting unit 806, configured to: set the mask area to the highlight color or the shadow color based on the lightness, and
(76) set, based on the lightness, a text in the text box area in which the word is located to the highlight color or the shadow color.
(77) It should be noted that content such as information exchange between the modules/units of the apparatus and the execution processes thereof is based on the same idea as the method embodiments of this application, and produces the same technical effects as the method embodiments of this application. For the specific content, refer to the foregoing description in the method embodiments of this application, and details are not described herein again.
(78) In addition, it should be noted that the apparatus embodiments are merely examples. The modules described as separate parts may or may not be physically separate, and modules displayed as units may or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all the modules may be selected according to an actual need to achieve the objectives of the solutions of the embodiments. In addition, in the accompanying drawings of the apparatus embodiments provided in this application, connection relationships between modules indicate that the modules have communication connections with each other, which may be specifically implemented as one or more communications buses or signal cables.
(79) Based on the description of the foregoing implementations, a person skilled in the art may clearly understand that this application may be implemented by software in addition to necessary universal hardware, or by dedicated hardware, including a dedicated integrated circuit, a dedicated CPU, a dedicated memory, a dedicated component, and the like. Generally, any functions that can be performed by a computer program can be easily implemented by using corresponding hardware. Moreover, a specific hardware structure used to achieve a same function may be of various forms, for example, in a form of an analog circuit, a digital circuit, a dedicated circuit, or the like. Based on such an understanding, the technical solutions of this application essentially or the part contributing to the conventional technology may be implemented in a form of a software product. The software product is stored in a readable storage medium, such as a floppy disk, a USB flash drive, a removable hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or a compact disc of a computer, and includes several instructions for instructing a computer device (which may be a personal computer, a server, a network device, or the like) to perform the method described in the embodiments of this application.
(80) The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer or a processor of the computer, the procedures or functions according to the embodiments of this application are all or partially generated. The computer may be a general-purpose computer, a dedicated computer, a computer network, or another programmable apparatus. The computer instructions may be stored in a computer-readable storage medium or may be transmitted from a computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center to another website, computer, server, or data center in a wired (for example, a coaxial cable, an optical fiber, or a digital subscriber line (DSL)) or wireless (for example, infrared, radio, or microwave) manner. The computer-readable storage medium may be any usable medium accessible by the computer, or a data storage device, such as a server or a data center, integrating one or more usable media. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, or a magnetic tape), an optical medium (for example, a DVD), a semiconductor medium (for example, a solid-state drive Solid State Disk (SSD)), or the like.