A DCT-transformed image compression coding method and system
By segmenting the image into blocks less than 8 for DCT transformation and entropy encoding, the problems of large calculation amount and large code streams in the prior art are solved, and more efficient image compression encoding is achieved, adapting to complex image content and reducing circuits cost.
Patent Information
- Application Number
- CN202410446280.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-15
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-04-15
AI Technical Summary
The existing image compression and encoding method based on DCT transformation is large in the circuit implementation, high resource consumption and high cost, and the 8×8 block size is not fine enough for the complex image processing of the content, resulting in long block encoding time and many code streams. .
The image is divided into NxN blocks less than 8 for DCT transformation, quantization processing and generation of an entropy encoding table, encode the non-zero coefficient position and amplitude through entropy encoding, generate a data code stream, and convert it into a code stream header through a specific format. Optimize the DCT transform block size to reduce computational complexity and code length.
It reduces the calculation complexity and power consumption of the circuit implementation, improves compression efficiency, adapts to complex image content, reduces code length, and reduces manufacturing costs.
Smart Images

Figure CN118055256B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to an image compression processing technology, and in particular to an image compression coding method and system based on DCT transformation. Background Art
[0002] At present, the main image compression coding method based on DCT transformation is the JPEG standard, which first uses 8×8 DCT transformation in the YCbCr format, then quantizes it, and then performs Huffman coding, and further encapsulates the code stream according to the specified format to achieve lossy compression coding of the image. However, since JPEG is based on 8×8 DCT transformation, the amount of calculation is too large when it is implemented in the circuit, which consumes a lot of resources, has high cost and high power consumption; Huffman coding processing uses 64 numbers as a unit, and there are many different run length entries that may appear, and the maximum codeword length is long; for images with complex content, the 8×8 block size tends to be coarse, and the non-zero coefficients are scattered after DCT transformation. There are still many non-zero numbers in the lower right corner of the 8×8 matrix, resulting in long block coding time and more code streams. Summary of the invention
[0003] In order to solve at least one of the above problems, the present invention provides an image compression coding method based on DCT transformation, which specifically comprises the following steps:
[0004] The Y, Cb and Cr components of the image after data preprocessing are divided into NxN blocks, where N is less than 8; each block is subjected to N×N DCT transformation to obtain a transformation coefficient block;
[0005] Quantizing the transform coefficient block to obtain a quantized data block, and performing data scanning on the quantized data block to obtain a one-dimensional number series;
[0006] Calculating the position information of each non-zero coefficient in the one-dimensional sequence, and encoding the position information and amplitude of the non-zero coefficient according to an entropy coding table configured with a data block size to generate a data code stream;
[0007] The image size, quantization parameter and entropy coding table configured according to the size of the basic unit of data processing are converted into a code stream in a specific format and output as a code stream header together with the data code stream.
[0008] Preferably, the method of performing table lookup encoding on the position information of the non-zero coefficient according to an entropy coding table configured with the size of the basic unit of data processing includes performing DC coefficient encoding, and performing AC coefficient encoding according to the entropy coding table of brightness and chrominance configured with the size of the basic unit of data processing.
[0009] Preferably, the AC coefficient encoding method comprises:
[0010] Determine the run length and bit width of the current AC coefficient, query the entropy coding table of brightness and chrominance according to the run length / bit width, and obtain the run length / bit width code; convert the AC data amplitude into an intermediate variable, and convert the intermediate variable into a binary code with a code length equal to the bit width.
[0011] Preferably, the code stream header includes a chroma code stream header, which includes the following contents: image height and image width, chroma quantization parameters, and code length parameters of a chroma entropy coding table. In the code table, the code length is first arranged from small to large, and the corresponding chroma run / bit width parameters are arranged from small to large according to the code value.
[0012] Preferably, the code stream header includes a brightness code stream header, which includes the following contents: image height and image width, brightness quantization parameter, code length parameter of brightness entropy coding table, and the code table is first arranged from small to large according to code length, and similarly, the corresponding brightness run / bit width parameters are arranged from small to large according to code value.
[0013] Preferably, the configuration method of the entropy coding table includes: counting the probability of occurrence of the run / bit width, and generating the entropy coding table according to the principle of using short codewords with high probability of occurrence of the run / bit width and long codewords with low probability of occurrence.
[0014] Preferably, the DC coefficient encoding method comprises: encoding the difference of DC coefficients between adjacent blocks by using differential pulse coding.
[0015] Preferably, the entropy coding of the DC coefficient includes a DC coefficient bit width code and a DC coefficient amplitude binary code.
[0016] If the current N×N block is the first block of the current image, the current data to be encoded is the DC coefficient of the current block; otherwise, the current data to be encoded is the difference between the DC coefficient of the current image block and the DC coefficient of the previous image block, recorded as DIFF;
[0017] After obtaining DIFF, the bit width of the current data to be encoded is calculated based on DIFF; the DC coefficient bit width code table is queried based on the bit width to obtain the bit width code of the DC coefficient, the data to be encoded is converted into an intermediate variable, and then the intermediate variable is converted into a binary code with a code length equal to the bit width.
[0018] The present invention also discloses an image compression coding system, comprising a preprocessing module for preprocessing input data;
[0019] DCT transformation module, performing N×N DCT transformation on the Y, Cb and Cr components of the data preprocessed image to obtain transformation coefficient blocks, where N is less than 8;
[0020] A quantization module performs quantization processing on the transform coefficient block to obtain a quantized data block;
[0021] A data scanning module is used to scan the quantized data blocks output by the quantization module in a certain order to obtain a one-dimensional sequence;
[0022] An entropy coding module, used to calculate the position information of each non-zero coefficient in the one-dimensional sequence, and encode the position information and amplitude of the non-zero coefficient according to an entropy coding table configured with a data block size to generate a data code stream;
[0023] An entropy coding table storage module, used for storing the called entropy coding table;
[0024] The code stream header generation module is used to convert the image size, quantization parameter and the entropy coding table configured according to the data processing basic unit size into a code stream in a specific format, and output it as a code stream header together with the data code stream.
[0025] Preferably, the system further comprises a pre-processing module for subtracting 128 from the Y, Cb and Cr components of the image respectively to convert the input data into signed numbers. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0027] Figure 1 It is a structural diagram of the image compression coding system;
[0028] Figure 2 It is a 2×2 data scanning sequence diagram;
[0029] Figure 3 It is a schematic diagram of DC coefficient;
[0030] Figure 4 This is a schematic diagram of the brightness code stream header information structure;
[0031] Figure 5 It is a schematic diagram of the chroma code stream header information structure;
[0032] Figure 6 It is a flow chart of the principle of derivation of code length distribution of entropy coding table;
[0033] Figure 7 It is a flow chart of the principle of derivation of entropy coding table content. DETAILED DESCRIPTION
[0034] The present invention is further described in detail below in conjunction with embodiments. The following embodiments are for explanation of the present invention but the present invention is not limited to the following embodiments.
[0035] Embodiment 1: A method for image compression encoding based on DCT transformation, referring to Figure 1 The following steps are involved:
[0036] The Y, Cb and Cr components of the image after data preprocessing are divided into NxN blocks, where N is less than 8; each block is subjected to N×N DCT transformation to obtain a transformation coefficient block;
[0037] Quantizing the transform coefficient block to obtain a quantized data block, and performing data scanning on the quantized data block to obtain a one-dimensional number series;
[0038] Calculating the position information of each non-zero coefficient in the one-dimensional sequence, and encoding the position information and amplitude of the non-zero coefficient according to an entropy coding table configured with a data block size to generate a data code stream;
[0039] The image size, quantization parameter and entropy coding table configured according to the size of the basic unit of data processing are converted into a code stream in a specific format and output as a code stream header together with the data code stream.
[0040] First, by reducing the data block size of the DCT transformation, the computational complexity of the circuit implementation is reduced, the circuit area is reduced, the circuit power consumption is reduced, and the manufacturing cost is further reduced.
[0041] Secondly, by reducing the size of DCT transform, it is more adaptable to complex image content. The closer the data values in the data block are, the more the data amplitude after DCT transform is concentrated to the upper left corner. Under high compression efficiency requirements, the image block effect is less obvious.
[0042] Thirdly, the reduction of the data block of DCT transformation leads to the reduction of the size of the data block processed by entropy coding, thereby reducing the possible values of "run / bit width", achieving an overall reduction in code length and improving compression efficiency with a certain probability.
[0043] Furthermore, this embodiment discloses a specific data preprocessing method, including: converting the input image data into YCbCr data, if the input data is already YCbCr data, subtracting 128 from the image Y, Cb and Cr components respectively, converting the input data unsigned number into a signed number, and reducing the data amplitude by half at most.
[0044] Furthermore, this embodiment discloses a specific DCT transformation method, the steps are as follows:
[0045] Secondly, the image components are divided into blocks of size N×N, and DCT processing is performed from left to right and from top to bottom in the image; wherein N is a configurable value, and in order to solve technical problems, N is an even number less than 8.
[0046] In this embodiment, N=2 is used as an example for specific description. If the input data block of the N×N DCT transform is recorded as X, and the output coefficient block of the DCT transform is recorded as W, then the expression of the DCT transform is as follows:
[0047]
[0048] in, It is an N×N matrix multiplication, A is the DCT transform coefficient, A' is the transposed matrix of A, and the value of n is related to the DCT transform coefficient.
[0049] The N×N DCT transform coefficient expression is as follows:
[0050]
[0051] Among them, i is the row number of the DCT transformation matrix, ranging from 0 to N-1; j is the column number of the DCT transformation matrix, ranging from 0 to N-1; n is the gain multiplied by the DCT coefficient as needed, and round means rounding the data. The larger the value of n is, the smaller the error between the original data and the data restored after DCT transformation, but the higher the implementation cost; in this embodiment, n = 10, and the corresponding DCT coefficient is a 10-bit signed number.
[0052] Furthermore, a specific quantization processing method is disclosed, which performs quantization processing on the N×N transformation matrix obtained by DCT transformation, thereby increasing the image compression efficiency without significantly changing the image quality; if the quantized result is recorded as Z, the mathematical expression of the quantization processing is as follows:
[0053]
[0054] Where i is the row number of the DCT transform matrix, ranging from 0 to N-1; j is the column number of the DCT transform matrix, ranging from 0 to N-1, and round means rounding the data. c0 It is the intermediate quantization parameter corresponding to brightness and chrominance. Its value is configurable and is determined by the quantization parameter Q y and Q c It is calculated as follows;
[0055]
[0056] As can be seen from the above, the value of b determines the accuracy of quantization. The larger the value, the smaller the calculation error, but the higher the implementation cost. In this embodiment, b = 10.
[0057] After quantization, scan the quantized data block and convert the N×N two-dimensional matrix into a one-dimensional sequence. Figure 2, which is a schematic diagram of converting a 2×2 two-dimensional matrix into a one-dimensional sequence.
[0058] The method for performing table lookup encoding on the position information of the non-zero coefficients includes performing DC coefficient encoding and encoding according to the entropy coding table of brightness and chrominance configured according to the data block size.
[0059] (I) The DC coefficient encoding method includes: the DC coefficient is the data at the upper left corner (0,0) in the N×N data block. Since the DC coefficients of adjacent blocks have a strong correlation, the DC coefficient is firstly coded using difference pulse coding (DPCM), the difference of the DC coefficients between adjacent blocks is calculated, and then the difference of the DC coefficients between adjacent blocks is encoded. The code stream of the DC coefficient difference consists of two parts: DC coefficient bit width code + DC coefficient amplitude binary code.
[0060] refer to Figure 3 , if the DC coefficient difference is recorded as DIFF, if the current N×N block is the first block of the current image, then DIFF is the DC coefficient of the current block; otherwise, DIFF is the difference between the DC coefficient of the current block and the DC coefficient of the previous block, thereby determining DIFF.
[0061] The encoding process is as follows: First, the bit width B of the current data to be encoded (DIFF) is calculated according to the following mathematical expression: dc ;
[0062]
[0063] Among them, || means taking the absolute value, log2 means taking the logarithm with base 2, and ceil means rounding up.
[0064] Secondly, according to the obtained bit width, the DC coefficient bit width code table is checked to obtain the DC coefficient bit width code
[0065]
[0066] Table 1 DC coefficient bit width code table
[0067] Third, the data to be encoded is converted into an intermediate variable T according to the following expression.
[0068]
[0069] Finally, convert T to a code length of B dc The binary code is the DC coefficient amplitude binary code.
[0070] (ii) The AC coefficient encoding method includes:
[0071] Determine the current AC coefficient's stroke, and obtain the current AC coefficient's bit width B by looking up the table ac, query the entropy coding table of brightness and chromaticity according to the run / bit width, and obtain the run / bit width code; convert the AC data amplitude into an intermediate variable, and convert the intermediate variable into a code length of bit width B ac The binary code.
[0072] Specifically, the AC coefficient is the non-zero data in other positions in the N×N data block except the DC data. Since adjacent image data has a strong correlation, most or all of the AC coefficients in the data block after DCT transformation and quantization are 0. Therefore, it is only necessary to record the position and data value of the non-zero coefficient in the scanned output data column.
[0073] The code stream of each AC coefficient consists of two parts: "run / bit width" code + AC coefficient amplitude binary code. The encoding process is as follows:
[0074] First, determine the run of the current AC coefficient; "run" refers to the number of 0s between the current coded AC coefficient and the previous adjacent non-zero AC coefficient; if the number of 0s is greater than 15, it is split into one or more segments of 15 0s, and the corresponding bit width during encoding is 0, that is, "run / bit width" is "F / 0", and the remaining number of 0s is used as the actual run, and is encoded normally together with the bit width by looking up the table.
[0075] Secondly, determine the bit width B of the current AC coefficient ac , can be obtained through the following mathematical expression.
[0076]
[0077] Among them, AC ij It represents the coefficient of the i-th row and j-th column in the data block, || means taking the absolute value, log2 means taking the logarithm with base 2, and ceil means rounding up.
[0078] Third, according to the "run / bit width", the brightness and chrominance entropy coding tables are queried to obtain the "run / bit width" code; this code table is configurable and can be generated by statistically analyzing the distribution of the "run / bit width" information of special sample images. In this embodiment, the code table is as follows:
[0079]
[0080] Table 2 Luminance AC entropy coding table
[0081]
[0082] Table 3 Chroma AC entropy coding table
[0083] Fourth, convert the AC data amplitude AC into ij Converted to intermediate variable T.
[0084]
[0085] AC ij Represents the number in the i-th row and j-th column of the data block.
[0086] Fifth, convert T to code length B ac The binary code is the AC coefficient amplitude binary code.
[0087] Finally, if there is no non-zero AC coefficient in the data block, or the last non-zero AC coefficient is not the last coefficient of the current block, after encoding all non-zero AC coefficients, a code stream with a "run / bit width" of "0 / 0" (EOB) is encoded to indicate the end of encoding the current data block.
[0088] The end of the DCT transform image compression coding method is to convert the image size, quantization coefficient and entropy coding table into a code stream according to a specific format, and output it together with the code stream as a code stream header.
[0089] The code stream header includes a chroma code stream header, which includes the following contents: image height and image width, chroma quantization parameters, and code length parameters of the chroma entropy coding table. In the code table, the code length is first arranged from small to large, and the code length is arranged from small to large according to the code value. The code stream header includes a luminance code stream header, image height and image width, luminance quantization parameters, and code length parameters of the luminance entropy coding table. In the code table, the code length is first arranged from small to large, and the code length is arranged from small to large according to the code value.
[0090] Stream header structure reference Figure 4 and Figure 5 , in the luminance code stream header information structure and the chrominance code stream header information structure, Q Y0 ~Q YN*N-1 Corresponding brightness quantization parameter Q Y According to the data scanning order described above, Q c0 ~Q cN*N-1 Corresponding chromaticity quantization parameter Q c The values are scanned in the order described above. Y0 ~ BIT Y15 The number of code words with code lengths of 1 to 16 in the corresponding brightness AC entropy coding table; BIT C0 ~ BIT C15 The number of code words with code lengths of 1 to 16 in the corresponding chroma AC entropy coding table; HUFFVAL Y0 ~ HUFFVAL YNUM-1 In the corresponding luminance AC entropy coding table, the code length is first arranged from small to large, and the corresponding chrominance run / bit width parameters are arranged from small to large according to the code value. C0 ~ HUFFVALCNUM-1 In the corresponding chroma AC entropy coding table, the code length is first arranged from small to large, and the corresponding chroma run / bit width parameters are arranged from small to large according to the code value.
[0091] Furthermore, in the AC coefficient encoding process, the AC coefficient entropy coding table is configurable. For the common Huffman coding processing method with 64 numbers as a unit, the processing unit block in the present application is significantly reduced compared to 8×8, which is different from the "run / bit width" probability distribution of the existing AC coefficient entropy coding table. In addition, since a processing block smaller than 8×8 can be selected in the present application, preferably an even-numbered processing block smaller than 8×8 is selected, it is necessary to implement the corresponding AC coefficient entropy coding table using a code table configuration method for different processing block sizes. The present invention proposes an improved AC coefficient entropy coding table configuration method, and the specific implementation process is as follows:
[0092] The main idea is: if the probability of "run / bit width" appearing is represented by the matrix freq (the first line is the statistical probability, and the second line is the "run / bit width" corresponding to the probability), then the code table is generated according to the principle of "using short code words for "run / bit width" with high probability of appearance and using long code words for "run / bit width" with low probability of appearance" (see attached). Figure 6 The specific process is as follows:
[0093] First, initialization: create two one-dimensional arrays with the same number of columns as the frequency matrix freq: denoted as Size and Prev_char, with initial values of all 0 and all -1 respectively.
[0094] Second, sort and update the frequency matrix. Sort freq from large to small and from left to right in columns according to the probability values counted in freq, and find the column number corresponding to the smallest non-zero probability value and record it as index.
[0095] Third, if index is greater than 1, then:
[0096] V1=freq(2,index), V1 is the "stroke / bit width" parameter of the current column;
[0097] V2 = freq(2, index-1), V2 is the "stroke / bit width" parameter of the previous column;
[0098] Update the value of freq(1,index) to freq(1,index) + freq(1,index-1),
[0099] The value of freq(1,index-1) is set to 0, and the probability value corresponding to the previous column "stroke / bit width" is cleared.
[0100] Fourth, update the code length of V1, Size(V1+1) = Size(V1+1)+1; if Prev_char(V1+1) is equal to -1, then Prev_char(V1+1) = V2, and jump to the next step; otherwise, V1 = Prev_char(V1+1), and repeat this step.
[0101] Fifth, update the code length of V2, Size(V2+1) = Size(V2+1)+1; if Prev_char(V2+1) is equal to -1, jump to the next step; otherwise, V2= Prev_char(V2+1), and repeat this step.
[0102] Sixth, index=index-1, if index is greater than 1, go to step 2; otherwise, jump to the next step.
[0103] Seventh, code length statistics and code table generation: The data in the Size array is the code length corresponding to each character in the Huffman table. According to Size statistics, the number of characters corresponding to each code length in the Huffman table is recorded as BITS (or understood as storing the result in the BITS array). The size is 1×16, and BITS(1)~BITS(16) are the number of characters with code lengths of 1 to 16 respectively.
[0104] Eighth, sort the "stroke / bit width" from high to low according to the probability of occurrence, recorded as HUFFVAL, as the code table according to the code length from small to large, the corresponding "stroke / bit width".
[0105] Ninth, code length statistics and code table generation: According to BITS and HUFFVAL, you can Figure 7 The process shown generates a Huffman coding table, denoted as HUFFTABLE.
[0106] Specifically include:
[0107] Step 10-1, initialization: The Huffman table HUFFTABLE includes an array of all zeros with a size of 2 rows and the same number of columns as the length of HUFFVAL. The code length and code value corresponding to the "run / bit width" contained in the i-th column of HUFFVAL are the values of the first and second rows of the i-th column of HUFFTABLE respectively;
[0108] Initialize 4 parameters, namely idx0=0, val=0, bit=0, j=1, where idx0 represents the column number of the Huffman table, val represents the codeword value, and j represents the codeword bit width;
[0109] Step 10-2, determine whether the current j is less than or equal to 16, if not, end this process, if so, execute step 10-3;
[0110] Step 10-3, add 1 to the parameter bit to determine whether there is a code word in the Huffman table when the code length is j; if BITS(j) is greater than 0, initialize a parameter k=1; otherwise, add 1 to the current code length j, and return to step 10-2 to determine the next code length;
[0111] Step 10-4, determine whether k is less than or equal to BITS(j), if not, reset bit to 0, add 1 to j, and go to step 10-2 to process the next code length, if yes, go to step 10-5;
[0112] Step 10-5, if k is equal to 1, then the code value val is equal to val*2 bit , then calculate the codeword value equal to the previous codeword value plus 1; idx0 plus 1, store the calculated codeword value val and the corresponding code length j in the idx0 column of the Huffman code table respectively; k plus 1, then return to step 10-4 to process the next codeword value of the current code length;
[0113] Otherwise, the codeword value is equal to the previous codeword value plus 1; idx0 is increased by 1, and the calculated codeword value val and the corresponding code length j are stored in the idx0 column of the Huffman code table respectively; k is increased by 1, and then return to step 10-4 to process the next codeword value of the current code length;
[0114] According to the above disclosed method, the brightness and chrominance AC coefficient code tables are generated. If there are any incomplete parts disclosed in this document, they can be explained and supplemented by those skilled in the art according to conventional means.
[0115] Embodiment 2: Disclosed is an image compression coding system or an image compression coding circuit, comprising:
[0116] DCT transformation module, performing N×N DCT transformation on the Y, Cb and Cr components of the data preprocessed image to obtain transformation coefficient blocks, where N is less than 8;
[0117] A quantization module performs quantization processing on the transform coefficient block to obtain a quantized data block;
[0118] A data scanning module is used to scan the quantized data blocks output by the quantization module in a certain order to obtain a one-dimensional sequence;
[0119] An entropy coding module, used for calculating the position information of each non-zero coefficient in the one-dimensional sequence, and encoding the position information and amplitude of the non-zero coefficient according to the Huffman entropy coding table configured according to the data block size to generate a data code stream;
[0120] An entropy coding table storage module, used for storing the called entropy coding table;
[0121] The code stream header generation module is used to convert the image size, quantization parameter and the entropy coding table configured according to the data processing basic unit size into a code stream in a specific format, and output it as a code stream header together with the data code stream.
[0122] Furthermore, it also includes: a pre-processing module, which is used to subtract 128 from the Y, Cb and Cr components of the image respectively, and convert the input data into signed numbers.
[0123] It is necessary to explain that the data processing basic unit described in the present invention is understood as the basic processing unit in the encoding process, the basic data block processed, such as NxN as the basic processing unit, NxN DCT transformation, NxN quantization processing, etc.
[0124] In the several embodiments provided in this application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic, for example, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.
[0125] The modules may or may not be physically separated, and the components displayed as modules may be one physical module or multiple physical modules, that is, they may be located in one place or distributed in multiple different places. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0126] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A DCT-based image compression coding method, characterized in that: The following steps are involved: The Y, Cb and Cr components of the image after data preprocessing are divided into NxN blocks, where N is less than 8; each block is subjected to N×N DCT transformation to obtain a transformation coefficient block; Quantizing the transform coefficient block to obtain a quantized data block, and performing data scanning on the quantized data block to obtain a one-dimensional number series; Calculating the position information of each non-zero coefficient in the one-dimensional sequence, and encoding the position information and amplitude of the non-zero coefficient according to an entropy coding table configured with a data block size to generate a data code stream; Convert the image size, quantization parameter and the entropy coding table configured according to the size of the data processing basic unit into a bit stream according to a preset specific format, and output it together with the data bit stream as a bit stream header; Among them, the entropy coding table includes the luminance and chrominance AC coefficient code table, and the configuration method is as follows: First, count the frequency of occurrence of different "strokes / bit widths" and save them in the frequency matrix freq; the first row of each column in the frequency matrix freq stores the number of occurrences of the current "stroke / bit width", and the second row stores the value used to represent the current "stroke / bit width"; Second, create two one-dimensional arrays with the same number of columns as the frequency matrix freq: denoted as Size and Prev_char, with initial values of all 0 and all -1 respectively; Third, sort and update the frequency matrix. Sort freq from left to right in columns according to the probability values in freq from large to small, and find the column number corresponding to the smallest non-zero probability value as index. Fourth, if index is greater than 1, then: V1=freq(2,index), V1 is the "stroke / bit width" parameter of the current column; V2 = freq(2, index-1), V2 is the "stroke / bit width" parameter of the previous column; Update the value of freq(1,index) to freq(1,index) + freq(1,index-1), The value of freq(1,index-1) is set to 0, and the probability value corresponding to the previous column "stroke / bit width" is cleared; Fifth, update the code length of V1, Size(V1+1) = Size(V1+1)+1; if Prev_char(V1+1) is equal to -1, then Prev_char(V1+1) = V2, and then jump to the next step; otherwise, V1 = Prev_char(V1+1), and repeat this step; Sixth, update the code length of V2, Size(V2+1) = Size(V2+1)+1; if Prev_char(V2+1) is equal to -1, jump to the next step; otherwise, V2 = Prev_char(V2+1), and repeat this step; Seventh, index=index-1, if index is greater than 1, go to step 2; otherwise, jump to the next step; Eighth, code length statistics and code table generation: The data in the Size array is the code length corresponding to each character in the Huffman table. According to Size, the number of characters corresponding to each code length in the Huffman table is counted. The result is recorded as BITS, with a size of 1×16. BITS(1)~BITS(16) are the number of characters with code lengths of 1 to 16 respectively. Ninth, sort the "stroke / bit width" from high to low according to the probability of occurrence, recorded as HUFFVAL, as a code table, according to the code length from small to large, the corresponding "stroke / bit width"; Tenth, code length statistics and code table generation: Generate a Huffman coding table based on BITS and HUFFVAL, denoted as HUFFTABLE; Step 10-1, initialization: The Huffman table HUFFTABLE includes an array of all zeros with a size of 2 rows and the same number of columns as the length of HUFFVAL. The code length and code value corresponding to the "run / bit width" contained in the i-th column of HUFFVAL are the values of the first and second rows of the i-th column of HUFFTABLE respectively; Initialize 4 parameters, namely idx0=0, val=0, bit=0, j=1, where idx0 represents the column number of the Huffman table, val represents the codeword value, and j represents the codeword bit width; Step 10-2, determine whether the current j is less than or equal to 16, if not, end this process, if so, execute step 10-3; Step 10-3, add 1 to the parameter bit to determine whether there is a code word in the Huffman table when the code length is j; if BITS(j) is greater than 0, initialize a parameter k=1; otherwise, add 1 to the current code length j, and return to step 10-2 to determine the next code length; Step 10-4, determine whether k is less than or equal to BITS(j), if not, reset bit to 0, add 1 to j, and go to step 10-2 to process the next code length, if yes, go to step 10-5; Step 10-5, if k is equal to 1, then the code value val is equal to val*2 bit , then calculate the codeword value equal to the previous codeword value plus 1; idx0 plus 1, store the calculated codeword value val and the corresponding code length j in the idx0 column of the Huffman code table respectively; k plus 1, then return to step 10-4 to process the next codeword value of the current code length; Otherwise, the codeword value is equal to the previous codeword value plus 1; idx0 is increased by 1, and the calculated codeword value val and the corresponding code length j are stored in the idx0 column of the Huffman code table respectively; k is increased by 1, and then return to step 10-4 to process the next codeword value of the current code length; According to the above method, the luminance and chrominance AC coefficient code tables are generated.
2. The image compression coding method based on DCT transform according to claim 1 is characterized in that: The method of performing table lookup encoding on the position information of the non-zero coefficient according to the entropy coding table configured with the data block size includes performing DC coefficient encoding and performing AC coefficient encoding according to the entropy coding tables of brightness and chrominance configured with the data block size.
3. The image compression coding method based on DCT transform according to claim 2 is characterized in that: The AC coefficient encoding method comprises: Determine the run length and bit width of the current AC coefficient, query the entropy coding table of brightness and chrominance according to the run length / bit width, and obtain the run length / bit width code; convert the AC data amplitude into an intermediate variable, and convert the intermediate variable into a binary code with a code length equal to the bit width.
4. The image compression coding method based on DCT transform according to claim 1 is characterized in that: The code stream header includes a chroma code stream header, which includes the following contents: image height and image width, chroma quantization parameters, and code length parameters of a chroma entropy coding table. In the code table, the code lengths are first arranged from small to large, and the corresponding chroma run / bit width parameters are arranged from small to large according to the code values.
5. The image compression coding method based on DCT transform according to claim 1 or 4, characterized in that: The code stream header includes a brightness code stream header, which includes the following contents: image height and image width, brightness quantization parameter, and code length parameter of brightness entropy coding table. In the code table, the code length is first arranged from small to large, and the corresponding brightness stroke / bit width parameters are arranged from small to large according to the code value.
6. The DCT transform-based image compression coding method according to any one of claims 1 to 3, characterized in that: The configuration method of the entropy coding table includes: counting the probability of occurrence of the run / bit width, and generating the entropy coding table according to the principle of using short code words with high probability of occurrence of the run / bit width and using long code words with low probability of occurrence.
7. The image compression coding method based on DCT transform according to claim 2 is characterized in that: The DC coefficient coding method includes: using difference pulse coding to encode the difference of DC coefficients between adjacent blocks.
8. The image compression coding method based on DCT transform according to claim 7 is characterized in that: The entropy coding of the DC coefficient includes a DC coefficient bit width code and a DC coefficient amplitude binary code; If the current N×N block is the first block of the current image, the current data to be encoded is the DC coefficient of the current block; Otherwise, the current data to be encoded is the difference between the DC coefficient of the current image block and the DC coefficient of the previous image block, recorded as DIFF; After obtaining DIFF, the bit width of the current data to be encoded is calculated based on DIFF; the DC coefficient bit width code table is queried based on the bit width to obtain the bit width code of the DC coefficient, the data to be encoded is converted into an intermediate variable, and then the intermediate variable is converted into a binary code with a code length of bit width B.
9. An image compression coding system, characterized in that: include DCT transformation module, performing N×N DCT transformation on the Y, Cb and Cr components of the data preprocessed image to obtain transformation coefficient blocks, where N is less than 8; A quantization module performs quantization processing on the transform coefficient block to obtain a quantized data block; A data scanning module is used to scan the quantized data blocks output by the quantization module in a certain order to obtain a one-dimensional sequence; An entropy coding module, used to calculate the position information of each non-zero coefficient in the one-dimensional sequence, and encode the position information and amplitude of the non-zero coefficient according to an entropy coding table configured with a data block size to generate a data code stream; An entropy coding table storage module, used for storing the called entropy coding table; A code stream header generation module, used to convert the image size, quantization parameter and the entropy coding table configured according to the data processing basic unit size into a code stream in a specific format as a code stream header, and output it together with the data code stream; Among them, the entropy coding table includes the luminance and chrominance AC coefficient code table, and the configuration method is as follows: First, count the frequency of occurrence of different "strokes / bit widths" and save them in the frequency matrix freq; the first row of each column in the frequency matrix freq stores the number of occurrences of the current "stroke / bit width", and the second row stores the value used to represent the current "stroke / bit width"; Second, create two one-dimensional arrays with the same number of columns as the frequency matrix freq: denoted as Size and Prev_char, with initial values of all 0 and all -1 respectively; Third, sort and update the frequency matrix. Sort freq from left to right in columns according to the probability values in freq from large to small, and find the column number corresponding to the smallest non-zero probability value as index. Fourth, if index is greater than 1, then: V1=freq(2,index), V1 is the "stroke / bit width" parameter of the current column; V2 = freq(2, index-1), V2 is the "stroke / bit width" parameter of the previous column; Update the value of freq(1,index) to freq(1,index) + freq(1,index-1), The value of freq(1,index-1) is set to 0, and the probability value corresponding to the previous column "stroke / bit width" is cleared; Fifth, update the code length of V1, Size(V1+1) = Size(V1+1)+1; if Prev_char(V1+1) is equal to -1, then Prev_char(V1+1) = V2, and then jump to the next step; otherwise, V1 = Prev_char(V1+1), and repeat this step; Sixth, update the code length of V2, Size(V2+1) = Size(V2+1)+1; if Prev_char(V2+1) is equal to -1, jump to the next step; otherwise, V2 = Prev_char(V2+1), and repeat this step; Seventh, index=index-1, if index is greater than 1, go to step 2; otherwise, jump to the next step; Eighth, code length statistics and code table generation: The data in the Size array is the code length corresponding to each character in the Huffman table. According to Size, the number of characters corresponding to each code length in the Huffman table is counted. The result is recorded as BITS, with a size of 1×16. BITS(1)~BITS(16) are the number of characters with code lengths of 1 to 16 respectively. Ninth, sort the "stroke / bit width" from high to low according to the probability of occurrence, recorded as HUFFVAL, as a code table, according to the code length from small to large, the corresponding "stroke / bit width"; Tenth, code length statistics and code table generation: Generate a Huffman coding table based on BITS and HUFFVAL, denoted as HUFFTABLE; Step 10-1, initialization: The Huffman table HUFFTABLE includes an array of all zeros with a size of 2 rows and the same number of columns as the length of HUFFVAL. The code length and code value corresponding to the "run / bit width" contained in the i-th column of HUFFVAL are the values of the first and second rows of the i-th column of HUFFTABLE respectively; Initialize 4 parameters, namely idx0=0, val=0, bit=0, j=1, where idx0 represents the column number of the Huffman table, val represents the codeword value, and j represents the codeword bit width; Step 10-2, determine whether the current j is less than or equal to 16, otherwise, end this process, if so, execute step 10-3; Step 10-3, add 1 to the parameter bit to determine whether there is a code word in the Huffman table when the code length is j; if BITS(j) is greater than 0, initialize a parameter k=1, otherwise, add 1 to the current code length j, and return to step 10-2 to determine the next code length; Step 10-4, determine whether k is less than or equal to BITS(j), if not, reset bit to 0, add 1 to j, and go to step 10-2 to process the next code length, if yes, go to step 10-5; Step 10-5, if k is equal to 1, then the code value val is equal to val*2 bit , then calculate the codeword value equal to the previous codeword value plus 1; idx0 plus 1, store the calculated codeword value val and the corresponding code length j in the idx0 column of the Huffman code table respectively; k plus 1, then return to step 10-4 to process the next codeword value of the current code length; Otherwise, the codeword value is equal to the previous codeword value plus 1; idx0 is increased by 1, and the calculated codeword value val and the corresponding code length j are stored in the idx0 column of the Huffman code table respectively; k is increased by 1, and then return to step 10-4 to process the next codeword value of the current code length; According to the above method, the luminance and chrominance AC coefficient code tables are generated.
10. An image compression coding system according to claim 9, characterized in that: Also includes: The preprocessing module is used to subtract 128 from the Y, Cb and Cr components of the image respectively to convert the input data into signed numbers.
