US-12626430-B2 - Image anti-aliasing method and apparatus, device, medium, and program product
Abstract
A method, apparatus, and a non-transitory computer-readable medium storing program code for anti-aliasing images may be provided. The method may include obtaining a first edge pixel of an image in a high-dynamic range (HDR) space and determining a first scaling factor based on a local brightness environment of the first edge pixel. The method may also include determining a color ratio corresponding with the first edge pixel and scaling the color ratio to obtain a first color ratio. Then the first color value is obtained based on a color value of the first edge pixel, a color value of a target pixel, and the first color ratio, wherein the target pixel has a large color value difference from the first edge pixel among a plurality of surrounding pixels of the first edge pixel; and updating the first color value to the color value of the first edge pixel.
Inventors
- Yuning Yang
Assignees
- TENCENT TECHNOLOGY (SHENZHEN) COMPANY LIMITED
Dates
- Publication Date
- 20260512
- Application Date
- 20240531
- Priority Date
- 20220830
Claims (20)
- 1 . A method for image anti-aliasing, performed by at least one processor, the method comprising: obtaining a first edge pixel of an image in a high-dynamic range (HDR) space; determining a first scaling factor based on a local brightness environment of the first edge pixel; determining a color ratio corresponding with the first edge pixel based on brightness values of a plurality of pixels in an image block where the first edge pixel is located; scaling the color ratio based on the first scaling factor to obtain a first color ratio; obtaining a first color value based on a color value of the first edge pixel, a color value of a target pixel, and the first color ratio, wherein the target pixel has a large color value difference from the first edge pixel among a plurality of surrounding pixels of the first edge pixel; and updating the first color value to the color value of the first edge pixel.
- 2 . The method according to claim 1 , wherein the determining the first scaling factor comprises: generating the first scaling factor based on a first brightness value of a first surrounding pixel and a second brightness value of a second surrounding pixel, the first surrounding pixel having a largest brightness value among the plurality of pixels in the image block where the first edge pixel is located, and the second surrounding pixel having a smallest brightness value among the plurality of pixels in the image block where the first edge pixel is located.
- 3 . The method according to claim 2 , wherein the generating the first scaling factor comprises: inputting the first brightness value of the first surrounding pixel and the second brightness value of the second surrounding pixel into a scaling function to obtain the first scaling factor, wherein the scaling function determines the first scaling factor based on one or more of the following: a value of the first scaling factor is directly proportional to the first brightness value of the first surrounding pixel; the value of the first scaling factor is directly proportional to the second brightness value of the second surrounding pixel; and the value of the first scaling factor is zero when the second brightness value of the second surrounding pixel is zero.
- 4 . The method according to claim 3 , wherein the inputting comprises: multiplying the first brightness value by the second brightness value to obtain a first sub-scaling factor; using the second brightness value as a second sub-scaling factor; and summing the first sub-scaling factor and the second sub-scaling factor and then performing normalization processing to obtain the first scaling factor.
- 5 . The method according claim 1 , wherein the determining the color ratio corresponding to the first edge pixel comprises: obtaining a plurality of brightness weights corresponding to the plurality of pixels in the image block where the first edge pixel is located; characterizing the local brightness environment of the first edge pixel by generating a first brightness difference based on a brightness value of each pixel and a corresponding brightness weight of each pixel in the image block; and mapping the first brightness difference to obtain the color ratio.
- 6 . The method according to claim 5 , wherein the image block is a square pixel array centered on the first edge pixel; and wherein the plurality of brightness weights corresponding to the plurality of pixels in the image block satisfy one or more of the following: pixels in the square pixel array that are at a same distance from the first edge pixel have a same brightness weight; pixels in the square pixel array that are closer to the first edge pixel have smaller brightness weights; when the brightness weights corresponding to pixels other than the first edge pixel in the square pixel array are positive numbers, then the brightness weight corresponding to the first edge pixel is a negative number; and a sum of the brightness weight of each pixel in the square pixel array is zero.
- 7 . The method according to claim 6 , wherein the generating the first brightness difference comprises: calculating a product of the brightness value of each pixel in the image block and the brightness weight of each pixel; and obtaining the first brightness difference by dividing a sum of products of all the pixels in the image block by an absolute value of the brightness weight corresponding to the first edge pixel.
- 8 . The method according to claim 7 , wherein the method further comprises: normalizing the first brightness difference; and wherein the mapping the first brightness difference to obtain the color ratio comprises: mapping the normalized first brightness difference to obtain the color ratio, wherein the color ratio is within a closed interval from zero to one and is positively correlated with the first brightness difference.
- 9 . The method according to claim 1 , wherein the obtaining the first color value comprises: multiplying a second color ratio by the color value of the first edge pixel to obtain a first color component, wherein a sum of the second color ratio and the first color ratio is one; multiplying the first color ratio by the color value of the target pixel to obtain a second color component; and summing the first color component and the second color component to obtain the first color value.
- 10 . The method according to claim 1 , wherein the method further comprises: when the first edge pixel is configured for forming a linear edge, obtaining a third color ratio corresponding to the first edge pixel based on a position of the first edge pixel on the linear edge; determining a maximum color ratio corresponding to the first edge pixel between the first color ratio and the third color ratio; and the obtaining the first color value based on the color value of the first edge pixel, the color value of the target pixel, and the first color ratio comprises: obtaining the first color value based on the color value of the first edge pixel, the color value of the target pixel, and the maximum color ratio, wherein the linear edge comprises a plurality of adjacent edge pixels.
- 11 . The method according to claim 1 , subsequent to the determining the first scaling factor, the method further comprises: performing a depth filtering operation and a brightness compensation operation on the image to obtain an edge pixel cluster; and determining that the first edge pixel is located in the edge pixel cluster, wherein the edge pixel cluster is configured for setting scaling factors corresponding to other pixels in the image than the edge pixel cluster to zero.
- 12 . The method according to claim 1 , wherein, before the obtaining the first color value, the method comprises: obtaining an edge direction corresponding to the first edge pixel, the edge direction being a vertical direction or a horizontal direction; and determining, as the target pixel, a pixel that crosses an edge and is located at a shortest distance from the first edge pixel in a direction perpendicular to the edge direction.
- 13 . An apparatus for image anti-aliasing, the apparatus comprising: at least one memory configured to store program code; and at least one processor configured to read the program code and operate as instructed by the program code, the program code comprising: first obtaining code configured to cause the at least one first processor to obtain a first edge pixel of an image in a high-dynamic range (HDR) space; first determining code configured to cause the at least one first processor to determine a first scaling factor based on a local brightness environment of the first edge pixel; second determining code configured to cause the at least one first processor to determine a color ratio corresponding with the first edge pixel based on brightness values of a plurality of pixels in an image block where the first edge pixel is located; first scaling code configured to cause the at least one first processor to scale the color ratio based on the first scaling factor to obtain a first color ratio; second obtaining code configured to cause the at least one first processor to obtain a first color value based on a color value of the first edge pixel, a color value of a target pixel, and the first color ratio, wherein the target pixel has a large color value difference from the first edge pixel among a plurality of surrounding pixels of the first edge pixel; and first updating code configured to cause the at least one first processor to update the first color value to the color value of the first edge pixel.
- 14 . The apparatus of claim 13 , wherein the first determining code comprises: first generating code configured to cause the at least one first processor to generate the first scaling factor based on a first brightness value of a first surrounding pixel and a second brightness value of a second surrounding pixel, the first surrounding pixel having a largest brightness value among the plurality of pixels in the image block where the first edge pixel is located, and the second surrounding pixel having a smallest brightness value among the plurality of pixels in the image block where the first edge pixel is located.
- 15 . The method of claim 14 , wherein the first determining code further comprises: first inputting code configured to cause the at least one first processor to input the first brightness value of the first surrounding pixel and the second brightness value of the second surrounding pixel into a scaling function to obtain the first scaling factor, wherein the scaling function determines the first scaling factor based on one or more of the following: a value of the first scaling factor is directly proportional to the first brightness value of the first surrounding pixel; the value of the first scaling factor is directly proportional to the second brightness value of the second surrounding pixel; and the value of the first scaling factor is zero when the second brightness value of the second surrounding pixel is zero.
- 16 . The apparatus of claim 15 , wherein the first inputting code comprises: first multiplying code configured to cause the at least one first processor to multiply the first brightness value by the second brightness value to obtain a first sub-scaling factor; first using code configured to cause the at least one first processor to use the second brightness value as a second sub-scaling factor; and first summing code configured to cause the at least one first processor to sum the first sub-scaling factor and the second sub-scaling factor and then performing normalization processing to obtain the first scaling factor.
- 17 . The apparatus of claim 13 , wherein the second determining code comprises: third obtaining code configured to cause the at least one first processor to obtain a plurality of brightness weights corresponding to the plurality of pixels in the image block where the first edge pixel is located; first characterizing code configured to cause the at least one first processor to characterize the local brightness environment of the first edge pixel by generating a first brightness difference based on a brightness value of each pixel and a corresponding brightness weight of each pixel in the image block; and first mapping code configured to cause the at least one first processor to map the first brightness difference to obtain the color ratio.
- 18 . The apparatus of claim 17 , wherein the image block is a square pixel array centered on the first edge pixel; and wherein the plurality of brightness weights corresponding to the plurality of pixels in the image block satisfy one or more of the following: pixels in the square pixel array that are at a same distance from the first edge pixel have a same brightness weight; pixels in the square pixel array that are closer to the first edge pixel have smaller brightness weights; when the brightness weights corresponding to pixels other than the first edge pixel in the square pixel array are positive numbers, then the brightness weight corresponding to the first edge pixel is a negative number; and a sum of the brightness weight of each pixel in the square pixel array is zero.
- 19 . The apparatus of claim 18 , wherein the first characterizing code comprises: first calculating code configured to cause the at least one first processor to calculate a product of the brightness value of each pixel in the image block and the brightness weight of each pixel; and fourth obtaining code configured to cause the at least one first processor to obtain the first brightness difference by dividing a sum of products of all the pixels in the image block by an absolute value of the brightness weight corresponding to the first edge pixel.
- 20 . A non-transitory computer-readable medium storing program code which, when executed by one or more processors of a device for image anti-aliasing, cause the one or more processors to at least: obtain a first edge pixel of an image in a high-dynamic range (HDR) space; determine a first scaling factor based on a local brightness environment of the first edge pixel; determine a color ratio corresponding with the first edge pixel based on brightness values of a plurality of pixels in an image block where the first edge pixel is located; scale the color ratio based on the first scaling factor to obtain a first color ratio; obtain a first color value based on a color value of the first edge pixel, a color value of a target pixel, and the first color ratio, wherein the target pixel has a large color value difference from the first edge pixel among a plurality of surrounding pixels of the first edge pixel; and update the first color value to the color value of the first edge pixel.
Description
CROSS-REFERENCES TO RELATED APPLICATIONS This application is a continuation of International Application No. PCT/CN2023/112837, filed on Aug. 14, 2023, at the China National Intellectual Property Administration, which claims priority to Chinese Patent Application No. 202211045046.6, filed with the China National Intellectual Property Administration on Aug. 30, 2022, the disclosures of which are incorporated by reference in their entireties. FIELD Embodiments of the present disclosure relate to the field of image rendering, and in particular, to an image anti-aliasing method and apparatus, a device, a medium, and a program product. BACKGROUND Aliasing refers to a phenomenon where geometric lines rendered are jagged due to low pixel accuracy during an image rendering process. The technical means of eliminating aliasing is called anti-aliasing. During image rendering, one image frame can be rendered through a plurality of rendering processes (passes). Each pass is a complete rendering process for one image frame. In a related technology, a fast approximate anti-aliasing (FXAA) solution that merges rendering processes is provided. According to this solution, tone mapping and an FXAA algorithm are completed within one rendering process. Tone mapping refers to mapping a high-dynamic range (HDR) space tone to low-dynamic range (LDR) space. In the FXAA solution that merges rendering processes, the FXAA algorithm acts directly on edges in HDR space. The FXAA solution that merges rendering processes includes a main anti-aliasing branch and a detail anti-aliasing branch. The main anti-aliasing branch is configured to de-alias major edge lines macroscopically. The detail anti-aliasing branch is configured to perform anti-aliasing on individual edge pixels to process edges that are not covered by the main anti-aliasing branch. Affected by a specific algorithm of the main anti-aliasing branch, the main anti-aliasing branch cannot eliminate aliasing in a highlight area in the HDR space. The detail anti-aliasing branch is needed to eliminate the aliasing in the highlight area in the HDR space. However, the detail anti-aliasing branch is based on a sub-pixel anti-aliasing quality parameter (SubPixQuality). When a value of the sub-pixel anti-aliasing quality parameter is 0, anti-aliasing is not performed on edges of image details. In this case, the image details are clear, but distinct aliasing exists in the highlight area. When the value of the sub-pixel anti-aliasing quality parameter is 1, a maximum anti-aliasing effect is realized at the edges of the image details, and an optimal anti-aliasing effect is achieved at an edge of the highlight area, but the image details are blurred. Therefore, in the FXAA solution that merges rendering processes, the value of the sub-pixel anti-aliasing quality parameter is continuously adjusted to balance clarity of the image details and the anti-aliasing effect in the highlight area. In spite of continuously adjusting the value of the sub-pixel anti-aliasing quality parameter, the clarity of the image details and the anti-aliasing effect in the highlight area cannot be balanced effectively. SUMMARY The present disclosure provides an image anti-aliasing method and apparatus, a device, a medium, and a program products, to solve the contradiction between clarity of image details and an anti-aliasing effect in a highlight area in a detail anti-aliasing branch. According to one aspect of the present disclosure, an image anti-aliasing method is provided. The method includes obtaining a first edge pixel of an image in a high-dynamic range (HDR) space; determining a first scaling factor based on a local brightness environment of the first edge pixel; determining a color ratio corresponding with the first edge pixel based on brightness values of a plurality of pixels in an image block where the first edge pixel is located; scaling the color ratio based on the first scaling factor to obtain a first color ratio; obtaining a first color value based on a color value of the first edge pixel, a color value of a target pixel, and the first color ratio, wherein the target pixel has a large color value difference from the first edge pixel among a plurality of surrounding pixels of the first edge pixel; and updating the first color value to the color value of the first edge pixel. According to an aspect of the present disclosure, an image anti-aliasing apparatus is provided. The apparatus includes at least one memory configured to store program code; and at least one processor configured to read the program code and operate as instructed by the program code. The program code may include first obtaining code configured to cause the at least one first processor to obtain a first edge pixel of an image in a high-dynamic range (HDR) space; first determining code configured to cause the at least one first processor to determine a first scaling factor based on a local brightness environment of the first edge pixe