Image encoding and decoding method and device
By using parameter matrix table lookup instead of floating-point operation during the conversion process of RGB to YUV, the problem of high computational volume in the prior art is solved, and efficient image encoding and decoding is achieved.
Patent Information
- Application Number
- CN202110314365.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-24
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2041-03-24
AI Technical Summary
The prior art has a large amount of calculation during the conversion process of RGB to YUV, resulting in low computing efficiency.
By setting up a parameter matrix, storing 255*3*3 integer numbers, using the search table instead of the process of multiplication and addition of floating-point numbers, reducing the amount of operations and saving operation time.
It significantly reduces the amount of computing, improves the computing efficiency, saves bandwidth in YUV transmission, and ensures timeliness.
Smart Images

Figure CN113194316B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image compression technology, and in particular to an image encoding and decoding method and device. Background Art
[0002] The RGB color model is a color standard in the industry. It obtains a variety of colors by changing the three color channels of red (R), green (G), and blue (B) and superimposing them on each other. RGB represents the colors of the three channels of red, green, and blue. This standard covers almost all colors that can be perceived by human vision and is one of the most widely used color systems.
[0003] YUV is the brightness Y (grayscale value) and the color difference signals U and V. Our eyes are more sensitive to color brightness information than color difference information. Without U and V information, the complete image can be displayed, but in black and white. By default, it is the standard for image and video compression. Therefore, in many scenarios, it is necessary to convert RGB format images into YUV format images first, because YUV format transmission saves bandwidth.
[0004] Some conversion methods in the prior art:
[0005] Y=p 11 *R+p 21 *G+p 31 *B+16
[0006] U=p 12 *R+p 22 *G+p 23 *B+128
[0007] V=p 13 *R+p 32 *G+p 33 *B+128
[0008] (YUV) = (RGB) * P
[0009] This is equivalent to having a transformation matrix P, where
[0010]
[0011] In the above formula, since the UV component may be a negative number, 128 is added.
[0012] In the above calculation process, each calculation involves multiplication and addition of floating-point numbers. Each pixel will undergo 9 multiplications and 6 additions, which is a huge amount of calculation for the computer. Summary of the invention
[0013] The purpose of the present invention is to overcome the deficiencies of the prior art and provide an image encoding and decoding method and device. The image encoding method reduces the floating point multiplication process in the prior art, thereby greatly reducing the amount of calculation and improving the calculation efficiency.
[0014] According to a first aspect of an embodiment of the present disclosure, there is provided an image encoding method, the method comprising:
[0015] Get the original image;
[0016] Obtaining the R component, the G component and the B component of the target pixel in the original image;
[0017] According to the R component, G component and B component of the target pixel point, the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point are searched in a preset table, and the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point are all integer data after being shifted left by A bits in binary, 10≤A≤23;
[0018] Calculate the integer data of the Y component, U component and V component of the target pixel after they are left-shifted by A bits in binary according to the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel;
[0019] The YUV of the target pixel is calculated according to the integer data of the Y component, U component and V component of the target pixel which are all binary-left shifted by A bits and binary-right shifted by A bits.
[0020] Since the coefficients are fixed during the conversion of RGB to YUV, and the value range of the R component, G component, and B component is 0 to 255, the result of multiplying each fixed R component, G component, and B component by the fixed coefficient is also fixed. Therefore, the image encoding method in the disclosed embodiment can set a parameter matrix to store 255*3*3 integers, and replace floating-point multiplication and floating-point addition with table lookup, thereby reducing the amount of calculation and saving calculation time. In the case of saving bandwidth in YUV transmission, timeliness is guaranteed as much as possible.
[0021] In one embodiment, the querying of the R component, G component and B component of the target pixel in a preset table according to the R component, G component and B component of the target pixel, and the integer data of the Y component, U component and V component corresponding to each of the R component, G component and B component of the target pixel after being shifted left by A bits in binary comprises:
[0022] According to the R component of the target pixel point, query the first preset table for integer data of the Y component, U component and V component corresponding to the R component of the target pixel point after being shifted left by A bits in binary;
[0023] According to the G component of the target pixel point, query the second preset table for integer data of the Y component, U component and V component corresponding to the G component of the target pixel point after being shifted left by A bits in binary;
[0024] According to the B component of the target pixel point, the Y component, U component and V component corresponding to the B component of the target pixel point are queried in the third preset table, all of which are integer data after being left-shifted by A bits in binary.
[0025] In one embodiment, the step of calculating the integer data of the Y component, U component and V component of the target pixel after being shifted left by A bits in binary according to the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel respectively, comprises:
[0026] Calculate the integer data of the Y component of the target pixel after being shifted left by A bits in binary according to the integer data of the Y component corresponding to the R component after being shifted left by A bits in binary, the integer data of the Y component corresponding to the G component after being shifted left by A bits in binary, the integer data of the Y component corresponding to the B component after being shifted left by A bits in binary, and the first calculation formula;
[0027] Calculate the integer data of the U component of the target pixel after being shifted left by A bits in binary according to the integer data of the U component corresponding to the R component after being shifted left by A bits in binary, the integer data of the U component corresponding to the G component after being shifted left by A bits in binary, and the second calculation formula;
[0028] According to the integer data of the V component corresponding to the R component after being binary-shifted left by A bits, the integer data of the V component corresponding to the G component after being binary-shifted left by A bits, the integer data of the V component corresponding to the B component after being binary-shifted left by A bits, and the third calculation formula, calculate the integer data of the V component of the target pixel after being binary-shifted left by A bits.
[0029] In one embodiment, the method comprises:
[0030] The first preset table includes a mapping relationship between the R component and the integer data after its projection on the Y component is shifted left by A bits in binary, the R component and the integer data after its projection on the U component is shifted left by A bits in binary, and the R component and the integer data after its projection on the V component is shifted left by A bits in binary;
[0031] The second preset table includes a mapping relationship between the G component and the integer data after its projection on the Y component is shifted left by A bits in binary, the G component and the integer data after its projection on the U component is shifted left by A bits in binary, and the G component and the integer data after its projection on the V component is shifted left by A bits in binary;
[0032] The third preset table contains the mapping relationship between the B component and the integer data after its projection on the Y component is binary shifted left by A bits, the B component and the integer data after its projection on the U component is binary shifted left by A bits, and the B component and the integer data after its projection on the V component is binary shifted left by A bits.
[0033] In one embodiment,
[0034] The first calculation formula is:
[0035] Y(int)=RY(int)+GY(int)+BY(int);
[0036] Among them, Y(int) is the integer data of the Y component of the target pixel after being shifted left by A bits in binary, RY(int) is the integer data of the Y component corresponding to the R component of the target pixel after being shifted left by A bits in binary, GY(int) is the integer data of the Y component corresponding to the G component of the target pixel after being shifted left by A bits in binary, BY(int) is the integer data of the Y component corresponding to the B component of the target pixel after being shifted left by A bits in binary;
[0037] The second calculation formula is:
[0038] U(int)=RU(int)+GU(int)+BU(int);
[0039] Among them, U(int) is the integer data of the U component of the target pixel after being shifted left by A bits in binary, RU(int) is the integer data of the U component corresponding to the R component of the target pixel after being shifted left by A bits in binary, GU(int) is the integer data of the U component corresponding to the G component of the target pixel after being shifted left by A bits in binary, and BU(int) is the integer data of the U component corresponding to the B component of the target pixel after being shifted left by A bits in binary;
[0040] The third calculation formula is:
[0041] V(int)=RV(int)+GV(int)+BV(int);
[0042] Among them, V(int) is the integer data of the V component of the target pixel after being shifted left by A bits in binary system, RV(int) is the integer data of the V component corresponding to the R component of the target pixel after being shifted left by A bits in binary system, GV(int) is the integer data of the V component corresponding to the G component of the target pixel after being shifted left by A bits in binary system, and BV(int) is the integer data of the V component corresponding to the B component of the target pixel after being shifted left by A bits in binary system.
[0043] In one embodiment, the calculating the YUV of the target pixel point according to the integer data of the Y component, the U component and the V component of the target pixel point after being binary-left-shifted by A bits and binary-right-shifted by A bits comprises:
[0044] The Y component of the target pixel is calculated according to the integer data of the Y component of the target pixel after the binary left shift A bits, according to the value of the integer data after the binary right shift A bits, and the fourth calculation formula; wherein the fourth calculation formula is:
[0045] Y = Y1 + 16;
[0046] Wherein, Y is the Y component of the target pixel, and Y1 is the value of the integer data of the Y component of the target pixel after being shifted left by A bits in binary and right by A bits in binary;
[0047] The U component of the target pixel is calculated according to the integer data of the U component of the target pixel after binary left shift A bits, according to the value of the integer data after binary right shift A bits, and the fifth calculation formula; wherein the fifth calculation formula is:
[0048] U=U1+128;
[0049] Among them, U is the U component of the target pixel, and U1 is the value of the integer data of the U component of the target pixel after being shifted left by A bits in binary and right by A bits in binary;
[0050] The V component of the target pixel is calculated according to the value of the integer data after the V component of the target pixel is shifted left by A bits in binary, and the sixth calculation formula after the integer data is shifted right by A bits in binary; wherein the sixth calculation formula is:
[0051] V = V1 + 128;
[0052] Among them, V is the V component of the target pixel, and V1 is the value of the integer data of the V component of the target pixel after being shifted left by A bits in binary and right by A bits in binary.
[0053] In the image encoding method of the disclosed embodiment, the encoding end only needs to store 255×3×3=2295 integers, and replaces floating-point multiplication and addition with a table lookup, thereby reducing the amount of calculation and saving calculation time. When the YUV transmission saves bandwidth, timeliness is guaranteed as much as possible.
[0054] According to a second aspect of an embodiment of the present disclosure, there is provided an image encoding device, the image encoding device comprising:
[0055] A first acquisition module acquires the original image;
[0056] A second acquisition module acquires an R component, a G component, and a B component of a target pixel in the original image;
[0057] The first query module queries the preset table for the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point according to the R component, G component and B component of the target pixel point, and the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point are all integer data after being shifted left by A bits in binary, 10≤A≤23;
[0058] A first calculation module calculates the integer data of the Y component, U component and V component of the target pixel after being shifted left by A bits in binary according to the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel after being shifted left by A bits in binary;
[0059] The second calculation module calculates the YUV of the target pixel point according to the integer data of the Y component, U component and V component of the target pixel point after being binary-left-shifted by A bits and binary-right-shifted by A bits.
[0060] According to a third aspect of an embodiment of the present disclosure, an image decoding method corresponding to the above-mentioned image encoding method is provided, and the image decoding method includes:
[0061] Get the Y component, U component and V component of the target pixel;
[0062] According to the Y component, U component and V component of the target pixel point, query the preset table for the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point;
[0063] The RGB of the target pixel is calculated according to the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel.
[0064] In the image decoding method in the disclosed embodiment, 255*3*3 integers are stored at the decoding end, and floating-point multiplication and addition are replaced by table lookup, which reduces the amount of calculation and saves calculation time. While saving bandwidth in YUV transmission, timeliness is guaranteed as much as possible.
[0065] According to a fourth aspect of an embodiment of the present disclosure, there is provided an image decoding device, the image decoding device comprising:
[0066] The third acquisition module acquires the Y component, U component and V component of the target pixel;
[0067] A second query module queries the preset table for the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point according to the Y component, U component and V component of the target pixel point;
[0068] The third calculation module calculates the RGB of the target pixel point according to the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] 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.
[0070] Figure 1 A schematic diagram of an image encoding system provided in an embodiment of the present disclosure.
[0071] Figure 2 A flowchart of an image encoding method provided by an embodiment of the present disclosure.
[0072] Figure 3 An architectural diagram of an image encoding device provided in an embodiment of the present disclosure.
[0073] Figure 4 A flowchart of an image decoding method provided by an embodiment of the present disclosure.
[0074] Figure 5 An architectural diagram of an image decoding device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0075] 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.
[0076] Figure 1 FIG. 1 is a schematic diagram of an image coding system provided by an embodiment of the present disclosure. Figure 1 As shown, the system includes a source end 101, a collection end 102, an encoder 103, a decoder 104 and a display 105. The collector 102 collects the picture, that is, the original image, from the source end 101. The original image may be in RGB format or YUV format. If it is in YUV format, it is directly encoded by the encoder 103 and transmitted to the decoder 104. The decoder 104 decodes and restores the YUV format to RGB format, and then displays it on the display 105.
[0077] The image encoding method described in the embodiment of the present disclosure is applied to format conversion after image acquisition and format restoration after decoding.
[0078] It should be noted that the above-mentioned system in the embodiment of the present disclosure is an example of a scenario to which the image encoding method and the image decoding method in the embodiment of the present disclosure are applicable. The image encoding method and the image decoding method in the embodiment of the present disclosure can also be applied to any scenario that requires format conversion of the image, and the present disclosure does not limit the usage scenario.
[0079] Figure 2 The following is a flowchart of an image encoding method provided by an embodiment of the present disclosure. Figure 2 As shown, the method includes:
[0080] Step 101, obtaining an original image;
[0081] The original image contains M×N pixels, where M and N are both positive integers;
[0082] It should be noted that if the original image is in YUV format, the conversion process ends. If the original image is in RGB format, step 102 is executed.
[0083] Step 102, obtaining the R component, G component and B component of the target pixel in the original image;
[0084] In this step, the R component value Rij, the G component value Gij and the B component value Bij of the i×j-th pixel in the original RGB image are obtained; wherein 1≤i≤M, 1≤j≤N.
[0085] Step 103, according to the R component, G component and B component of the target pixel point, query the preset table to obtain the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point respectively after the Y component, U component and V component are shifted left by A bits in binary, 10≤A≤23;
[0086] It should be noted that if A in this step is too large, overflow will occur, and if A is too small, the accuracy will be relatively reduced. The embodiment of the present disclosure takes A as 23 as an example for explanation.
[0087] In one embodiment, the querying of the R component, G component and B component of the target pixel in a preset table according to the R component, G component and B component of the target pixel, and the integer data of the Y component, U component and V component corresponding to each of the R component, G component and B component of the target pixel after being shifted left by A bits in binary comprises:
[0088] According to the R component of the target pixel point, query the first preset table for integer data of the Y component, U component and V component corresponding to the R component of the target pixel point after being shifted left by A bits in binary;
[0089] As shown in Table 1, the first preset table contains the mapping relationship between the R component and the integer data after its projection on the Y component is shifted left by 23 bits in binary, the R component and the integer data after its projection on the U component is shifted left by 23 bits in binary, and the R component and the integer data after its projection on the V component is shifted left by 23 bits in binary;
[0090] Table 1 shows the integer data corresponding to each Rij value after the projection RijY on the Y component, the projection RijU on the U component and the projection RijV on the V component are shifted left by 23 bits in binary.
[0091] Rij value RijY(int) RijU(int) RijV(int) 0 0 0 0 1 2155872 -1241513 3682598 2 4311744 -2483027 7365197 …… …… …… …… 254 547591553 -315344551 935380123 255 579747425 -316586065 939062722
[0092] In Table 1, R ij Represents the R component value of the i×j-th pixel, R ij Y(int) represents the integer data after the projection of the R component value of the i×j-th pixel on the Y component is shifted 23 bits to the left in binary format; R ij U(int) represents the integer data after the projection of the R component value of the i×j-th pixel on the U component is shifted left by 23 bits in binary format; R ij V(int) represents the integer data after the projection of the R component value of the i×j-th pixel on the V component is shifted left by 23 bits in binary.
[0093] According to the G component of the target pixel point, query the second preset table for integer data of the Y component, U component and V component corresponding to the G component of the target pixel point after being shifted left by A bits in binary;
[0094] As shown in Table 2, the second preset table includes a mapping relationship between the G component and the integer data after the projection of the Y component is shifted left by 23 bits in binary, the G component and the integer data after the projection of the U component is shifted left by 23 bits in binary, and the G component and the integer data after the projection of the V component is shifted left by 23 bits in binary;
[0095] Table 2 shows the ij The projection G of the Y component ij Y, projection G on the U component ij U and the projection G on the V component ij V is the integer data corresponding to the binary data after being shifted left by 23 bits.
[0096] Gij value GijY(int) GijU(int) GijV(int) 0 0 0 0 1 4227858 -2441084 -3087007 2 8455716 4882169 -6174015 …… …… …… …… 200 845571686 -488216985 -617401548 …… …… …… …… 255 1078103900 -622476656 -787186974
[0097] In Table 2, G ij Represents the G component value of the i×j-th pixel, G ij Y(int) represents the integer data after the projection of the G component value of the i×j-th pixel on the Y component is shifted 23 bits to the left in binary format; Gij U(int) represents the integer data after the projection of the G component value of the i×j-th pixel on the U component is shifted left by 23 bits in binary format; G ij V(int) represents the integer data after the projection of the G component value of the i×j-th pixel on the V component is shifted left by 23 bits in binary format;
[0098] According to the B component of the target pixel point, the Y component, U component and V component corresponding to the B component of the target pixel point are queried in the third preset table, all of which are integer data after being left-shifted by A bits in binary.
[0099] As shown in Table 3, the third preset table contains the mapping relationship between the B component and the integer data after its projection on the Y component is binary shifted left by A bits, the B component and the integer data after its projection on the U component is binary shifted left by A bits, and the B component and the integer data after its projection on the V component is binary shifted left by A bits.
[0100] Table 3 shows the integer data corresponding to the projection BijY of each Bij value on the Y component, the projection BijU of the U component and the projection BijV of the V component after being shifted left by 23 bits in binary.
[0101] Bij value BijY(int) BijU(int) BijV(int) 0 0 0 0 1 822083 3682598 -595591 2 1644167 7365197 -1191182 …… …… …… …… 233 191545475 858045546 -138772742 …… …… …… …… 255 209631313 939062722 -151875747
[0102] In Table 3, B ij Indicates the B component value of the i×j-th pixel, B ij Y(int) represents the integer data after the projection of the B component value of the i×j-th pixel on the Y component is shifted left by 23 bits in binary; B ij U(int) represents the integer data after the projection of the R component value of the i×j-th pixel on the B component is shifted left by 23 bits in binary; B ij V(int) represents the integer data after the projection of the B component value of the i×j-th pixel on the V component is shifted left by 23 bits in binary.
[0103] According to the data in Tables 1 to 3 above, in the image encoding method in the disclosed embodiment, the encoding end only needs to store 255×3×3=2295 integers, and replaces floating-point multiplication and floating-point addition with table lookup, which reduces the amount of calculation and saves calculation time. When the YUV transmission saves bandwidth, timeliness is guaranteed as much as possible.
[0104] Step 104, calculating the integer data of the Y component, U component and V component of the target pixel after being shifted left by A bits in binary system according to the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel after being shifted left by A bits in binary system;
[0105] In one embodiment, the step of calculating the integer data of the Y component, U component and V component of the target pixel after being shifted left by A bits in binary according to the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel respectively, comprises:
[0106] Calculate the integer data of the Y component of the target pixel after being shifted left by A bits in binary according to the integer data of the Y component corresponding to the R component after being shifted left by A bits in binary, the integer data of the Y component corresponding to the G component after being shifted left by A bits in binary, the integer data of the Y component corresponding to the B component after being shifted left by A bits in binary, and the first calculation formula;
[0107] Calculate the integer data of the U component of the target pixel after being shifted left by A bits in binary according to the integer data of the U component corresponding to the R component after being shifted left by A bits in binary, the integer data of the U component corresponding to the G component after being shifted left by A bits in binary, and the second calculation formula;
[0108] According to the integer data of the V component corresponding to the R component after being binary-shifted left by A bits, the integer data of the V component corresponding to the G component after being binary-shifted left by A bits, the integer data of the V component corresponding to the B component after being binary-shifted left by A bits, and the third calculation formula, calculate the integer data of the V component of the target pixel after being binary-shifted left by A bits.
[0109] In one embodiment, the first calculation formula is:
[0110] Y(int)=RY(int)+GY(int)+BY(int);
[0111] Among them, Y(int) is the integer data of the Y component of the target pixel after being shifted left by A bits in binary, RY(int) is the integer data of the Y component corresponding to the R component of the target pixel after being shifted left by A bits in binary, GY(int) is the integer data of the Y component corresponding to the G component of the target pixel after being shifted left by A bits in binary, BY(int) is the integer data of the Y component corresponding to the B component of the target pixel after being shifted left by A bits in binary;
[0112] The second calculation formula is:
[0113] U(int)=RU(int)+GU(int)+BU(int);
[0114] Among them, U(int) is the integer data of the U component of the target pixel after being shifted left by A bits in binary, RU(int) is the integer data of the U component corresponding to the R component of the target pixel after being shifted left by A bits in binary, GU(int) is the integer data of the U component corresponding to the G component of the target pixel after being shifted left by A bits in binary, and BU(int) is the integer data of the U component corresponding to the B component of the target pixel after being shifted left by A bits in binary;
[0115] The third calculation formula is:
[0116] V(int)=RV(int)+GV(int)+BV(int);
[0117] Among them, V(int) is the integer data of the V component of the target pixel after being shifted left by A bits in binary system, RV(int) is the integer data of the V component corresponding to the R component of the target pixel after being shifted left by A bits in binary system, GV(int) is the integer data of the V component corresponding to the G component of the target pixel after being shifted left by A bits in binary system, and BV(int) is the integer data of the V component corresponding to the B component of the target pixel after being shifted left by A bits in binary system.
[0118] Step 105 , calculate the YUV of the target pixel point according to the integer data of the Y component, U component and V component of the target pixel point after being binary-left-shifted by A bits and binary-right-shifted by A bits.
[0119] In one embodiment, the calculating the YUV of the target pixel point according to the integer data of the Y component, the U component and the V component of the target pixel point after being binary-left-shifted by A bits and binary-right-shifted by A bits comprises:
[0120] The Y component of the target pixel is calculated according to the integer data of the Y component of the target pixel after the binary left shift A bits, according to the value of the integer data after the binary right shift A bits, and the fourth calculation formula; wherein the fourth calculation formula is:
[0121] Y = Y1 + 16;
[0122] Wherein, Y is the Y component of the target pixel, and Y1 is the value of the integer data of the Y component of the target pixel after being shifted left by A bits in binary and right by A bits in binary;
[0123] The U component of the target pixel is calculated according to the integer data of the U component of the target pixel after binary left shift A bits, according to the value of the integer data after binary right shift A bits, and the fifth calculation formula; wherein the fifth calculation formula is:
[0124] U=U1+128;
[0125] Among them, U is the U component of the target pixel, and U1 is the value of the integer data of the U component of the target pixel after being shifted left by A bits in binary and right by A bits in binary;
[0126] The V component of the target pixel is calculated according to the value of the integer data after the V component of the target pixel is shifted left by A bits in binary, and the sixth calculation formula after the integer data is shifted right by A bits in binary; wherein the sixth calculation formula is:
[0127] V = V1 + 128;
[0128] Among them, V is the V component of the target pixel, and V1 is the value of the integer data of the V component of the target pixel after being shifted left by A bits in binary and right by A bits in binary.
[0129] Since the coefficients are fixed during the conversion of RGB to YUV, and the value range of the R component, G component, and B component is 0 to 255, the result of multiplying each fixed R component, G component, and B component by the fixed coefficient is also fixed. Therefore, the image encoding method in the disclosed embodiment can set a parameter matrix to store 255*3*3 integers, and replace floating-point multiplication and floating-point addition with table lookup, thereby reducing the amount of calculation and saving calculation time. In the case of saving bandwidth in YUV transmission, timeliness is guaranteed as much as possible.
[0130] Optionally, the method further comprises:
[0131] The Y component of the target pixel point, the U component of the target pixel point, and the V component of the target pixel point are rounded to integers to obtain the YUV of the target pixel point.
[0132] It should be noted that, in the embodiments of the present disclosure, there is no restriction on the order of querying the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point in the preset table according to the R component, G component and B component of the target pixel point, and calculating the YUV of the target pixel point according to the integer data after the binary left shift A bits, the integer data after the binary left shift A bits, and the integer data after the binary left shift A bits of the Y component corresponding to the R component, G component and B component of the target pixel point.
[0133] Based on the above Figure 2 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 image encoding method disclosed herein.
[0134] Figure 3 FIG. 1 is a diagram of an architecture of an image encoding device provided by an embodiment of the present disclosure. Figure 3As shown, the image encoding device includes a first acquisition module 301, a second acquisition module 302, a first query module 303, a first calculation module 304, and a second calculation module 305; the first acquisition module 301 is used to acquire an original image, wherein the original image contains M×N pixels, wherein M and N are both positive integers; the second acquisition module 302 is used to acquire the R component, G component and B component of the target pixel in the original image; the first query module 303 is used to query the R component, G component and B component of the target pixel in a preset table according to the R component, G component and B component of the target pixel. The corresponding Y component, U component and V component are all integer data after binary left shift A bits, 10≤A≤23; the first calculation module 304 is used to calculate the integer data of the Y component, U component and V component of the target pixel point according to the integer data after binary left shift A bits of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point; the second calculation module 305 is used to calculate the YUV of the target pixel point according to the integer data after binary left shift A bits of the Y component, U component and V component of the target pixel point according to the value after binary right shift A bits.
[0135] Figure 4 The following is a flowchart of an image encoding method provided by an embodiment of the present disclosure. Figure 4 As shown, the method includes:
[0136] Step 401, obtaining the Y component, U component and V component of the target pixel;
[0137] Step 402: Look up the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel in a preset table according to the Y component, U component and V component of the target pixel;
[0138] Step 403: Calculate the RGB of the target pixel according to the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel.
[0139] Based on the above Figure 4 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 image decoding method disclosed herein.
[0140] Figure 5 FIG. 1 is an architecture diagram of an image decoding device provided by an embodiment of the present disclosure. Figure 5As shown, the image encoding device includes a third acquisition module 501, a second query module 502, and a third calculation module 503; wherein the third acquisition module 501 is used to obtain the Y component, U component and V component of the target pixel point; the second query module 502 is used to query the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point in a preset table according to the Y component, U component and V component of the target pixel point; the third calculation module 503 is used to calculate the RGB of the target pixel point according to the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point.
[0141] The image encoding and decoding methods of the embodiments of the present disclosure are exemplarily described below using pixel point i×j.
[0142] For example, the RGB components of pixel i×j are (255, 200, 233);
[0143] First, the Y component of pixel i×j is calculated as the integer data Y(int) after binary left shift 23 bits:
[0144] Y ij (int)=RY(int)+GY(int)+BY(int)=579747425+
[0145] 845571686+191545475=1095064602;
[0146] Among them, RY(int) is the integer data of the Y component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GY(int) is the integer data of the Y component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, BY(int) is the integer data of the Y component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary;
[0147] The integer data U (int) of the U component of pixel i×j after binary left shift 23 bits is:
[0148] U ij (int)=RU(int)+GU(int)+BU(int)=-316586065+
[0149] (-488216985)+858045546=54484010;
[0150] RU(int) is the integer data of the U component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GU(int) is the integer data of the U component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, BU(int) is the integer data of the U component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary;
[0151] The integer data of the V component of pixel i×j after binary left shift 23 bits is:
[0152] V ij (int)=RV(int)+GV(int)+BV(int)=939062722+
[0153] (-617401548)+(-138772742)=182888432;
[0154] Among them, RV(int) is the integer data of the V component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary system, GV(int) is the integer data of the V component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary system, and BV(int) is the integer data of the V component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary system.
[0155] Then for Y ij (int), U ij (int) and V ij (int) is shifted right by 23 bits according to the binary system, and rounded to the integer. The calculation result is:
[0156] The value Y1 of the integer data of the target pixel after the binary left shift is 23 bits and the binary right shift is 23 bits is 189;
[0157] The value U1 of the integer data of the target pixel after the binary left shift is 23 bits and the binary right shift is 23 bits is 6;
[0158] The value V1 of the integer data of the target pixel after the binary left shift of 23 bits and the binary right shift of 23 bits is 21;
[0159] Finally, the Y component of the target pixel is calculated according to the integer data after the binary left shift of 23 bits, the value Y1 after the binary right shift of 23 bits, and the following formula:
[0160] Y=Y1+16=189+16=205;
[0161] According to the U component of the target pixel point, the integer data after binary left shift A bits, and the value U1 after binary right shift 23 bits, and the following formula, the U component of the target pixel point is calculated as:
[0162] U = U1 + 128 = 6 + 128 = 134;
[0163] According to the V component of the target pixel point, the integer data after binary left shift 23 bits is converted to the value V1 after binary right shift 23 bits, and the following formula is used to calculate the V component of the target pixel point:
[0164] V=V1+128=21+128=149
[0165] When restoring color format,
[0166] R = q 11 (Y-16)+q 12 (U-128)+q 13 (V-128)
[0167] U=q 21 (Y-16)+q 22 (U-128)+q 23 (V-128)
[0168] R = q 31 (Y-16)+q 32 (U-128)+q 33 (V-128)
[0169] Among them, q is the restoration coefficient, and the restoration coefficient matrix is the inverse matrix of the conversion matrix, that is:
[0170] Q=P -1 .
[0171] in,
[0172] Similarly, by rounding off after calculation, the RGB value can be restored and the image can be displayed.
[0173] It can be seen that the decoding end of the embodiment of the present disclosure stores 255*3*3 integers, and replaces floating-point multiplication and floating-point addition with table lookup, which reduces the amount of calculation and saves calculation time. When the YUV transmission saves bandwidth, timeliness is guaranteed as much as possible.
[0174] Specifically, taking 1080P resolution (that is, 1920*1080) as an example, after computer testing, the processing time for one frame of image in an office scenario is shown in the following table:
[0175] plan Processing time Prior art 10.932400 (ms) - Embodiments of the present invention 6.602200(ms) ffmpeg 7.176500 (ms) libyuv 8.693800 (ms)
[0176] Among them, libyuv is a Google open source library that implements various YUV and RGB conversion, rotation, and scaling. FFmpeg is a set of open source computer programs that can be used to record, convert digital audio and video, and convert them into streams. It includes the current leading audio / video encoding library libavcodec.
[0177] Specifically, taking 1080P resolution (that is, 1920*1080) as an example, after computer testing, the processing time for one frame of image in the picture scene is shown in the following table:
[0178]
[0179]
[0180] It can be seen from the test results that in the picture scenario, the solution provided by this embodiment is also the most time-saving.
[0181] It can be determined from the test values in the table that the image encoding method and the image decoding method provided by the embodiments of the present disclosure take the shortest time to process a frame of image.
[0182] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The above-mentioned program can be pre-stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the above-mentioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0183] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the disclosure disclosed herein. The present disclosure 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 to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0184] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An image coding method, characterized in that: The method comprises: Get the original image; Obtaining the R component, the G component and the B component of the target pixel in the original image; According to the R component, G component and B component of the target pixel point, the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point are searched in a preset table, and the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point are all integer data after being shifted left by A bits in binary, 10≤A≤23; Calculate the integer data of the Y component, U component and V component of the target pixel after they are left-shifted by A bits in binary according to the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel; Calculate the YUV of the target pixel point according to the integer data of the Y component, U component and V component of the target pixel point after they are all shifted left by A bits in binary and right by A bits in binary; The step of searching the preset table for the R component, G component and B component of the target pixel point and obtaining the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point after the Y component, U component and V component are shifted left by A bits in binary includes: According to the R component of the target pixel point, query the first preset table for integer data of the Y component, U component and V component corresponding to the R component of the target pixel point after being shifted left by A bits in binary; According to the G component of the target pixel point, query the second preset table for integer data of the Y component, U component and V component corresponding to the G component of the target pixel point after being shifted left by A bits in binary; According to the B component of the target pixel, query the third preset table for integer data of the Y component, U component and V component corresponding to the B component of the target pixel, all of which are left-shifted by A bits in binary; The first preset table includes a mapping relationship between the R component and the integer data after its projection on the Y component is shifted left by A bits in binary, the R component and the integer data after its projection on the U component is shifted left by A bits in binary, and the R component and the integer data after its projection on the V component is shifted left by A bits in binary; The second preset table includes a mapping relationship between the G component and the integer data after its projection on the Y component is shifted left by A bits in binary, the G component and the integer data after its projection on the U component is shifted left by A bits in binary, and the G component and the integer data after its projection on the V component is shifted left by A bits in binary; The third preset table contains the mapping relationship between the B component and the integer data after its projection on the Y component is binary shifted left by A bits, the B component and the integer data after its projection on the U component is binary shifted left by A bits, and the B component and the integer data after its projection on the V component is binary shifted left by A bits.
2. The method according to claim 1, characterized in that The step of calculating the integer data of the Y component, U component and V component of the target pixel after being shifted left by A bits in binary according to the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel respectively, comprising: Calculate the integer data of the Y component of the target pixel after being shifted left by A bits in binary according to the integer data of the Y component corresponding to the R component after being shifted left by A bits in binary, the integer data of the Y component corresponding to the G component after being shifted left by A bits in binary, the integer data of the Y component corresponding to the B component after being shifted left by A bits in binary, and the first calculation formula; Calculate the integer data of the U component of the target pixel after being shifted left by A bits in binary according to the integer data of the U component corresponding to the R component after being shifted left by A bits in binary, the integer data of the U component corresponding to the G component after being shifted left by A bits in binary, and the second calculation formula; According to the integer data of the V component corresponding to the R component after being binary-shifted left by A bits, the integer data of the V component corresponding to the G component after being binary-shifted left by A bits, the integer data of the V component corresponding to the B component after being binary-shifted left by A bits, and the third calculation formula, calculate the integer data of the V component of the target pixel after being binary-shifted left by A bits.
3. The method according to claim 2, characterized in that The first calculation formula is: Y(int)=RY(int)+GY(int)+BY(int); Among them, Y(int) is the integer data of the Y component of the target pixel after being shifted left by A bits in binary, RY(int) is the integer data of the Y component corresponding to the R component of the target pixel after being shifted left by A bits in binary, GY(int) is the integer data of the Y component corresponding to the G component of the target pixel after being shifted left by A bits in binary, BY(int) is the integer data of the Y component corresponding to the B component of the target pixel after being shifted left by A bits in binary; The second calculation formula is: U(int)=RU(int)+GU(int)+BU(int); Among them, U(int) is the integer data of the U component of the target pixel after being shifted left by A bits in binary, RU(int) is the integer data of the U component corresponding to the R component of the target pixel after being shifted left by A bits in binary, GU(int) is the integer data of the U component corresponding to the G component of the target pixel after being shifted left by A bits in binary, and BU(int) is the integer data of the U component corresponding to the B component of the target pixel after being shifted left by A bits in binary; The third calculation formula is: V(int)=RV(int)+GV(int)+BV(int); Among them, V(int) is the integer data of the V component of the target pixel after being shifted left by A bits in binary system, RV(int) is the integer data of the V component corresponding to the R component of the target pixel after being shifted left by A bits in binary system, GV(int) is the integer data of the V component corresponding to the G component of the target pixel after being shifted left by A bits in binary system, and BV(int) is the integer data of the V component corresponding to the B component of the target pixel after being shifted left by A bits in binary system.
4. The method according to claim 3, characterized in that: Calculating the YUV of the target pixel point according to the integer data of the Y component, U component and V component of the target pixel point after being binary-left-shifted by A bits and binary-right-shifted by A bits includes: The Y component of the target pixel is calculated according to the integer data of the Y component of the target pixel after the binary left shift A bits, according to the value of the integer data after the binary right shift A bits, and the fourth calculation formula; wherein the fourth calculation formula is: Y = Y1 + 16; Wherein, Y is the Y component of the target pixel, and Y1 is the value of the integer data of the Y component of the target pixel after being shifted left by A bits in binary and right by A bits in binary; The U component of the target pixel is calculated according to the integer data of the U component of the target pixel after binary left shift A bits, according to the value of the integer data after binary right shift A bits, and the fifth calculation formula; wherein the fifth calculation formula is: U=U1+128; Among them, U is the U component of the target pixel, and U1 is the value of the integer data of the U component of the target pixel after being shifted left by A bits in binary and right by A bits in binary; The V component of the target pixel is calculated according to the value of the integer data after the V component of the target pixel is shifted left by A bits in binary, and the sixth calculation formula after the integer data is shifted right by A bits in binary; wherein the sixth calculation formula is: V = V1 + 128; Among them, V is the V component of the target pixel, and V1 is the value of the integer data of the V component of the target pixel after being shifted left by A bits in binary and right by A bits in binary.
5. An image encoding device, characterized in that: The image encoding device comprises: A first acquisition module acquires the original image; A second acquisition module acquires an R component, a G component, and a B component of a target pixel in the original image; The first query module queries the preset table for the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point according to the R component, G component and B component of the target pixel point, and the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point are all integer data after being shifted left by A bits in binary, 10≤A≤23; A first calculation module calculates the integer data of the Y component, U component and V component of the target pixel after being shifted left by A bits in binary according to the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel after being shifted left by A bits in binary; The second calculation module calculates the YUV of the target pixel point according to the integer data of the Y component, U component and V component of the target pixel point after being binary-right-shifted by A bits according to the binary-left shift of A bits; The step of searching the preset table for the R component, G component and B component of the target pixel point and obtaining the integer data of the Y component, U component and V component corresponding to the R component, G component and B component of the target pixel point after the Y component, U component and V component are shifted left by A bits in binary includes: According to the R component of the target pixel point, query the first preset table for integer data of the Y component, U component and V component corresponding to the R component of the target pixel point after being shifted left by A bits in binary; According to the G component of the target pixel point, query the second preset table for integer data of the Y component, U component and V component corresponding to the G component of the target pixel point after being shifted left by A bits in binary; According to the B component of the target pixel, query the third preset table for integer data of the Y component, U component and V component corresponding to the B component of the target pixel, all of which are left-shifted by A bits in binary; The first preset table includes a mapping relationship between the R component and the integer data after its projection on the Y component is shifted left by A bits in binary, the R component and the integer data after its projection on the U component is shifted left by A bits in binary, and the R component and the integer data after its projection on the V component is shifted left by A bits in binary; The second preset table includes a mapping relationship between the G component and the integer data after its projection on the Y component is shifted left by A bits in binary, the G component and the integer data after its projection on the U component is shifted left by A bits in binary, and the G component and the integer data after its projection on the V component is shifted left by A bits in binary; The third preset table contains the mapping relationship between the B component and the integer data after its projection on the Y component is binary shifted left by A bits, the B component and the integer data after its projection on the U component is binary shifted left by A bits, and the B component and the integer data after its projection on the V component is binary shifted left by A bits.
6. An image decoding method corresponding to the image encoding method according to any one of claims 1 to 4, characterized in that: The image decoding method comprises: Get the Y component, U component and V component of the target pixel; According to the Y component, U component and V component of the target pixel point, query the preset table for the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point; Calculate the RGB of the target pixel according to the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel; Calculating the RGB of the target pixel point according to the R component, the G component, and the B component corresponding to the Y component, the U component, and the V component of the target pixel point includes: The Y component of pixel i×j is calculated as the integer data Y(int) after binary left shift 23 bits: Y ij (int)=RY(int)+GY(int)+BY(int); Among them, RY(int) is the integer data of the Y component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GY(int) is the integer data of the Y component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, BY(int) is the integer data of the Y component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary; The integer data U (int) of the U component of pixel i×j after binary left shift 23 bits is: And ij (int)=RU(int)+GU(int)+BU(int); RU(int) is the integer data of the U component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GU(int) is the integer data of the U component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, BU(int) is the integer data of the U component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary; The integer data of the V component of pixel i×j after binary left shift 23 bits is: V ij (int)=RV(int)+GV(int)+BV(int); Among them, RV(int) is the integer data of the V component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GV(int) is the integer data of the V component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, and BV(int) is the integer data of the V component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary; Y ij (int), U ij (int) and V ij (int) shift right 23 bits according to binary and round up; Calculate the Y component of the target pixel according to the integer data after the Y component of the target pixel is shifted left by 23 bits in binary and the value Y1 after the integer data is shifted right by 23 bits in binary; Calculate the U component of the target pixel according to the integer data after binary left shift A bits and the value U1 after binary right shift 23 bits; The V component of the target pixel is calculated according to the integer data after the V component of the target pixel is shifted left by 23 bits in binary and the value V1 after the integer data is shifted right by 23 bits in binary.
7. An image decoding device, characterized in that: The image decoding device comprises: The third acquisition module acquires the Y component, U component and V component of the target pixel; A second query module queries the preset table for the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point according to the Y component, U component and V component of the target pixel point; A third calculation module calculates the RGB of the target pixel point according to the R component, G component and B component corresponding to the Y component, U component and V component of the target pixel point; Calculating the RGB of the target pixel point according to the R component, the G component, and the B component corresponding to the Y component, the U component, and the V component of the target pixel point includes: The Y component of pixel i×j is calculated as the integer data Y(int) after binary left shift 23 bits: Y ij (int)=RY(int)+GY(int)+BY(int); Among them, RY(int) is the integer data of the Y component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GY(int) is the integer data of the Y component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, BY(int) is the integer data of the Y component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary; The integer data U (int) of the U component of pixel i×j after binary left shift 23 bits is: And ij (int)=RU(int)+GU(int)+BU(int); RU(int) is the integer data of the U component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GU(int) is the integer data of the U component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, BU(int) is the integer data of the U component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary; The integer data of the V component of pixel i×j after binary left shift 23 bits is: V ij (int)=RV(int)+GV(int)+BV(int); Among them, RV(int) is the integer data of the V component corresponding to the R component of pixel point i×j after being shifted left by 23 bits in binary, GV(int) is the integer data of the V component corresponding to the G component of pixel point i×j after being shifted left by 23 bits in binary, and BV(int) is the integer data of the V component corresponding to the B component of pixel point i×j after being shifted left by 23 bits in binary; Y ij (int), U ij (int) and V ij (int) shift right 23 bits according to binary and round up; Calculate the Y component of the target pixel according to the integer data after the Y component of the target pixel is shifted left by 23 bits in binary and the value Y1 after the integer data is shifted right by 23 bits in binary; Calculate the U component of the target pixel according to the integer data after binary left shift A bits and the value U1 after binary right shift 23 bits; Calculate the V component of the target pixel according to the integer data after the V component of the target pixel is shifted left by 23 bits in binary and the value V1 after the integer data is shifted right by 23 bits in binary; The image decoding device is used to execute the image decoding method according to claim 6.
Citation Information
Patent Citations
Color adjustment table system for YUV to RGB color conversion
US6172714B1