Image coding method and device
Through the generation of three-level wavelet transform and Huffman coding table, as well as the selection of coding methods for different sub-bands, the problem of slow image coding speed in the existing technology is solved, and the effects of fast coding and low bit rate are achieved.
Patent Information
- Application Number
- CN202011177335.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-28
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-10-28
Smart Images

Figure CN112422992B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing, and in particular to an image encoding method and device. Background Art
[0002] Currently, the image coding methods used for wavelet transform include: ECBOT used by JPEG2000, embedded zerotree wavelet (EZW) and set partitioning in hierarchical trees (SPIHT).
[0003] However, among the above encoding methods, the encoding method used by ECBOT is too slow; the encoding speed of EZW is also relatively slow; the SPIHT method requires that the length and width of the image are both 2 n , and the larger the image, the slower the encoding speed. Summary of the invention
[0004] The embodiment of the present disclosure provides an image encoding method and device, which can solve the problem of slow encoding speed when using wavelet transform to encode images in related technologies. 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] After performing three-level wavelet transform on the image, the LL3 subband is updated according to the preset update method;
[0007] Scan all sub-bands to obtain the occurrence frequency of a preset value, and generate a Huffman coding table according to the occurrence frequency;
[0008] encoding each of the sub-bands;
[0009] Obtaining a coded bitstream of the image according to the coded data corresponding to each of the sub-bands;
[0010] The step of encoding each of the sub-bands includes:
[0011] Obtain the subband to be encoded, and determine whether the current subband to be encoded is an LL3 subband;
[0012] If it is LL3 subband, Huffman coding is used for encoding;
[0013] If it is not the LL3 subband, the improved run length coding algorithm is used to encode and obtain the intermediate coded data;
[0014] The intermediate coded data is encoded using an adaptive arithmetic coding method.
[0015] The image encoding method provided by the embodiment of the present disclosure includes: after performing a three-level wavelet transform on the image, updating the LL3 subband according to a preset update method; scanning all subbands, obtaining the frequency of occurrence of a preset value, and generating a Huffman coding table according to the frequency of occurrence; encoding each subband; obtaining the encoded code stream of the image according to the encoded data corresponding to each subband; wherein encoding each subband includes: obtaining the subband to be encoded, judging whether the current subband to be encoded is an LL3 subband; if it is an LL3 subband, encoding using the Huffman coding method; if it is not an LL3 subband, encoding using an improved run length coding algorithm to obtain intermediate encoded data; encoding the intermediate encoded data using an adaptive arithmetic coding method. wherein, according to the characteristics of the image after the three-level wavelet transform, different encoding methods are used for different subbands, so that the effect of fast encoding speed and low code stream can be achieved.
[0016] In one embodiment, updating the LL3 subband according to a preset update method includes:
[0017] The result obtained by subtracting the adjacent previous element from the current element in the LL3 subband replaces the current element.
[0018] In one embodiment, if it is not the LL3 subband, encoding using an improved run length coding algorithm to obtain intermediate coded data includes:
[0019] The following encoding method is performed on each element to be encoded in the subband that is not the LL3 subband:
[0020] Determine whether the current element to be encoded is zero;
[0021] If the current element to be encoded is zero, increment the counter by one;
[0022] If the current element to be encoded is not zero, converting the value of the counter into a binary number;
[0023] Using a preset symbol to replace the binary digit to obtain replacement data;
[0024] clearing the counter;
[0025] The intermediate coded data of the current element to be coded is obtained according to the replacement data and the Huffman coding corresponding to the current element to be coded.
[0026] In one embodiment, the replacing the binary digit with a preset symbol to obtain replacement data includes:
[0027] Replace 1 in the binary number with a positive sign;
[0028] Use a minus sign to replace the 0 in the binary number.
[0029] In one embodiment, the preset value is a non-zero value.
[0030] According to a second aspect of an embodiment of the present disclosure, there is provided an image encoding apparatus, including:
[0031] An updating module, used for updating the LL3 subband according to a preset updating method after performing a three-level wavelet transform on the image;
[0032] A coding table generation module, used for scanning all sub-bands, obtaining the occurrence frequency of a preset value, and generating a Huffman coding table according to the occurrence frequency;
[0033] A coding module, used for encoding each of the sub-bands;
[0034] A code stream generation module, used for obtaining a coded code stream of the image according to the coded data corresponding to each of the sub-bands;
[0035] Wherein, the encoding module includes:
[0036] A first judgment submodule is used to obtain a subband to be encoded and judge whether the current subband to be encoded is an LL3 subband;
[0037] A first encoding submodule, configured to use Huffman encoding to encode the subband to be encoded if the subband to be encoded is an LL3 subband;
[0038] A second encoding submodule, configured to, if the subband to be encoded is not the LL3 subband, use an improved run-length encoding algorithm to encode to obtain intermediate encoded data;
[0039] The third encoding submodule is used to encode the intermediate coded data by using an adaptive arithmetic coding method.
[0040] In one embodiment, the update module includes:
[0041] The updating submodule is used to replace the current element in the LL3 subband with the result obtained by subtracting the adjacent previous element from the current element.
[0042] In one embodiment, the second encoding submodule includes:
[0043] The second judgment submodule is used to judge whether the current element to be encoded is zero;
[0044] A first processing submodule, configured to increase a counter by one if the current element to be encoded is zero;
[0045] A conversion submodule, configured to convert the value of the counter into a binary number if the current element to be encoded is not zero;
[0046] A replacement submodule, used for replacing the binary digits with preset symbols to obtain replacement data;
[0047] A second processing submodule, used for clearing the counter;
[0048] The acquisition submodule is used to obtain the intermediate coding data of the current element to be coded according to the replacement data and the Huffman coding corresponding to the current element to be coded.
[0049] In one embodiment, the replacement submodule includes:
[0050] A first replacement subunit, used for replacing 1 in the binary number with a positive sign;
[0051] The second replacing subunit is used to replace 0 in the binary number with a minus sign.
[0052] In one embodiment, the preset value is a non-zero value.
[0053] 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
[0054] 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.
[0055] Figure 1 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0056] Figure 2 is a schematic diagram of the distribution of each sub-band after a three-level wavelet transform provided by an embodiment of the present disclosure;
[0057] Figure 3 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0058] Figure 4 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0059] Figure 5 is a flowchart of an image encoding method provided by an embodiment of the present disclosure;
[0060] Figure 6 is a structural diagram of an image encoding device provided by an embodiment of the present disclosure;
[0061] Figure 7is a structural diagram of an update module in an image encoding device provided by an embodiment of the present disclosure;
[0062] Figure 8 It is a structural diagram of a second encoding submodule in an image encoding device provided by an embodiment of the present disclosure.
[0063] Fig. 9 It is a structural diagram of a replacement submodule in an image encoding device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0064] 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.
[0065] The present disclosure provides an image encoding method. Figure 1 As shown, the image encoding method comprises the following steps:
[0066] 101. After performing three-level wavelet transform on the image, the LL3 subband is updated according to a preset updating method.
[0067] Among them, after the image is transformed by three-level wavelet, the distribution of each subband is as follows: Figure 2 shown.
[0068] 102. Scan all sub-bands to obtain the occurrence frequency of a preset value, and generate a Huffman coding table according to the occurrence frequency.
[0069] For example, the preset value is a non-zero value. That is, all sub-bands are scanned, the occurrence frequencies of all values except 0 are counted, and a Huffman code table is generated according to the frequencies.
[0070] 103. Encode each sub-band.
[0071] 104. Obtain an encoded bitstream of the image according to the encoded data corresponding to each sub-band.
[0072] After statistics, it is found that the LL3 subband contains the least number of 0s, and the remaining subbands contain more 0s. Since the size of the encoded code will not be greatly affected after processing the subbands containing more 0s, the respective encoding algorithms are designed according to the characteristics of each subband. Specifically, encoding each subband includes the following sub-steps:
[0073] 1031. Obtain a subband to be encoded, and determine whether the current subband to be encoded is an LL3 subband.
[0074] 1032. If it is LL3 subband, Huffman coding is used for encoding.
[0075] 1033. If it is not an LL3 subband, use an improved run length coding algorithm to encode to obtain intermediate coded data.
[0076] 1034. Encode the intermediate coded data using adaptive arithmetic coding.
[0077] When it is determined that the current subband to be encoded is the LL3 subband, the Huffman coding method can be directly used for encoding. When it is determined that the current subband to be encoded is not the LL3 subband, the Runlength encoding (RLE) improved algorithm will be used for encoding to obtain intermediate encoded data, which can also be called an intermediate result, and then the intermediate result is encoded using an adaptive arithmetic coding method.
[0078] Among them, the encoding method using adaptive arithmetic coding is similar to that in the related art and will not be repeated here.
[0079] It is worth noting that the above steps 1031-1034 are executed in a loop, that is, after executing steps 1031-1034 for the current sub-band to be encoded, the encoded data corresponding to the current sub-band to be encoded is obtained, and then steps 1031-1034 are continued to be executed for the next sub-band to be encoded to obtain the encoded data corresponding to the next sub-band to be encoded, and so on, until all sub-bands to be encoded are processed.
[0080] In the process of obtaining the encoded code stream of the image, after encoding is performed on each sub-band to be encoded, the encoded data can be directly stored in the encoded code stream of the image, or after encoding is performed on all sub-bands to be encoded, the encoded data can be uniformly put into the encoded code stream of the image, and the present disclosure does not limit it.
[0081] The image encoding method provided by the embodiment of the present disclosure includes: after performing a three-level wavelet transform on the image, updating the LL3 subband according to a preset update method; scanning all subbands, obtaining the frequency of occurrence of a preset value, and generating a Huffman coding table according to the frequency of occurrence; encoding each subband; obtaining the encoded code stream of the image according to the encoded data corresponding to each subband; wherein encoding each subband includes: obtaining the subband to be encoded, judging whether the current subband to be encoded is an LL3 subband; if it is an LL3 subband, encoding using the Huffman coding method; if it is not an LL3 subband, encoding using an improved run length coding algorithm to obtain intermediate encoded data; encoding the intermediate encoded data using an adaptive arithmetic coding method. wherein, according to the characteristics of the image after the three-level wavelet transform, different encoding methods are used for different subbands, so that the effect of fast encoding speed and low code stream can be achieved.
[0082] In one embodiment, updating the LL3 subband according to a preset updating method includes the following sub-steps:
[0083] Subtract the adjacent previous element from the current element in the LL3 subband to replace the current element.
[0084] After performing the three-level wavelet transform on the image, the LL3 subband is first transformed by subtracting the previous element from the next element in the subband, and the processed result is stored in the original LL3 subband position.
[0085] For example: {100, 103, 105} becomes {100, 3, 2} after processing.
[0086] By replacing the current element with the result obtained by subtracting the adjacent previous element from the current element in the LL3 subband, the value of the current element can be significantly reduced, thereby significantly reducing the bandwidth required for the obtained coded data.
[0087] In one embodiment, Figure 3 As shown, the above step 1033 includes the following sub-steps:
[0088] The following encoding method is performed for each element to be encoded in the subband that is not the LL3 subband:
[0089] 10331. Determine whether the current element to be encoded is zero.
[0090] 10332. If the current element to be encoded is zero, increment the counter by one.
[0091] 10333. If the current element to be encoded is not zero, convert the value of the counter into a binary number.
[0092] 10334. Use a preset symbol to replace the binary digit to obtain replacement data.
[0093] For example, using a preset symbol to replace a binary digit to obtain replacement data includes:
[0094] Use the positive sign to replace a 1 in a binary number; use the negative sign to replace a 0 in a binary number.
[0095] That is, use "-" instead of "0" and use "+" instead of "1".
[0096] For example, the value of the counter is 6. After conversion to binary, it is "110". Substituting "-" for "0" and "+" for "1" gives "++-".
[0097] It is worth noting that the correspondence between the above-mentioned preset symbols and binary numbers is only an example. In actual applications, the preset symbols of the day before yesterday can also be used, for example: using characters as preset symbols, using a to replace 1 in binary numbers; using b to replace 0 in binary numbers, etc.
[0098] 10335. Clear the counter.
[0099] 10336. Obtain intermediate coded data of the current element to be coded according to the replacement data and the Huffman coding corresponding to the current element to be coded.
[0100] It is worth noting that the above steps 10331-10336 are executed in a loop, that is, after executing steps 10331-10336 on the current element to be encoded, the intermediate encoded data corresponding to the current element to be encoded is obtained, and then steps 10331-10336 are continued to be executed on the next element to be encoded to obtain the intermediate encoded data corresponding to the next element to be encoded, and so on, until all elements to be encoded are processed.
[0101] By improving the existing RLE algorithm, intermediate coded data is first obtained, and then the intermediate coded data is encoded using an adaptive arithmetic coding method, which can effectively reduce the size of the bit stream obtained after encoding.
[0102] The present disclosure provides an image encoding method. Figure 4 As shown, the image encoding method comprises the following steps:
[0103] 1. After performing the three-level wavelet transform on the image, first transform the LL3 subband by subtracting the previous element from the next element in the subband.
[0104] For example: {100, 103, 105} becomes {100, 3, 2} after processing. The processed result is stored in the original LL3 subband position.
[0105] 2. Scan all subbands, count the frequency of occurrence of all values except 0, and generate a Huffman code table based on the frequency.
[0106] 3. Get an uncoded subband and determine whether the current coded subband is an LL3 subband.
[0107] 3.1 If the current subband is LL3, directly use Huffman coding to encode, and then store the encoded bit stream.
[0108] 3.2 If the current subband is not LL3, use the RLE (Run length encoding) improved algorithm to obtain the intermediate result. Then use arithmetic coding to encode and store the encoded bitstream.
[0109] 4. If all sub-bands have been encoded, the process ends. Otherwise, go to step 2.
[0110] The present disclosure provides a method for implementing an improved RLE algorithm. Figure 5 As shown, the implementation method of the improved RLE algorithm includes the following steps:
[0111] 1. Get an uncoded element from the subband.
[0112] 2. Determine whether the element is zero.
[0113] 2.1 If the element is 0, increase the counter by one.
[0114] 2.2 If the element is not 0, convert the counter value to the following form. First, convert the counter value to binary form. Then, replace "0" with "-" and replace "1" with "+".
[0115] For example, the value of the counter is 6. After conversion to binary, it is "110". Replace "0" with "-" and "1" with "+" to get "++-". Then clear the counter. Finally, record the result of the run length conversion above and the result of the Huffman encoding of the current value.
[0116] 3. Determine whether all elements have been processed. If all have been processed, the program ends. Otherwise, go to step 1.
[0117] Based on the above Figure 1-5 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.
[0118] The present disclosure provides an image encoding device. Figure 6 As shown, the image encoding device includes:
[0119] An updating module 11 is used to update the LL3 subband according to a preset updating method after performing a three-level wavelet transform on the image;
[0120] A coding table generating module 12 is used to scan all sub-bands, obtain the occurrence frequency of a preset value, and generate a Huffman coding table according to the occurrence frequency;
[0121] An encoding module 13, configured to encode each of the sub-bands;
[0122] A code stream generating module 14, configured to obtain a coded code stream of the image according to the coded data corresponding to each of the sub-bands;
[0123] Wherein, the encoding module 13 includes:
[0124] The first judgment submodule 131 is used to obtain a subband to be encoded and judge whether the subband to be encoded is an LL3 subband;
[0125] A first encoding submodule 132, configured to use Huffman coding to encode the subband to be encoded if the subband to be encoded is an LL3 subband;
[0126] The second encoding submodule 133 is used for encoding the subband to be encoded by using an improved run length coding algorithm to obtain intermediate coded data if the subband to be encoded is not an LL3 subband;
[0127] The third encoding submodule 134 is configured to encode the intermediate encoded data using an adaptive arithmetic coding method.
[0128] In one embodiment, Figure 7 As shown, the update module 11 includes:
[0129] The updating submodule 111 is used to replace the current element in the LL3 subband with a result obtained by subtracting the adjacent previous element from the current element.
[0130] In one embodiment, Figure 8 As shown, the second encoding submodule 133 includes:
[0131] The second judgment submodule 1331 is used to judge whether the current element to be encoded is zero;
[0132] A first processing submodule 1332 is configured to increase a counter by one if the current element to be encoded is zero;
[0133] A conversion submodule 1333 is used to convert the value of the counter into a binary number if the current element to be encoded is not zero;
[0134] A replacement submodule 1334 is used to replace the binary digit with a preset symbol to obtain replacement data;
[0135] A second processing submodule 1335 is used to clear the counter;
[0136] The acquisition submodule 1336 is used to obtain the intermediate coding data of the current element to be coded according to the replacement data and the Huffman coding corresponding to the current element to be coded.
[0137] In one embodiment, Fig. 9 As shown, the replacement submodule 1334 includes:
[0138] A first replacement subunit 13341 is used to replace 1 in the binary number with a positive sign;
[0139] The second replacement subunit 13342 is used to replace 0 in the binary number with a minus sign.
[0140] In one embodiment, the preset value is a non-zero value.
[0141] Based on the above Figure 1-Figure 5 In accordance with the image encoding method described in the embodiment, the embodiment of the present disclosure further provides a computer-readable storage medium, for example, a non-temporary computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device. The storage medium stores computer instructions for executing the above Figure 1-Figure 5 The image encoding method described in the corresponding embodiment will not be repeated here.
[0142] 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.
[0143] 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: After performing three-level wavelet transform on the image, the LL3 subband is updated according to the preset update method; Scan all sub-bands to obtain the occurrence frequency of a preset value, and generate a Huffman coding table according to the occurrence frequency; encoding each of the sub-bands; Obtaining a coded bitstream of the image according to the coded data corresponding to each of the sub-bands; The step of encoding each of the sub-bands includes: Obtain the subband to be encoded, and determine whether the current subband to be encoded is an LL3 subband; If it is LL3 subband, Huffman coding is used for encoding; If it is not the LL3 subband, the improved run length coding algorithm is used to encode and obtain the intermediate coded data; Encoding the intermediate coded data using an adaptive arithmetic coding method; If it is not the LL3 subband, the intermediate coded data is encoded using an improved run length coding algorithm, including: The following encoding method is performed on each element to be encoded in the subband that is not the LL3 subband: Determine whether the current element to be encoded is zero; If the current element to be encoded is zero, increment the counter by one; If the current element to be encoded is not zero, converting the value of the counter into a binary number; Using a preset symbol to replace the binary digit to obtain replacement data; clearing the counter; The intermediate coded data of the current element to be coded is obtained according to the replacement data and the Huffman coding corresponding to the current element to be coded.
2. The method according to claim 1, characterized in that The updating of the LL3 subband according to a preset updating method includes: The result obtained by subtracting the adjacent previous element from the current element in the LL3 subband replaces the current element.
3. The method according to claim 1, characterized in that The step of replacing the binary digit with a preset symbol to obtain replacement data includes: Replace 1 in the binary number with a positive sign; Use a minus sign to replace the 0 in the binary number.
4. The method according to any one of claims 1 to 3, characterized in that: The preset value is a non-zero value.
5. An image encoding device, characterized in that: include: An updating module, used for updating the LL3 subband according to a preset updating method after performing a three-level wavelet transform on the image; A coding table generation module, used for scanning all sub-bands, obtaining the occurrence frequency of a preset value, and generating a Huffman coding table according to the occurrence frequency; A coding module, used for encoding each of the sub-bands; A code stream generation module, used for obtaining a coded code stream of the image according to the coded data corresponding to each of the sub-bands; Wherein, the encoding module includes: A first judgment submodule is used to obtain a subband to be encoded and determine whether the current subband to be encoded is an LL3 subband; A first encoding submodule, configured to use Huffman encoding to encode the subband to be encoded if the subband to be encoded is an LL3 subband; A second encoding submodule, configured to, if the subband to be encoded is not the LL3 subband, use an improved run-length encoding algorithm to encode to obtain intermediate encoded data; A third encoding submodule, used for encoding the intermediate coded data using an adaptive arithmetic coding method; The second encoding submodule includes: The second judgment submodule is used to judge whether the current element to be encoded is zero; A first processing submodule, configured to increase a counter by one if the current element to be encoded is zero; A conversion submodule, configured to convert the value of the counter into a binary number if the current element to be encoded is not zero; A replacement submodule, used for replacing the binary digits with preset symbols to obtain replacement data; A second processing submodule, used for clearing the counter; The acquisition submodule is used to obtain the intermediate coding data of the current element to be coded according to the replacement data and the Huffman coding corresponding to the current element to be coded.
6. The device according to claim 5, characterized in that The update module includes: The updating submodule is used to replace the current element in the LL3 subband with the result obtained by subtracting the adjacent previous element from the current element.
7. The device according to claim 5, characterized in that The replacement submodule comprises: A first replacement subunit, used for replacing 1 in the binary number with a positive sign; The second replacing subunit is used to replace 0 in the binary number with a minus sign.
8. The device according to any one of claims 5 to 7, characterized in that: The preset value is a non-zero value.
Citation Information
Patent Citations
An embedded image compression technique based on wavelet transformation
CN1571514A
