Image compression method and device
Through macroblock division and prediction mode analysis of image data, efficient compression of RAW data is achieved, solving the problems of high hardware cost and bandwidth waste in image signal processing, and improving system performance.
Patent Information
- Application Number
- CN202111623841.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-12-28
AI Technical Summary
The existing technology has low compression efficiency for RAW data images in image signal processing, resulting in high hardware implementation costs and difficulty in ensuring performance, and serious waste of system bus read and write bandwidth.
Divide the image data into multiple macroblocks, and perform compression encoding to reduce storage usage and bandwidth requirements by analyzing the optimal prediction mode and number of encoding bits.
It achieves efficient compression of image data, reduces hardware memory usage and system bus read and write bandwidth, and improves hardware performance and cost-effectiveness.
Smart Images

Figure CN114339250B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image compression, and in particular to an image compression method and device. Background Art
[0002] Image compression technology is mainly divided into two types: lossless compression and lossy compression. In the process of image signal processing (ISP) for processing RAW data images output by optical sensors, since the RAW data images need to be cached, not only a large amount of storage space is occupied in the hardware implementation process, but also a huge amount of system bandwidth is wasted in the reading and writing process, resulting in increased hardware implementation costs and difficult performance guarantees. Therefore, how to compress RAW image data to reduce the memory usage of the hardware and reduce the read and write bandwidth of the system bus is a technical problem that has yet to be solved by those skilled in the art. Summary of the invention
[0003] The technical problem to be solved by the present invention is how to compress RAW image data, and to provide an image compression method and device, which can reduce the memory usage of hardware and reduce the read and write bandwidth of the system bus.
[0004] In order to solve the above technical problem, the first aspect of the present invention discloses an image compression method, the method comprising:
[0005] Dividing the target image data into a plurality of macroblocks, and arranging and storing the plurality of macroblocks in order to obtain a macroblock set of the target image data;
[0006] Acquire a macroblock to be processed, wherein the macroblock to be processed is a macroblock that is ranked the frontmost in a macroblock set of the target image data and has not been compressed and encoded;
[0007] Analyze the macroblock to be processed to obtain the optimal prediction mode corresponding to the macroblock to be processed;
[0008] Determining the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed;
[0009] Determining a final encoding quantization value of the macroblock to be processed according to the number of pre-encoding bits of the macroblock to be processed and a code rate parameter corresponding to the macroblock to be processed;
[0010] The macroblock to be processed is compressed and encoded according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoded quantization value of the macroblock to be processed.
[0011] As an optional implementation manner, in the first aspect of the present invention, analyzing the macroblock to be processed to obtain the optimal prediction mode corresponding to the macroblock to be processed includes:
[0012] Determine a plurality of preset prediction modes and their corresponding prediction algorithms;
[0013] According to all the preset prediction modes and their corresponding prediction algorithms, determining the accumulated residual of the macroblock to be processed in each prediction mode;
[0014] The accumulated residuals of the macroblock to be processed under each of the prediction modes are compared to obtain the prediction mode with the smallest accumulated residual, and the prediction mode with the smallest accumulated residual is determined as the optimal prediction mode of the macroblock to be processed.
[0015] As an optional implementation manner, in the first aspect of the present invention, determining the accumulated residual of the macroblock to be processed in each prediction mode according to all the preset prediction modes and their corresponding prediction algorithms includes:
[0016] For any prediction mode among all the preset prediction modes, determining the predicted pixel value of each pixel to be predicted in the macroblock to be processed according to the prediction mode and its corresponding prediction algorithm;
[0017] Obtaining the original pixel value of each pixel to be predicted in the macroblock to be processed;
[0018] For each pixel to be predicted in the macroblock to be processed, calculating the absolute value of the difference between the predicted pixel value and the original pixel value of the pixel to be predicted to obtain a pixel residual;
[0019] The pixel residual of each pixel to be predicted in the macroblock to be processed is accumulated to obtain a pixel residual accumulation result, and the pixel residual accumulation result is determined as the accumulated residual of the macroblock to be processed in the prediction mode.
[0020] As an optional implementation, in the first aspect of the present invention, the preset multiple prediction modes include a correlation prediction mode, a left prediction mode, an upper prediction mode, an upper-left prediction mode, an upper-right prediction mode, a left-upper-left prediction mode, an upper-left-upper prediction mode, and an upper-upper-right prediction mode;
[0021] For any one of all the preset prediction modes, determining the predicted pixel value of each pixel to be predicted in the macroblock to be processed according to the prediction mode and its corresponding prediction algorithm, comprises:
[0022] For each pixel to be predicted in the macroblock to be processed, pixel values of four adjacent pixels of the pixel to be predicted are obtained, wherein the pixel values of the four adjacent pixels of the pixel to be predicted include a pixel value A of a left pixel located on the left side of the pixel to be predicted, a pixel value B of an upper pixel located above the pixel to be predicted, a pixel value C of an upper-left pixel located above the left side of the pixel to be predicted, and a pixel value D of an upper-right pixel located above the right side of the pixel to be predicted;
[0023] For any prediction mode among all the preset prediction modes, when the prediction mode is the correlation prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula:
[0024]
[0025] For any prediction mode among all the preset prediction modes, when the prediction mode is the left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=A;
[0026] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=B;
[0027] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=C;
[0028] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper right prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=D;
[0029] For any prediction mode among all the preset prediction modes, when the prediction mode is the left-upper-left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(A+C) / 2;
[0030] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper left-upper prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(C+B) / 2;
[0031] For any prediction mode among all the preset prediction modes, when the prediction mode is the top-top-right prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(B+D) / 2.
[0032] As an optional implementation manner, in the first aspect of the present invention, determining the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed includes:
[0033] Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0034] If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, determining the preset encoding quantization value as the pre-encoding quantization value of the macroblock to be processed;
[0035] If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, obtaining a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed from the macroblock set of the target image data as a reference macroblock;
[0036] Acquire the final coded quantization value of the reference macroblock, and determine the final coded quantization value of the reference macroblock as the pre-coded quantization value of the macroblock to be processed;
[0037] Determining a quantization residual of the macroblock to be processed according to an optimal prediction mode corresponding to the macroblock to be processed and a pre-encoded quantization value of the macroblock to be processed;
[0038] Performing folding mapping on the quantized residual of the macroblock to be processed to obtain the mapped quantized residual of the macroblock to be processed;
[0039] The quantized residual after mapping of the macroblock to be processed is encoded by Golomb coding to obtain the number of pre-coding bits of the macroblock to be processed.
[0040] As an optional implementation manner, in the first aspect of the present invention, determining the final encoding quantization value of the macroblock to be processed according to the number of pre-encoded bits of the macroblock to be processed and the code rate parameter corresponding to the macroblock to be processed includes:
[0041] Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0042] If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, determining the preset encoding quantization value as the final encoding quantization value of the macroblock to be processed;
[0043] If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, obtaining a macroblock that is before the macroblock to be processed and closest to the macroblock to be processed from the macroblock set of the target image data as an adjustment macroblock;
[0044] Determining an adjustment range of a coding quantization value of the macroblock to be processed according to a bit rate parameter corresponding to the macroblock to be processed;
[0045] Determining the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock;
[0046] Determining whether the adjusted encoding quantization value of the macroblock to be processed is within the adjustment range of the encoding quantization value of the macroblock to be processed;
[0047] If yes, the adjusted encoding quantization value of the macroblock to be processed is determined as the final encoding quantization value of the macroblock to be processed;
[0048] If not, the adjusted coding quantization value of the macroblock to be processed is updated according to the adjustment range of the coding quantization value of the macroblock to be processed, and the updated adjusted coding quantization value of the macroblock to be processed is determined as the final coding quantization value of the macroblock to be processed.
[0049] As an optional implementation manner, in the first aspect of the present invention, the bit rate parameter corresponding to the macroblock to be processed is determined by:
[0050] Acquire, from the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed as a reference macroblock;
[0051] Acquire the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed, and calculate a first difference between the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed;
[0052] According to the first difference, a rate parameter matching the first difference is searched in a preset rate parameter cache, and the rate parameter matching the first difference is determined as the rate parameter corresponding to the macroblock to be processed.
[0053] As an optional implementation manner, in the first aspect of the present invention, determining the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coded bits of the macroblock to be processed and the final coded quantization value of the adjusted macroblock includes:
[0054] Acquire a final coded quantization value of the adjusted macroblock, and determine a second difference between the final coded quantization value of the adjusted macroblock and a pre-coded quantization value of the macroblock to be processed;
[0055] Determining, according to the second difference, an adjustment range of the number of precoding bits of the macroblock to be processed;
[0056] According to the adjustment range of the precoding bit number of the macroblock to be processed, the precoding bit number of the macroblock to be processed is adjusted to obtain a final precoding bit number of the macroblock to be processed;
[0057] Determining a third difference between a final number of pre-encoded bits of the macroblock to be processed and a final number of encoded bits of the adjusted macroblock;
[0058] Determining, according to the third difference, an adjustment value based on a final encoded quantization value of the adjusted macroblock;
[0059] According to the adjustment value based on the final coded quantization value of the adjusted macroblock, the pre-coded quantization value of the macroblock to be processed is adjusted to obtain the adjusted coded quantization value of the macroblock to be processed.
[0060] As an optional implementation manner, in the first aspect of the present invention, the compression encoding of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoded quantization value of the macroblock to be processed includes:
[0061] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the adaptive exponential Golomb coding, entropy coding is performed on the macroblock to be processed to obtain a first number of coded bits of the macroblock to be processed;
[0062] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual maximum value coding, entropy coding is performed on the macroblock to be processed to obtain a second number of coded bits of the macroblock to be processed;
[0063] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual direct transfer coding, entropy coding is performed on the macroblock to be processed to obtain a third number of coded bits of the macroblock to be processed;
[0064] The first number of coding bits, the second number of coding bits and the third number of coding bits are compared, and the coding method with the smallest number of coding bits is determined as the final coding method to obtain the compression coding result of the macroblock to be processed.
[0065] A second aspect of the present invention discloses an image compression device, the device comprising:
[0066] A division module, used for dividing the target image data into a plurality of macroblocks, and arranging and storing the plurality of macroblocks in order to obtain a macroblock set of the target image data;
[0067] An acquisition module, used for acquiring a macroblock to be processed, wherein the macroblock to be processed is a macroblock which is ranked the frontmost in a macroblock set of the target image data and has not been compressed and encoded;
[0068] An analysis module, used for analyzing the macroblock to be processed to obtain an optimal prediction mode corresponding to the macroblock to be processed;
[0069] A prediction module, used to determine the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed;
[0070] An adjustment module, configured to determine a final encoding quantization value of the macroblock to be processed according to the number of pre-encoding bits of the macroblock to be processed and a code rate parameter corresponding to the macroblock to be processed;
[0071] The encoding module is used to compress and encode the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoding quantization value of the macroblock to be processed.
[0072] As an optional implementation, in the second aspect of the present invention, the analysis module includes:
[0073] A first determination submodule, used to determine a plurality of preset prediction modes and their corresponding prediction algorithms;
[0074] A second determination submodule is used to determine the accumulated residual of the macroblock to be processed in each prediction mode according to all the preset prediction modes and their corresponding prediction algorithms;
[0075] The comparison submodule is used to compare the accumulated residuals of the macroblock to be processed under each prediction mode, obtain the prediction mode with the smallest accumulated residual, and determine the prediction mode with the smallest accumulated residual as the optimal prediction mode of the macroblock to be processed.
[0076] As an optional implementation, in the second aspect of the present invention, the second determination submodule determines the cumulative residual of the macroblock to be processed in each prediction mode according to all the preset prediction modes and their corresponding prediction algorithms, including:
[0077] For any prediction mode among all the preset prediction modes, determining the predicted pixel value of each pixel to be predicted in the macroblock to be processed according to the prediction mode and its corresponding prediction algorithm;
[0078] Obtaining the original pixel value of each pixel to be predicted in the macroblock to be processed;
[0079] For each pixel to be predicted in the macroblock to be processed, calculating the absolute value of the difference between the predicted pixel value and the original pixel value of the pixel to be predicted to obtain a pixel residual;
[0080] The pixel residual of each pixel to be predicted in the macroblock to be processed is accumulated to obtain a pixel residual accumulation result, and the pixel residual accumulation result is determined as the accumulated residual of the macroblock to be processed in the prediction mode.
[0081] As an optional implementation, in the second aspect of the present invention, the preset multiple prediction modes include a correlation prediction mode, a left prediction mode, an upper prediction mode, an upper-left prediction mode, an upper-right prediction mode, a left-upper-left prediction mode, an upper-left-upper prediction mode, and an upper-upper-right prediction mode;
[0082] The second determining submodule determines the predicted pixel value of each to-be-predicted pixel point in the to-be-processed macroblock according to any one of all the preset prediction modes and its corresponding prediction algorithm, including:
[0083] For each pixel to be predicted in the macroblock to be processed, pixel values of four adjacent pixels of the pixel to be predicted are obtained, wherein the pixel values of the four adjacent pixels of the pixel to be predicted include a pixel value A of a left pixel located on the left side of the pixel to be predicted, a pixel value B of an upper pixel located above the pixel to be predicted, a pixel value C of an upper-left pixel located above the left side of the pixel to be predicted, and a pixel value D of an upper-right pixel located above the right side of the pixel to be predicted;
[0084] For any prediction mode among all the preset prediction modes, when the prediction mode is the correlation prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula:
[0085]
[0086] For any prediction mode among all the preset prediction modes, when the prediction mode is the left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=A;
[0087] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=B;
[0088] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=C;
[0089] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper right prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=D;
[0090] For any prediction mode among all the preset prediction modes, when the prediction mode is the left-upper-left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(A+C) / 2;
[0091] For any prediction mode among all the preset prediction modes, when the prediction mode is the upper left-upper prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(C+B) / 2;
[0092] For any prediction mode among all the preset prediction modes, when the prediction mode is the top-top-right prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(B+D) / 2.
[0093] As an optional implementation, in the second aspect of the present invention, the prediction module determines the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed, including:
[0094] Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0095] If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, determining the preset encoding quantization value as the pre-encoding quantization value of the macroblock to be processed;
[0096] If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, obtaining a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed from the macroblock set of the target image data as a reference macroblock;
[0097] Acquire the final coded quantization value of the reference macroblock, and determine the final coded quantization value of the reference macroblock as the pre-coded quantization value of the macroblock to be processed;
[0098] Determining a quantization residual of the macroblock to be processed according to an optimal prediction mode corresponding to the macroblock to be processed and a pre-encoded quantization value of the macroblock to be processed;
[0099] Performing folding mapping on the quantized residual of the macroblock to be processed to obtain the mapped quantized residual of the macroblock to be processed;
[0100] The quantized residual after mapping of the macroblock to be processed is encoded by Golomb coding to obtain the number of pre-coding bits of the macroblock to be processed.
[0101] As an optional implementation, in the second aspect of the present invention, the adjustment module includes:
[0102] A first judgment submodule is used to judge whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0103] A third determination submodule is used to determine the preset coding quantization value as the final coding quantization value of the macroblock to be processed if the determination submodule determines that the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0104] an acquisition submodule, configured to acquire, from the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and closest to the macroblock to be processed as an adjustment macroblock if the judgment submodule judges that the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data;
[0105] A parameter submodule, used to determine the adjustment range of the encoding quantization value of the macroblock to be processed according to the bit rate parameter corresponding to the macroblock to be processed;
[0106] An adjustment submodule, configured to determine an adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock;
[0107] A second judgment submodule is used to judge whether the adjusted coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value of the macroblock to be processed;
[0108] The third determination submodule is further configured to determine the adjusted encoding quantization value of the macroblock to be processed as the final encoding quantization value of the macroblock to be processed if the determination result of the second determination submodule is yes;
[0109] The third determination submodule is also used to update the adjusted coding quantization value of the macroblock to be processed according to the adjustment range of the coding quantization value of the macroblock to be processed if the judgment result of the second judgment submodule is no, and determine the updated adjusted coding quantization value of the macroblock to be processed as the final coding quantization value of the macroblock to be processed.
[0110] As an optional implementation manner, in the second aspect of the present invention, the bit rate parameter corresponding to the macroblock to be processed is determined in the following manner:
[0111] Acquire, from the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed as a reference macroblock;
[0112] Acquire the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed, and calculate a first difference between the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed;
[0113] According to the first difference, a rate parameter matching the first difference is searched in a preset rate parameter cache, and the rate parameter matching the first difference is determined as the rate parameter corresponding to the macroblock to be processed.
[0114] As an optional implementation, in the second aspect of the present invention, the adjustment submodule determines the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coded bits of the macroblock to be processed and the final coded quantization value of the adjusted macroblock, including:
[0115] Acquire a final coded quantization value of the adjusted macroblock, and determine a second difference between the final coded quantization value of the adjusted macroblock and a pre-coded quantization value of the macroblock to be processed;
[0116] Determining, according to the second difference, an adjustment range of the number of precoding bits of the macroblock to be processed;
[0117] According to the adjustment range of the precoding bit number of the macroblock to be processed, the precoding bit number of the macroblock to be processed is adjusted to obtain a final precoding bit number of the macroblock to be processed;
[0118] Determining a third difference between a final number of pre-encoded bits of the macroblock to be processed and a final number of encoded bits of the adjusted macroblock;
[0119] Determining, according to the third difference, an adjustment value based on a final encoded quantized value of the adjusted macroblock;
[0120] According to the adjustment value based on the final coded quantization value of the adjusted macroblock, the pre-coded quantization value of the macroblock to be processed is adjusted to obtain the adjusted coded quantization value of the macroblock to be processed.
[0121] As an optional implementation, in the second aspect of the present invention, the encoding module compresses and encodes the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoded quantization value of the macroblock to be processed, including:
[0122] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the adaptive exponential Golomb coding, entropy coding is performed on the macroblock to be processed to obtain a first number of coded bits of the macroblock to be processed;
[0123] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual maximum value coding, entropy coding is performed on the macroblock to be processed to obtain a second number of coded bits of the macroblock to be processed;
[0124] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual direct transfer coding, entropy coding is performed on the macroblock to be processed to obtain a third number of coded bits of the macroblock to be processed;
[0125] The first number of coding bits, the second number of coding bits and the third number of coding bits are compared, and the coding method with the smallest number of coding bits is determined as the final coding method to obtain the compression coding result of the macroblock to be processed.
[0126] A third aspect of the present invention discloses another image compression device, the device comprising:
[0127] A memory storing executable program code;
[0128] a processor coupled to the memory;
[0129] The processor calls the executable program code stored in the memory to execute the image compression method disclosed in the first aspect of the present invention.
[0130] The fourth aspect of the present invention discloses a computer storable medium, wherein the computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the image compression method disclosed in the first aspect of the present invention.
[0131] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0132] In an embodiment of the present invention, the target image data is divided into a plurality of macroblocks, and the plurality of macroblocks are arranged in order to obtain a macroblock set of the target image data; the macroblock that is ranked the front and has not been compressed and encoded in the macroblock set of the target image data is obtained as a macroblock to be processed; the macroblock to be processed is analyzed to obtain the optimal prediction mode corresponding to the macroblock to be processed; the number of pre-coding bits of the macroblock to be processed is determined according to the optimal prediction mode corresponding to the macroblock to be processed; the final encoding quantization value of the macroblock to be processed is determined according to the number of pre-coding bits of the macroblock to be processed and the code rate parameter corresponding to the macroblock to be processed; the macroblock to be processed is compressed and encoded according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoding quantization value of the macroblock to be processed. It can be seen that the implementation of the present invention can efficiently compress image data, reduce the memory usage of hardware, and reduce the read and write bandwidth of the system bus. BRIEF DESCRIPTION OF THE DRAWINGS
[0133] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. 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 creative work.
[0134] Figure 1 It is a flowchart of an image compression method disclosed in an embodiment of the present invention;
[0135] Figure 2 It is a schematic diagram of a flow chart of obtaining an optimal prediction mode corresponding to a macroblock to be processed disclosed in an embodiment of the present invention;
[0136] Figure 3 It is a schematic diagram of a process of determining a final encoding quantization value of a macroblock to be processed disclosed in an embodiment of the present invention;
[0137] Figure 4 is a schematic diagram of a buffer zone model disclosed in an embodiment of the present invention;
[0138] Figure 5 is a structural schematic diagram of an image compression device disclosed in an embodiment of the present invention;
[0139] Figure 6 is a structural schematic diagram of another image compression device disclosed in an embodiment of the present invention;
[0140] Figure 7 It is a structural schematic diagram of another image compression device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0141] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0142] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or end including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or ends.
[0143] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0144] The present invention discloses an image compression method and device, which can efficiently compress image data, reduce hardware memory usage, and reduce the read and write bandwidth of the system bus. Detailed descriptions are given below.
[0145] Embodiment 1
[0146] See also Figure 1 , Figure 1 is a flow chart of an image compression method disclosed in an embodiment of the present invention. Figure 1 The described image compression method can be applied to a mobile terminal or a server, and the embodiment of the present invention does not limit this. Figure 1 As shown, the image compression method may include the following operations:
[0147] S101, dividing target image data into multiple macroblocks, and arranging the multiple macroblocks in order to obtain a macroblock set of the target image data.
[0148] In the embodiment of the present invention, a frame of RAW image data in a video stream is used as target image data. Before compressing the target image data, the target image data needs to be divided into a plurality of macroblocks. For example, the size of the macroblock may be 32*1. After the target image data is divided into a plurality of macroblocks, each macroblock is numbered, and all macroblocks of the target image data are arranged in order from small to large numbers to obtain a macroblock set of the target image data.
[0149] In the embodiment of the present invention, optionally, the R channel component data, the G channel component data and the B channel component data target image data in the RAW data are obtained; and the R channel component data, the G channel component data and / or the B channel component data target image data are respectively divided into a plurality of macroblocks. It can be seen that this optional embodiment can avoid the influence of other channel component data on pixel prediction in real time.
[0150] S102 , obtaining a macroblock to be processed, wherein the macroblock to be processed is a macroblock that is ranked at the front in a macroblock set of target image data and has not been compressed and encoded.
[0151] In the embodiment of the present invention, each macroblock in the macroblock set of the target image data is compressed in order, so the macroblock that is ranked the front and has not been compressed is used as the macroblock to be processed for subsequent operations to achieve compression processing of the macroblock to be processed.
[0152] S103: Analyze the macroblock to be processed to obtain the optimal prediction mode corresponding to the macroblock to be processed.
[0153] In the embodiment of the present invention, the macroblock to be processed is analyzed, and the optimal prediction mode corresponding to the macroblock to be processed is obtained from multiple prediction modes.
[0154] In the embodiment of the present invention, optionally, please refer to Figure 2 , Figure 2 FIG. 1 is a flow chart of obtaining the optimal prediction mode corresponding to the macroblock to be processed disclosed in an embodiment of the present invention. Figure 2 As shown, step S103, analyzing the macroblock to be processed to obtain the optimal prediction mode corresponding to the macroblock to be processed, includes:
[0155] S1031. Determine a plurality of preset prediction modes and their corresponding prediction algorithms.
[0156] In an optional embodiment of the present invention, the eight preset prediction modes include correlation prediction mode, left prediction mode, upper prediction mode, upper left prediction mode, upper right prediction mode, left-upper left prediction mode, upper left-upper prediction mode, and upper-upper right prediction mode.
[0157] For any pixel to be predicted, firstly, the pixel values of the four adjacent pixels of the pixel to be predicted are determined, and the pixel values of the four adjacent pixels of the pixel to be predicted include the pixel value A of the left pixel located on the left side of the pixel to be predicted, the pixel value B of the upper pixel located above the pixel to be predicted, the pixel value C of the upper left pixel located above the left side of the pixel to be predicted, and the pixel value D of the upper right pixel located above the right side of the pixel to be predicted. Preferably, the pixel values of the four adjacent pixels may be the reconstructed pixel values of the four adjacent pixels.
[0158] In the correlation prediction mode, the predicted pixel value X of the pixel to be predicted is determined according to the following formula:
[0159]
[0160] In the left prediction mode, the predicted pixel value X=A of the pixel to be predicted;
[0161] In the upper prediction mode, the predicted pixel value X=B of the pixel to be predicted;
[0162] In the upper left prediction mode, the predicted pixel value X=C of the pixel to be predicted;
[0163] In the upper right prediction mode, the predicted pixel value X=D of the pixel to be predicted;
[0164] In the left-upper-left prediction mode, the predicted pixel value X of the pixel to be predicted is X=(A+C) / 2;
[0165] In the top-left-top prediction mode, the predicted pixel value X of the pixel to be predicted is X=(C+B) / 2;
[0166] In the top-upper-right prediction mode, the predicted pixel value X of the pixel to be predicted is X=(B+D) / 2.
[0167] S1032: Determine the accumulated residual of the macroblock to be processed in each prediction mode according to all preset prediction modes and their corresponding prediction algorithms.
[0168] In an optional embodiment of the present invention, step S1032, determining the accumulated residual of the macroblock to be processed in each prediction mode according to all preset prediction modes and their corresponding prediction algorithms, specifically includes the following steps:
[0169] For any prediction mode among all the preset prediction modes, determining the predicted pixel value of each pixel to be predicted in the macroblock to be processed according to the prediction mode and its corresponding prediction algorithm;
[0170] Obtaining the original pixel value of each pixel to be predicted in the macroblock to be processed;
[0171] For each pixel to be predicted in the macroblock to be processed, the absolute value of the difference between the predicted pixel value and the original pixel value of the pixel to be predicted is calculated to obtain a pixel residual;
[0172] The pixel residual of each pixel to be predicted in the macroblock to be processed is accumulated to obtain a pixel residual accumulation result, and the pixel residual accumulation result is determined as the accumulated residual of the macroblock to be processed in the prediction mode.
[0173] In an optional embodiment of the present invention, according to the preset multiple prediction modes and their corresponding prediction algorithms determined in step S1031, the predicted pixel value of each pixel to be predicted in the macroblock to be processed in each prediction mode is calculated. The sum of the absolute values of the difference between the predicted pixel value and the original pixel value of each pixel in the macroblock to be processed in each prediction mode is calculated, and the accumulated residual of the macroblock to be processed in the prediction mode is calculated. Finally, eight accumulated residuals corresponding to the macroblock to be processed in the eight prediction modes are obtained.
[0174] S1033 , comparing the accumulated residuals of the macroblock to be processed in each prediction mode, obtaining the prediction mode with the smallest accumulated residual, and determining the prediction mode with the smallest accumulated residual as the optimal prediction mode of the macroblock to be processed.
[0175] In an optional embodiment of the present invention, the smallest cumulative residual among the eight prediction modes is selected to obtain the prediction mode with the smallest cumulative residual, and the optimal prediction mode of the macroblock to be processed is obtained. In an optional embodiment of the present invention, the optimal prediction modes for different macroblocks to be processed can be the same prediction mode or different prediction modes.
[0176] It can be seen that implementing this optional embodiment can determine the most appropriate prediction mode for the macroblock to be processed.
[0177] S104: Determine the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed.
[0178] In the embodiment of the present invention, after the optimal prediction mode corresponding to the macroblock to be processed is determined, the number of precoding bits of the macroblock to be processed can be obtained.
[0179] In the embodiment of the present invention, optionally, step S104, determining the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed, includes:
[0180] Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0181] If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, the preset encoding quantization value is determined as the pre-encoding quantization value of the macroblock to be processed;
[0182] If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and the second closest to the macroblock to be processed is obtained from the macroblock set of the target image data as a reference macroblock;
[0183] Acquire the final coded quantization value of the reference macroblock, and determine the final coded quantization value of the reference macroblock as the pre-coded quantization value of the macroblock to be processed;
[0184] Determine the quantization residual of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the pre-encoded quantization value of the macroblock to be processed;
[0185] Perform folding mapping on the quantized residual of the macroblock to be processed to obtain the mapped quantized residual of the macroblock to be processed;
[0186] The quantized residual after mapping of the macroblock to be processed is encoded by Golomb coding to obtain the number of pre-coding bits of the macroblock to be processed.
[0187] In an optional embodiment of the present invention, for the first two macroblocks in the macroblock set of the target image data, it is impossible to predict their coding bit numbers through the compressed macroblocks, therefore, the preset coding quantization value is directly determined as the pre-coding quantization value of the first two macroblocks. For other macroblocks to be processed except the first two macroblocks in the macroblock set of the target image data, due to the delay caused by the parallel operation of the data, it is impossible to directly use the final coding quantization value of the previous macroblock of the macroblock to be processed, therefore, the final coding quantization value of the previous macroblock is used as the pre-coding quantization value of the macroblock to be processed, and prediction and reconstruction are performed according to the optimal prediction mode and the pre-coded quantization value of the macroblock to be processed, the quantization residual is calculated, and the quantization residual is folded and mapped to reduce the residual range, and the mapped quantization residual is encoded by Columbus coding to calculate the number of pre-coding bits of the macroblock to be processed.
[0188] It can be seen that implementing this optional embodiment can realize coding prediction for the macroblock to be processed.
[0189] S105 , determining a final encoding quantization value of the macroblock to be processed according to the number of pre-encoding bits of the macroblock to be processed and a code rate parameter corresponding to the macroblock to be processed.
[0190] In the embodiment of the present invention, after predictive coding is performed on the macroblock to be processed, it is necessary to perform rate control on the macroblock to be processed to ensure that the macroblock to be processed is effectively coded.
[0191] In the embodiment of the present invention, optionally, please refer to Figure 3 , Figure 3 FIG. 1 is a flow chart of determining the final encoding quantization value of a macroblock to be processed disclosed in an embodiment of the present invention. Figure 3 As shown, step S105, determining the final encoding quantization value of the macroblock to be processed according to the number of pre-encoding bits of the macroblock to be processed and the code rate parameter corresponding to the macroblock to be processed, includes:
[0192] S1051. Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data; if the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, execute step S1052; if the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, execute steps S1053-S1058.
[0193] S1052: Determine the preset coding quantization value as the final coding quantization value of the macroblock to be processed.
[0194] In an optional embodiment of the present invention, for the first two macroblocks in the macroblock set of the target image data, their coding bit numbers cannot be adjusted through the compressed macroblocks, so the preset coding quantization value is directly determined as the final coding quantization value of the first two macroblocks.
[0195] S1053. Acquire, from the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and closest to the macroblock to be processed as an adjustment macroblock.
[0196] In an optional embodiment of the present invention, for other macroblocks to be processed in the macroblock set of the target image data except the first two macroblocks, due to the delay caused by the parallel operation of the data, the final encoded quantization value of the macroblock before the macroblock to be processed cannot be directly used. Therefore, after pre-encoding, it is necessary to adjust the pre-encoded quantization value according to the final encoded quantization value of the macroblock before the macroblock to be processed.
[0197] S1054: Determine an adjustment range of the encoding quantization value of the macroblock to be processed according to a bit rate parameter corresponding to the macroblock to be processed.
[0198] In an optional embodiment of the present invention, the macroblock to be processed has a corresponding bit rate parameter, and the bit rate parameter defines a set of quantization value ranges, including upper and lower limits of the quantization value.
[0199] In an optional embodiment of the present invention, further optionally, the bit rate parameter corresponding to the macroblock to be processed is determined by:
[0200] Acquire a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed from the macroblock set of the target image data as a reference macroblock;
[0201] Obtaining a final number of coded bits of a reference macroblock and a preset target number of bits of a macroblock to be processed, and calculating a first difference between the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed;
[0202] According to the first difference, a rate parameter matching the first difference is searched in a preset rate parameter cache, and the rate parameter matching the first difference is determined as the rate parameter corresponding to the macroblock to be processed.
[0203] In an optional embodiment of the present invention, Figure 4 As shown, Figure 4 It is a schematic diagram of a buffer model disclosed in an embodiment of the present invention, wherein a buffer is set, and there are multiple declaration states in the buffer, and each state corresponds to a set of upper and lower limits of quantization values. The position of the bit rate parameter pointer Ptr_buffer is adjusted according to the difference between the final coded bits of the previous macroblock and the initially set macroblock target bit number, and the range of the coded QP is obtained according to Ptr_buffer.
[0204] S1055 . Determine the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock.
[0205] In an optional embodiment of the present invention, the pre-encoded quantization value is adjusted by the final coded quantization value of the macroblock preceding the macroblock to be processed.
[0206] In an optional embodiment of the present invention, further optional S1055, determining the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock, specifically includes the following steps:
[0207] Acquire a final coded quantization value of the adjusted macroblock, and determine a second difference between the final coded quantization value of the adjusted macroblock and a pre-coded quantization value of the macroblock to be processed;
[0208] Determining an adjustment range of the number of pre-encoding bits of the macroblock to be processed according to the second difference;
[0209] According to the adjustment range of the precoding bit number of the macroblock to be processed, the precoding bit number of the macroblock to be processed is adjusted to obtain the final precoding bit number of the macroblock to be processed;
[0210] Determining a third difference between a final number of pre-encoded bits of the macroblock to be processed and a final number of encoded bits of the adjusted macroblock;
[0211] Determining, according to the third difference, an adjustment value based on a final encoded quantized value of the adjusted macroblock;
[0212] According to the adjustment value based on the final coded quantization value of the adjusted macroblock, the pre-coded quantization value of the macroblock to be processed is adjusted to obtain the adjusted coded quantization value of the macroblock to be processed.
[0213] In an optional embodiment of the present invention, exemplarily, the macroblock to be processed is recorded as macroblock N, and the previous macroblock is recorded (adjusted macroblock) as macroblock N-1. According to the difference between the final coded quantization value of macroblock N-1 and the precoded quantization value of macroblock N, the adjustment amplitude of the precoded bit number of macroblock N is determined. Among them, the corresponding relationship between the adjustment amplitude and the difference can be determined by a machine learning algorithm, and can also be set according to the needs of the actual application. According to the adjustment amplitude of the precoded bit number of macroblock N, the precoded bit number of macroblock N is adjusted to obtain the final precoded bit number of macroblock N. The difference between the final precoded bit number of macroblock N and the final coded bit number of macroblock N-1 is compared to obtain the adjustment value of the coded quantization value of macroblock N based on the final coded quantization value of macroblock N-1, and the precoded quantization value of macroblock N is adjusted according to the adjustment value to obtain the adjusted coded quantization value of macroblock N.
[0214] Exemplarily, the final number of coded bits of macroblock N-1 is x1, the final number of coded bits of macroblock N is x2, M is the difference between the final number of pre-coded bits of macroblock N and the final number of coded bits of macroblock N-1, and k is the size of the macroblock:
[0215] Difference Adjustment value -k<M<k 0 <h2 style=";text-align:left;direction:ltr">-2k <M<=-k <h2 style=";text-align:left;direction:ltr"> -1 M<=-2k -2 k<=M<2k 1 <h2 style=";text-align:left;direction:ltr">2k <M <h2 style=";text-align:left;direction:ltr"> 2
[0216] S1056, determine whether the adjusted coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value of the macroblock to be processed; if so, execute step S1057; if not, execute step S1058.
[0217] S1057: Determine the adjusted encoding quantization value of the macroblock to be processed as the final encoding quantization value of the macroblock to be processed.
[0218] S1058. Update the adjusted coding quantization value of the macroblock to be processed according to the adjustment range of the coding quantization value of the macroblock to be processed, and determine the updated adjusted coding quantization value of the macroblock to be processed as the final coding quantization value of the macroblock to be processed.
[0219] In an optional embodiment of the present invention, after obtaining the adjusted coding quantization value of the macroblock to be processed and the adjustment range of the coding quantization value of the macroblock to be processed, it is necessary to determine whether the adjusted coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value of the macroblock to be processed. If the adjusted coding quantization value of the macroblock to be processed exceeds the upper and lower limits of the adjustment range of the coding quantization value of the macroblock to be processed, it is necessary to update the adjusted coding quantization value of the macroblock to be processed according to the upper and lower limits of the adjustment range of the coding quantization value of the macroblock to be processed, so that the final coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value.
[0220] It can be seen that implementing this optional embodiment can determine the optimal encoding quantization value of the macroblock to be processed.
[0221] S106 , performing compression encoding on the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoded quantization value of the macroblock to be processed.
[0222] In the embodiment of the present invention, after obtaining the optimal prediction mode corresponding to the macroblock to be processed and the final coded quantization value of the macroblock to be processed, compression coding of the macroblock to be processed can be achieved.
[0223] In the embodiment of the present invention, optionally, step S106, performing compression encoding on the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoded quantization value of the macroblock to be processed, includes:
[0224] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the adaptive exponential Golomb coding, entropy coding is performed on the macroblock to be processed to obtain a first coded bit number of the macroblock to be processed;
[0225] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual maximum value coding, entropy coding is performed on the macroblock to be processed to obtain a second coding bit number of the macroblock to be processed;
[0226] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual direct transfer coding, entropy coding is performed on the macroblock to be processed to obtain a third number of coded bits of the macroblock to be processed;
[0227] The first number of coding bits, the second number of coding bits and the third number of coding bits are compared, and the coding method with the smallest number of coding bits is determined as the final coding method to obtain the compression coding result of the macroblock to be processed.
[0228] In an optional embodiment of the present invention, the optimal prediction mode and the final coded quantization value are encoded using three entropy coding methods, and the one with the smallest number of coding bits is selected as the final entropy coding method. The three entropy coding methods are: adaptive exponential Golomb coding, residual maximum coding, and residual direct coding:
[0229] Adaptive Exponential Golomb coding: The quantized residual of the macroblock is encoded using Exponential Golomb coding, where the k value of the current quantized residual is adaptively changed according to the size of the previous quantized residual.
[0230] Residual maximum value encoding: For all quantized residuals in the sub-block, the maximum value is calculated, and the number of bits that can represent the maximum value is obtained as the direct transmission bit number. All quantized residuals in the sub-block are encoded using the direct transmission bit number as the code length; at the same time, the direct transmission bit value is written into the bit stream.
[0231] Residual direct coding: All quantized residuals in the sub-block are encoded using the pixel bit depth minus the number of quantization clipping bits as the code length.
[0232] It can be seen that implementing this optional embodiment can determine the most appropriate encoding method for the macroblock to be processed.
[0233] It can be seen that the implementation Figure 1 The image compression method shown can efficiently compress image data, reduce hardware memory usage, and reduce the read and write bandwidth of the system bus.
[0234] Embodiment 2
[0235] See also Figure 4 , Figure 4 Schematic diagram of the structure of an image compression device disclosed in an embodiment of the present invention. Figure 4 As shown, the image compression device includes: a division module 501, an acquisition module 502, an analysis module 503, a prediction module 504, an adjustment module 505, and an encoding module 506. Among them:
[0236] The division module 501 is used to divide the target image data into a plurality of macroblocks, and arrange the plurality of macroblocks in order to obtain a macroblock set of the target image data.
[0237] In the embodiment of the present invention, a frame of RAW image data in a video stream is used as target image data. Before compressing the target image data, the target image data needs to be divided into a plurality of macroblocks. For example, the size of the macroblock may be 32*1. After the target image data is divided into a plurality of macroblocks, each macroblock is numbered, and all macroblocks of the target image data are arranged in order from small to large numbers to obtain a macroblock set of the target image data.
[0238] In the embodiment of the present invention, optionally, the R channel component data, the G channel component data and the B channel component data target image data in the RAW data are obtained; and the R channel component data, the G channel component data and / or the B channel component data target image data are respectively divided into a plurality of macroblocks. It can be seen that this optional embodiment can avoid the influence of other channel component data on pixel prediction in real time.
[0239] The acquisition module 502 is used to acquire a macroblock to be processed, wherein the macroblock to be processed is a macroblock that is ranked the front in the macroblock set of the target image data and has not been compressed and encoded.
[0240] In the embodiment of the present invention, each macroblock in the macroblock set of the target image data is compressed in order, so the macroblock that is ranked the front and has not been compressed is used as the macroblock to be processed for subsequent operations to achieve compression processing of the macroblock to be processed.
[0241] The analysis module 503 is used to analyze the macroblock to be processed and obtain the optimal prediction mode corresponding to the macroblock to be processed.
[0242] In the embodiment of the present invention, the macroblock to be processed is analyzed, and the optimal prediction mode corresponding to the macroblock to be processed is obtained from multiple prediction modes.
[0243] The prediction module 504 is used to determine the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed.
[0244] In the embodiment of the present invention, after the optimal prediction mode corresponding to the macroblock to be processed is determined, the number of precoding bits of the macroblock to be processed can be obtained.
[0245] The adjustment module 505 is used to determine the final encoding quantization value of the macroblock to be processed according to the number of pre-encoding bits of the macroblock to be processed and the code rate parameter corresponding to the macroblock to be processed.
[0246] In the embodiment of the present invention, after predictive coding is performed on the macroblock to be processed, it is necessary to perform rate control on the macroblock to be processed to ensure that the macroblock to be processed is effectively coded.
[0247] The encoding module 506 is used to compress and encode the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoding quantization value of the macroblock to be processed.
[0248] In the embodiment of the present invention, after obtaining the optimal prediction mode corresponding to the macroblock to be processed and the final coded quantization value of the macroblock to be processed, compression coding of the macroblock to be processed can be achieved.
[0249] It can be seen that the implementation Figure 5 The image compression method shown can efficiently compress image data, reduce hardware memory usage, and reduce the read and write bandwidth of the system bus.
[0250] In the embodiment of the present invention, optionally, please refer to Figure 6 , Figure 6 is a schematic diagram of the structure of another image compression device disclosed in an embodiment of the present invention, wherein the analysis module 503 includes:
[0251] The first determination submodule 5031 is used to determine a plurality of preset prediction modes and their corresponding prediction algorithms.
[0252] In an optional embodiment of the present invention, the eight preset prediction modes include correlation prediction mode, left prediction mode, upper prediction mode, upper left prediction mode, upper right prediction mode, left-upper left prediction mode, upper left-upper prediction mode, and upper-upper right prediction mode.
[0253] For any pixel to be predicted, firstly, the pixel values of the four adjacent pixels of the pixel to be predicted are determined, and the pixel values of the four adjacent pixels of the pixel to be predicted include the pixel value A of the left pixel located on the left side of the pixel to be predicted, the pixel value B of the upper pixel located above the pixel to be predicted, the pixel value C of the upper left pixel located above the left side of the pixel to be predicted, and the pixel value D of the upper right pixel located above the right side of the pixel to be predicted. Preferably, the pixel values of the four adjacent pixels may be the reconstructed pixel values of the four adjacent pixels.
[0254] In the correlation prediction mode, the predicted pixel value X of the pixel to be predicted is determined according to the following formula:
[0255]
[0256] In the left prediction mode, the predicted pixel value X=A of the pixel to be predicted;
[0257] In the upper prediction mode, the predicted pixel value X=B of the pixel to be predicted;
[0258] In the upper left prediction mode, the predicted pixel value X=C of the pixel to be predicted;
[0259] In the upper right prediction mode, the predicted pixel value X=D of the pixel to be predicted;
[0260] In the left-upper-left prediction mode, the predicted pixel value X of the pixel to be predicted is X=(A+C) / 2;
[0261] In the top-left-top prediction mode, the predicted pixel value X of the pixel to be predicted is X=(C+B) / 2;
[0262] In the top-upper-right prediction mode, the predicted pixel value X of the pixel to be predicted is X=(B+D) / 2.
[0263] The second determination submodule 5032 is used to determine the accumulated residual of the macroblock to be processed in each prediction mode according to all preset prediction modes and their corresponding prediction algorithms.
[0264] In the embodiment of the present invention, the second determining submodule 5032 determines the accumulated residual of the macroblock to be processed in each prediction mode according to all the prediction modes and their corresponding prediction algorithms preset in the first determining submodule 5031, including:
[0265] For any prediction mode among all the preset prediction modes, determining the predicted pixel value of each pixel to be predicted in the macroblock to be processed according to the prediction mode and its corresponding prediction algorithm;
[0266] Obtaining the original pixel value of each pixel to be predicted in the macroblock to be processed;
[0267] For each pixel to be predicted in the macroblock to be processed, the absolute value of the difference between the predicted pixel value and the original pixel value of the pixel to be predicted is calculated to obtain a pixel residual;
[0268] The pixel residual of each pixel to be predicted in the macroblock to be processed is accumulated to obtain a pixel residual accumulation result, and the pixel residual accumulation result is determined as the accumulated residual of the macroblock to be processed in the prediction mode.
[0269] In an optional embodiment of the present invention, according to the determined preset multiple prediction modes and their corresponding prediction algorithms, the predicted pixel value of each pixel to be predicted in the macroblock to be processed in each prediction mode is calculated. The sum of the absolute values of the difference between the predicted pixel value and the original pixel value of each pixel in the macroblock to be processed in each prediction mode is calculated, and the accumulated residual of the macroblock to be processed in the prediction mode is calculated. Finally, eight accumulated residuals corresponding to the macroblock to be processed in the eight prediction modes are obtained.
[0270] The comparison submodule 5033 is used to compare the accumulated residuals of the macroblock to be processed in each prediction mode, obtain the prediction mode with the smallest accumulated residual, and determine the prediction mode with the smallest accumulated residual as the optimal prediction mode of the macroblock to be processed.
[0271] In an optional embodiment of the present invention, the smallest cumulative residual among the eight prediction modes is selected to obtain the prediction mode with the smallest cumulative residual, and the optimal prediction mode of the macroblock to be processed is obtained. In an optional embodiment of the present invention, the optimal prediction modes for different macroblocks to be processed can be the same prediction mode or different prediction modes.
[0272] It can be seen that implementing this optional embodiment can determine the most appropriate prediction mode for the macroblock to be processed.
[0273] In the embodiment of the present invention, optionally, the prediction module 504 determines the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed, including:
[0274] Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0275] If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, the preset encoding quantization value is determined as the pre-encoding quantization value of the macroblock to be processed;
[0276] If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and the second closest to the macroblock to be processed is obtained from the macroblock set of the target image data as a reference macroblock;
[0277] Acquire the final coded quantization value of the reference macroblock, and determine the final coded quantization value of the reference macroblock as the pre-coded quantization value of the macroblock to be processed;
[0278] Determine the quantization residual of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the pre-encoded quantization value of the macroblock to be processed;
[0279] Perform folding mapping on the quantized residual of the macroblock to be processed to obtain the mapped quantized residual of the macroblock to be processed;
[0280] The quantized residual after mapping of the macroblock to be processed is encoded by Golomb coding to obtain the number of pre-coding bits of the macroblock to be processed.
[0281] In an optional embodiment of the present invention, for the first two macroblocks in the macroblock set of the target image data, it is impossible to predict their coding bit numbers through the compressed macroblocks, therefore, the preset coding quantization value is directly determined as the pre-coding quantization value of the first two macroblocks. For other macroblocks to be processed except the first two macroblocks in the macroblock set of the target image data, due to the delay caused by the parallel operation of the data, it is impossible to directly use the final coding quantization value of the previous macroblock of the macroblock to be processed, therefore, the final coding quantization value of the previous macroblock is used as the pre-coding quantization value of the macroblock to be processed, and prediction and reconstruction are performed according to the optimal prediction mode and the pre-coded quantization value of the macroblock to be processed, the quantization residual is calculated, and the quantization residual is folded and mapped to reduce the residual range, and the mapped quantization residual is encoded by Columbus coding to calculate the number of pre-coding bits of the macroblock to be processed.
[0282] It can be seen that implementing this optional embodiment can realize coding prediction for the macroblock to be processed.
[0283] In the embodiment of the present invention, optionally, the adjustment module 505 includes:
[0284] The first judgment submodule 5051 is used to judge whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0285] The third determination submodule 5052 is used to determine the preset coding quantization value as the final coding quantization value of the macroblock to be processed if the first determination submodule 5051 determines that the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data;
[0286] The acquisition submodule 5053 is used for acquiring a macroblock that is before the macroblock to be processed and closest to the macroblock to be processed from the macroblock set of the target image data as an adjustment macroblock if the first judgment submodule 5051 judges that the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data;
[0287] The parameter submodule 5054 is used to determine the adjustment range of the encoding quantization value of the macroblock to be processed according to the bit rate parameter corresponding to the macroblock to be processed;
[0288] The adjustment submodule 5055 is used to determine the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock;
[0289] The second judgment submodule 5056 is used to judge whether the adjusted coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value of the macroblock to be processed;
[0290] The third determination submodule 5052 is further configured to determine the adjusted coded quantization value of the macroblock to be processed as the final coded quantization value of the macroblock to be processed if the determination result of the second determination submodule 5056 is yes;
[0291] The third determination submodule 5052 is also used to update the adjusted coding quantization value of the macroblock to be processed according to the adjustment range of the coding quantization value of the macroblock to be processed if the judgment result of the second judgment submodule 5056 is no, and determine the updated adjusted coding quantization value of the macroblock to be processed as the final coding quantization value of the macroblock to be processed.
[0292] In an optional embodiment of the present invention, for the first two macroblocks in the macroblock set of the target image data, the number of coding bits thereof cannot be adjusted by the compressed macroblocks, and therefore, the preset coding quantization value is directly determined as the final coding quantization value of the first two macroblocks. For other macroblocks to be processed except the first two macroblocks in the macroblock set of the target image data, due to the delay caused by the parallel operation of the data, the final coding quantization value of the previous macroblock of the macroblock to be processed cannot be directly used. Therefore, after pre-coding, the pre-coding quantization value needs to be adjusted by the final coding quantization value of the previous macroblock of the macroblock to be processed. The macroblock to be processed has a corresponding bit rate parameter, and the bit rate parameter defines a set of quantization value ranges, including upper and lower limits of the quantization value. The pre-coding quantization value is adjusted by the final coding quantization value of the previous macroblock of the macroblock to be processed. After obtaining the adjusted coding quantization value of the macroblock to be processed and the adjustment range of the coding quantization value of the macroblock to be processed, it is necessary to determine whether the adjusted coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value of the macroblock to be processed. If the adjusted coding quantization value of the macroblock to be processed exceeds the upper and lower limits of the adjustment range of the coding quantization value of the macroblock to be processed, it is necessary to update the adjusted coding quantization value of the macroblock to be processed according to the upper and lower limits of the adjustment range of the coding quantization value of the macroblock to be processed, so that the final coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value.
[0293] It can be seen that implementing this optional embodiment can determine the optimal encoding quantization value of the macroblock to be processed.
[0294] In the embodiment of the present invention, optionally, the bit rate parameter corresponding to the macroblock to be processed is determined in the following manner:
[0295] Acquire a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed from the macroblock set of the target image data as a reference macroblock;
[0296] Obtaining a final number of coded bits of a reference macroblock and a preset target number of bits of a macroblock to be processed, and calculating a first difference between the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed;
[0297] According to the first difference, a rate parameter matching the first difference is searched in a preset rate parameter cache, and the rate parameter matching the first difference is determined as the rate parameter corresponding to the macroblock to be processed.
[0298] In an optional embodiment of the present invention, a buffer buffer is set, and there are multiple declaration states in the buffer buffer, and each state corresponds to a set of upper and lower limits of quantization values. The position of the bit rate parameter pointer Ptr_buffer is adjusted according to the difference between the final coded bits of the previous macroblock and the initially set macroblock target bit number, and the range of the coded QP is obtained according to Ptr_buffer.
[0299] In the embodiment of the present invention, optionally, the adjustment submodule 5055 determines the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coded quantization value of the adjusted macroblock, including:
[0300] Acquire a final coded quantization value of the adjusted macroblock, and determine a second difference between the final coded quantization value of the adjusted macroblock and a pre-coded quantization value of the macroblock to be processed;
[0301] Determining an adjustment range of the number of pre-encoding bits of the macroblock to be processed according to the second difference;
[0302] According to the adjustment range of the precoding bit number of the macroblock to be processed, the precoding bit number of the macroblock to be processed is adjusted to obtain the final precoding bit number of the macroblock to be processed;
[0303] Determining a third difference between a final number of pre-encoded bits of the macroblock to be processed and a final number of encoded bits of the adjusted macroblock;
[0304] Determining, according to the third difference, an adjustment value based on a final encoded quantized value of the adjusted macroblock;
[0305] According to the adjustment value based on the final coded quantization value of the adjusted macroblock, the pre-coded quantization value of the macroblock to be processed is adjusted to obtain the adjusted coded quantization value of the macroblock to be processed.
[0306] In an optional embodiment of the present invention, exemplarily, the macroblock to be processed is recorded as macroblock N, and the previous macroblock is recorded (adjusted macroblock) as macroblock N-1. According to the difference between the final coded quantization value of macroblock N-1 and the precoded quantization value of macroblock N, the adjustment amplitude of the precoded bit number of macroblock N is determined. Among them, the corresponding relationship between the adjustment amplitude and the difference can be determined by a machine learning algorithm, and can also be set according to the needs of the actual application. According to the adjustment amplitude of the precoded bit number of macroblock N, the precoded bit number of macroblock N is adjusted to obtain the final precoded bit number of macroblock N. The difference between the final precoded bit number of macroblock N and the final coded bit number of macroblock N-1 is compared to obtain the adjustment value of the coded quantization value of macroblock N based on the final coded quantization value of macroblock N-1, and the precoded quantization value of macroblock N is adjusted according to the adjustment value to obtain the adjusted coded quantization value of macroblock N.
[0307] Exemplarily, the final number of coded bits of macroblock N-1 is x1, the final number of coded bits of macroblock N is x2, M is the difference between the final number of pre-coded bits of macroblock N and the final number of coded bits of macroblock N-1, and k is the size of the macroblock:
[0308] Difference Adjustment value -k<M<k 0 <h2 style=";text-align:left;direction:ltr">-2k <M<=-k <h2 style=";text-align:left;direction:ltr"> -1 M<=-2k -2 k<=M<2k 1 <h2 style=";text-align:left;direction:ltr">2k <M <h2 style=";text-align:left;direction:ltr"> 2
[0309] In the embodiment of the present invention, the encoding module 506 compresses and encodes the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final encoding quantization value of the macroblock to be processed, including:
[0310] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the adaptive exponential Golomb coding, entropy coding is performed on the macroblock to be processed to obtain a first coded bit number of the macroblock to be processed;
[0311] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual maximum value coding, entropy coding is performed on the macroblock to be processed to obtain a second coding bit number of the macroblock to be processed;
[0312] According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual direct transfer coding, entropy coding is performed on the macroblock to be processed to obtain a third number of coded bits of the macroblock to be processed;
[0313] The first number of coding bits, the second number of coding bits and the third number of coding bits are compared, and the coding method with the smallest number of coding bits is determined as the final coding method to obtain the compression coding result of the macroblock to be processed.
[0314] In an optional embodiment of the present invention, the optimal prediction mode and the final coded quantization value are encoded using three entropy coding methods, and the one with the smallest number of coding bits is selected as the final entropy coding method. The three entropy coding methods are: adaptive exponential Golomb coding, residual maximum coding, and residual direct coding:
[0315] Adaptive Exponential Golomb coding: The quantized residual of the macroblock is encoded using Exponential Golomb coding, where the k value of the current quantized residual is adaptively changed according to the size of the previous quantized residual.
[0316] Residual maximum value encoding: For all quantized residuals in the sub-block, the maximum value is calculated, and the number of bits that can represent the maximum value is obtained as the direct transmission bit number. All quantized residuals in the sub-block are encoded using the direct transmission bit number as the code length; at the same time, the direct transmission bit value is written into the bit stream.
[0317] Residual direct coding: All quantized residuals in the sub-block are encoded using the pixel bit depth minus the number of quantization clipping bits as the code length.
[0318] It can be seen that implementing this optional embodiment can determine the most appropriate encoding method for the macroblock to be processed.
[0319] Embodiment 3
[0320] See also Figure 7 , Figure 7 FIG. 1 is a schematic diagram of the structure of another image compression device disclosed in an embodiment of the present invention. Figure 7 As shown, the image compression device may include:
[0321] A memory 701 storing executable program codes;
[0322] a processor 702 coupled to the memory 701;
[0323] The processor 702 calls the executable program code stored in the memory 701 to execute the steps of the image compression method described in the first embodiment of the present invention or the second embodiment of the present invention.
[0324] Embodiment 5
[0325] An embodiment of the present invention discloses a computer storable medium, which stores computer instructions. When the computer instructions are called, they are used to execute the steps in the image compression method described in the first embodiment of the present invention or the second embodiment of the present invention.
[0326] Embodiment 6
[0327] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute the steps in the image compression method described in Embodiment 1 or Embodiment 2.
[0328] The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
[0329] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or partly contributed to the prior art in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0330] Finally, it should be noted that the image compression method and device disclosed in the embodiments of the present invention are only preferred embodiments of the present invention, and are only used to illustrate the technical solution of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features therein can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An image compression method, characterized in that: The method comprises: Dividing the target image data into a plurality of macroblocks, and arranging and storing the plurality of macroblocks in order to obtain a macroblock set of the target image data; Acquire a macroblock to be processed, wherein the macroblock to be processed is a macroblock that is ranked the frontmost in a macroblock set of the target image data and has not been compressed and encoded; Analyze the macroblock to be processed to obtain the optimal prediction mode corresponding to the macroblock to be processed; Determining the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed; Determining a final encoding quantization value of the macroblock to be processed according to the number of pre-encoding bits of the macroblock to be processed and a code rate parameter corresponding to the macroblock to be processed; According to the optimal prediction mode corresponding to the macroblock to be processed and the final coded quantization value of the macroblock to be processed, the macroblock to be processed is compressed and encoded; The step of determining the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed includes: Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data; If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, determining the preset encoding quantization value as the pre-encoding quantization value of the macroblock to be processed; If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, obtaining a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed from the macroblock set of the target image data as a reference macroblock; Acquire the final coded quantization value of the reference macroblock, and determine the final coded quantization value of the reference macroblock as the pre-coded quantization value of the macroblock to be processed; Determining a quantization residual of the macroblock to be processed according to an optimal prediction mode corresponding to the macroblock to be processed and a pre-encoded quantization value of the macroblock to be processed; Performing folding mapping on the quantized residual of the macroblock to be processed to obtain the mapped quantized residual of the macroblock to be processed; Encoding the quantized residual after mapping the macroblock to be processed by Golomb coding to obtain the number of pre-coding bits of the macroblock to be processed; And, determining the final encoding quantization value of the macroblock to be processed according to the number of pre-encoded bits of the macroblock to be processed and the code rate parameter corresponding to the macroblock to be processed includes: Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data; If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, determining the preset encoding quantization value as the final encoding quantization value of the macroblock to be processed; If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, obtaining a macroblock that is before the macroblock to be processed and closest to the macroblock to be processed from the macroblock set of the target image data as an adjustment macroblock; Determining an adjustment range of a coding quantization value of the macroblock to be processed according to a bit rate parameter corresponding to the macroblock to be processed; Determining the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock; Determining whether the adjusted encoding quantization value of the macroblock to be processed is within the adjustment range of the encoding quantization value of the macroblock to be processed; If yes, the adjusted encoding quantization value of the macroblock to be processed is determined as the final encoding quantization value of the macroblock to be processed; If not, the adjusted coding quantization value of the macroblock to be processed is updated according to the adjustment range of the coding quantization value of the macroblock to be processed, and the updated adjusted coding quantization value of the macroblock to be processed is determined as the final coding quantization value of the macroblock to be processed.
2. The image compression method according to claim 1, characterized in that: The analyzing the macroblock to be processed to obtain the optimal prediction mode corresponding to the macroblock to be processed includes: Determine a plurality of preset prediction modes and their corresponding prediction algorithms; According to all the preset prediction modes and their corresponding prediction algorithms, determining the accumulated residual of the macroblock to be processed in each prediction mode; The accumulated residuals of the macroblock to be processed under each of the prediction modes are compared to obtain the prediction mode with the smallest accumulated residual, and the prediction mode with the smallest accumulated residual is determined as the optimal prediction mode of the macroblock to be processed.
3. The image compression method according to claim 2, characterized in that: The step of determining the accumulated residual of the macroblock to be processed in each prediction mode according to all the preset prediction modes and their corresponding prediction algorithms includes: For any prediction mode among all the preset prediction modes, determining the predicted pixel value of each pixel to be predicted in the macroblock to be processed according to the prediction mode and its corresponding prediction algorithm; Obtaining the original pixel value of each pixel to be predicted in the macroblock to be processed; For each pixel to be predicted in the macroblock to be processed, calculating the absolute value of the difference between the predicted pixel value and the original pixel value of the pixel to be predicted to obtain a pixel residual; The pixel residual of each pixel to be predicted in the macroblock to be processed is accumulated to obtain a pixel residual accumulation result, and the pixel residual accumulation result is determined as the accumulated residual of the macroblock to be processed in the prediction mode.
4. The image compression method according to claim 3, characterized in that: The preset multiple prediction modes include a correlation prediction mode, a left prediction mode, an upper prediction mode, an upper-left prediction mode, an upper-right prediction mode, a left-upper-left prediction mode, an upper-left-upper prediction mode, and an upper-upper-right prediction mode; For any one of all the preset prediction modes, determining the predicted pixel value of each pixel to be predicted in the macroblock to be processed according to the prediction mode and its corresponding prediction algorithm, comprises: For each pixel to be predicted in the macroblock to be processed, pixel values of four adjacent pixels of the pixel to be predicted are obtained, wherein the pixel values of the four adjacent pixels of the pixel to be predicted include a pixel value A of a left pixel located on the left side of the pixel to be predicted, a pixel value B of an upper pixel located above the pixel to be predicted, a pixel value C of an upper-left pixel located above the left side of the pixel to be predicted, and a pixel value D of an upper-right pixel located above the right side of the pixel to be predicted; For any prediction mode among all the preset prediction modes, when the prediction mode is the correlation prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: For any prediction mode among all the preset prediction modes, when the prediction mode is the left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=A; For any prediction mode among all the preset prediction modes, when the prediction mode is the upper prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=B; For any prediction mode among all the preset prediction modes, when the prediction mode is the upper left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=C; For any prediction mode among all the preset prediction modes, when the prediction mode is the upper right prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=D; For any prediction mode among all the preset prediction modes, when the prediction mode is the left-upper-left prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(A+C) / 2; For any prediction mode among all the preset prediction modes, when the prediction mode is the upper left-upper prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(C+B) / 2; For any prediction mode among all the preset prediction modes, when the prediction mode is the top-top-right prediction mode, the predicted pixel value X of each pixel to be predicted is determined according to the following formula: X=(B+D) / 2.
5. The image compression method according to claim 1, characterized in that: The code rate parameter corresponding to the macroblock to be processed is determined in the following manner: Acquire, from the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed as a reference macroblock; Acquire the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed, and calculate a first difference between the final number of coded bits of the reference macroblock and the preset target number of bits of the macroblock to be processed; According to the first difference, a rate parameter matching the first difference is searched in a preset rate parameter cache, and the rate parameter matching the first difference is determined as the rate parameter corresponding to the macroblock to be processed.
6. The image compression method according to claim 1, characterized in that: The step of determining the adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock includes: Acquire a final coded quantization value of the adjusted macroblock, and determine a second difference between the final coded quantization value of the adjusted macroblock and a pre-coded quantization value of the macroblock to be processed; Determining, according to the second difference, an adjustment range of the number of precoding bits of the macroblock to be processed; According to the adjustment range of the precoding bit number of the macroblock to be processed, the precoding bit number of the macroblock to be processed is adjusted to obtain a final precoding bit number of the macroblock to be processed; Determining a third difference between a final number of pre-encoded bits of the macroblock to be processed and a final number of encoded bits of the adjusted macroblock; Determining, according to the third difference, an adjustment value based on a final encoded quantization value of the adjusted macroblock; According to the adjustment value based on the final coded quantization value of the adjusted macroblock, the pre-coded quantization value of the macroblock to be processed is adjusted to obtain the adjusted coded quantization value of the macroblock to be processed.
7. The image compression method according to claim 1, characterized in that: The step of compressing and encoding the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed and the final coded quantization value of the macroblock to be processed comprises: According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the adaptive exponential Golomb coding, entropy coding is performed on the macroblock to be processed to obtain a first number of coded bits of the macroblock to be processed; According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual maximum value coding, entropy coding is performed on the macroblock to be processed to obtain a second number of coded bits of the macroblock to be processed; According to the optimal prediction mode corresponding to the macroblock to be processed, the final coded quantization value of the macroblock to be processed, and the residual direct transfer coding, entropy coding is performed on the macroblock to be processed to obtain a third number of coded bits of the macroblock to be processed; The first number of coding bits, the second number of coding bits and the third number of coding bits are compared, and the coding method with the smallest number of coding bits is determined as the final coding method to obtain the compression coding result of the macroblock to be processed.
8. An image compression device, characterized in that: The device comprises: A division module, used for dividing the target image data into a plurality of macroblocks, and arranging and storing the plurality of macroblocks in order to obtain a macroblock set of the target image data; An acquisition module, used for acquiring a macroblock to be processed, wherein the macroblock to be processed is a macroblock which is ranked the frontmost in a macroblock set of the target image data and has not been compressed and encoded; An analysis module, used for analyzing the macroblock to be processed to obtain an optimal prediction mode corresponding to the macroblock to be processed; A prediction module, used to determine the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed; An adjustment module, configured to determine a final encoding quantization value of the macroblock to be processed according to the number of pre-encoding bits of the macroblock to be processed and a code rate parameter corresponding to the macroblock to be processed; An encoding module, configured to compress and encode the macroblock to be processed according to an optimal prediction mode corresponding to the macroblock to be processed and a final encoding quantization value of the macroblock to be processed; The prediction module determines the number of precoding bits of the macroblock to be processed according to the optimal prediction mode corresponding to the macroblock to be processed, including: Determine whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data; If the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data, determining the preset encoding quantization value as the pre-encoding quantization value of the macroblock to be processed; If the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data, obtaining a macroblock that is before the macroblock to be processed and is the second closest to the macroblock to be processed from the macroblock set of the target image data as a reference macroblock; Acquire the final coded quantization value of the reference macroblock, and determine the final coded quantization value of the reference macroblock as the pre-coded quantization value of the macroblock to be processed; Determining a quantization residual of the macroblock to be processed according to an optimal prediction mode corresponding to the macroblock to be processed and a pre-encoded quantization value of the macroblock to be processed; Performing folding mapping on the quantized residual of the macroblock to be processed to obtain the mapped quantized residual of the macroblock to be processed; Encoding the quantized residual after mapping the macroblock to be processed by Golomb coding to obtain the number of pre-coding bits of the macroblock to be processed; And, the adjustment module includes: A first judgment submodule is used to judge whether the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data; A third determination submodule is used to determine the preset coding quantization value as the final coding quantization value of the macroblock to be processed if the determination submodule determines that the macroblock to be processed is one of the first two macroblocks in the macroblock set of the target image data; an acquisition submodule, configured to acquire, from the macroblock set of the target image data, a macroblock that is before the macroblock to be processed and closest to the macroblock to be processed as an adjustment macroblock if the judgment submodule judges that the macroblock to be processed is not one of the first two macroblocks in the macroblock set of the target image data; A parameter submodule, used to determine the adjustment range of the encoding quantization value of the macroblock to be processed according to the bit rate parameter corresponding to the macroblock to be processed; An adjustment submodule, configured to determine an adjusted coding quantization value of the macroblock to be processed according to the number of pre-coding bits of the macroblock to be processed and the final coding quantization value of the adjusted macroblock; A second judgment submodule is used to judge whether the adjusted coding quantization value of the macroblock to be processed is within the adjustment range of the coding quantization value of the macroblock to be processed; The third determination submodule is further configured to determine the adjusted encoding quantization value of the macroblock to be processed as the final encoding quantization value of the macroblock to be processed if the determination result of the second determination submodule is yes; The third determination submodule is also used to update the adjusted coding quantization value of the macroblock to be processed according to the adjustment range of the coding quantization value of the macroblock to be processed if the judgment result of the second judgment submodule is no, and determine the updated adjusted coding quantization value of the macroblock to be processed as the final coding quantization value of the macroblock to be processed.
