Image coding method and device, equipment and storage medium
By merging pixels in the pixel value distribution histogram, a simplified palette table is generated and a graph index is established, which solves the problem of slow encoding speed caused by too many color values in the palette mode and improves the speed and efficiency of image encoding. .
Patent Information
- Application Number
- CN202410834984.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-09-10
AI Technical Summary
In the prior art, when an image is encoded through the palette mode, the palette contains more color values, resulting in a slower encoding speed.
By combining the pixel value distribution histogram of the image to be encoded and merging the pixel points within the preset pixel value interval in the pixel value distribution histogram, a palette table is generated, and a palette map index is established based on the table to reduce the number of color values. to speed up encoding.
By reducing the number of color values in the palette table, the encoding speed and efficiency are improved, the selection of palette modes is simplified, and it is suitable for the transmission and storage of high-quality videos.
Smart Images

Figure CN118632005A
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image encoding method, apparatus, device and storage medium. Background Art
[0002] Video media has been widely used because it can provide richer information. Especially with the development of Internet bandwidth technology, more and more high-quality videos have emerged. However, high-quality videos often require more storage space, so solving the transmission and storage problems of high-quality videos is an urgent challenge facing researchers.
[0003] In the prior art, higher coding efficiency can be achieved through the palette mode, where the palette mode is a way to sparsely represent a video image based on values such as brightness or chrominance and encode it into image blocks. The palette is a table containing color values in a coding unit (CU), and for each pixel in the CU, its index in the table is transmitted in the bitstream, and the decoder uses the index and the palette to reconstruct the CU.
[0004] However, in the prior art, when encoding an image using a palette mode, the palette contains many color values, resulting in a slow encoding speed. Summary of the invention
[0005] The present application provides an image encoding method, apparatus, device and storage medium to solve the defect of slow encoding speed in the prior art, simplify the color values in the palette table, and thus improve the encoding speed.
[0006] The present application provides an image encoding method, comprising: Determining a pixel value distribution histogram based on the pixel value of each pixel in the image to be encoded; Merge the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a color palette table, wherein the number of pixel points represented by the second bar before merging is greater than the number of pixel points represented by the first bar, and the same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value; Based on the palette table, establish a palette map index; The to-be-encoded image is encoded based on the palette map index.
[0007] According to an image encoding method provided by the present application, the pixel points represented by the first block within the preset pixel value spacing in the pixel value distribution histogram are merged into the second block to obtain a palette table, including: Merge the pixel points represented by the first block within the preset pixel value interval in the pixel value distribution histogram into the second block to obtain an initial color palette table; Verifying each merged second block in the initial color palette table to obtain a verification result; When the verification result represents that the difference between the brightness value of the pixel point represented by the target first strip block merged into the second strip block and the brightness value of the pixel point represented by the second strip block before the merger is greater than a preset threshold, the target first strip block is merged into other second strip blocks adjacent to the second strip block before the merger to obtain the palette table.
[0008] According to an image encoding method provided by the present application, encoding the image to be encoded based on the palette map index includes: For a current image block of the encoded image, determining a sum of absolute errors corresponding to a best matching block of the current image block based on the current image block and a reference image block; Determine a target optimal matching block based on the absolute error corresponding to the optimal matching block and the absolute error corresponding to the previous optimal matching block; The current image block of the to-be-encoded image is encoded based on the palette map index and the target best matching block.
[0009] According to an image coding method provided by the present application, determining a target optimal matching block based on the absolute error corresponding to the optimal matching block and the absolute error corresponding to the previous optimal matching block includes: When the absolute error sum corresponding to the best matching block is less than or equal to the absolute error sum corresponding to the previous best matching block, determining the best matching block as the target best matching block; When the sum of absolute errors corresponding to the best matching block is greater than the sum of absolute errors corresponding to the previous best matching block, the previous best matching block is determined as the target best matching block.
[0010] According to an image encoding method provided by the present application, encoding the image to be encoded based on the palette map index includes: In the case where the image to be encoded is an RGB image, determining a rate-distortion optimization (RDO) cost of a current coding unit CU in the image to be encoded; When the rate-distortion optimization RDO cost is greater than a preset cost, performing color space transformation on the current coding unit CU; The current coding unit CU after color space transformation is encoded based on the palette map index.
[0011] According to an image encoding method provided by the present application, encoding the image to be encoded based on the palette map index includes: Determining a motion vector between a current image block and a reference image block in the image to be encoded; Determine a motion vector difference of the current image block based on the motion vector and a predicted motion vector of the current image block; and, if the motion vector difference is greater than a preset motion vector, encode the current image block based on a first sampling resolution and the palette map index; When the motion vector difference is less than or equal to the preset motion vector, the current image block is encoded based on a second sampling resolution and the palette map index; the second sampling resolution is greater than the first sampling resolution.
[0012] The present application also provides an image encoding device, comprising: A determination module, used to determine a pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded; a merging module, configured to merge the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a color palette table, wherein before the merging, the number of pixel points represented by the second bar is greater than the number of pixel points represented by the first bar, and the same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value; An establishing module, used for establishing a palette map index based on the palette table; An encoding module is used to encode the image to be encoded based on the palette map index.
[0013] The present application also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the image encoding method described above is implemented.
[0014] The present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the image encoding method described in any one of the above is implemented.
[0015] The present application also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the image encoding method described above is implemented.
[0016] The image encoding method, device, equipment and storage medium provided by the present application determine the pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded, merge the pixel points represented by the first bar block within the preset pixel value spacing in the pixel value distribution histogram into the second bar block, and obtain a palette table, wherein the number of pixel points represented by the second bar block before merging is greater than the number of pixel points represented by the first bar block, and the number of pixel points with the same pixel value represented by the same bar block in the pixel value distribution histogram is established based on the palette table, and the image to be encoded is encoded based on the palette map index. Since the pixel points with a small number of pixel values in the pixel value distribution histogram can be merged into the pixel points with a large number of pixel values within the preset pixel value spacing, the number of color values in the palette table can be reduced. When encoding the image to be encoded based on the palette table, the encoding purpose can be achieved by traversing a small number of color values, which speeds up the selection of the palette mode and improves the speed and efficiency of encoding. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 A flowchart of an image encoding method provided in an embodiment of the present application.
[0019] Figure 2 A schematic diagram of a palette table provided in an embodiment of the present application.
[0020] Figure 3 A system architecture diagram of the image encoding method provided in an embodiment of the present application.
[0021] Figure 4 A schematic diagram of the structure of an image encoding device provided in an embodiment of the present application.
[0022] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0024] Currently, a palette mode can be used to achieve higher coding efficiency. A palette is a table containing color values in a CU. When an image is complex, the palette usually contains more color values. When encoding an image using the palette mode, the encoding speed will be slower.
[0025] In response to the above problems, in an embodiment of the present application, considering that for some images, especially screenshots or screen recording images, there is no noise in the image, the tones are relatively discrete, and the number of color values contained is small, therefore, the color values in the palette table can be merged to obtain a palette table with a small number of color values. When encoding through the palette table with a small number of color values, the speed and efficiency of image encoding can be improved.
[0026] Combine the following Figures 1 to 3 The image encoding method provided by the embodiment of the present application is described. The embodiment of the present application can be applicable to image encoding in any scenario, and is particularly applicable to the scenario of image encoding of screen content. The execution subject of the method can be an electronic device such as a terminal device, a computer, a server, a server cluster, or a specially designed image encoding device, or an image encoding device set in the electronic device, and the image encoding device can be implemented by software, hardware, or a combination of the two.
[0027] Figure 1 A schematic diagram of a flow chart of an image encoding method provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, the method comprises: Step 101: determining a pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded.
[0028] Specifically, the image to be encoded may include an image captured by an image acquisition device, or may include an image obtained by taking a screenshot or recording the screen content.
[0029] By traversing the pixel value of each pixel in the image to be encoded, it is possible to count how many pixels have the same pixel value and represent it using a pixel value distribution histogram, wherein the pixel value distribution histogram includes multiple bars, each of which represents the number of pixels with the same pixel value.
[0030] Step 102: In the pixel value distribution histogram, the pixel points represented by the first block within the preset pixel value spacing are merged into the second block to obtain a palette table, wherein before the merger, the number of pixel points represented by the second block is greater than the number of pixel points represented by the first block, and the same block in the pixel value distribution histogram represents the number of pixel points with the same pixel value.
[0031] Specifically, the preset pixel value spacing can be set according to actual conditions or experience, for example, it can be set to 2 or 3. The same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value. By traversing the bars in the pixel value distribution histogram, the number of pixel points corresponding to each pixel value can be determined, and the first bar representing a smaller number of pixel points within the preset pixel spacing and the second bar representing a larger number of pixel points are merged, thereby reducing the pixel values in the palette table, that is, reducing the color values in the palette table, and obtaining a palette table with optimized color quantity. It should be understood that after the above-mentioned merging operation, the palette table contains pixel points corresponding to the pixel values with a larger number of pixel values distributed in the histogram.
[0032] In addition, when the number of bars in the obtained color palette table reaches a preset upper limit and the bars in the histogram have not been completely traversed, the pixel points with a smaller number of distribution in the histogram can be deleted from the color palette table.
[0033] Figure 2 A schematic diagram of a color palette table provided in an embodiment of the present application, such as Figure 2 As shown, assuming that the preset pixel spacing is 3, the number of pixels with a pixel value of 0 and the number of pixels with a pixel value of 2 are both less than the number of pixels with a pixel value of 1. Therefore, the pixels with a pixel value of 0 and the pixel value of 2 can be merged into the pixel value of 1. In this way, during subsequent encoding, there will be no pixel values 0 and 2 in the palette table, and the original pixel values 0 and 2 will all be encoded according to the pixel value of 1. Figure 2 The merging of other pixels in is similar and will not be described here.
[0034] Step 103: Create a palette map index based on the palette table.
[0035] In this step, in order to further remove redundant information in the palette table, remove uncommon color information and repeated information in the palette table, the color information in the palette table can be mapped to specific pixels, so that the color can be correctly restored when the image is displayed, that is, it is necessary to construct a palette map index based on the palette table. The palette map index can be used to conveniently search and reference the color information in the palette table.
[0036] Step 104: Encode the image to be encoded based on the palette map index.
[0037] In this step, after the palette map index is constructed, the palette map index can be used to compress the color information in the image to be encoded.
[0038] In the process of encoding and compression, the rate-distortion optimization (Rate-DistortionOptimization) technology can be introduced to improve the encoding efficiency. The RDO cost function can be expressed as shown in the following formula (1):
[0039] Where Di and Ri represent the distortion and bit rate of the coding unit respectively, M represents the total number of coding units, oi represents the coding mode, and Rt represents the target number of bits.
[0040] RDO considers both bit rate and distortion constraints when calculating the cost function, ensuring low bit rate while ensuring low distortion, which is more conducive to the transmission of video streams. By introducing the Lagrange multiplier method, the constrained rate-distortion optimization problem in the above formula is transformed into an unconstrained form, as shown in the following formula (2): min{J=D+λR} (2)
[0041] Wherein, λ represents the Lagrangian coefficient, D represents the sum of the mean square errors between the reconstructed block and the image to be encoded. In this embodiment, the sum of absolute differences (SAD) is used instead of the sum of the mean square errors, and the above formula (2) can finally be expressed as formula (3): min{J=SAD+λR} (3)
[0042] In the specific implementation process, RDO actually encodes each mode once to obtain J, and then selects the mode with the smallest J as the actual coding mode. A better J can achieve the best coding efficiency.
[0043] The image encoding method provided by the embodiment of the present application determines a pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded, merges the pixel points represented by the first bar block within the preset pixel value spacing in the pixel value distribution histogram into the second bar block, and obtains a palette table, wherein the number of pixel points represented by the second bar block before merging is greater than the number of pixel points represented by the first bar block, and the number of pixel points with the same pixel value represented by the same bar block in the pixel value distribution histogram is established based on the palette table, and the image to be encoded is encoded based on the palette map index. Since the pixel points with a small number of pixel values in the pixel value distribution histogram can be merged into the pixel points with a large number of pixel values within the preset pixel value spacing, the number of color values in the palette table can be reduced. When encoding the image to be encoded based on the palette table, the encoding purpose can be achieved by traversing a small number of color values, which speeds up the selection of the palette mode and improves the speed and efficiency of encoding.
[0044] After simplifying the palette table, the video is encoded through the color coding of the palette mode, and different palette tables are generated for video information of different complexity. Due to the sparsity of color information, even for relatively complex videos, the sparsely constructed palette table can be simplified to improve the encoding speed.
[0045] In addition, when the number of pixel values in the pixel value distribution histogram is evenly distributed, that is, when there are multiple color types, the palette selection can be exited in advance, thereby speeding up the palette mode selection process.
[0046] Exemplarily, on the basis of the above-mentioned embodiments, when merging the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a color palette table, the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram can be merged into the second bar to obtain an initial color palette table, and each merged second bar in the initial color palette table is verified to obtain a verification result. When the verification result indicates that the difference between the brightness value of the pixel point represented by the target first bar merged into the second bar and the brightness value of the pixel point represented by the second bar before the merger is greater than a preset threshold, the target first bar is merged into other second bars adjacent to the second bar before the merger to obtain a color palette table.
[0047] Specifically, after traversing each bar in the pixel value distribution histogram, the first bar where the number of pixels with the same pixel value is small is merged into the second bar to obtain the initial palette table. In practical applications, after merging in the above manner, some unreasonable color combinations may occur. For example, for a first bar, it may be in two adjacent preset pixel value intervals at the same time. After merging the first bar with the second bar in the first preset pixel value interval, the brightness of the pixel represented by the first bar and the brightness of the pixel represented by the second bar are quite different. At this time, if the color value of the pixel represented by the first bar is encoded according to the color value of the pixel represented by the second bar, the encoding effect will be reduced. To address this problem, in this embodiment, the brightness component of the image to be encoded can be processed to verify each merged second bar in the initial palette table to obtain a verification result. If the difference between the brightness value of the pixel represented by the first target strip merged into the second strip in the verification result and the brightness value of the pixel represented by the second strip before the merge is greater than a preset threshold, it means that the difference between the color of the pixel represented by the first target strip and the color of the pixel represented by the second strip is too large, and the color of the pixel represented by the second strip cannot be used to encode the color of the pixel represented by the first target strip. Therefore, it is necessary to correct the merge result of the first target strip, that is, to re-merge the pixel corresponding to the first target strip into other second strips adjacent to the second strip before the merge, to obtain a palette table. For example, Figure 2 As shown, if the pixel value of the pixel represented by the second block before the merge is 4, and the pixel value of the pixel represented by the first block is 5, if the initial palette table is to merge the pixel represented by the first block into the second block, when it is found during the verification that the difference between the brightness value of the pixel represented by the first block and the brightness value of the pixel represented by the second block is greater than the preset threshold, the pixel represented by the first block will be merged into the second block corresponding to the pixel with a pixel value of 6.
[0048] In addition, after correcting each color combination in the initial palette table, the size of the image block can be determined by processing the UV component of the image based on these color combinations, thereby better controlling the range and accuracy of image processing and reducing unnecessary computing costs.
[0049] In this embodiment, each merged second strip in the initial color palette table can be checked. When the obtained check result indicates that the difference between the brightness value of the pixel represented by the target first strip merged into the second strip and the brightness value of the pixel represented by the second strip before the merger is greater than a preset threshold, the target first strip can be merged into other second strips adjacent to the second strip before the merger, that is, the target first strip is re-merged, so that the color combination in the final color palette table is more reasonable, thereby improving the accuracy of the color palette table.
[0050] Exemplarily, based on the above embodiments, when encoding an image to be encoded based on a palette map index, the absolute error sum corresponding to the best matching block of the current image block can be determined for the current image block of the encoded image based on the current image block and the reference image block, and the target best matching block can be determined based on the absolute error sum corresponding to the best matching block and the absolute error sum corresponding to the previous best matching block, and the current image block of the image to be encoded is encoded based on the palette map index and the target best matching block.
[0051] Specifically, in the AV1 encoder, Intra Block Copy (IntraBC) is an extended tool for encoding screen content sequences, which can significantly improve the coding efficiency of the image sequence to be encoded. When predicting the current block, it first searches for the reconstructed image part of the image to be encoded, and then searches for a better prediction result through the intra-frame copy mode, which greatly improves the efficiency of video compression.
[0052] In IntraBC, the diamond search algorithm is used to search for prediction blocks. In the prior art, if the point with the smallest error is found in the four corners of a diamond centered on the current station, it is taken as the best matching block. However, the current best matching block in the prior art is not compared with the previous best matching block. Directly taking it as the best matching block may result in quality loss due to not being the global best matching block.
[0053] In view of the above problem, in an embodiment of the present application, for a current image block of an image to be encoded, the best matching block of the current image block can be determined by a search algorithm, and based on the current image block and the reference image block, the absolute error sum corresponding to the best matching block of the current image block can be determined. Specifically, the absolute error sum corresponding to the best matching block of the current image block can be determined by the following method (4):
[0054] Among them, u, v represent the pixel position in the image to be encoded, (m, n) represents the displacement between the reference block and the current image block, S represents the current image block, T represents the reference block, M represents the number of pixels in the reference block, N represents the number of pixels in the current image block, SAD(u, v) represents the sum of absolute differences. SAD is an indicator to measure the similarity between two image blocks and is used to search for the best matching block in a frame. It evaluates the similarity between different blocks by calculating the SAD of each 8-bit block to find the best matching block.
[0055] After the absolute error corresponding to the current best matching block is determined, a target best matching block is determined based on the absolute error corresponding to the current best matching block and the absolute error corresponding to the best matching block determined last time.
[0056] Exemplarily, when the sum of absolute errors corresponding to the best matching block is less than or equal to the sum of absolute errors corresponding to the previous best matching block, the best matching block is determined as the target best matching block; when the sum of absolute errors corresponding to the best matching block is greater than the sum of absolute errors corresponding to the previous best matching block, the previous best matching block is determined as the target best matching block.
[0057] Specifically, the target optimal matching block can be determined based on formula (5): D(u,v)=T u,v (SAD cur (u,v), SAD las (u,v)) (5)
[0058] Where D(u, v) represents the target optimal matching block, SAD represents the sum of absolute differences, and T judgment processing calculation is shown in formula (6):
[0059] Among them, SAD cur (u, v) represents the absolute error and SAD corresponding to the current optimal matching block las (u, v) represents the absolute error sum corresponding to the previous best matching block.
[0060] In this embodiment, by calculating the absolute error sum corresponding to the current best matching block and the absolute error sum corresponding to the previous best matching block, the best matching block with the smallest absolute error sum is used as the target best matching block. Since the absolute error sum SAD is an indicator to measure the similarity between two image blocks, the smaller the absolute error sum is, the greater the similarity is, so the target best matching block determined based on the above method has a higher accuracy.
[0061] Furthermore, after the target best matching block is determined, the current image block of the image to be encoded may be encoded based on the palette map index and the target best matching block.
[0062] In IntraBC, two best candidate MVs can be selected from the motion vector (MV) candidate list as the initial MVs for subsequent motion search, and the best matching motion vector of the target optimal matching block can be searched based on the above method, which can reduce the amount of video data and improve compression efficiency. In order to speed up the search speed and improve the matching accuracy, a reference prediction block is set for IntraBC, which is a block adjacent to the target block in the current frame. Similarly, in video coding, the prediction plane is a plane model used to predict image blocks. By setting the prediction plane, the shape and texture of the image block can be better fitted, thereby reducing the amount of encoded data and improving compression efficiency. In addition, by controlling the search range of the motion vector, the speed and accuracy of the search can be controlled to find the best matching motion vector.
[0063] In this embodiment, after determining the optimal matching block of the current image block, the optimal matching block of the current image block is not directly used as the final optimal matching block, but the target optimal matching block is determined based on the absolute error of the optimal matching block of the current image block and the absolute error with the previous optimal matching block, and the current image block is encoded based on the determined target optimal matching block. Since there may be many repeated textures in the same frame for screen content such as text and graphics, which have strong spatial correlation, through the above method, when encoding the current image block, the encoded blocks in the image to be encoded can be referred to for encoding, thereby greatly improving the encoding efficiency and quality. In addition, in the above search calculation process, in order to speed up the search speed, SIMP technology is used to accelerate the search speed.
[0064] Exemplarily, on the basis of the above embodiments, encoding the image to be encoded based on the palette map index includes: when the image to be encoded is an RGB image, determining the rate-distortion optimization RDO cost of the current coding unit CU in the image to be encoded; when the rate-distortion optimization RDO cost is greater than a preset cost, performing a color space transformation on the current coding unit CU; and encoding the current coding unit CU after the color space transformation based on the palette map index.
[0065] Specifically, since most screen content uses the RGB color space, and for RGB blocks, there may be strong correlations between different channels, color space conversion can be used to remove redundant information between different color channels. In this way, when the correlation between RGB blocks in different channels is weak, they can be encoded directly in the RGB space, which can greatly improve the encoding efficiency. In other words, blocks in the RGB space can be directly encoded or converted to the YCbCr space and then encoded.
[0066] When the image to be encoded is an RGB image, the RDO cost of the current CU in the image to be encoded can be determined. When the RDO cost is greater than the preset cost, the current CU needs to be transformed in color space, such as from RGB space to YCbCr space, so that the current CU after the color space transformation can be encoded.
[0067] When the RDO cost is less than or equal to the preset cost, the color space transformation will not be performed on the current CU, and the current CU can be directly encoded.
[0068] In this embodiment, when the image to be encoded is an RGB image and the RDO cost of the current CU in the image to be encoded is greater than a preset cost, an adaptive color transform (Adaptive Color Transform, ACT) is performed on the current CU, the residual signal between the current block and the prediction block is mapped to another color space, and the encoder encodes the transformed current CU in the color space, thereby simplifying the encoding information and improving the encoding speed.
[0069] Exemplarily, based on the above embodiments, when encoding an image to be encoded based on a palette map index, a motion vector between a current image block and a reference image block in the image to be encoded can be determined; based on the motion vector and a predicted motion vector of the current image block, a motion vector difference of the current image block can be determined; when the motion vector difference is greater than a preset motion vector, the current image block is encoded based on a first sampling resolution and a palette map index; when the motion vector difference is less than or equal to a preset motion vector, the current image block is encoded based on a second sampling resolution and a palette map index; the second sampling resolution is greater than the first sampling resolution.
[0070] Specifically, for the motion vector difference (MVD) of the coding block, different sampling resolutions can be used for encoding according to different image blocks, that is, adaptive motion vector resolution (AMVR) is used for encoding. AMVR is an adaptive coding technology based on different sampling resolutions of image blocks or coding units CU.
[0071] The motion vector difference between the motion vector between the current image block and the reference image block and the predicted motion vector of the current image block can be determined based on the following formula (7): MVD=MV opt -MVP (7)
[0072] Among them, MVD represents motion vector difference, MV optIt represents the motion vector between the current image block and the reference image block, and MVP represents the predicted motion vector of the current image block.
[0073] When the MVD is greater than the preset motion vector, the current image block will be encoded based on a lower first sampling resolution and palette index. When the MVD is less than or equal to the preset motion vector, the current image block will be encoded based on a higher second sampling resolution and palette index, wherein the second sampling resolution is greater than the first sampling resolution.
[0074] In this embodiment, the sampling resolution can be adaptively determined based on the motion vector difference of the current image block. When the motion vector difference is greater than the preset motion vector, a lower first sampling resolution is selected. When the motion vector difference is less than or equal to the preset motion vector, a higher second sampling resolution is selected to encode the current image block, thereby avoiding encoding distortion, improving encoding quality, and improving encoding efficiency. In addition, by adaptively adjusting and optimizing the resolution of the motion vector, the bit rate and storage space of the video can be reduced.
[0075] Figure 3 The system architecture diagram of the image encoding method provided in the embodiment of the present application is as follows: Figure 3 As shown, the image processing system includes an image input module, a screen content coding (Screen Content Coding, SCC) processing module and an output buffer, wherein the image input module is used to receive input video data, parse the video data, and send the parsed image to the SCC processing module. The video data may be data obtained by taking a screenshot or recording the screen content.
[0076] The SCC processing module includes an intra-frame block copy unit, a palette mode determination unit, an adaptive color conversion unit and an adaptive motion vector precision determination unit. The intra-frame block copy unit is used to determine the target optimal matching block, the palette mode determination unit is used to optimize the structure of the palette table and establish a palette map index, the adaptive color conversion unit is used to determine whether it is necessary to perform color space conversion on the image to be encoded, and the adaptive motion vector precision determination unit is used to determine different encoding precisions for different image blocks. After one or more of the above-mentioned processes, the image to be processed is encoded to achieve the desired image effect and meet different image processing requirements.
[0077] The image data processed by the SCC processing module will be stored in an output buffer, and the image data will be output, for example, saved to a storage device or sent to other devices through a network.
[0078] The image encoding device provided by the present application is described below. The image encoding device described below and the image encoding method described above can be referenced to each other.
[0079] Figure 4 A schematic diagram of the structure of an image encoding device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the image encoding device 400 includes: A determination module 11, configured to determine a pixel value distribution histogram based on the pixel value of each pixel in the image to be encoded; A merging module 12 is used to merge the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a color palette table, wherein before the merging, the number of pixel points represented by the second bar is greater than the number of pixel points represented by the first bar, and the same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value; An establishing module 13, used for establishing a palette map index based on the palette table; The encoding module 14 is used to encode the image to be encoded based on the palette map index.
[0080] In one implementation, the merging module 12 is specifically configured to: Merge the pixel points represented by the first block within the preset pixel value interval in the pixel value distribution histogram into the second block to obtain an initial color palette table; Verifying each merged second block in the initial color palette table to obtain a verification result; When the verification result represents that the difference between the brightness value of the pixel point represented by the target first strip block merged into the second strip block and the brightness value of the pixel point represented by the second strip block before the merger is greater than a preset threshold, the target first strip block is merged into other second strip blocks adjacent to the second strip block before the merger to obtain the palette table.
[0081] In one implementation, the encoding module 14 is specifically configured to: For a current image block of the encoded image, determining a sum of absolute errors corresponding to a best matching block of the current image block based on the current image block and a reference image block; Determine a target optimal matching block based on the absolute error corresponding to the optimal matching block and the absolute error corresponding to the previous optimal matching block; The current image block of the to-be-encoded image is encoded based on the palette map index and the target best matching block.
[0082] In one implementation, the determination module 11 is specifically configured to: When the absolute error sum corresponding to the best matching block is less than or equal to the absolute error sum corresponding to the previous best matching block, determining the best matching block as the target best matching block; When the sum of absolute errors corresponding to the best matching block is greater than the sum of absolute errors corresponding to the previous best matching block, the previous best matching block is determined as the target best matching block.
[0083] In one implementation, the encoding module 14 is specifically configured to: In the case where the image to be encoded is an RGB image, determining a rate-distortion optimization (RDO) cost of a current coding unit CU in the image to be encoded; When the rate-distortion optimization RDO cost is greater than a preset cost, performing color space transformation on the current coding unit CU; The current coding unit CU after color space transformation is encoded based on the palette map index.
[0084] In one implementation, the encoding module 14 is specifically configured to: Determining a motion vector between a current image block and a reference image block in the image to be encoded; Determine a motion vector difference of the current image block based on the motion vector and a predicted motion vector of the current image block; and, if the motion vector difference is greater than a preset motion vector, encode the current image block based on a first sampling resolution and the palette map index; When the motion vector difference is less than or equal to the preset motion vector, the current image block is encoded based on a second sampling resolution and the palette map index; the second sampling resolution is greater than the first sampling resolution.
[0085] The image encoding device of this embodiment can be used to execute the method of any embodiment in the image encoding method side embodiment. Its specific implementation process and technical effects are similar to those in the image encoding method side embodiment. For details, please refer to the detailed description in the image encoding method side embodiment, which will not be repeated here.
[0086] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 5As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute the image encoding method, which includes: determining a pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded; merging the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a palette table, wherein before the merging, the number of pixel points represented by the second bar is greater than the number of pixel points represented by the first bar, and the same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value; establishing a palette map index based on the palette table; encoding the image to be encoded based on the palette map index.
[0087] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0088] On the other hand, the present application also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the image encoding method provided by the above-mentioned methods, which includes: determining a pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded; merging the pixel points represented by the first block within a preset pixel value spacing in the pixel value distribution histogram into the second block to obtain a palette table, wherein before the merging, the number of pixel points represented by the second block is greater than the number of pixel points represented by the first block, and the same block in the pixel value distribution histogram represents the number of pixel points with the same pixel value; based on the palette table, establishing a palette map index; encoding the image to be encoded based on the palette map index.
[0089] On the other hand, the present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the image encoding method provided by the above-mentioned methods, the method comprising: determining a pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded; merging the pixel points represented by the first bar within a preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a palette table, wherein before the merging, the number of pixel points represented by the second bar is greater than the number of pixel points represented by the first bar, and the same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value; establishing a palette map index based on the palette table; and encoding the image to be encoded based on the palette map index.
[0090] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0091] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0092] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for encoding an image, It is characterized in that include: Determining a pixel value distribution histogram based on the pixel value of each pixel in the image to be encoded; Merge the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a color palette table, wherein the number of pixel points represented by the second bar before merging is greater than the number of pixel points represented by the first bar, and the same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value; Based on the palette table, establish a palette map index; The to-be-encoded image is encoded based on the palette map index.
2. The image encoding method according to claim 1, It is characterized in that The step of merging the pixel points represented by the first bar within the preset pixel value interval in the pixel value distribution histogram into the second bar to obtain a color palette table includes: Merge the pixel points represented by the first block within the preset pixel value interval in the pixel value distribution histogram into the second block to obtain an initial color palette table; Verifying each merged second block in the initial color palette table to obtain a verification result; When the verification result represents that the difference between the brightness value of the pixel point represented by the target first strip block merged into the second strip block and the brightness value of the pixel point represented by the second strip block before the merger is greater than a preset threshold, the target first strip block is merged into other second strip blocks adjacent to the second strip block before the merger to obtain the palette table.
3. The image encoding method according to claim 1, It is characterized in that The encoding of the to-be-encoded image based on the palette map index comprises: For a current image block of the encoded image, determining a sum of absolute errors corresponding to a best matching block of the current image block based on the current image block and a reference image block; Determine a target optimal matching block based on the absolute error corresponding to the optimal matching block and the absolute error corresponding to the previous optimal matching block; The current image block of the to-be-encoded image is encoded based on the palette map index and the target best matching block.
4. The image encoding method according to claim 3, It is characterized in that The determining of a target optimal matching block based on the absolute error corresponding to the optimal matching block and the absolute error corresponding to the previous optimal matching block includes: When the absolute error sum corresponding to the best matching block is less than or equal to the absolute error sum corresponding to the previous best matching block, determining the best matching block as the target best matching block; When the sum of absolute errors corresponding to the best matching block is greater than the sum of absolute errors corresponding to the previous best matching block, the previous best matching block is determined as the target best matching block.
5. The image encoding method according to any one of claims 1 to 4, It is characterized in that The encoding of the to-be-encoded image based on the palette map index comprises: In the case where the image to be encoded is an RGB image, determining a rate-distortion optimization (RDO) cost of a current coding unit CU in the image to be encoded; When the rate-distortion optimization RDO cost is greater than a preset cost, performing color space transformation on the current coding unit CU; The current coding unit CU after color space transformation is encoded based on the palette map index.
6. The image encoding method according to any one of claims 1 to 4, It is characterized in that The encoding of the to-be-encoded image based on the palette map index comprises: Determining a motion vector between a current image block and a reference image block in the image to be encoded; Determine a motion vector difference of the current image block based on the motion vector and a predicted motion vector of the current image block; and, if the motion vector difference is greater than a preset motion vector, encode the current image block based on a first sampling resolution and the palette map index; When the motion vector difference is less than or equal to the preset motion vector, the current image block is encoded based on a second sampling resolution and the palette map index; the second sampling resolution is greater than the first sampling resolution.
7. An image encoding device, It is characterized in that include: A determination module, used to determine a pixel value distribution histogram based on the pixel value of each pixel point in the image to be encoded; a merging module, configured to merge the pixel points represented by the first bar within the preset pixel value spacing in the pixel value distribution histogram into the second bar to obtain a color palette table, wherein before the merging, the number of pixel points represented by the second bar is greater than the number of pixel points represented by the first bar, and the same bar in the pixel value distribution histogram represents the number of pixel points with the same pixel value; An establishing module, used for establishing a palette map index based on the palette table; An encoding module is used to encode the image to be encoded based on the palette map index.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the image encoding method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the image encoding method according to any one of claims 1 to 6 is implemented.
10. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the image encoding method according to any one of claims 1 to 6 is implemented.
