Method, device and equipment for determining image peak signal to noise ratio and medium
By generating the original texture map and downsampling and summing the squared differences in pixel blocks, the rounding error caused by floating-point summation is solved, which improves the accuracy of peak signal-to-noise ratio calculation and image processing quality assessment.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2024-11-29
- Publication Date
- 2026-05-29
AI Technical Summary
In image processing, existing techniques suffer from rounding errors caused by floating-point summation when calculating the peak signal-to-noise ratio of an image, which affects the accuracy of the calculation.
By generating the original texture map and downsampling the squared differences in pixel blocks, the rounding error of floating-point summation is reduced, and the computational task is performed interactively by the CPU and GPU to improve efficiency.
It improves the accuracy of peak signal-to-noise ratio calculation, reduces rounding floating-point errors, and improves the accuracy of image processing quality assessment.
Smart Images

Figure CN122115304A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a method, apparatus, device, and medium for determining the peak signal-to-noise ratio of an image. Background Technology
[0002] In the field of image processing, peak signal-to-noise ratio (PSNR) is a metric for measuring image quality and is commonly used to assess the degree of distortion during image compression or reconstruction.
[0003] In related technologies, when calculating the peak signal-to-noise ratio (PSNR) of two images, the images are usually treated as two-dimensional data (with dimensions of length and width, respectively). The pixel values at relative positions in the two images are summed by iterating through the two dimensions, and the PSNR of the images is further calculated based on the sum of the squared differences.
[0004] However, when the pixel values of an image are represented using floating-point numbers, summing large amounts of floating-point numbers will increase the rounding error, which in turn will affect the accuracy of PSNR calculation. Summary of the Invention
[0005] This application provides a method, apparatus, device, and medium for determining the peak signal-to-noise ratio of an image. The technical solution is as follows:
[0006] On one hand, embodiments of this application provide a method for determining the peak signal-to-noise ratio of an image, the method comprising:
[0007] Acquire a first image and a second image, wherein the first image and the second image have the same resolution;
[0008] Based on the pixel values of the pixels contained in the first image and the second image respectively, an original texture map is generated, wherein the pixel value of each pixel in the original texture map is the squared difference of the pixel values at the corresponding pixel positions in the first image and the second image;
[0009] The original texture image is downsampled and summed in units of pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture image, wherein each pixel block consists of at least two adjacent pixels;
[0010] The peak signal-to-noise ratio of the first image and the second image is determined based on the summation of the squared differences.
[0011] On the other hand, embodiments of this application provide an apparatus for determining the peak signal-to-noise ratio of an image, the apparatus comprising:
[0012] An acquisition module is used to acquire a first image and a second image, wherein the first image and the second image have the same resolution;
[0013] The generation module is used to generate an original texture map based on the pixel values of the pixels contained in the first image and the second image respectively, wherein the pixel value of each pixel in the original texture map is the squared difference of the pixel values at the corresponding pixel positions in the first image and the second image;
[0014] The downsampling module is also used to downsample and sum the original texture image in units of pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture image, wherein the pixel block is composed of at least two adjacent pixels;
[0015] The determination module is used to determine the peak signal-to-noise ratio of the first image and the second image based on the summation result of the squared differences.
[0016] On the other hand, embodiments of this application provide a computer device including a processor and a memory, wherein the memory stores at least one computer instruction, which is loaded and executed by the processor to implement the image peak signal-to-noise ratio determination method as described above.
[0017] On the other hand, embodiments of this application provide a computer-readable storage medium storing at least one computer instruction, which is loaded and executed by a processor to implement the image peak signal-to-noise ratio determination method as described above.
[0018] On the other hand, embodiments of this application provide a computer program product, the computer program product including computer instructions stored in a computer-readable storage medium, a processor obtaining the computer instructions from the computer-readable storage medium, and the processor executing the computer instructions to implement the image peak signal-to-noise ratio determination method as described above.
[0019] When determining the peak signal-to-noise ratio (PSNR) of two similar images using the scheme provided in this application, an original texture map is first generated based on the squared difference of pixel values at corresponding pixel positions in the two similar images. Then, the squared differences of pixels in the original texture map are summed according to pixel blocks. Since the variance information between similar images usually exhibits regional clustering, i.e., the variance information within local image regions is relatively close, summing the squared differences on a pixel block basis can reduce the rounding floating-point error of floating-point summation. Furthermore, by performing multiple rounds of downsampling and summation, the final result of the summed squared differences of each pixel in the original texture map is obtained. Because the rounding floating-point error of the summed squared differences is reduced, the accuracy of the PSNR determined based on the summed squared differences can be improved. Attached Figure Description
[0020] Figure 1 This is a schematic diagram illustrating the interaction between the CPU and GPU to calculate the peak signal-to-noise ratio of an image, as shown in an exemplary embodiment of this application.
[0021] Figure 2 A flowchart illustrating a method for determining the peak signal-to-noise ratio of an image provided in an exemplary embodiment of this application is shown;
[0022] Figure 3 This is a schematic diagram illustrating the process of determining the original texture map in an exemplary embodiment of this application;
[0023] Figure 4 This is a schematic diagram illustrating a pixel block sampling process in an exemplary embodiment of this application;
[0024] Figure 5 This is a schematic diagram illustrating redundant calculations in an exemplary embodiment of this application;
[0025] Figure 6 This is a flowchart illustrating an expanded texture map and a downsampling summation process, as shown in an exemplary embodiment of this application;
[0026] Figure 7 This is a schematic diagram illustrating an exemplary embodiment of the texture map expansion and downsampling summation process of this application;
[0027] Figure 8 This is a flowchart illustrating a downsampling summation process in an exemplary embodiment of this application;
[0028] Figure 9 This is a schematic diagram illustrating the implementation of texture map expansion and downsampling summation process in another exemplary embodiment of this application;
[0029] Figure 10 This is a schematic diagram illustrating the CPU and GPU interaction to calculate the peak signal-to-noise ratio of an image, as shown in another exemplary embodiment of this application.
[0030] Figure 11 This is a flowchart illustrating a memory block allocation and texture map read / write process in an exemplary embodiment of this application;
[0031] Figure 12 This is a schematic diagram illustrating a texture atlas stored in a memory block, as shown in an exemplary embodiment of this application;
[0032] Figure 13 This is a schematic diagram illustrating the user interface of a script component in an exemplary embodiment of this application;
[0033] Figure 14 This is a structural block diagram of an image peak signal-to-noise ratio determination apparatus provided in an exemplary embodiment of this application;
[0034] Figure 15 A schematic diagram of the structure of a computer device provided in an exemplary embodiment of this application is shown. Detailed Implementation
[0035] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0036] For ease of understanding, the terms used in the embodiments of this application will be explained below.
[0037] Peak signal-to-noise ratio (PSNR): A metric used to measure image quality; a higher PSNR indicates better image quality. PSNR is defined using mean-square error (MSE). For two similar m*n images (image I and image K), their mean-square errors can be expressed as:
[0038]
[0039] Where I(i,j) represents the pixel value of the pixel at coordinate (i,j) in image I, and K(i,j) represents the pixel value of the pixel at coordinate (i,j) in image K.
[0040] The peak signal-to-noise ratio (PSNR) between images can be expressed as:
[0041]
[0042] Where MAX is the maximum pixel value of the image. If the pixel value is represented by 8 bits, then the value of MAX is 2. 8 -1 = 255; the unit of peak signal-to-noise ratio (PSNR) of the image is dB.
[0043] A pixel shader is a program that runs on the GPU and is used to rasterize pixels. In this embodiment, the pixel shader is used to generate a texture map representing the squared difference of pixel values between two similar images, and to perform multiple rounds of downsampling and summing of the pixel values in the texture map.
[0044] A vertex shader is a program that runs on the GPU for vertex rendering. It primarily processes input vertex data (position, color, coordinates, etc.), performs a series of transformation operations (translation, rotation, scaling, etc.), and outputs the transformed vertices. In this embodiment, the vertex shader is used to dilate the texture map based on downsampling requirements, resulting in an expanded texture map whose resolution meets the downsampling requirements.
[0045] The method for determining the peak signal-to-noise ratio of an image provided in this application embodiment can be executed by a computer device, which can be a user terminal such as a smartphone, tablet computer, personal computer, or workstation, or a server or server cluster.
[0046] In one possible implementation, determining the peak signal-to-noise ratio of an image can be performed independently by the CPU (Central Processing Unit) in a computer device.
[0047] In another possible implementation, determining the peak signal-to-noise ratio of an image can be performed interactively by the CPU and GPU (Graphics Processing Unit) in a computer device.
[0048] Regarding the computational tasks executed by the CPU and GPU during the interaction process, in some embodiments, computational tasks are allocated based on the respective working characteristics of the CPU and GPU (CPU is suitable for executing general and complex logic operations serially, while GPU is suitable for executing a large number of simple instructions in parallel) and the task characteristics of different stages of the image peak signal-to-noise ratio calculation task, in order to improve the computational efficiency of image peak signal-to-noise ratio.
[0049] Indicative, such as Figure 1 As shown, the CPU 110 can transmit the first image and the second image involved in the image peak signal-to-noise ratio calculation to the GPU 120. Since the GPU 120 generates a texture map based on the first image and the second image, and performs multiple rounds of downsampling and summation on the texture map, it writes the sum of squared differences obtained from the final downsampling and summation back to the CPU 110. The CPU 110 calculates the image peak signal-to-noise ratio between the first image and the second image based on the sum of squared differences.
[0050] Figure 2 A flowchart illustrating a method for determining the peak signal-to-noise ratio of an image according to an exemplary embodiment of this application is shown. This embodiment describes the method as being executed by a computer device, and the method includes the following steps.
[0051] Step 202: Obtain the first image and the second image, which have the same resolution.
[0052] The first image and the second image are two similar images used to determine the peak signal-to-noise ratio of the image.
[0053] Optionally, the second image is obtained by compressing the first image (using a compression algorithm that does not change the resolution); or, the second image is obtained by denoising a noisy image (obtained by adding noise to the first image); or, the second image is obtained by super-resolution processing of a low-resolution image (obtained by downscaling the first image); or, the second image is obtained by image enhancement of the first image. This application does not limit the generation method of the first image and the second image.
[0054] Optionally, both the first and second images can be grayscale or color images.
[0055] Step 204: Generate an original texture map based on the pixel values contained in the first image and the second image respectively. The pixel value of each pixel in the original texture map is the squared difference of the pixel values at the corresponding pixel positions in the first image and the second image.
[0056] In one possible implementation, a computer device acquires the pixel values at the same pixel location in two images and calculates the squared difference between the two pixel values, thereby determining the squared difference as the pixel value of the pixel corresponding to that pixel location in the original texture image. In this embodiment, the pixel values of pixels in the first and second images are represented using floating-point numbers, such as single-precision floating-point numbers (float32).
[0057] The resolution of the original texture map is the same as that of the first and second images.
[0058] Corresponding pixel positions in the first and second images refer to pixels with the same coordinates in both images. These pixel coordinates can be represented using the x-coordinate and y-coordinate relative to the top-left vertex pixel of the image.
[0059] Indicative, such as Figure 3 As shown, taking the first image 31 and the second image 32 as examples, both of which are 4*4 images, the computer device generates a 4*4 original texture map 33.
[0060] In some embodiments, when both the first image and the second image are grayscale images, the squared difference is the squared difference of the grayscale values at the same pixel location.
[0061] In other embodiments, when both the first and second images are color images, the squared difference is the sum of the squared differences of the channel values of different channels (RGB or RGBA channels) at the same pixel location; or, the squared difference is the squared difference of the channel values of a single channel at the same pixel location (in which case the original texture map corresponding to each channel will be obtained), wherein the single channel is the R channel, G channel, B channel or A channel.
[0062] Step 206: Downsample and sum the original texture image in units of pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture image. A pixel block consists of at least two adjacent pixels.
[0063] Optionally, the size of the pixel block can be a fixed size, or it can be dynamically adjusted according to the accuracy requirements of the image's peak signal-to-noise ratio. For example, the higher the accuracy requirement, the smaller the size of the pixel block; the lower the accuracy requirement, the larger the size of the pixel block.
[0064] In this embodiment, the pixel block is a rectangular pixel block. Optionally, the rectangular pixel block is a square pixel block, such as a pixel block with a size of 2*2, 3*3, etc.; or, the rectangular pixel block is a non-square pixel block, such as a pixel block with a size of 2*3, 2*4, etc. This embodiment does not limit the specific size of the pixel block.
[0065] In this embodiment, downsampling and summing on a pixel-block basis means sampling pixel blocks from the texture map and summing the pixel values (squared differences) of each pixel in the pixel block. For example, when the size of the pixel block is 2*2, the computer device sums the four pixel values (squared differences) in the sampled 2*2 pixel block.
[0066] Since a pixel block includes at least two pixels, and the sum of the pixel values in the pixel block will be used as the pixel value of the corresponding single pixel in the downsampled texture map, the size of the texture map is continuously reduced during the process of summing the squared differences of the sampled pixel blocks, thus achieving downsampling and summing of the texture map.
[0067] In this process of sampling pixel blocks, there is no overlap between the various pixel blocks to ensure that a pixel participates in the summation of pixel values within only a single pixel block. (Illustrative example, such as...) Figure 4 As shown, when the size of the original texture map 41 is 8*8 and the size of the pixel block 42 is 2*2, the computer device can sample 16 pixel blocks 42 from the original texture map 41 and sum the pixel values in the 16 pixel blocks 42 respectively.
[0068] Optionally, when the resolution of the first image and the second image are both m*n, the resolution of the original texture image is m*n. When the pixel block size is k1*k2, the resolution of the downsampled texture image obtained by performing a round of downsampling and summing on the original texture image in units of pixel blocks is (m / k1)*(n / k2).
[0069] More generally, the original texture image is downsampled and summed for i rounds, resulting in a downsampled texture image with a resolution of (m / k1). i )*(n / k2 i Furthermore, before and after one round of downsampling and summing, the resolution length after downsampling and summing is 1 / k1 of the resolution length before downsampling and summing, and the resolution width after downsampling and summing is 1 / k2 of the resolution width before downsampling and summing.
[0070] In some embodiments, when the resolution of the original texture map is an integer power of the pixel block size, after at least one round of downsampling and summation, the resolution of the final downsampled texture map is 1*1.
[0071] During each round of downsampling and summation, the sum of the pixel values of all pixels in a pixel block is used as the pixel value of the corresponding pixel in the next-level downsampled texture map. In some embodiments, if the current image is divided into X*Y (X rows and Y columns) pixel blocks, for the pixel block located at the x-th row and y-th column, the sum of the pixel values of all pixels in that pixel block is the pixel value of the pixel at the x-th row and y-th column in the next-level downsampled texture map.
[0072] Normally, rounding errors in floating-point numbers are caused by the mantissa. If a loop is used to traverse the dimensions directly and the pixel values of each pixel in the original texture image are accumulated in a zigzag pattern, the rounding error generated by the accumulation will be large because the mantissas of the pixel values differ significantly.
[0073] Since the last digits of different pixel values in the same pixel block are similar, the solution adopted in this application embodiment can offset the rounding error to a certain extent by accumulating the pixel values in the pixel block.
[0074] In some embodiments, when the size of the original texture map differs significantly from that of the pixel blocks, in order to obtain the sum of the squared differences of the squared differences of each pixel in the original texture map, the computer device needs to perform multiple rounds of downsampling summation, wherein the size of the texture map is continuously reduced during the multiple rounds of downsampling summation.
[0075] The first round of downsampling summation is performed on the original texture map, while subsequent rounds of downsampling summation are performed on the result of the previous round of downsampling summation.
[0076] Step 208: Determine the peak signal-to-noise ratio of the first image and the second image based on the summation of squared differences.
[0077] After obtaining the sum of the squared differences of each pixel in the original texture image through the above downsampling summation method, the computer device determines the peak signal-to-noise ratio between the images.
[0078] In some embodiments, the computer device determines the maximum pixel value of the first image and the second image, as well as the resolution of the first image and the second image, and then determines the peak signal-to-noise ratio of the image based on the maximum pixel value, the resolution, and the sum of squared differences. This process can be represented as:
[0079]
[0080] Where MAX is the maximum pixel value, SSE is the sum of squared differences, and m and n are the resolution length and resolution width of the first image, respectively.
[0081] Optionally, computer equipment can evaluate the image processing quality based on the peak signal-to-noise ratio of the image, thereby improving the image processing method.
[0082] Optionally, if the second image is obtained by compressing the first image, the computer device can evaluate the image compression quality based on the peak signal-to-noise ratio of the image, and then improve the image compression algorithm.
[0083] Optionally, if the second image is obtained by denoising the noisy image (obtained by adding noise to the first image), the computer device can evaluate the image denoising quality based on the peak signal-to-noise ratio of the image, and then improve the image denoising algorithm.
[0084] Optionally, if the second image is obtained by super-resolution processing of a low-resolution image (obtained by down-resolution of the first image), the computer device can evaluate the super-resolution quality of the image based on the peak signal-to-noise ratio of the image, and then improve the image super-resolution algorithm.
[0085] Optionally, if the second image is obtained by enhancing the first image, the computer device can evaluate the image enhancement quality based on the peak signal-to-noise ratio of the image, and then improve the image enhancement algorithm.
[0086] The embodiments of this application do not limit the specific use of image peak signal-to-noise ratio.
[0087] In summary, when determining the peak signal-to-noise ratio (PSNR) of two similar images using the scheme provided in this application, an original texture map is first generated based on the squared difference of pixel values at corresponding pixel positions in the two similar images. Then, the squared differences of pixels in the original texture map are summed according to pixel blocks. Since the variance information between similar images usually exhibits regional clustering, meaning the variance information within local image regions is relatively close, summing the squared differences on a pixel block basis can reduce the rounding floating-point error of floating-point summation. Furthermore, by performing multiple rounds of downsampling and summation, the final result of the summed squared differences of each pixel in the original texture map is obtained. Because the rounding floating-point error of the summed squared differences is reduced, the accuracy of the PSNR determined based on this summed squared difference result can be improved.
[0088] downsampling summation process
[0089] When the resolution of the original texture image is much larger than the size of the pixel blocks, the computer needs to perform multiple rounds of downsampling and summing to finally obtain the sum of the squared differences of each pixel in the original texture image. For each round of downsampling and summing, if the resolution of the texture image is not an integer multiple of the pixel block size, there will be overlap between the sampled pixel blocks, which will cause some squared differences to be included in multiple summations, affecting the accuracy of the final calculated sum of squared differences.
[0090] Indicative, such as Figure 5 As shown, when the resolution of texture map 51 is 3*3 and the size of pixel block 52 is 2*2, the sampling and summing process is as follows: the computer device sums the 2*2 pixel block 52 at the top left corner of texture map 51 to obtain the top left pixel value 4 (1+1+1+1) of the next level texture map 53; it sums the 2*2 pixel block 52 at the top right corner of texture map 51 to obtain the top right pixel value 6 (1+2+2+1) of the next level texture map 53; it sums the 2*2 pixel block 52 at the bottom left corner of texture map 51 to obtain the bottom left pixel value 8 (3+3+1+1) of the next level texture map 53; and it sums the 2*2 pixel block 52 at the bottom right corner of texture map 51 to obtain the bottom right pixel value 10 (3+4+2+1) of the next level texture map 53.
[0091] Clearly, the 2x2 pixel block in the upper left corner of the texture map overlaps with the 2x2 pixel blocks in the upper right, lower left, upper right, and lower right corners, causing some pixel values to be redundantly calculated. This leads to an error in the next-level texture map 53 obtained by sampling and summing (the sum of the squared differences of the pixel values in texture map 51 is 18, but the sum of the squared differences of the pixel values in the next-level texture map 53 is 28).
[0092] In one possible implementation, to avoid the aforementioned redundant calculation problem, such as Figure 6 As shown, the above downsampling summation can include the following sub-steps:
[0093] Step 206A: Based on the pixel block size and the resolution of the original texture map, expand the original texture map to obtain an expanded texture map. The pixel value of the pixels in the expanded region of the expanded texture map is 0.
[0094] In one possible implementation, the computer device determines whether the original texture image needs to be expanded based on the resolution of the original texture image and the pixel block size. If expansion is needed, the original texture image is expanded to obtain an expanded texture image; if expansion is not needed, downsampling and summing are performed based on the original texture image.
[0095] Regarding the method for determining whether to expand the original texture image, optionally, if the resolution of the original texture image and the resolution of each level of texture image obtained by downsampling from the original texture image are both integer multiples of the pixel block size, the computer device determines that the original texture image does not need to be expanded. If at least one of the resolutions of the original texture image and the resolutions of each level of texture image obtained by downsampling from the original texture image is not an integer multiple of the pixel block size, the computer device determines that the original texture image needs to be expanded. In other words, the purpose of expanding the original texture image is to ensure that in each round of downsampling, an integer number of non-overlapping pixel blocks can be sampled in both the length and width directions of the texture image.
[0096] In some embodiments, when the same pixel block size is used in each round of downsampling, if the resolution of the original texture map is an integer power of the pixel block size, the original texture map does not need to be expanded; if the resolution of the original texture map is not an integer power of the pixel block size, the original texture map needs to be expanded.
[0097] The resolution of the original texture image being an integer power of the pixel block size means that the length of the original texture image is an integer power of the pixel block length, and the width of the original texture image is an integer power of the pixel block width. Both length and width are measured in pixels.
[0098] Correspondingly, based on the pixel block size and the resolution of the original texture image, the process of expanding the original texture image to obtain the expanded texture image is as follows: with the resolution length being an integer power of the pixel block length and the resolution width being an integer power of the pixel block width as the target, the original texture image is expanded to obtain the expanded texture image, where the resolution length of the expanded texture image is an integer power of the pixel block length and the resolution width of the expanded texture image is an integer power of the pixel block width.
[0099] Furthermore, to avoid pixels within the expanded region of the expanded texture map affecting the summation result, the pixel values of pixels within the expanded region are set to 0.
[0100] In one possible implementation, when the length of the original texture map is a first length, the width of the original texture map is a first width, the length of the pixel block is a second length, and the width of the pixel block is a second width, expanding the original texture map may include at least one of the following two cases:
[0101] Case 1: If the first length is not an integer power of the second length, expand the length of the original texture map to obtain an expanded texture map, where the length of the expanded texture map is an integer power of the second length.
[0102] The computer device determines whether the length of the original texture image is an integer power of the length of the pixel block. If not, the computer device expands the length of the original texture image to the integer power of the length of the pixel block, resulting in an expanded texture image with a length that is an integer power of the length of the pixel block.
[0103] In one possible implementation, the length of the expanded texture map is a preset length, which is an integer power of a second length. For example, the preset length could be the length of the largest image that supports peak signal-to-noise ratio (PSNR) calculation.
[0104] In an illustrative example, when the length of the original texture image is 500 and the length of the pixel block is 2, the computer device expands the length of the original texture image to the maximum image length of 2048 to support the calculation of the peak signal-to-noise ratio of the image; when the length of the original texture image is 1920 and the length of the pixel block is 2, the computer device similarly expands the length of the original texture image to 2048.
[0105] In another possible implementation, the length of the expanded texture map is dynamically determined based on the length of the original texture map and the length of the pixel block.
[0106] Optionally, the computer device determines the length of the expanded texture map as the smallest integer power of the second length among lengths greater than the first length. That is, when the length of the expanded texture map is a third length, the third length is the smallest integer power of the second length among lengths greater than the first length.
[0107] In an illustrative example, when the length of the original texture image is 500 and the length of the pixel block is 2, the computer device expands the length of the original texture image to 512 because 512 is the smallest power of 2 greater than 500; when the length of the original texture image is 1920 and the length of the pixel block is 2, the computer device expands the length of the original texture image to 2048 because 2048 is the smallest power of 2 greater than 1920.
[0108] Case 2: If the first width is not an integer power of the second width, expand the width of the original texture map to obtain an expanded texture map, where the width of the expanded texture map is an integer power of the second width.
[0109] The computer device determines whether the width of the original texture image is an integer power of the width of the pixel block. If not, the computer device expands the width of the original texture image to an integer power of the width of the pixel block, resulting in an expanded texture image with a width that is an integer power of the width of the pixel block.
[0110] In one possible implementation, the width of the expanded texture map is a preset width, which is an integer power of a second width. For example, the preset width could be the width of the largest image that supports peak signal-to-noise ratio (PSNR) calculation.
[0111] In an illustrative example, when the width of the original texture image is 500 and the width of the pixel block is 2, the computer device expands the width of the original texture image to 2048, which is the width of the maximum image that supports the calculation of the peak signal-to-noise ratio of the image; when the width of the original texture image is 1920 and the width of the pixel block is 2, the computer device similarly expands the width of the original texture image to 2048.
[0112] In another possible implementation, the width of the expanded texture map is dynamically determined based on the width of the original texture map and the width of the pixel blocks.
[0113] Optionally, the computer device determines the width of the expanded texture map as the smallest integer power of the second width among widths greater than the first width. That is, when the width of the expanded texture map is a third width, the third width is the smallest integer power of the second width among widths greater than the first width.
[0114] In an illustrative example, when the width of the original texture image is 500 and the width of the pixel block is 2, the computer device expands the width of the original texture image to 512 because 512 is the smallest power of 2 greater than 500; when the width of the original texture image is 1920 and the width of the pixel block is 2, the computer device expands the width of the original texture image to 2048 because 2048 is the smallest power of 2 greater than 1920.
[0115] like Figure 7 As shown, with texture map 71 having a resolution of 3*3 and pixel block 73 having a size of 2*2, the computer device first expands texture map 71 to obtain expanded texture map 72 with a resolution of 4*4. The pixel values in the expanded area of expanded texture map 72 are all 0. Subsequently, the expanded texture map 72 is downsampled and summed in units of 2*2 pixel blocks 73 to obtain the next level texture map 74.
[0116] Compared to CPUs, GPUs are more efficient at processing texture maps; therefore, expanding the original texture map can be performed by the GPU. In one possible implementation, this step may include the following sub-steps:
[0117] Step 206A1: Determine the resolution of the expanded texture map based on the pixel block size and the resolution of the original texture map.
[0118] Optionally, if the resolution of the original texture map is not an integer power of the pixel block size, the computer device determines the resolution of the expanded texture map.
[0119] In some embodiments, if the length of the original texture image is not an integer power of the length of the pixel block, the length of the extended texture image is determined to be greater than the length of the original texture image and is an integer power of the length of the pixel block; if the width of the original texture image is not an integer power of the width of the pixel block, the width of the extended texture image is determined to be greater than the width of the original texture image and is an integer power of the width of the pixel block.
[0120] Optionally, the length is greater than the length of the original texture image and is an integer power of the length of the pixel block. It can be a preset length or the smallest integer power of the length of the pixel block. The width is greater than the width of the original texture image and is an integer power of the width of the pixel block. It can be a preset width or the smallest integer power of the width of the pixel block.
[0121] The specific process for determining the resolution of the expanded texture map can be referred to in the above embodiments, and will not be repeated here.
[0122] Step 206A2: Determine the expansion ratio based on the resolution of the expanded texture map and the resolution of the original texture map.
[0123] Since texture expansion via the GPU is performed proportionally, the ratio of the resolution of the expanded texture to that of the original texture needs to be determined as the expansion ratio. Optionally, this expansion ratio may include a length expansion ratio and a width expansion ratio.
[0124] To illustrate, using a square texture image as an example, when the resolution of the original texture image is RES... current The resolution of the expanded texture map is RES. render At this point, the expansion ratio can be expressed as: viewport = RES render / RES current .
[0125] Step 206A3: The original texture map is expanded using the GPU's vertex shader according to the expansion ratio to obtain the expanded texture map.
[0126] In one possible implementation, after inputting the original texture map and the expansion ratio into the vertex shader of the GPU, the vertex shader performs vertex offset processing on the original texture map according to the expansion ratio, thereby obtaining the expanded texture map.
[0127] Schematic, when the original texture map is represented as UVs, the expanded texture map obtained after the vertex shader expansion process can be represented as: UVs new =UV*viewport.
[0128] Step 206B: Downsample and sum the expanded texture map in units of pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture map.
[0129] Since the size of the original texture map (or expanded texture map) is usually much larger than the size of the pixel blocks, determining the sum of the squared differences of each pixel in the original texture map using a downsampling summation method requires multiple rounds of downsampling summation. In one possible implementation, such as Figure 8 As shown, the downsampling summation process may include the following sub-steps:
[0130] Step 206B1: Sample pixel blocks from the expanded texture map or the downsampled texture map, where the downsampled texture map is a texture map obtained by summing the expanded texture map after at least one level of downsampling.
[0131] In some embodiments, during the first round of downsampling summation, the computer device samples pixel blocks from the expanded texture map; during the nth round of downsampling summation, the computer device samples pixel blocks from the downsampled texture map obtained from the previous round of downsampling summation, where n≥2.
[0132] In this embodiment of the application, the downsampled texture map obtained after the i-th round of downsampling and summation is called the i-th level downsampled texture map.
[0133] Since sampling pixel blocks and summing the pixel values within those blocks is a simple operation that requires a lot of execution, computer devices can use GPUs to perform downsampling summation, thereby improving the efficiency of downsampling summation.
[0134] In one possible implementation, the computer device samples pixel blocks by invoking an aggregation function. The aggregation function is a function used to collect pixel values from different regions of an image.
[0135] In some embodiments, a computer device samples pixel blocks by calling the Gather function. The Gather function is used to collect pixel values from a pixel block of a specified size in an image. For example, a GPU can collect pixel values from a 2x2 pixel block by calling the Gather function.
[0136] Step 206B2: Sum the pixel values of the pixels in the pixel block, and generate the next level downsampled texture map based on the sum of the pixel values.
[0137] In some embodiments, the computer device acquires the pixel values of each pixel block, accumulates the pixel values, and determines the sum of the accumulated pixel values as the pixel value of the pixel at the corresponding pixel position in the next-level downsampled texture map. After performing pixel value summation on each sampled pixel block, the next-level downsampled texture map is obtained.
[0138] In some embodiments, where the pixel block is sampled from an extended texture map, the computer device sums the pixel values of the pixels in the pixel block and generates a first-level downsampled texture map based on the sum of the pixel values.
[0139] When a pixel block is sampled from a level i downsampled texture map, the computer device sums the pixel values of the pixels in the pixel block and generates a level i+1 downsampled texture map based on the sum of the pixel values. The resolution of the level i+1 downsampled texture map is lower than that of the level i downsampled texture map, where i is a positive integer.
[0140] Optionally, when the pixel block size is m*m, the resolution of the (i+1)th level downsampled texture map is 1 / m of the resolution of the i-th level downsampled texture map.
[0141] Regarding the method of generating the next-level downsampled texture map based on the sum of pixel values of different pixel blocks, in one possible implementation, for the sampled i-th row j-th pixel block, the sum of pixel values of the pixel block is the pixel value of the i-th row j-th pixel in the next-level downsampled texture map, where i and j are both positive integers.
[0142] Regarding the method of summing pixel values, one possible implementation is to represent the pixel values obtained by calling the aggregation function through the GPU in the form of a vector. For example, when the Gather function is called to sample a 2*2 pixel block, it returns a four-dimensional vector (r, g, b, a), where r is the pixel value of the bottom-left pixel of the pixel block, g is the pixel value of the bottom-right pixel of the pixel block, b is the pixel value of the top-right pixel of the pixel block, and a is the pixel value of the top-left pixel of the pixel block. That is, the Gather function returns the pixel values in the pixel block in counterclockwise order.
[0143] When a 1xn vector is obtained by calling the aggregation function, the GPU multiplies this vector with a vector of nx1 elements, where all elements are 1, and determines the sum of the pixel values in the pixel block.
[0144] In some embodiments, the pixel values can be summed and a downsampled texture map can be generated by calling the pixel shader through the GPU.
[0145] Indicative, such as Figure 9 As shown, after expanding the original 5*5 texture map 91 into an 8*8 expanded texture map 92, the GPU calls the Gather function to sample a 2*2 pixel block 93 from the expanded texture map 92, and sums the pixel values in the pixel block 93 through the pixel shader to generate the first-level downsampled texture map 94.
[0146] The GPU calls the Gather function to sample a 2*2 pixel block 93 from the first-level downsampled texture map 94, and then sums the pixel values in the pixel block 93 through the pixel shader to generate the second-level downsampled texture map 95.
[0147] The GPU calls the Gather function to sample a 2*2 pixel block 93 from the second-level downsampled texture map 95, and then sums the pixel values in the pixel block 93 through the pixel shader to generate the third-level downsampled texture map 96.
[0148] Step 206B3: Given the lowest-level downsampled texture map, the pixel value of the pixel in the lowest-level downsampled texture map is determined as the sum of the squared differences of the squared differences of each pixel in the original texture map. The lowest-level downsampled texture map contains one pixel.
[0149] When the resolution of the expanded texture map is an integer power of the pixel block size, after multiple rounds of downsampling and summation, a downsampled texture map containing one pixel will be obtained. This downsampled texture map is the lowest-level downsampled texture map.
[0150] Indicative, such as Figure 9 As shown, after the expanded texture map 92 is downsampled and summed three times, the resulting third-level downsampled texture map 96 is the lowest-level downsampled texture map.
[0151] Since the pixel value of a pixel in the lowest-level downsampled texture map is obtained by summing the squared differences of pixel blocks obtained from multiple rounds of sampling, the pixel value of that pixel is the sum of the squared differences of the squared differences of each pixel in the original texture map.
[0152] Indicative, such as Figure 9 As shown, the computer device determines the pixel value 85 of the pixel in the third-level downsampled texture map 96 as the sum of the squared differences of the squared differences of each pixel in the original texture map 91.
[0153] Regarding when to stop downsampling summation, in some embodiments, when the resolution of the expanded texture map is a power of n for the pixel block size, the computer device stops downsampling summation after the nth downsampling summation.
[0154] In this embodiment, considering that the resolution of the original texture image may not be an integer power of the pixel block size, in order to avoid redundant calculations when performing pixel block sampling and summation, the computer device expands the original texture image based on the pixel block size before performing downsampling and summation, so that the resolution of the expanded texture image is an integer power of the pixel block size, thereby avoiding redundant calculations in the downsampling and summation process and improving the accuracy of the squared difference summation result obtained by downsampling and summation.
[0155] Furthermore, in this embodiment, the computer device uses the GPU to call the vertex shader and pixel shader to perform texture map expansion and downsampling summation, which can give full play to the GPU's ability to execute a large number of simple tasks in parallel. Compared with performing texture map expansion and downsampling summation through the CPU, this can improve computational efficiency.
[0156] To verify the effectiveness of the solution provided in this application, taking two similar images with a resolution of 2048*2048 as an example, the peak signal-to-noise ratio (PSNR) of the image calculated by the CPU using a double loop is 49.79797, while the PSNR calculated by the solution provided in this application is 49.437. For two similar images with a resolution of 1000*1000, the PSNR of the image calculated by the CPU using a double loop is 45.41238, while the PSNR calculated by the solution provided in this application is 45.244. It can be seen that the PSNR calculated by the solution provided in this application is lower because the rounding error is reduced, resulting in a more accurate calculation result.
[0157] Generation of original texture map & calculation of peak signal-to-noise ratio of image
[0158] When generating the original texture map, it is necessary to calculate the squared difference of pixel values of a large number of co-located pixels in the first and second images. Therefore, in order to improve the efficiency of generating the original texture map, computer devices can generate the original texture map using the GPU.
[0159] In one possible implementation, the computer device inputs a first image and a second image into the GPU, thereby generating an original texture map through the GPU's pixel shader based on the pixel values at the same pixel locations in the first and second images.
[0160] In some embodiments, the GPU can leverage its ability to execute tasks in parallel by using pixel shaders to compute the squared differences of pixel values of a large number of co-pixels in parallel.
[0161] Optionally, the pixel shader determines the squared difference between the pixel values of the pixel at pixel position (i, j) in the first and second images, and uses this squared difference as the pixel value of the pixel at pixel position (i, j) in the original texture image.
[0162] In some embodiments, the computer device offloads a large number of simple tasks that need to be executed in parallel to the GPU to obtain the sum of squared differences of pixel values of each pixel in the original texture image. Since the subsequent calculation of the peak signal-to-noise ratio (PSNR) of the image based on the sum of squared differences involves division and square root operations, the computer device can offload the task of calculating the final PNR of the image to the CPU to leverage the CPU's ability to perform complex calculations.
[0163] In one possible implementation, the computer device reads back the sum of squared differences from the GPU to the CPU, thereby determining the peak signal-to-noise ratio of the first image and the second image based on the sum of squared differences by the CPU.
[0164] In an illustrative example, such as Figure 10 As shown, after receiving the task of calculating the peak signal-to-noise ratio of the image, the CPU 110 writes the first image and the second image to the GPU 120.
[0165] GPU 120 generates an original texture map 122 using a pixel shader based on the squared difference of pixel values of co-occurring pixels (i.e., pixels in the same position in the image) in the first and second images. If the resolution of the original texture map 122 is not an integer power of the pixel block size used in downsampling and summing, GPU 120 expands the original texture map 122 using a vertex shader 123 to obtain an expanded texture map 124.
[0166] GPU 120 uses pixel shader 121 to perform multiple rounds of downsampling and summing on the expanded texture map 124 in units of pixel blocks to obtain downsampled texture map 125, and finally determines the pixel value of the lowest-level downsampled texture map as the result of summation of squared differences.
[0167] GPU 120 reads back the sum of squared differences 126 to CPU 110. Based on the sum of squared differences 126, and the image resolution & maximum pixel value 127 of the first and second images, CPU 110 calculates the peak signal-to-noise ratio 128 of the image.
[0168] In particular, when it is necessary to calculate the peak signal-to-noise ratio (PSNR) between multiple groups of images, while the CPU calculates the PSNR of the current group of images, the GPU can calculate the sum of squared differences of pixel values of the next group of images in parallel to improve computational efficiency.
[0169] In this embodiment, based on the respective operating characteristics of the CPU and GPU, the computational tasks at different stages of the image peak signal-to-noise ratio (PSNR) calculation process are assigned to the most suitable processor for execution. Specifically, assigning tasks such as texture map generation, texture map expansion, and downsampling summation to the GPU fully leverages its parallel processing capabilities, thereby improving the computational efficiency of the image PSNR.
[0170] It should be noted that tasks performed by the GPU in the above embodiments can also be performed by the CPU (with relatively lower efficiency), that is, the CPU independently performs the image peak signal-to-noise ratio calculation. This embodiment will not elaborate on this further.
[0171] Memory block allocation process
[0172] As can be seen from the above embodiments, calculating the sum of squared differences requires multiple texture map reads and writes. If dynamic memory requests are made during each texture map read and write, efficiency will be affected. Therefore, to further improve the calculation efficiency of the peak signal-to-noise ratio (PSNR), in one possible implementation, such as... Figure 11 As shown, computer devices can perform memory allocation and texture map reading / writing in the following manner during the calculation of peak signal-to-noise ratio of an image.
[0173] Step 1101: Allocate a memory block in memory based on the maximum image resolution. The memory block is used to store texture atlases. The texture atlases include original texture maps and downsampled texture maps of different resolutions. The maximum image resolution is the resolution of the largest image that supports the calculation of the peak signal-to-noise ratio of the image.
[0174] Optionally, before calculating the peak signal-to-noise ratio of the image, the CPU may request a memory block in memory with contiguous addresses.
[0175] In some embodiments, when setting up the image peak signal-to-noise ratio calculation task, a maximum image resolution is set, and the resolution of subsequent images participating in the calculation is less than or equal to this maximum image resolution.
[0176] Optionally, the maximum image resolution is an integer power of the pixel size of the pixel block used for downsampling and summing. For example, if the downsampling and summing uses a 2x2 pixel block, the maximum image resolution is 2048x2048.
[0177] Since subsequent texture map reads and writes are performed within this memory block without needing to allocate memory blocks in real time, it is necessary to ensure that the allocated memory block can completely store the texture atlas, including the original texture map and downsampled texture maps at different resolutions.
[0178] Since the resolution of the images used for subsequent peak signal-to-noise ratio (PSNR) calculations is less than or equal to the maximum image resolution, the computer device allocates a memory block in memory based on the data volume of the texture atlas corresponding to the maximum image resolution. The capacity of this memory block is greater than or equal to the data volume of the texture atlas corresponding to the maximum image resolution, to accommodate the original texture atlas using the maximum image resolution, as well as the downsampled texture atlases obtained by downsampling and summing the original texture atlases.
[0179] Optionally, allocating a memory block in memory based on the maximum image resolution may include the following sub-steps:
[0180] Step 1101A: Based on the maximum image resolution and the pixel block size, determine each downsampling resolution obtained by downsampling from the maximum image resolution.
[0181] Among them, the lowest resolution obtained by downsampling from the maximum image resolution is determined to be 1*1.
[0182] In one possible implementation, the (i+1)th level downsampling resolution = the i-th level downsampling resolution / pixel block size, and the first level downsampling resolution = the maximum image resolution / pixel block size.
[0183] To illustrate, with a maximum image resolution of 16*16 and a pixel block size of 2*2, the computer device determines the downsampling resolutions for each level as 8*8, 4*4, 2*2, and 1*1, respectively.
[0184] Step 1101B: Based on the maximum image resolution and each downsampling resolution, allocate a memory block in memory. The capacity of the memory block is the sum of the image data volume of the texture images at the maximum image resolution and each downsampling resolution.
[0185] In one possible implementation, the computer device determines the image data size of the original texture map at the maximum image resolution based on the data size of the pixel values of individual pixels and the maximum image resolution; and determines the image data size of the downsampled texture map using the downsampled resolution based on the data size of the pixel values of individual pixels and the downsampled resolution. The computer device then uses the sum of the image data size of the original texture map and the image data sizes of each level of downsampled texture map to determine the capacity of the memory block to be requested.
[0186] The amount of data for a single pixel value can be determined by the data storage method. For example, when using float32 to store pixel values, this amount of data is 4 bytes.
[0187] Indicative, such as Figure 12As shown, when the maximum image resolution is 16*16 and the pixel block size is 2*2, the capacity of the memory block 1200 requested by the computer device is the sum of the image data of the 16*16 texture map 1201, the 8*8 texture map 1202, the 4*4 texture map 1203, the 2*2 texture map 1204, and the 1*1 texture map 1205.
[0188] Step 1102: Based on the resolution of the original texture map and the downsampled texture map, read and write the original texture map and the downsampled texture map in the memory block.
[0189] Since the resolution of both the original texture map and the downsampled texture map obtained by summing downsampled texture maps at each step is consistent with a certain resolution in the texture map set, the computer device can determine the storage area of the texture map in the memory block that matches the resolution of the original texture map based on the resolution of the original texture map, and thus perform original texture map reading and writing in that storage area; it can also determine the storage area of the texture map in the memory block that matches the resolution of the downsampled texture map based on the resolution of the downsampled texture map, and thus perform downsampled texture map reading and writing in that storage area.
[0190] Optionally, reading and writing texture maps within the allocated memory block may include the following sub-steps:
[0191] Step 1102A: Determine the memory address range of the original texture map and the downsampled texture map in the memory block based on their resolutions.
[0192] In one possible implementation, when requesting a memory block, the computer device determines the memory address range of the texture map at each resolution within the memory block based on the amount of image data of the texture map at each resolution, and establishes a mapping relationship between the resolution and the memory address range.
[0193] To illustrate, after allocating memory block 1200 (address range of add1-add10), the computer determines the memory address range corresponding to the 16*16 texture map 1201 as add1-add2, the memory address range corresponding to the 8*8 texture map 1202 as add3-add4, the memory address range corresponding to the 4*4 texture map 1203 as add5-add6, the memory address range corresponding to the 2*2 texture map 1204 as add7-add8, and the memory address range corresponding to the 1*1 texture map 1205 as add9-add10.
[0194] When reading or writing raw texture maps, the computer device determines the memory address range of the raw texture map from the mapping relationship based on the resolution of the raw texture map; when reading or writing downsampled texture maps, the computer device determines the memory address range of the downsampled texture map from the mapping relationship based on the resolution of the downsampled texture map.
[0195] For example, when the resolution of the original texture image is 8*8, the computer device determines the memory address range as add3-add4 based on the correspondence; when the resolution of the original texture image is 4*4, the computer device determines the memory address range as add5-add6 based on the correspondence.
[0196] Step 1102B: Read and write the original texture map and the downsampled texture map in the memory block based on the memory address range.
[0197] In one possible implementation, the computer device writes the image data of the texture map to the memory space indicated by the memory address range, or reads the image data already written to the texture map from the memory space indicated by the memory address range.
[0198] In one possible application scenario, when texture map generation, texture map expansion, and downsampling summation are performed by the GPU, the CPU can report the requested memory block to the GPU, allowing the GPU to access the memory block.
[0199] In this embodiment, the computer device pre-allocates a memory block in memory based on the maximum image resolution and uses the memory block to read and write texture maps of different resolutions. Compared with dynamically allocating memory each time a texture map is read and written, this can improve the efficiency of texture map reading and writing, thereby improving the calculation efficiency of the peak signal-to-noise ratio of the image.
[0200] In one possible application scenario, the image peak signal-to-noise ratio determination method provided in this application embodiment can be implemented as a script component to support the graphics development process. In an illustrative example, the user interface of this script component is as follows: Figure 13 As shown.
[0201] In this user interface, the first image upload control 1301 and the second image upload control 1302 are used to upload the first image and the second image that need to be calculated for PSNR. The transparency channel check control 1303 is used to determine whether the channel value of the transparency channel needs to be included in the PSNR calculation. The auto run check control 1304 is used to determine whether the PSNR calculation needs to be performed automatically.
[0202] In some embodiments, the script component can perform PSNR calculations driven by other scripts.
[0203] In one example, the PSNR calculation script component performs PSNR calculations driven by an image compression script. The image compression script compresses a first image to obtain a compressed second image. After obtaining the second image, the image compression script drives the PSNR calculation script component to run. The PSNR calculation script component calculates and outputs the PSNR between the first and second images, allowing developers to evaluate the image compression quality based on this PSNR.
[0204] Figure 14 This is a structural block diagram of an image peak signal-to-noise ratio determination apparatus provided in an exemplary embodiment of this application. The apparatus includes:
[0205] The acquisition module 1401 is used to acquire a first image and a second image, wherein the first image and the second image have the same resolution;
[0206] The generation module 1420 is used to generate an original texture map based on the pixel values of the pixels contained in the first image and the second image respectively, wherein the pixel value of each pixel in the original texture map is the square difference of the pixel values at the corresponding pixel positions in the first image and the second image;
[0207] The downsampling module 1430 is further configured to downsample and sum the original texture image in units of pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture image, wherein the pixel block is composed of at least two adjacent pixels;
[0208] The determination module 1440 is used to determine the peak signal-to-noise ratio of the first image and the second image based on the summation result of the squared differences.
[0209] Optionally, the downsampling module 1430 is used for:
[0210] Based on the pixel block size and the resolution of the original texture map, the original texture map is expanded to obtain an expanded texture map, wherein the pixel value of the pixels in the expanded region of the expanded texture map is 0;
[0211] The expanded texture map is downsampled and summed on a pixel-block basis to obtain the sum of the squared differences of the squared differences of each pixel in the original texture map.
[0212] Optionally, when the length of the original texture image is a first length, the width of the original texture image is a first width, the length of the pixel block is a second length, and the width of the pixel block is a second width,
[0213] In the process of expanding the original texture map based on the pixel block size and the resolution of the original texture map to obtain the expanded texture map, the downsampling module 1430 is used to:
[0214] If the first length is not an integer power of the second length, the length of the original texture map is expanded to obtain the expanded texture map, wherein the length of the expanded texture map is an integer power of the second length;
[0215] If the first width is not an integer power of the second width, the width of the original texture map is expanded to obtain the expanded texture map, wherein the width of the expanded texture map is an integer power of the second width.
[0216] Optionally, the length of the expanded texture map is a third length, and the width of the expanded texture map is a third width;
[0217] The third length is the smallest integer power of the second length among lengths greater than the first length;
[0218] The third width is the smallest integer power of the second width among the widths that are greater than the first width.
[0219] Optionally, during the process of expanding the original texture map based on the pixel block size and the resolution of the original texture map to obtain an expanded texture map, the downsampling module 1430 is used to:
[0220] The resolution of the expanded texture map is determined based on the pixel block size and the resolution of the original texture map;
[0221] The expansion ratio is determined based on the resolution of the expanded texture map and the resolution of the original texture map;
[0222] The original texture map is expanded using the GPU's vertex shader according to the expansion ratio to obtain the expanded texture map.
[0223] Optionally, in the process of downsampling and summing the expanded texture map on a pixel-block basis to obtain the sum of the squared differences of the squared differences of each pixel in the original texture map, the downsampling module 1430 is used to:
[0224] The pixel block is sampled from the expanded texture map or the downsampled texture map, wherein the downsampled texture map is a texture map obtained by summing the expanded texture map after at least one level of downsampling.
[0225] The pixel values of the pixels in the pixel block are summed, and the next level downsampled texture map is generated based on the sum of the pixel values;
[0226] Given a lowest-level downsampled texture map, the pixel value of a pixel in the lowest-level downsampled texture map is determined as the sum of the squared differences of the squared differences of each pixel in the original texture map, wherein the lowest-level downsampled texture map contains one pixel.
[0227] Optionally, in the process of summing the pixel values of the pixels in the pixel block and generating the next-level downsampled texture map based on the sum of pixel values, the downsampling module 1430 is used to:
[0228] When the pixel block is sampled from the extended texture map, the pixel values of the pixels in the pixel block are summed, and a first-level downsampled texture map is generated based on the sum of the pixel values;
[0229] When the pixel block is sampled from the i-th level downsampled texture map, the pixel values of the pixels in the pixel block are summed, and an (i+1)-th level downsampled texture map is generated based on the sum of the pixel values, wherein the resolution of the (i+1)-th level downsampled texture map is lower than the resolution of the i-th level downsampled texture map, and i is a positive integer.
[0230] Optionally, during the sampling of the pixel block from the expanded texture map or the downsampled texture map, the downsampling module 1430 is configured to:
[0231] The pixel blocks are sampled from the expanded texture map or the downsampled texture map by calling an aggregation function through the GPU. The aggregation function is a function used to collect pixel values from different regions of the image.
[0232] Optionally, the device further includes:
[0233] The memory allocation module is used to allocate a memory block in memory based on the maximum image resolution. The memory block is used to store a texture atlas, which includes the original texture map and the downsampled texture maps at different resolutions. The maximum image resolution is the resolution of the largest image that supports the calculation of the peak signal-to-noise ratio of the image.
[0234] The read / write module is used to read and write the original texture map and the downsampled texture map in the memory block based on the resolution of the original texture map and the downsampled texture map.
[0235] Optional, a memory allocation module, used for:
[0236] Based on the maximum image resolution and the pixel block size of the pixel block, determine each downsampling resolution obtained by downsampling from the maximum image resolution;
[0237] Based on the maximum image resolution and each of the downsampling resolutions, a memory block is allocated in the memory, and the capacity of the memory block is the sum of the image data volume of the texture images at the maximum image resolution and each of the downsampling resolutions.
[0238] Optional, read / write module, used for:
[0239] Based on the resolution of the original texture map and the downsampled texture map, determine the memory address range of the original texture map and the downsampled texture map in the memory block;
[0240] Based on the memory address range, the original texture map and the downsampled texture map are read and written in the memory block.
[0241] Optionally, module 1420 is used for:
[0242] Input the first image and the second image into the GPU;
[0243] The original texture map is generated by the pixel shader of the GPU based on the pixel values at the corresponding pixel positions in the first image and the second image.
[0244] Optionally, if the sum of squared differences is calculated by the GPU,
[0245] The determination module 1440 is used to read back the summation result of the squared differences from the GPU to the CPU;
[0246] The CPU determines the peak signal-to-noise ratio of the first image and the second image based on the summation of the squared differences.
[0247] In summary, when determining the peak signal-to-noise ratio (PSNR) of two similar images using the apparatus provided in this application, an original texture map is first generated based on the squared difference of pixel values at corresponding pixel positions in the two similar images. Then, the squared differences of pixels in the original texture map are summed according to pixel blocks. Since the variance information between similar images usually exhibits regional clustering, i.e., the variance information within local image regions is relatively close, summing the squared differences on a pixel block basis can reduce the rounding floating-point error of floating-point summation. Furthermore, by performing multiple rounds of downsampling and summation, the final result of the sum of squared differences of each pixel in the original texture map is obtained. Because the rounding floating-point error of the sum of squared differences is reduced, the accuracy of the image PSNR determined based on the sum of squared differences can be improved.
[0248] Please refer to Figure 15 The diagram illustrates a structural schematic of a computer device provided in an exemplary embodiment of this application.
[0249] Computer device 1500 includes a processing unit 1501, a system memory 1504 including random access memory 1502 and read-only memory 1503, and a system bus 1505 connecting the system memory 1504 and the processing unit 1501. Computer device 1500 also includes a basic input / output system (I / O system) 1506 to facilitate information transfer between various devices within the computer, and a mass storage device 1507 for storing the operating system 1513, application programs 1514, and other program modules 1515. The processing unit 1501 may include a CPU and a GPU.
[0250] The basic input / output system 1506 includes a display 1508 for displaying information and an input device 1509 for user input, such as a mouse or keyboard. Both the display 1508 and the input device 1509 are connected to the processing unit 1501 via an input / output controller 1510 connected to the system bus 1505. The basic input / output system 1506 may also include the input / output controller 1510 for receiving and processing input from multiple other devices such as a keyboard, mouse, or electronic stylus. Similarly, the input / output controller 1510 also provides output to a display screen, printer, or other types of output devices.
[0251] The mass storage device 1507 is connected to the processing unit 1501 via a mass storage controller (not shown) connected to the system bus 1505. The mass storage device 1507 and its associated computer-readable media provide non-volatile storage for the computer device 1500. That is, the mass storage device 1507 may include computer-readable media (not shown) such as a hard disk or drive.
[0252] Without loss of generality, the computer-readable medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media include random access memory (RAM), read-only memory (ROM), flash memory or other solid-state storage technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic tape cassettes, magnetic tape, disk storage, or other magnetic storage devices. Of course, those skilled in the art will recognize that the computer storage media are not limited to the above-mentioned types. The system memory 1504 and mass storage device 1507 described above can be collectively referred to as memory.
[0253] The memory stores one or more programs, which are configured to be executed by one or more processing units 1501. The one or more programs contain instructions for implementing the methods described above, and the processing unit 1501 executes the one or more programs to implement the methods provided in the various method embodiments described above.
[0254] According to various embodiments of this application, the computer device 1500 can also be connected to a remote computer on a network, such as the Internet. That is, the computer device 1500 can be connected to the network 1512 via the network interface unit 1511 connected to the system bus 1505, or the network interface unit 1511 can be used to connect to other types of networks or remote computer systems (not shown).
[0255] This application also provides a computer-readable storage medium storing at least one instruction, which is loaded and executed by a processor to implement the image peak signal-to-noise ratio determination method provided in the above embodiments.
[0256] Optionally, the computer-readable storage medium may include ROM, RAM, solid-state drives (SSDs), or optical discs, etc. The RAM may include resistive random access memory (ReRAM) and dynamic random access memory (DRAM).
[0257] This application provides a computer program product including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the image peak signal-to-noise ratio determination method described in the above embodiments.
[0258] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0259] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for determining the peak signal-to-noise ratio of an image, characterized in that, The method includes: Acquire a first image and a second image, wherein the first image and the second image have the same resolution; Based on the pixel values of the pixels contained in the first image and the second image respectively, an original texture map is generated, wherein the pixel value of each pixel in the original texture map is the squared difference of the pixel values at the corresponding pixel positions in the first image and the second image; The original texture image is downsampled and summed in units of pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture image, wherein each pixel block consists of at least two adjacent pixels; The peak signal-to-noise ratio of the first image and the second image is determined based on the summation of the squared differences.
2. The method according to claim 1, characterized in that, The step of downsampling and summing the original texture image on a pixel-block basis to obtain the sum of the squared differences of the squared differences of each pixel in the original texture image includes: Based on the pixel block size and the resolution of the original texture map, the original texture map is expanded to obtain an expanded texture map, wherein the pixel value of the pixels in the expanded region of the expanded texture map is 0; The expanded texture map is downsampled and summed on a pixel-block basis to obtain the sum of the squared differences of the squared differences of each pixel in the original texture map.
3. The method according to claim 2, characterized in that, When the length of the original texture image is a first length, the width of the original texture image is a first width, the length of the pixel block is a second length, and the width of the pixel block is a second width, The process of expanding the original texture map based on the pixel block size and the resolution of the original texture map to obtain an expanded texture map includes at least one of the following: If the first length is not an integer power of the second length, the length of the original texture map is expanded to obtain the expanded texture map, wherein the length of the expanded texture map is an integer power of the second length; If the first width is not an integer power of the second width, the width of the original texture map is expanded to obtain the expanded texture map, wherein the width of the expanded texture map is an integer power of the second width.
4. The method according to claim 3, characterized in that, The length of the expanded texture map is the third length, and the width of the expanded texture map is the third width; The third length is the smallest integer power of the second length among lengths greater than the first length; The third width is the smallest integer power of the second width among the widths that are greater than the first width.
5. The method according to any one of claims 2 to 4, characterized in that, The process of expanding the original texture map based on the pixel block size and the resolution of the original texture map to obtain an expanded texture map includes: The resolution of the expanded texture map is determined based on the pixel block size and the resolution of the original texture map; The expansion ratio is determined based on the resolution of the expanded texture map and the resolution of the original texture map; The original texture map is expanded using the GPU's vertex shader according to the expansion ratio to obtain the expanded texture map.
6. The method according to any one of claims 2 to 5, characterized in that, The step of downsampling and summing the expanded texture map in units of the pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture map includes: The pixel block is sampled from the expanded texture map or the downsampled texture map, wherein the downsampled texture map is a texture map obtained by summing the expanded texture map after at least one level of downsampling. The pixel values of the pixels in the pixel block are summed, and the next level downsampled texture map is generated based on the sum of the pixel values; Given a lowest-level downsampled texture map, the pixel value of a pixel in the lowest-level downsampled texture map is determined as the sum of the squared differences of the squared differences of each pixel in the original texture map, wherein the lowest-level downsampled texture map contains one pixel.
7. The method according to claim 6, characterized in that, The step of summing the pixel values of the pixels in the pixel block and generating the next-level downsampled texture map based on the sum of pixel values includes: When the pixel block is sampled from the extended texture map, the pixel values of the pixels in the pixel block are summed, and a first-level downsampled texture map is generated based on the sum of the pixel values; When the pixel block is sampled from the i-th level downsampled texture map, the pixel values of the pixels in the pixel block are summed, and an (i+1)-th level downsampled texture map is generated based on the sum of the pixel values, wherein the resolution of the (i+1)-th level downsampled texture map is lower than the resolution of the i-th level downsampled texture map, and i is a positive integer.
8. The method according to claim 7, characterized in that, The step of sampling the pixel block from the expanded texture map or the downsampled texture map includes: The pixel blocks are sampled from the expanded texture map or the downsampled texture map by calling an aggregation function through the GPU. The aggregation function is a function used to collect pixel values from different regions of the image.
9. The method according to any one of claims 6 to 8, characterized in that, The method further includes: A memory block is allocated in memory based on the maximum image resolution. The memory block is used to store a texture atlas, which includes the original texture map and downsampled texture maps at different resolutions. The maximum image resolution is the resolution of the largest image that supports the calculation of the peak signal-to-noise ratio of the image. Based on the resolution of the original texture map and the downsampled texture map, the original texture map and the downsampled texture map are read and written in the memory block.
10. The method according to claim 9, characterized in that, The process of allocating a memory block in memory based on the maximum image resolution includes: Based on the maximum image resolution and the pixel block size of the pixel block, determine each downsampling resolution obtained by downsampling from the maximum image resolution; Based on the maximum image resolution and each of the downsampling resolutions, a memory block is allocated in the memory, and the capacity of the memory block is the sum of the image data volume of the texture images at the maximum image resolution and each of the downsampling resolutions.
11. The method according to claim 9, characterized in that, The step of reading and writing the original texture map and the downsampled texture map in the memory block based on the resolution of the original texture map and the downsampled texture map includes: Based on the resolution of the original texture map and the downsampled texture map, determine the memory address range of the original texture map and the downsampled texture map in the memory block; Based on the memory address range, the original texture map and the downsampled texture map are read and written in the memory block.
12. The method according to any one of claims 1 to 11, characterized in that, The step of generating an original texture map based on the pixel values of the pixels contained in the first image and the second image includes: Input the first image and the second image into the GPU; The original texture map is generated by the pixel shader of the GPU based on the pixel values of corresponding pixel positions in the first image and the second image.
13. The method according to any one of claims 1 to 12, characterized in that, When the sum of the squared differences is calculated by the GPU. Determining the peak signal-to-noise ratio (PSNR) of the first image and the second image based on the summation of the squared differences includes: The summation result of the squared differences is read back from the GPU to the CPU; The CPU determines the peak signal-to-noise ratio of the first image and the second image based on the summation of the squared differences.
14. A device for determining the peak signal-to-noise ratio of an image, characterized in that, The device includes: An acquisition module is used to acquire a first image and a second image, wherein the first image and the second image have the same resolution; The generation module is used to generate an original texture map based on the pixel values of the pixels contained in the first image and the second image respectively, wherein the pixel value of each pixel in the original texture map is the squared difference of the pixel values at the same pixel position in the first image and the second image; The downsampling module is also used to downsample and sum the original texture image in units of pixel blocks to obtain the sum of the squared differences of the squared differences of each pixel in the original texture image, wherein the pixel block is composed of at least two adjacent pixels; The determination module is used to determine the peak signal-to-noise ratio of the first image and the second image based on the summation result of the squared differences.
15. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one computer instruction, the at least one computer instruction being loaded and executed by the processor to implement the method for determining the peak signal-to-noise ratio of an image as described in any one of claims 1 to 13.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer instruction, which is loaded and executed by a processor to implement the method for determining the peak signal-to-noise ratio of an image as described in any one of claims 1 to 13.
17. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium, a processor retrieving the computer instructions from the computer-readable storage medium, and the processor executing the computer instructions to implement the method for determining the peak signal-to-noise ratio of an image as described in any one of claims 1 to 13.