Image encoding and decoding method and device
By identifying and processing the color gradient area in image encoding, using a unified encoding method and performing boundary filtering processing, the problem of boundary color jump of adjacent macroblocks after image decoding in the prior art is solved, and the user experience is improved.
Patent Information
- Application Number
- CN202011591252.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-29
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2040-12-29
AI Technical Summary
In the prior art, when encoding images, adjacent macroblocks in the color gradient area are different, resulting in visual mosaic style boundaries after decoding, which makes the user experience poor.
By dividing the image into macroblocks and determining the color gradient area, the macroblocks in the color gradient area are encoded using a unified encoding method to ensure that the boundaries of adjacent macroblocks are filtered after decoding to eliminate color jumps.
Effectively avoid color jumps in adjacent macroblock boundaries after decoding, improve the gradient effect of the image and improve the user experience.
Smart Images

Figure CN112738523B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and more particularly to an image encoding and decoding method and device. Background Art
[0002] At present, the encoding of images usually involves classifying the macroblocks of the image into text macroblocks and picture macroblocks, and different types of macroblocks are encoded using different encoding methods. However, if different types of macroblocks are encoded using different encoding methods, if the types of macroblocks in two adjacent parts of a color gradient area are different, the encoding methods adopted are different, then the boundaries of the macroblocks of the two adjacent parts will be visually deficient after decoding and reconstruction, and the macroblocks of the two adjacent parts that should be displayed gradually will appear as a mosaic-style boundary, so that users can perceive the discontinuity between the colors of the macroblocks of the two adjacent parts, resulting in a poor user experience.
[0003] For example Figure 1 As shown, Figure 1 is a color gradient area in the image to be encoded, where the dotted line indicates the pixel values of the four macroblocks in the color gradient area, and the size of each macroblock is 16*16 pixels. If the existing technology is used to encode the image to be encoded, the image will be decoded at the decoding end. Figure 2 shown. Figure 2 The dotted line in the figure indicates the color jump. The color of the upper left corner macroblock (marked as 1) is different from the other three macroblocks, and there is a color jump. Figure 2 As shown in the figure, there is a color ladder-like change band in the lower left and upper right blocks of the color gradient area, that is, the color gradient area has a color jump after decoding. And this color ladder-like change band should be displayed as a gradient color. The pixels of the four macroblocks in this area after decoding are the parts marked with dotted lines, such as the parts circled by ellipses. The reason why there is a color jump at the junction of macroblock 1 and macroblocks 2 and 3 is that although macroblock 1 is adjacent to macroblocks 2 and 3, there is a relatively obvious jump in the pixel value. Summary of the invention
[0004] The disclosed embodiment provides an image encoding and decoding method and device, which can solve the problem that the existing technology causes two adjacent macroblocks that should be displayed gradually to appear as having a mosaic-style boundary after decoding, so that the user can perceive the discontinuity between the colors of the two adjacent macroblocks, resulting in a poor user experience. The technical solution is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, there is provided an image encoding method, the method comprising:
[0006] Divide the current frame image into macroblocks to generate N macroblocks, where N is an integer greater than 1;
[0007] Determine a color gradient macroblock from the N macroblocks and determine a color gradient region according to the color gradient macroblock, wherein the color gradient region includes at least two adjacent color gradient macroblocks;
[0008] Encoding the color gradient area according to a first encoding method to generate a code stream of the color gradient area;
[0009] Encoding the text macroblocks except the color gradient area according to the second encoding method and encoding the picture macroblocks except the color gradient area according to the third encoding method, and generating a code stream of the text macroblock and a code stream of the picture macroblock respectively;
[0010] The code stream of the current frame image is generated according to the code stream of the color gradient area, the code stream of the text macroblock and the code stream of the picture macroblock, and the code stream of the current frame image is sent to a decoding end.
[0011] The image encoding method provided by the embodiment of the present disclosure can divide the current frame image into macroblocks to generate N macroblocks; determine a color gradient macroblock from the N macroblocks and determine a color gradient area according to the color gradient macroblock, wherein the color gradient area includes at least two adjacent color gradient macroblocks; encode the color gradient area according to a first encoding method to generate a code stream of the color gradient area; encode the text macroblocks except the color gradient area according to a second encoding method and encode the picture macroblocks except the color gradient area according to a third encoding method to respectively generate a code stream of the text macroblock and a code stream of the picture macroblock; encode the text macroblocks except the color gradient area according to the second encoding method Encoding is performed and the picture macros except the color gradient area are encoded according to the third encoding method, and the code streams of the text macroblocks and the picture macroblocks are generated respectively. Regardless of the type of macroblocks in the color gradient area, the first encoding method is used for encoding. This can avoid the situation where the types of macroblocks in two adjacent parts of a color gradient area are different, and the encoding methods adopted are different. In this case, the boundaries of the macroblocks in the two adjacent parts will have visual deficiencies after decoding and reconstruction. The macroblocks of the two adjacent parts that should be displayed gradually appear as boundaries with a mosaic style, so that the user can perceive the discontinuity between the colors of the macroblocks in the two adjacent parts, resulting in a poor user experience, thereby improving the user experience.
[0012] In one embodiment, determining a color gradient macroblock from the N macroblocks includes:
[0013] Calculate a pixel difference between a target macroblock and a first macroblock, where the first macroblock is a macroblock adjacent to the left or right of the target macroblock, and the target macroblock is any one of the N macroblocks;
[0014] If the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than a preset threshold, then calculating the pixel difference between the target macroblock and a second macroblock, where the second macroblock is a macroblock adjacent to the upper side or the lower side of the target macroblock;
[0015] If the pixel difference between the target macroblock and the second macroblock is greater than 0 and less than a preset threshold, the target macroblock is a color gradient macroblock.
[0016] In one embodiment, calculating the pixel difference between the target macroblock and the first macroblock includes:
[0017] The difference between the last column of pixels of the target macroblock and the first column of pixels of the first macroblock is used as the pixel difference between the target macroblock and the first macroblock, or the difference between the last column of pixels of the first macroblock and the first column of pixels of the target macroblock is used as the pixel difference between the target macroblock and the first macroblock.
[0018] In one embodiment, determining the color gradient area according to the color gradient macroblock comprises:
[0019] A rectangular macroblock area composed of at least two adjacent color gradient macroblocks is used as a color gradient area and / or a rectangular macroblock area composed of at least two adjacent color gradient macroblocks and a row and / or a column of non-color gradient macroblocks is used as a color gradient area.
[0020] According to a second aspect of an embodiment of the present disclosure, there is provided an image decoding method, the method comprising:
[0021] Receive a code stream of a current frame image sent by an encoding end and determine a code stream of a text macroblock, a code stream of a picture macroblock, and a code stream of a color gradient area from the code stream of the current frame image;
[0022] Decoding the code stream of the color gradient area according to the first decoding method to generate a color gradient area, wherein the color gradient area includes at least 2 macroblocks;
[0023] Determining the boundary between every two adjacent macroblocks in the color gradient region and filtering the boundary to generate a filtered color gradient region;
[0024] Decoding the code stream of the text macroblock according to the second decoding method and decoding the code stream of the picture macroblock according to the third decoding method to generate a text macroblock and a picture macroblock respectively;
[0025] The current frame image is generated according to the filtered color gradient area, the text macroblock and the picture macroblock.
[0026] The image decoding method provided by the embodiment of the present disclosure can receive the code stream of the current frame image sent by the encoding end and determine the code stream of the text macroblock, the code stream of the picture macroblock and the code stream of the color gradient area from the code stream of the current frame image; decode the code stream of the color gradient area according to the first decoding method to generate a color gradient area, and the color gradient area includes at least 2 macroblocks; determine the boundary between every two adjacent macroblocks in the color gradient area and filter the boundary to generate a filtered color gradient area; decode the code stream of the text macroblock according to the second decoding method and decode the code stream of the picture macroblock according to the third decoding method to generate a text macroblock and a picture macroblock respectively; generate the current frame image according to the filtered color gradient area, the text macroblock and the picture macroblock, and can determine the boundary between every two adjacent macroblocks in the color gradient area and filter the boundary, so that the color jump of the boundary between adjacent macroblocks in the color gradient area is eliminated, and the user can perceive that the color of the boundary between adjacent macroblocks in the color gradient area is continuous, thereby improving the user experience.
[0027] In one embodiment, determining the boundary between every two adjacent macroblocks in the color gradient area includes:
[0028] The adjacent M rows or adjacent M columns of pixels between every two adjacent macroblocks in the color gradient area are used as the boundary between the two adjacent macroblocks, where M is an integer greater than 1.
[0029] In one embodiment, filtering the boundary includes:
[0030] If the two adjacent macroblocks are vertically adjacent, performing a difference operation on the first row of pixels and the last row of pixels of the adjacent M rows of pixels of the two adjacent macroblocks to obtain a first pixel difference;
[0031] Obtain a pixel gradient value according to the first pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the first pixel difference value by M;
[0032] For each row of pixels in the M-1 rows of pixels except the first row of pixels, the pixel value of the row of pixels is determined according to the pixel value of the previous row of pixels adjacent to the row of pixels and the pixel gradient value.
[0033] In one embodiment, filtering the boundary includes:
[0034] If the two adjacent macroblocks are adjacent to each other, performing a difference operation on the first column of pixels and the last column of pixels of the adjacent M columns of pixels of the two adjacent macroblocks to obtain a second pixel difference;
[0035] Obtain a pixel gradient value according to the second pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the second pixel difference value by M;
[0036] For each column of pixels in the M-1 columns of pixels except the first column of pixels, the pixel value of the column of pixels is determined according to the pixel value of the previous column of pixels adjacent to the column of pixels and the pixel gradient value.
[0037] According to a third aspect of an embodiment of the present disclosure, there is provided an image encoding apparatus, including:
[0038] The macroblock division module is used to divide the current frame image into macroblocks to generate N macroblocks, where N is an integer greater than 1;
[0039] A color gradient region determination module, configured to determine a color gradient macroblock from the N macroblocks and determine a color gradient region according to the color gradient macroblock, wherein the color gradient region includes at least two adjacent color gradient macroblocks;
[0040] A color gradient region encoding module, used for encoding the color gradient region according to a first encoding method to generate a code stream of the color gradient region;
[0041] A text macroblock encoding module, used to encode the text macroblocks except the color gradient area according to the second encoding method and encode the picture macroblocks except the color gradient area according to the third encoding method, and generate a code stream of the text macroblock and a code stream of the picture macroblock respectively;
[0042] The current frame image code stream generation module is used to generate the code stream of the current frame image according to the code stream of the color gradient area, the code stream of the text macroblock and the code stream of the picture macroblock, and send the code stream of the current frame image to the decoding end.
[0043] In one embodiment, the color gradient area determination module is used to:
[0044] Calculate a pixel difference between a target macroblock and a first macroblock, where the first macroblock is a macroblock adjacent to the left or right of the target macroblock, and the target macroblock is any one of the N macroblocks;
[0045] If the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than a preset threshold, then calculating the pixel difference between the target macroblock and a second macroblock, where the second macroblock is a macroblock adjacent to the upper side or the lower side of the target macroblock;
[0046] If the pixel difference between the target macroblock and the second macroblock is greater than 0 and less than a preset threshold, the target macroblock is a color gradient macroblock.
[0047] In one embodiment, the color gradient area determination module is used to:
[0048] The difference between the last column of pixels of the target macroblock and the first column of pixels of the first macroblock is used as the pixel difference between the target macroblock and the first macroblock, or the difference between the last column of pixels of the first macroblock and the first column of pixels of the target macroblock is used as the pixel difference between the target macroblock and the first macroblock.
[0049] In one embodiment, the color gradient area determination module is used to:
[0050] A rectangular macroblock area composed of at least two adjacent color gradient macroblocks is used as a color gradient area and / or a rectangular macroblock area composed of at least two adjacent color gradient macroblocks and a row and / or a column of non-color gradient macroblocks is used as a color gradient area.
[0051] According to a fourth aspect of an embodiment of the present disclosure, there is provided an image decoding apparatus, including:
[0052] A current frame image code stream receiving module, used to receive the code stream of the current frame image sent by the encoding end and determine the code stream of the text macroblock, the code stream of the picture macroblock and the code stream of the color gradient area from the code stream of the current frame image;
[0053] A color gradient region code stream decoding module, configured to decode the code stream of the color gradient region according to a first decoding method to generate a color gradient region, wherein the color gradient region includes at least 2 macroblocks;
[0054] A boundary filtering processing module, used for determining the boundary between every two adjacent macroblocks in the color gradient area and filtering the boundary to generate a filtered color gradient area;
[0055] A text macroblock code stream decoding module, used to decode the code stream of the text macroblock according to the second decoding method and decode the code stream of the picture macroblock according to the third decoding method, to generate a text macroblock and a picture macroblock respectively;
[0056] The current frame image generation module is used to generate the current frame image according to the filtered color gradient area, the text macroblock and the picture macroblock.
[0057] In one embodiment, the boundary filtering processing module is used to:
[0058] The adjacent M rows or adjacent M columns of pixels between every two adjacent macroblocks in the color gradient area are used as the boundary between the two adjacent macroblocks, where M is an integer greater than 1.
[0059] In one embodiment, the boundary filtering processing module is used to:
[0060] If the two adjacent macroblocks are vertically adjacent, performing a difference operation on the first row of pixels and the last row of pixels of the adjacent M rows of pixels of the two adjacent macroblocks to obtain a first pixel difference;
[0061] Obtain a pixel gradient value according to the first pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the first pixel difference value by M;
[0062] For each row of pixels in the M-1 rows of pixels except the first row of pixels, the pixel value of the row of pixels is determined according to the pixel value of the previous row of pixels adjacent to the row of pixels and the pixel gradient value.
[0063] In one embodiment, the boundary filtering processing module is used to:
[0064] If the two adjacent macroblocks are adjacent to each other, performing a difference operation on the first column of pixels and the last column of pixels of the adjacent M columns of pixels of the two adjacent macroblocks to obtain a second pixel difference;
[0065] Obtain a pixel gradient value according to the second pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the second pixel difference value by M;
[0066] For each column of pixels in the M-1 columns of pixels except the first column of pixels, the pixel value of the column of pixels is determined according to the pixel value of the previous column of pixels adjacent to the column of pixels and the pixel gradient value.
[0067] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0069] Figure 1 is a schematic diagram of a current frame image to be encoded provided by an embodiment of the present disclosure;
[0070] Figure 2 It is a schematic diagram of a decoded current frame image provided by the prior art;
[0071] Figure 3 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0072] Figure 4A This is a schematic diagram of a color gradient area provided by an embodiment of the present disclosure. Figure 1 ;
[0073] Figure 4BThis is a schematic diagram of a color gradient area provided by an embodiment of the present disclosure. Figure 2 ;
[0074] Figure 5 is a flowchart of an image decoding method provided by an embodiment of the present disclosure;
[0075] Fig. 6A is a schematic diagram of a boundary between two adjacent macroblocks provided by an embodiment of the present disclosure;
[0076] Figure 6B is a pixel schematic diagram of a decoded color gradient area provided by an embodiment of the present disclosure;
[0077] Figure 6C is a pixel schematic diagram of a color gradient area after filtering provided by an embodiment of the present disclosure;
[0078] Figure 7 is a schematic diagram of a decoded current frame image provided by an embodiment of the present disclosure;
[0079] Figure 8 is a component diagram of an image decoding system provided by an embodiment of the present disclosure;
[0080] Fig. 9 is a structural schematic diagram of an image encoding device provided by an embodiment of the present disclosure;
[0081] Fig.10 It is a structural schematic diagram of an image decoding device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0082] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0083] Figure 3 1 is a flowchart of an image encoding method provided by an embodiment of the present disclosure, and the method is applied to an encoding end. Figure 3 As shown, the method includes:
[0084] S301. Divide the current frame image into macroblocks to generate N macroblocks, where N is an integer greater than 1.
[0085] Exemplarily, the current frame image is divided into macroblocks to generate N macroblocks and identification information of each macroblock in the N macroblocks. The identification information is the index value of the macroblock, which is used to indicate the position of the macroblock in the current frame image. Taking a 1920*1080 image as an example, after the 1920*1080 image is divided into macroblocks, 120*68 macroblocks are generated, that is, 120 macroblocks per row and 68 macroblocks per column, and the size of each macroblock is 16*16 pixels, that is, each macroblock contains 16 pixels per row (0th to 15th) and 16 pixels per column (0th to 15th). Then the index values of the 120*68 macroblocks are from 0 to 8159 respectively. According to the index value of the macroblock, the row and column position of the macroblock can be known.
[0086] S302: Determine a color gradient macroblock from the N macroblocks and determine a color gradient region according to the color gradient macroblock, wherein the color gradient region includes at least two adjacent color gradient macroblocks.
[0087] The following describes how to determine a color gradient macroblock from N macroblocks.
[0088] Calculate the pixel difference between the target macroblock and the first macroblock, the first macroblock is a macroblock adjacent to the left or right of the target macroblock, and the target macroblock is any macroblock among the N macroblocks; if the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than a preset threshold, calculate the pixel difference between the target macroblock and the second macroblock, the second macroblock is a macroblock adjacent to the top or bottom of the target macroblock; if the pixel difference between the target macroblock and the second macroblock is greater than 0 and less than the preset threshold, the target macroblock is a color gradient macroblock.
[0089] Exemplarily, the difference between the last column of pixels of the target macroblock and the first column of pixels of the first macroblock can be used as the pixel difference between the target macroblock and the first macroblock, or the difference between the last column of pixels of the first macroblock and the first column of pixels of the target macroblock can be used as the pixel difference between the target macroblock and the first macroblock.
[0090] Specifically, if the first macroblock is a macroblock adjacent to the right side of the target macroblock, the difference between the last column of pixels of the target macroblock and the first column of pixels of the first macroblock is used as the pixel difference between the target macroblock and the first macroblock. If the first macroblock is a macroblock adjacent to the left side of the target macroblock, the difference between the last column of pixels of the first macroblock and the first column of pixels of the target macroblock is used as the pixel difference between the target macroblock and the first macroblock.
[0091] Here, the macroblock size of 16*16 pixels is used as an example for explanation. If the first macroblock is the macroblock adjacent to the right side of the target macroblock, that is, the first macroblock is on the right side of the target macroblock and adjacent to the target macroblock, then the difference between the pixels in the 15th column of the target macroblock and the pixels in the 0th column of the first macroblock is used as the pixel difference between the target macroblock and the first macroblock. Since each column of the macroblock has 16 rows, that is, each column has 16 pixels in total, the difference between the pixels in the 15th column and the 0th row of the target macroblock and the pixels in the 0th column and the 0th row of the first macroblock, the difference between the pixels in the 15th column and the 1st row of the target macroblock and the pixels in the 0th column and the 1st row of the first macroblock, the difference between the pixels in the 15th column and the 2nd row of the target macroblock and the pixels in the 0th column and the 2nd row of the first macroblock... The difference between the pixels in the 15th column and the 15th row of the target macroblock and the pixels in the 0th column and the 15th row of the first macroblock are all used as the pixel difference between the target macroblock and the first macroblock. value, and the difference between the pixel in the 15th column and the 0th row of the target macroblock and the pixel in the 0th column and the 0th row of the first macroblock, the difference between the pixel in the 15th column and the 1st row of the first macroblock, the difference between the pixel in the 15th column and the 2nd row of the target macroblock and the pixel in the 0th column and the 2nd row of the first macroblock…the difference between the pixel in the 15th column and the 15th row of the target macroblock and the pixel in the 0th column and the 15th row of the first macroblock are all greater than 0 and less than the preset threshold, the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than the preset threshold.
[0092] Similarly, if the first macroblock is the macroblock adjacent to the left side of the target macroblock, that is, the first macroblock is on the left side of the target macroblock and adjacent to the target macroblock, the difference between the pixels in the 15th column of the first macroblock and the pixels in the 0th column of the target macroblock is used as the pixel difference between the target macroblock and the first macroblock. Since each column has 16 rows, that is, each column has 16 pixels, the difference between the pixels in the 15th column and the 0th row of the first macroblock and the pixels in the 0th column and the 0th row of the target macroblock, the difference between the pixels in the 15th column and the 1st row of the first macroblock and the pixels in the 0th column and the 1st row of the target, the difference between the pixels in the 15th column and the 2nd row of the first macroblock and the pixels in the 0th column and the 2nd row of the target macroblock... The difference between the pixels in the 15th column and the 15th row of the first macroblock and the pixels in the 0th column and the 15th row of the target are all used as the pixel difference between the target macroblock and the first macroblock, and When the difference between the pixels in the 15th column and the 0th row of the first macroblock and the pixels in the 0th column and the 0th row of the target macroblock, the difference between the pixels in the 15th column and the 1st row of the first macroblock and the pixels in the 0th column and the 1st row of the target macroblock, the difference between the pixels in the 15th column and the 2nd row of the first macroblock and the pixels in the 0th column and the 2nd row of the target macroblock…when the difference between the pixels in the 15th column and the 15th row of the first macroblock and the pixels in the 0th column and the 15th row of the target macroblock are all greater than 0 and less than a preset threshold, the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than the preset threshold.
[0093] How to determine the pixel difference between the target macroblock and the second macroblock is described below. Exemplarily, the difference between the last row of pixels of the target macroblock and the first row of pixels of the second macroblock can be used as the pixel difference between the target macroblock and the second macroblock, or the difference between the last row of pixels of the second macroblock and the first row of pixels of the target macroblock can be used as the pixel difference between the target macroblock and the second macroblock.
[0094] The specific method for calculating the pixel difference between the target macroblock and the second macroblock is similar to the method for calculating the pixel difference between the target macroblock and the first macroblock, and will not be described in detail in this embodiment.
[0095] The following step of determining the color gradient area according to the color gradient macroblock includes:
[0096] Exemplarily, a rectangular macroblock area composed of at least two adjacent color gradient macroblocks is used as a color gradient area and / or a rectangular macroblock area composed of at least two adjacent color gradient macroblocks and a row and / or a column of non-color gradient macroblocks is used as a color gradient area.
[0097] For example Figure 4A and Figure 4B As shown, if Figure 4A If macroblocks 1 / 2 / 3 are color gradient macroblocks, or macroblocks 1 / 2 / 3 / 4 are color gradient macroblocks, then the rectangle formed by these four macroblocks is the color gradient area.
[0098] Figure 4B In the figure, the dotted line marks the color gradient macroblock, and the X-marked area is the non-color gradient macroblock. Then the macroblock rectangular area composed of the dotted line color gradient macroblock and the X-marked non-color gradient macroblock is the color gradient area. It should be noted that in order to consider the accuracy of each macroblock pixel of the image when the decoding end decodes and reconstructs, when delineating the color gradient area, at most one row and / or one column of non-color gradient macroblocks are allowed in the color gradient area.
[0099] S303: Encode the color gradient area according to a first encoding method to generate a code stream of the color gradient area.
[0100] Exemplarily, the color gradient region is encoded according to the Huffman coding method to generate a code stream of the color gradient region. Exemplarily, while encoding the color gradient region, the identification information of the color gradient region is encoded, and the identification information of the color gradient region is encoded for the index values of the first macroblock (i.e., the macroblock in the upper left corner) and the last macroblock (i.e., the macroblock in the lower right corner) in the color gradient region.
[0101] S304, encode the text macroblocks except the color gradient area according to the second encoding method and encode the picture macroblocks except the color gradient area according to the third encoding method, and generate a code stream of the text macroblock and a code stream of the picture macroblock respectively.
[0102] In this step, each macroblock in the macroblocks other than the color gradient area is identified and classified according to its content, and is divided into text macroblocks and picture macroblocks. The text block is a macroblock with more details, and the picture macroblock is a macroblock with a relatively smooth change. The text macroblock needs to be displayed clearly, so the palette quantization and huffman coding are used to encode the text macroblock to generate the code stream of the text macroblock. The picture macroblock is encoded using the coding method information of the Joint Photographic Experts Group (JPEG) encoding to generate the code stream of the picture macroblock. Exemplarily, while the text macroblock and the picture macroblock are encoded respectively, the index value of the text macroblock and the index value of the picture macroblock are encoded respectively.
[0103] S305 , generating a code stream of the current frame image according to the code stream of the color gradient area, the code stream of the text macroblock, and the code stream of the picture macroblock, and sending the code stream of the current frame image to a decoding end.
[0104] In this step, the code stream of the color gradient area, the code stream of the text macroblock and the code stream of the picture macroblock are packaged to generate the code stream of the current frame image and send the code stream of the current frame image to the decoding end. Exemplarily, while the code stream of the color gradient area, the code stream of the text macroblock and the code stream of the picture macroblock are packaged, the identification information of the color gradient area, the index value of the text macroblock and the index value of the picture macroblock are packaged and sent to the decoding end.
[0105] The image encoding method provided by the embodiment of the present disclosure can divide the current frame image into macroblocks to generate N macroblocks; determine a color gradient macroblock from the N macroblocks and determine a color gradient area according to the color gradient macroblock, wherein the color gradient area includes at least two adjacent color gradient macroblocks; encode the color gradient area according to a first encoding method to generate a code stream of the color gradient area; encode the text macroblocks except the color gradient area according to a second encoding method and encode the picture macroblocks except the color gradient area according to a third encoding method to respectively generate a code stream of the text macroblock and a code stream of the picture macroblock; encode the text macroblocks except the color gradient area according to the second encoding method Encoding is performed and the picture macros except the color gradient area are encoded according to the third encoding method, and the code streams of the text macroblocks and the picture macroblocks are generated respectively. Regardless of the type of macroblocks in the color gradient area, the first encoding method is used for encoding. This can avoid the situation where the types of macroblocks in two adjacent parts of a color gradient area are different, and the encoding methods adopted are different. In this case, the boundaries of the macroblocks in the two adjacent parts will have visual deficiencies after decoding and reconstruction. The macroblocks of the two adjacent parts that should be displayed gradually appear as boundaries with a mosaic style, so that the user can perceive the discontinuity between the colors of the macroblocks in the two adjacent parts, resulting in a poor user experience, thereby improving the user experience.
[0106] The following describes how to decode the code stream of the current frame image to generate the current frame image. Figure 5 is a flowchart of an image decoding method provided by an embodiment of the present disclosure, and the method is applied to a decoding end. Figure 5 As shown, the method includes:
[0107] S501, receiving a code stream of a current frame image sent by an encoding end, and determining a code stream of a text macroblock, a code stream of a picture macroblock, and a code stream of a color gradient area from the code stream of the current frame image.
[0108] Exemplarily, the code stream of the current frame image includes the code stream of the text macroblock, the code stream of the picture macroblock, the code stream of the color gradient area, the index value of the text macroblock, the index value of the picture macroblock, and the identification information of the color gradient area. After receiving the code stream of the current frame image sent by the encoding end, the decoding end determines the code stream of the text macroblock, the code stream of the picture macroblock, and the code stream of the color gradient area from the code stream of the current frame image.
[0109] S502: Decode the code stream of the color gradient area according to a first decoding method to generate a color gradient area, where the color gradient area includes at least 2 macroblocks.
[0110] Exemplarily, the code stream of the color gradient area is decoded according to the decoding method corresponding to the Huffman coding method to generate the color gradient area, the color gradient area includes at least 2 macroblocks, the color gradient area is a macroblock rectangular area composed of the at least 2 macroblocks, and the at least 2 macroblocks are color gradient macroblocks determined by the encoding end.
[0111] S503: Determine the boundary between every two adjacent macroblocks in the color gradient region and perform filtering on the boundary to generate a filtered color gradient region.
[0112] The following describes how to determine every two adjacent macroblocks in the color gradient area.
[0113] Exemplarily, the adjacent M rows or adjacent M columns of pixels between every two adjacent macroblocks in the color gradient area are used as the boundary between the two adjacent macroblocks, where M is an integer greater than 1.
[0114] Specifically, if the two adjacent macroblocks are vertically adjacent, then the adjacent M rows of pixels of the two adjacent macroblocks are the boundary of the two adjacent macroblocks. If the two adjacent macroblocks are horizontally adjacent, then the adjacent M columns of pixels of the two adjacent macroblocks are the boundary of the two adjacent macroblocks.
[0115] Here, the size of the macroblock is 16*16 pixels as an example. The size of the macroblock is 16*16 pixels, that is, each macroblock contains 16 pixels in each row (0th to 15th) and 16 pixels in each column (0th to 15th). Then, the boundary between the two adjacent macroblocks above and below is the adjacent 6 rows of pixels of the two adjacent macroblocks, that is, the 13th to 15th rows of pixels of the upper macroblock and the 0th to 2nd rows of pixels of the lower macroblock, and the boundary between the two adjacent macroblocks on the left and right is the adjacent 6 columns of pixels of the two adjacent macroblocks, that is, the 13th to 15th columns of pixels of the left macroblock and the 0th to 2nd columns of pixels of the right macroblock.
[0116] How to filter the boundary is described below.
[0117] In one embodiment, if the two adjacent macroblocks are vertically adjacent, a difference operation is performed between the first row of pixels and the last row of pixels of the M adjacent rows of pixels of the two adjacent macroblocks to obtain a first pixel difference; a pixel gradient value is obtained based on the first pixel difference and M, and the pixel gradient value is a value obtained by dividing the first pixel difference by M and rounding it to an integer; for each row of pixels in the M-1 rows of pixels except the first row of pixels, the pixel value of the row of pixels is determined based on the pixel value of the previous row of pixels adjacent to the row of pixels and the pixel gradient value.
[0118] Here, the macroblock size is 16*16 pixels. If the two adjacent macroblocks are vertically adjacent, the first row of pixels and the last row of pixels of the adjacent 6 rows of pixels of the two adjacent macroblocks are subjected to difference calculation to obtain the first pixel difference, that is, the 13th row of pixels of the left macroblock and the 2nd row of pixels of the right macroblock are subjected to difference calculation to obtain the first pixel difference. Since each column of the macroblock has 16 rows, that is, each column has a total of 16 pixels, the pixels of the two rows of each column are subjected to difference calculation to obtain the first pixel difference of the two rows of pixels of each column. Then, the first pixel difference of the two rows of pixels of each column is divided by 6 to obtain the pixel gradient value of the two rows of pixels of each column. The first row of pixels in each column at the boundary of two adjacent macroblocks remains unchanged, the pixel value of the second row of pixels in each column is the pixel value of the first row of pixels in each column minus the pixel gradient value, the pixel value of the third row of pixels in each column is the pixel value of the second row of pixels in each column minus the pixel gradient value...the pixel value of the sixth row of pixels in each column is equal to the pixel value of the fifth row of pixels in each column minus the pixel gradient value.
[0119] It should be noted here that the last row of pixels in each column at the boundary of two adjacent macroblocks can also remain unchanged, the pixel value of the fifth row of pixels in each column is the pixel value of the last row of pixels in each column plus the pixel gradient value, the pixel value of the fourth row of pixels in each column is the pixel value of the fifth row of pixels in each column plus the pixel gradient value… and the pixel value of the first row of pixels in each column is equal to the pixel value of the second row of pixels in each column plus the pixel gradient value.
[0120] In another embodiment, if the two adjacent macroblocks are adjacent to each other on the left and right, a difference operation is performed between the first column of pixels and the last column of pixels of the M adjacent columns of pixels of the two adjacent macroblocks to obtain a second pixel difference; a pixel gradient value is obtained based on the second pixel difference and M, and the pixel gradient value is a value obtained by dividing the second pixel difference by M and rounding it to an integer; for each column of pixels in the M-1 columns of pixels except the first column of pixels, the pixel value of the column of pixels is determined based on the pixel value of the previous column of pixels adjacent to the column of pixels and the pixel gradient value.
[0121] The manner of filtering the boundary between left and right adjacent macroblocks is similar to the manner of filtering the boundary between top and bottom adjacent macroblocks, and will not be described in detail in this embodiment.
[0122] Combined here FIG. 6A to FIG. 6C For explanation. Fig. 6AAs shown, the dotted line marks the boundary between two adjacent macroblocks. Macroblock 1 and macroblock 2 are adjacent to each other on the left and right. The boundary between macroblock 1 and macroblock 2 is the 13th column of pixels in macroblock 1 to the 2nd column of pixels in macroblock 2. That is, the 13th column of pixels in macroblock 1 is the first column of pixels on the boundary between macroblock 1 and macroblock 2, and the 2nd column of pixels in macroblock 2 is the last column of pixels on the boundary between macroblock 1 and macroblock 2. The pixels in the two columns of each row are subtracted by 6 to obtain the pixel gradient value of the two columns of pixels in each row. Then, the 13th column of pixels in macroblock 1 in each row remains unchanged. For the 5 columns of pixels other than the 13th column of macroblock 1, the pixel values of the previous column of pixels in each row adjacent to the pixel in this column in each row are subtracted from the pixel gradient value as the pixel value of the pixel in this column in each row. For example, the pixel values of the 6 adjacent pixels in the first row of the two adjacent macroblocks, macroblock 1 and macroblock 2 before filtering, are:
[0123] 72 71 71|65 65 65
[0124] Then calculate (65-72) / 6=-1.17, which is rounded to 1, that is, the pixel gradient value is 1. Then the pixel value after filtering the boundary between macroblock 1 and macroblock 2 is:
[0125] 72 71 70|69 68 67
[0126] It can be seen that the first row of pixels of the original adjacent macroblocks jumps from 71 to 65. After smoothing, the pixel boundaries are smoothed.
[0127] right Fig. 6A In the example, the six boundary pixels in each row adjacent to macroblock 1 and macroblock 2 are processed by the above method, so that the boundary between macroblocks can be smoothed.
[0128] Figure 6B is a pixel schematic diagram of a decoded color gradient area provided by an embodiment of the present disclosure. Figure 6B As shown, the color gradient area is composed of 4 macroblocks. After decoding, the pixel values of the 4 macroblocks in the gradient area are as follows Figure 6B As shown, there are pixel jumps at boundary 1 (the boundary between macroblock 1 and macroblock 2) and boundary 2 (the boundary between macroblock 1 and macroblock 3), for example, there is a jump from 71 to 65. Figure 6C FIG. 1 is a pixel schematic diagram of a color gradient region after filtering provided by an embodiment of the present disclosure. After filtering the boundaries of four adjacent macroblocks in the color gradient region, the pixel values of the four macroblocks are as follows: Figure 6C As shown, the boundary pixel jump is eliminated and the boundary pixels change smoothly.
[0129] S504, decode the code stream of the text macroblock according to the second decoding method and decode the code stream of the picture macroblock according to the third decoding method, to generate a text macroblock and a picture macroblock respectively.
[0130] Exemplarily, the code stream of the text macroblock is decoded according to a decoding method corresponding to the palette quantization and Huffman coding method to generate the text macroblock; the code stream of the picture macroblock is decoded according to the JPEG coding method to generate the picture macroblock.
[0131] S505 , generating the current frame image according to the filtered color gradient area, the text macroblock, and the picture macroblock.
[0132] Exemplarily, the filtered color gradient area, the text macroblock and the picture macroblock are arranged according to the identification information of the color gradient area, the index value of the text macroblock and the index value of the picture macroblock, respectively, to generate the current frame image.
[0133] Figure 7 is a schematic diagram of a decoded current frame image provided by an embodiment of the present disclosure. The current frame image generated by the image decoding method provided by the embodiment of the present disclosure is as follows Figure 7 As shown, in Figure 7 In the image part, the step-like color jump has been eliminated, and the image is close to the original image before encoding. Figure 7 As shown, the portion enclosed by the ellipse is the pixel at the boundary of the adjacent macroblocks in the color gradient area, the pixel jump portion at the boundary of the adjacent macroblocks in the color gradient area is smoothed, and the color jump at the macroblock boundary in the color gradient area is eliminated.
[0134] The image decoding method provided by the embodiment of the present disclosure can receive the code stream of the current frame image sent by the encoding end and determine the code stream of the text macroblock, the code stream of the picture macroblock and the code stream of the color gradient area from the code stream of the current frame image; decode the code stream of the color gradient area according to the first decoding method to generate a color gradient area, and the color gradient area includes at least 2 macroblocks; determine the boundary between every two adjacent macroblocks in the color gradient area and filter the boundary to generate a filtered color gradient area; decode the code stream of the text macroblock according to the second decoding method and decode the code stream of the picture macroblock according to the third decoding method to generate a text macroblock and a picture macroblock respectively; generate the current frame image according to the filtered color gradient area, the text macroblock and the picture macroblock, and can determine the boundary between every two adjacent macroblocks in the color gradient area and filter the boundary, so that the color jump of the boundary between adjacent macroblocks in the color gradient area is eliminated, and the user can perceive that the color of the boundary between adjacent macroblocks in the color gradient area is continuous, thereby improving the user experience.
[0135] Combine the following Figure 8 , the image encoding and decoding method provided by the embodiment of the present disclosure is further described in detail. Figure 8is a component diagram of an image decoding system provided by an embodiment of the present disclosure. Figure 8 As shown in the figure, the functions of each component are as follows:
[0136] 801: To-be-encoded image acquisition module. This module acquires a frame of image of the computer desktop in the YUV format.
[0137] 802: Macroblock identification and classification module. This module logically divides the full frame into macroblocks of 16*16 pixels. Each macroblock is identified and classified according to its content. This module mainly divides macroblocks into two categories, text blocks and picture blocks. Text blocks are macroblocks with more details, while picture blocks are macroblocks with more gradual changes. Text blocks need to be displayed clearly, so the palette quantization and huffman encoding methods are used. Picture blocks are encoded using JPEG.
[0138] 803: Gradient region identification module. While 802 is dividing macroblocks, this module will search for gradient color macroblocks in the whole frame. After 802 is executed, the macroblocks with gradient colors in the whole frame are analyzed to form rectangular gradient regions. There may be multiple gradient regions in the whole frame, and these regions will be put into the encoded bitstream. The workflow of this module is as follows:
[0139] 1. When the 802 module performs macroblock identification and classification, it also analyzes whether each macroblock is a gradual change macroblock. The analysis method is:
[0140] Analyze 16*16 pixels from left to right to determine whether the color difference between every two adjacent macroblocks is greater than 0 and less than Delta. Delta can take a smaller value, such as 2, according to the specific situation of the actual application. If this condition is met, analyze from top to bottom whether the two adjacent pixels are greater than 0 and less than Delta. If they are also met, the macroblock is a gradient macroblock, otherwise it is not a gradient macroblock. After the 402 module performs the full frame macroblock analysis, the 803 module has recorded the positions of all the gradient macroblocks in the full frame. The position recording method can use the index value of the macroblock. Taking a 1920*1080 size picture as an example, there are 120 macroblocks in each row and 68 macroblocks in each column. The macroblock index value is from 0 to 8159. According to the index value, the row and column position of the macroblock can be obtained.
[0141] 2. After the 802 module has finished its work, the 803 module analyzes all the gradient macroblocks and generates multiple gradient regions. The generation method is:
[0142] (1) If two gradient macroblocks are adjacent horizontally or vertically, the gradient region includes both macroblocks;
[0143] (2) If several gradient macroblocks are adjacent to each other, but the rectangle they form also contains a row or a column of macroblocks that are not all gradient macroblocks, then the gradient area will be defined as the rectangle, and the row or column of non-gradient macroblocks will also be included. Figure 4A and Figure 4B shown.
[0144] Figure 4A If macroblock 1 / 2 / 3 is a gradual change macroblock, or macroblock 1 / 2 / 3 / 4 is a gradual change macroblock, the gradual change area is a rectangle formed by these four macroblocks.
[0145] Figure 4B In the figure, the dotted line marks the gradual change macroblock, and the X marks the non-gradient macroblock. In this case, the peripheral non-gradient macroblocks are also defined in the gradual change area. It should be noted that, in order to consider the accuracy of reconstruction at the decoding end, when defining the gradual change area, at most one layer of non-gradient macroblocks is allowed to be included in the rectangle.
[0146] 804: Text macroblock encoding module. Encodes all text macroblocks, and the encoding method mainly includes palette quantization and Huffman encoding.
[0147] 805: Picture macroblock encoding module: Encode all picture macroblocks using JPEG encoding method.
[0148] 806: Gradient area information generation module. The previous 803 module generates one or more gradient areas, which are rectangular and contain multiple macroblocks. 806 module records these areas. For each gradient area, the index number of the first macroblock and the last macroblock is recorded. After the information of all gradient areas is encoded using Huffman, it is the gradient area information.
[0149] 807: Code stream generation module. Pack the previously generated text block code stream, picture block code stream and gradient area information data to form a whole frame encoding code stream.
[0150] The components of the decoder are:
[0151] 808: Code stream splitting module. The code stream is divided into text block code stream, picture block code stream and gradient area information data. The first two are sent to module 809 for decoding. The gradient area information data is sent to module 810 for gradient area filtering processing.
[0152] 810: Gradient region filtering module: This module receives the gradient region information and performs filtering on the boundaries of the macroblocks in the region. Fig. 6A A gradient region consisting of four macroblocks is shown. This figure is used as an example to illustrate the boundary filtering method.
[0153] First, define the macroblock boundary as: 6 rows or 6 columns of pixels at the junction of two macroblocks. Fig. 6A In the example, there are two macroblock boundaries, as shown by the dotted lines. Taking the boundary between macroblock 1 and macroblock 2 as an example, when all the text and picture blocks are decoded, module 410 analyzes the 13th column of pixels in macroblock 1 and the 2nd column of pixels in macroblock 2, and makes a difference between the pixels in the two columns of each row, and then divides by 6 to obtain the gradient value. Then, the 13th column of macroblock 1 and the 2nd column of macroblock 2 are regarded as minimum and maximum values, and the pixel value of the 13th column of macroblock 1 remains unchanged. The pixel values of other columns of pixels are the previous column of pixels adjacent to the column of pixels minus the pixel gradient value. For example, the adjacent 6 pixel values of two adjacent macroblocks before filtering are:
[0154] 72 71 71|65 65 65
[0155] Then calculate (72-65) / 6=1.17, which can be regarded as 1 in engineering calculations, or calculated as a decimal and then rounded to an integer pixel value. The filtered value is:
[0156] 72 71 70|69 68 67
[0157] It can be seen that there is a jump from 71 to 65 between the original macroblocks. After smoothing, the pixel boundaries are smoothed.
[0158] right Fig. 6A In the example, the six boundary pixels of each row adjacent to macroblock 1 and macroblock 2 are processed by the above method, so that the boundary between macroblocks can be smoothed. Finally, module 811 reconstructs the filtered image.
[0159] Figure 6B It is a gradient area composed of four macroblocks. It can be seen that there are pixel jumps on both boundary 1 and boundary 2, for example, there is a jump from 71 to 65. Figure 6C This is the situation after filtering. It can be seen that pixel jumps are eliminated and the boundaries are smoothed.
[0160] This solution proposes a method that can handle the phenomenon of the stepped visual effect formed at the junction of different types of macroblocks in the gradient color area. When encoding computer-generated images, different encoding methods are often used for different macroblocks, or the same type of macroblocks suffer pixel loss due to quantization. It is not obvious in non-gradient areas and is acceptable, but in gradient color areas, the macroblock boundaries formed are more sensitive to the human eye. This solution identifies the gradient area when classifying macroblocks, and smoothes the macroblock boundaries in the gradient area at the decoding end, thereby enhancing the visual experience of the gradient area.
[0161] Based on the above Figure 3 The image encoding method described in the corresponding embodiment is as follows: an embodiment of the device disclosed herein, which can be used to execute the embodiment of the method disclosed herein.
[0162] Fig. 9 is a schematic diagram of the structure of an image encoding device provided by an embodiment of the present disclosure, such as Fig. 9 As shown, the device 90 comprises:
[0163] The macroblock division module 901 is used to divide the current frame image into macroblocks to generate N macroblocks, where N is an integer greater than 1;
[0164] A color gradient region determining module 902, configured to determine a color gradient macroblock from the N macroblocks and determine a color gradient region according to the color gradient macroblock, wherein the color gradient region includes at least two adjacent color gradient macroblocks;
[0165] A color gradient region encoding module 903 is used to encode the color gradient region according to a first encoding method to generate a code stream of the color gradient region;
[0166] A text macroblock encoding module 904 is used to encode the text macroblocks except the color gradient area according to the second encoding method and encode the picture macroblocks except the color gradient area according to the third encoding method, and generate a code stream of the text macroblock and a code stream of the picture macroblock respectively;
[0167] The current frame image code stream generation module 905 is used to generate the code stream of the current frame image according to the code stream of the color gradient area, the code stream of the text macroblock and the code stream of the picture macroblock, and send the code stream of the current frame image to the decoding end.
[0168] In one embodiment, the color gradient region determination module 903 is used to:
[0169] Calculate a pixel difference between a target macroblock and a first macroblock, where the first macroblock is a macroblock adjacent to the left or right of the target macroblock, and the target macroblock is any one of the N macroblocks;
[0170] If the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than a preset threshold, then calculating the pixel difference between the target macroblock and a second macroblock, where the second macroblock is a macroblock adjacent to the upper side or the lower side of the target macroblock;
[0171] If the pixel difference between the target macroblock and the second macroblock is greater than 0 and less than a preset threshold, the target macroblock is a color gradient macroblock.
[0172] In one embodiment, the color gradient region determination module 903 is used to:
[0173] The difference between the last column of pixels of the target macroblock and the first column of pixels of the first macroblock is used as the pixel difference between the target macroblock and the first macroblock, or the difference between the last column of pixels of the first macroblock and the first column of pixels of the target macroblock is used as the pixel difference between the target macroblock and the first macroblock.
[0174] In one embodiment, the color gradient region determination module 903 is used to:
[0175] A rectangular macroblock area composed of at least two adjacent color gradient macroblocks is used as a color gradient area and / or a rectangular macroblock area composed of at least two adjacent color gradient macroblocks and a row and / or a column of non-color gradient macroblocks is used as a color gradient area.
[0176] The image encoding device provided in the embodiment of the present disclosure, its implementation process and technical effects can be seen in the above Figure 3 The embodiments are not described in detail here.
[0177] Based on the above Figure 5 The image decoding method described in the corresponding embodiment is as follows: an embodiment of the device disclosed herein, which can be used to execute the embodiment of the method disclosed herein.
[0178] Fig.10 is a schematic diagram of the structure of an image decoding device provided by an embodiment of the present disclosure, such as Fig.10 As shown, the device 100 includes:
[0179] The current frame image code stream receiving module 1001 is used to receive the code stream of the current frame image sent by the encoder and determine the code stream of the text macroblock, the code stream of the picture macroblock and the code stream of the color gradient area from the code stream of the current frame image;
[0180] A color gradient region code stream decoding module 1002, configured to decode the code stream of the color gradient region according to a first decoding method to generate a color gradient region, wherein the color gradient region includes at least 2 macroblocks;
[0181] The boundary filtering processing module 1003 is used to determine the boundary between every two adjacent macroblocks in the color gradient area and filter the boundary to generate a filtered color gradient area;
[0182] The text macroblock code stream decoding module 1004 is used to decode the code stream of the text macroblock according to the second decoding method and decode the code stream of the picture macroblock according to the third decoding method to generate a text macroblock and a picture macroblock respectively;
[0183] The current frame image generation module 1005 is used to generate the current frame image according to the filtered color gradient area, the text macroblock and the picture macroblock.
[0184] In one embodiment, the boundary filtering processing module is used to:
[0185] The adjacent M rows or adjacent M columns of pixels between every two adjacent macroblocks in the color gradient area are taken as the boundary between the two adjacent macroblocks, where M is an integer greater than 1.
[0186] In one embodiment, the boundary filtering processing module 1003 is used to:
[0187] If the two adjacent macroblocks are vertically adjacent, performing a difference operation on the first row of pixels and the last row of pixels of the adjacent M rows of pixels of the two adjacent macroblocks to obtain a first pixel difference;
[0188] Obtain a pixel gradient value according to the first pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the first pixel difference value by M;
[0189] For each row of pixels in the M-1 rows of pixels except the first row of pixels, the pixel value of the row of pixels is determined according to the pixel value of the previous row of pixels adjacent to the row of pixels and the pixel gradient value.
[0190] In one embodiment, the boundary filtering processing module 1003 is used to:
[0191] If the two adjacent macroblocks are adjacent to each other, performing a difference operation on the first column of pixels and the last column of pixels of the adjacent M columns of pixels of the two adjacent macroblocks to obtain a second pixel difference;
[0192] Obtain a pixel gradient value according to the second pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the second pixel difference value by M;
[0193] For each column of pixels in the M-1 columns of pixels except the first column of pixels, the pixel value of the column of pixels is determined according to the pixel value of the previous column of pixels adjacent to the column of pixels and the pixel gradient value.
[0194] The image decoding device provided in the embodiment of the present disclosure, its implementation process and technical effects can be seen in the above Figure 5 The embodiments are not described in detail here.
[0195] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0196] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
Claims
1. An image coding method, characterized in that: include: Divide the current frame image into macroblocks to generate N macroblocks, where N is an integer greater than 1; Determine a color gradient macroblock from the N macroblocks and determine a color gradient region according to the color gradient macroblock, wherein the color gradient region includes at least two adjacent color gradient macroblocks; Encoding the color gradient area according to a first encoding method to generate a code stream of the color gradient area; Encoding the text macroblocks except the color gradient area according to the second encoding method and encoding the picture macroblocks except the color gradient area according to the third encoding method, and generating a code stream of the text macroblock and a code stream of the picture macroblock respectively; Generate the code stream of the current frame image according to the code stream of the color gradient area, the code stream of the text macroblock and the code stream of the picture macroblock, and send the code stream of the current frame image to a decoding end; Determining a color gradient macroblock from the N macroblocks includes: Calculate a pixel difference between a target macroblock and a first macroblock, where the first macroblock is a macroblock adjacent to the left or right of the target macroblock, and the target macroblock is any one of the N macroblocks; If the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than a preset threshold, then calculating the pixel difference between the target macroblock and a second macroblock, where the second macroblock is a macroblock adjacent to the upper side or the lower side of the target macroblock; If the pixel difference between the target macroblock and the second macroblock is greater than 0 and less than a preset threshold, the target macroblock is a color gradient macroblock.
2. The method according to claim 1, characterized in that The calculating the pixel difference between the target macroblock and the first macroblock comprises: The difference between the last column of pixels of the target macroblock and the first column of pixels of the first macroblock is used as the pixel difference between the target macroblock and the first macroblock, or the difference between the last column of pixels of the first macroblock and the first column of pixels of the target macroblock is used as the pixel difference between the target macroblock and the first macroblock; wherein; If the first macroblock is a macroblock adjacent to the right side of the target macroblock, the difference between the last column of pixels of the target macroblock and the first column of pixels of the first macroblock is used as the pixel difference between the target macroblock and the first macroblock; If the first macroblock is a macroblock adjacent to the left side of the target macroblock, the difference between the last column of pixels of the first macroblock and the first column of pixels of the target macroblock is used as the pixel difference between the target macroblock and the first macroblock.
3. The method according to claim 1, characterized in that: Determining the color gradient area according to the color gradient macroblock comprises: A rectangular macroblock area composed of at least two adjacent color gradient macroblocks is used as a color gradient area and / or a rectangular macroblock area composed of at least two adjacent color gradient macroblocks and a row and / or a column of non-color gradient macroblocks is used as a color gradient area.
4. An image decoding method, characterized in that: include: Receive a code stream of a current frame image sent by an encoding end and determine a code stream of a text macroblock, a code stream of a picture macroblock, and a code stream of a color gradient area from the code stream of the current frame image; Decoding the code stream of the color gradient area according to a first decoding method to generate a color gradient area, wherein the color gradient area includes at least 2 macroblocks; Determining the boundary between every two adjacent macroblocks in the color gradient region and filtering the boundary to generate a filtered color gradient region; Decoding the code stream of the text macroblock according to the second decoding method and decoding the code stream of the picture macroblock according to the third decoding method to generate a text macroblock and a picture macroblock respectively; Generate the current frame image according to the filtered color gradient area, the text macroblock and the picture macroblock; Determining the boundary between every two adjacent macroblocks in the color gradient area comprises: Taking the adjacent M rows or adjacent M columns of pixels of every two adjacent macroblocks in the color gradient area as the boundary of the two adjacent macroblocks, where M is an integer greater than 1; The filtering of the boundary comprises: If the two adjacent macroblocks are vertically adjacent, performing a difference operation on the first row of pixels and the last row of pixels of the adjacent M rows of pixels of the two adjacent macroblocks to obtain a first pixel difference; Obtain a pixel gradient value according to the first pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the first pixel difference value by M; For each row of pixels in the M-1 rows of pixels except the first row of pixels, the pixel value of the row of pixels is determined according to the pixel value of the previous row of pixels adjacent to the row of pixels and the pixel gradient value.
5. The method according to claim 4, characterized in that The filtering of the boundary comprises: If the two adjacent macroblocks are adjacent to each other, performing a difference operation on the first column of pixels and the last column of pixels of the adjacent M columns of pixels of the two adjacent macroblocks to obtain a second pixel difference; Obtain a pixel gradient value according to the second pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the second pixel difference value by M; For each column of pixels in the M-1 columns of pixels except the first column of pixels, the pixel value of the column of pixels is determined according to the pixel value of the previous column of pixels adjacent to the column of pixels and the pixel gradient value.
6. An image encoding device, characterized in that: include: The macroblock division module is used to divide the current frame image into macroblocks to generate N macroblocks, where N is an integer greater than 1; A color gradient region determination module, configured to determine a color gradient macroblock from the N macroblocks and determine a color gradient region according to the color gradient macroblock, wherein the color gradient region includes at least two adjacent color gradient macroblocks; A color gradient region encoding module, used for encoding the color gradient region according to a first encoding method to generate a code stream of the color gradient region; A text macroblock encoding module, used to encode the text macroblocks except the color gradient area according to the second encoding method and encode the picture macroblocks except the color gradient area according to the third encoding method, and generate a code stream of the text macroblock and a code stream of the picture macroblock respectively; A current frame image code stream generation module, used to generate the code stream of the current frame image according to the code stream of the color gradient area, the code stream of the text macroblock and the code stream of the picture macroblock, and send the code stream of the current frame image to a decoding end; The color gradient area determination module is used for: Calculate a pixel difference between a target macroblock and a first macroblock, where the first macroblock is a macroblock adjacent to the left or right of the target macroblock, and the target macroblock is any one of the N macroblocks; If the pixel difference between the target macroblock and the first macroblock is greater than 0 and less than a preset threshold, then calculating the pixel difference between the target macroblock and a second macroblock, where the second macroblock is a macroblock adjacent to the upper side or the lower side of the target macroblock; If the pixel difference between the target macroblock and the second macroblock is greater than 0 and less than a preset threshold, the target macroblock is a color gradient macroblock.
7. An image decoding device, characterized in that: include: A current frame image code stream receiving module, used to receive the code stream of the current frame image sent by the encoding end and determine the code stream of the text macroblock, the code stream of the picture macroblock and the code stream of the color gradient area from the code stream of the current frame image; A color gradient region code stream decoding module, configured to decode the code stream of the color gradient region according to a first decoding method to generate a color gradient region, wherein the color gradient region includes at least 2 macroblocks; A boundary filtering processing module, used for determining the boundary between every two adjacent macroblocks in the color gradient area and filtering the boundary to generate a filtered color gradient area; A text macroblock code stream decoding module, used to decode the code stream of the text macroblock according to the second decoding method and decode the code stream of the picture macroblock according to the third decoding method, to generate a text macroblock and a picture macroblock respectively; A current frame image generation module, used to generate the current frame image according to the filtered color gradient area, the text macroblock and the picture macroblock; The boundary filtering processing module is used for: Taking the adjacent M rows or adjacent M columns of pixels of every two adjacent macroblocks in the color gradient area as the boundary of the two adjacent macroblocks, where M is an integer greater than 1; The boundary filtering processing module is used for: If the two adjacent macroblocks are vertically adjacent, performing a difference operation on the first row of pixels and the last row of pixels of the adjacent M rows of pixels of the two adjacent macroblocks to obtain a first pixel difference; Obtain a pixel gradient value according to the first pixel difference value and M, wherein the pixel gradient value is a value rounded to an integer after dividing the first pixel difference value by M; For each row of pixels in the M-1 rows of pixels except the first row of pixels, the pixel value of the row of pixels is determined according to the pixel value of the previous row of pixels adjacent to the row of pixels and the pixel gradient value.
Citation Information
Patent Citations
Video shot detection method based on histogram improvement and clustering algorithm
CN103426176A
Image coding method and device
CN110505483A