Image rendering method and apparatus, device, storage medium, and program product
View Patent ↗Embodiments of this disclosure discloses an image rendering method, an apparatus, a device, a storage medium, and a program product. The image rendering method includes processing an image to be rendered to determine a text area determining a target character style of text based on attribute information of the text area determining a target pattern style of text based on the image to be rendered; and rendering the image to be rendered based on the target character style of text and the target pattern style of text.
1 . An image rendering method, comprising:
processing an image to be rendered to determine a text area;
determining a character style of text based on attribute information of the text area;
determining a pattern style of text based on the image to be rendered; and
rendering the image to be rendered based on the character style of text and the pattern style of text,
wherein the pattern style of text comprises a color of text, and the determining the pattern style of text based on the image to be rendered comprises:
converting the image to be rendered to a Hue, Saturation, Value (HSV) color space,
for one or more pixels in the image to be rendered, obtaining hue values of the pixels in the HSV color space, and
determining the color of text based on the hue values of the one or more pixels, wherein the determining the color of text based on the hue values of the one or more pixels comprises:
calculating an average hue value of the hue values of the one or more pixels,
determining a candidate set of color based on the average hue value,
for at least one pixel in the image to be rendered, obtaining at least one of a saturation value or a brightness value of the pixel in the HSV color space, and
selecting the color of text from the candidate set of color based on at least one of saturation values or brightness values of the one or more pixels.
2 . The image rendering method according to claim 1 , wherein the processing the image to be rendered to determine the text area comprises:
inputting the image to be rendered into a segmentation model to obtain an image mask; and
determining the text area corresponding to the image to be rendered based on the image mask.
3 . The image rendering method according to claim 2 , wherein the determining the text area corresponding to the image to be rendered based on the image mask comprises:
in response to a foreground region in the image mask being greater than or equal to a first threshold, arranging the text area in an area corresponding to the foreground region in the image to be rendered.
4 . The image rendering method according to claim 2 , further comprising:
dividing the image to be rendered into a first region and a second region in response to a foreground region in the image mask being less than a first threshold; and
arranging the text area in the first region or the second region.
5 . The image rendering method according to claim 4 , further comprising:
arranging the text area at a preset position in the image to be rendered in response to the first region being less than a second threshold or the second region being less than the second threshold.
6 . The image rendering method according to claim 1 , wherein the selecting the color of text from the candidate set of color based on at least one of the saturation values or the brightness values of the one or more pixels comprises:
calculating at least one of an average saturation value or an average brightness value of the one or more pixels;
for each color value in the candidate set of color, calculating at least one of a first difference between the color value and the average saturation value, or a second difference between the color value and the average brightness value; and
determining at least one of a color corresponding to a maximum value of first differences or a color corresponding to a maximum value of second differences as the color of text.
7 . The image rendering method according to claim 1 , wherein the attribute information of the text area comprises a width of a bounding box of the text area, and the character style of text comprises a character size of text, and the determining the character style of text based on the attribute information of the text area comprises:
determining the character size of text based on the width of the bounding box and a number of text characters.
8 . The image rendering method according to claim 7 , wherein the determining the character size of text based on the width of the bounding box and the number of text characters comprises:
traversing each character size, starting with a largest character size;
determining a text width based on a current character size and the number of text characters; and
determining the current character size as the character size of text in response to the text width being less than or equal to the width of the bounding box.
9 . The image rendering method according to claim 1 , further comprising:
selecting a video frame from a video to be processed as the image to be rendered; and
after rendering the image to be rendered based on the character style of text and the pattern style of text, using the rendered image as a cover of the video to be processed.
10 . The image rendering method according to claim 9 , further comprising:
after receiving a video uploaded by a user, generating a cover generation instruction in response to detecting the video does not have a cover.
11 . An electronic device, comprising:
one or more processors;
a memory device for storing one or more programs that, when executed by the one or more processors, cause the one or more processors to implement operations comprising:
processing an image to be rendered to determine a text area;
determining a character style of text based on attribute information of the text area;
determining a pattern style of text based on the image to be rendered; and
rendering the image to be rendered based on the character style of text and the pattern style of text,
wherein the pattern style of text comprises a color of text, and the determining the pattern style of text based on the image to be rendered comprises:
converting the image to be rendered to a Hue, Saturation, Value (HSV) color space,
for one or more pixels in the image to be rendered, obtaining hue values of the pixels in the HSV color space, and
determining the color of text based on the hue values of the one or more pixels, wherein the determining the color of text based on the hue values of the one or more pixels comprises:
calculating an average hue value of the hue values of the one or more pixels,
determining a candidate set of color based on the average hue value,
for at least one pixel in the image to be rendered, obtaining at least one of a saturation value or a brightness value of the pixel in the HSV color space, and
selecting the color of text from the candidate set of color based on at least one of saturation values or brightness values of the one or more pixels.
12 . The electronic device according to claim 11 , wherein the one or more programs further cause the one or more processors to:
input the image to be rendered into a segmentation model to obtain an image mask; and
determine the text area corresponding to the image to be rendered based on the image mask.
13 . The electronic device according to claim 12 , wherein the one or more programs further cause the one or more processors to:
in response to a foreground region in the image mask being greater than or equal to a first threshold, arrange the text area in an area corresponding to the foreground region in the image to be rendered.
14 . The electronic device according to claim 12 , wherein the one or more programs further cause the one or more processors to:
divide the image to be rendered into a first region and a second region in response to a foreground region in the image mask being less than a first threshold; and
arrange the text area in the first region or the second region.
15 . The electronic device according to claim 14 , wherein the one or more programs further cause the one or more processors to:
arrange the text area at a preset position in the image to be rendered in response to the first region being less than a second threshold or the second region being less than the second threshold.
16 . A non-transitory computer-readable storage medium stored thereon a computer program that, when executed by a processor, implements operations comprising:
processing an image to be rendered to determine a text area;
determining a character style of text based on attribute information of the text area;
determining a pattern style of text based on the image to be rendered; and
rendering the image to be rendered based on the character style of text and the pattern style of text,
wherein the pattern style of text comprises a color of text, and the determining the pattern style of text based on the image to be rendered comprises:
converting the image to be rendered to a Hue, Saturation, Value (HSV) color space,
for one or more pixels in the image to be rendered, obtaining hue values of the pixels in the HSV color space, and
determining the color of text based on the hue values of the one or more pixels, wherein the determining the color of text based on the hue values of the one or more pixels comprises:
calculating an average hue value of the hue values of the one or more pixels,
determining a candidate set of color based on the average hue value,
for at least one pixel in the image to be rendered, obtaining at least one of a saturation value or a brightness value of the pixel in the HSV color space, and
selecting the color of text from the candidate set of color based on at least one of saturation values or brightness values of the one or more pixels.
17 . The non-transitory computer-readable storage medium according to claim 16 , wherein the processing the image to be rendered to determine the text area comprises:
inputting the image to be rendered into a segmentation model to obtain an image mask; and
determining the text area corresponding to the image to be rendered based on the image mask.
18 . The non-transitory computer-readable storage medium according to claim 16 , wherein the selecting the color of text from the candidate set of color based on at least one of the saturation values or the brightness values of the one or more pixels comprises:
calculating at least one of an average saturation value or an average brightness value of the one or more pixels;
for each color value in the candidate set of color, calculating at least one of a first difference between the color value and the average saturation value, or a second difference between the color value and the average brightness value; and
determining at least one of a color corresponding to a maximum value of first differences or a color corresponding to a maximum value of second differences as the color of text.
19 . The non-transitory computer-readable storage medium according to claim 16 , wherein the attribute information of the text area comprises a width of a bounding box of the text area, and the character style of text comprises a character size of text, and the determining the character style of text based on the attribute information of the text area comprises:
determining the character size of text based on the width of the bounding box and a number of text characters.
20 . The non-transitory computer-readable storage medium according to claim 16 , the operations further comprising:
selecting a video frame from a video to be processed as the image to be rendered; and
after rendering the image to be rendered based on the character style of text and the pattern style of text, using the rendered image as a cover of the video to be processed.