Image compression device and method, and computer readable medium
By dynamically adjusting the target overhead of the image block in the image compression device, and reasonably allocating the code stream space according to the compression difficulty level of the image block, the problems of degradation of image compression effect and waste of code stream in the prior art are solved, and the compression quality of complex areas is improved.
Patent Information
- Application Number
- CN202311444323.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-31
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2043-10-31
AI Technical Summary
In the prior art, when image compression is compressed, the compression effect decreases when the difficulty and easy distribution is complex, and the code stream space allocation is unreasonable, resulting in low compression quality in complex areas and waste of code streams.
By introducing a data acquisition module, an overhead determination module and a compression module in the image compression device, the image data of the image to be compressed is acquired, the target overhead number of each image block is determined, and the pixel data is compressed and encoded according to the target overhead number. This method dynamically adjusts the target overhead according to the compression difficulty level of the image block and allocates the code stream space reasonably.
Improve the compression quality of complex areas in the image, avoid waste of code stream space, and ensure the overall effect of image compression.
Smart Images

Figure CN117499642B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to an image compression device and method, and a computer-readable storage medium. Background Art
[0002] The basic idea of current image compression methods is to use the spatial correlation of images, remove redundant information, and then perform compression coding. There are three basic methods of image compression: image compression methods based on prediction and coding, image compression methods based on transformation, and compression methods based on block truncation. Among them, the image compression methods based on prediction and coding have higher accuracy, but when the image difficulty distribution is more complex, the compression effect will be reduced to a certain extent. Summary of the invention
[0003] The present disclosure aims to solve at least one of the technical problems existing in the prior art, and proposes an image compression device and method, and a computer-readable storage medium.
[0004] In a first aspect, the present disclosure provides an image compression device, comprising:
[0005] A data acquisition module is configured to acquire image data of an image to be compressed; the image to be compressed includes a plurality of rows and columns of image blocks, the image blocks include a plurality of pixels, and the image data includes pixel data of each pixel in the image to be compressed;
[0006] an overhead number determination module, configured to determine a target overhead number for each of the image blocks; wherein, in at least one row, the target overhead number for the image blocks is obtained based on the compression difficulty level of the image blocks; and, for two image blocks with different compression difficulty levels in the same row, the target overhead number corresponding to the image block with a relatively higher compression difficulty level is greater than the target overhead number for the image block with a relatively lower compression difficulty level;
[0007] The compression module is configured to compress and encode the pixel data in the corresponding image block according to the target overhead number of each image block.
[0008] In some embodiments, the overhead number determination module is further configured to:
[0009] When it is determined that the compression difficulty levels of the plurality of image blocks in the i-th row after the first row are not completely the same, the initial overhead number is adjusted according to the compression difficulty level of the j-th image block in the i-th row to obtain a target overhead number of the j-th image block in the i-th row;
[0010] Among them, i and j are both integers, i is greater than 1 and not greater than the total number of rows of the image blocks, j is greater than 0 and not greater than the number of pixel blocks in each row; the initial overhead number corresponding to each image block in the image to be compressed is the same; in the same row, the sum of the target overhead numbers of multiple image blocks is 0.9 to 1 times the sum of the initial overhead numbers of multiple image blocks.
[0011] In some embodiments, the overhead number determination module is further configured to:
[0012] Obtain, from the image blocks that have completed data compression processing, cost differences between actual cost numbers of each adjacent image block of the j-th image block in the i-th row after compression encoding and corresponding target cost numbers;
[0013] Determine, according to the cost difference of each adjacent image block and the mapping relationship between the compression difficulty level and the cost difference range, the compression difficulty level corresponding to the cost difference of each adjacent image block;
[0014] And, the compression difficulty level of the j-th image block in the ith row is determined according to the compression difficulty level corresponding to the cost difference of each adjacent image block.
[0015] In some embodiments, the overhead number determination module is further configured to:
[0016] When multiple image blocks in the i-th row have multiple different compression difficulty levels, at least the initial overhead number of each image block with the highest compression difficulty level is increased by a first adjustment amount, and the initial overhead number of each image block with the lowest compression difficulty level is reduced by a second adjustment amount to obtain a target overhead number for each image block in the i-th row.
[0017] In some embodiments, the image compression apparatus further comprises:
[0018] A pre-compression module, configured to pre-compress the pixel data in each of the image blocks using a pre-allocated initial overhead number;
[0019] A difference determination module is configured to obtain a cost difference between an actual cost number of each image block in a pre-compression process and the initial cost number;
[0020] a level determination module configured to determine the compression difficulty level corresponding to each cost difference according to the cost difference of each image block and the mapping relationship between the compression difficulty level and the cost difference range, and use the determined compression difficulty levels as the compression difficulty levels of each image block;
[0021] Among them, the overhead number determination module is specifically configured to adjust the initial overhead number according to the compression difficulty level of the image block to obtain the target overhead number of the image block; and, in the same row, the sum of the target overhead numbers of multiple image blocks is 0.9 to 1 times the sum of the initial overhead numbers of the multiple image blocks.
[0022] In some embodiments, the compression module includes:
[0023] A prediction coding unit, configured to perform prediction coding on each pixel of the image block to obtain prediction data of each pixel in the image block;
[0024] a data difference determination unit, configured to determine a data difference between pixel data of each pixel in the image block and prediction data;
[0025] a quantization unit, configured to quantize the data difference of each pixel in the image block according to the target overhead number to obtain a quantized value of each pixel;
[0026] The encoding unit is configured to encode the quantized value of each pixel in the image block.
[0027] In some embodiments, the compression module further comprises:
[0028] a dequantization unit configured to dequantize the quantized value of each pixel in the image block, and reconstruct data according to the dequantization result of each pixel and the prediction data to obtain a reconstructed value of each pixel;
[0029] The dequantization unit reconstructs the data of each pixel in sequence, and the prediction data of at least part of the pixels are determined based on the reconstructed values of the neighboring pixels for which the data reconstruction has been completed.
[0030] In a second aspect, the present disclosure further provides an image compression method, comprising:
[0031] Acquire image data of an image to be compressed; the image to be compressed includes image blocks of multiple rows and columns, the image blocks include multiple pixels, and the image data includes pixel data of each pixel in the image to be compressed;
[0032] Performing data compression processing on each of the image blocks; wherein the data compression processing includes: determining a target overhead number corresponding to the image block, and compressing and encoding pixel data in the image block according to the target overhead number;
[0033] Among them, in at least one row of the image blocks, the target overhead number corresponding to the image blocks is obtained based on the compression difficulty level of the image blocks; and, for two image blocks with different compression difficulty levels in the same row, the target overhead number corresponding to the image block with a relatively higher compression difficulty level is greater than the target overhead number of the image block with a relatively lower compression difficulty level.
[0034] In some embodiments, for the first row of image blocks, the target overhead number of each image block is a pre-assigned initial overhead number;
[0035] For the jth image block in the i-th row, the step of determining the target overhead number corresponding to the image block includes:
[0036] Determining a compression difficulty level of the j-th image block in the i-th row;
[0037] In a case where the compression difficulty levels of multiple image blocks in the i-th row are not completely the same, adjusting the pre-allocated initial overhead number according to the compression difficulty level of the j-th image block in the i-th row to obtain a target overhead number for the j-th image block in the i-th row;
[0038] Among them, i and j are both integers, i is greater than 1 and not greater than the total number of rows of the image blocks, j is greater than 0 and not greater than the number of pixel blocks in each row; the initial overhead number corresponding to each image block in the image to be compressed is the same; in the same row, the sum of the initial overhead numbers of multiple image blocks is equal to the sum of the target overhead numbers of multiple image blocks.
[0039] In a third aspect, the present disclosure further provides a computer-readable medium having a computer program stored thereon, wherein the program implements the above method when executed by a processor.
[0040] When the image compression device of the embodiment of the present disclosure performs image compression, the target overhead number of at least one row of image blocks is obtained based on the compression difficulty level of the image blocks. The higher the compression difficulty level, the larger the target overhead number; the lower the compression difficulty level, the smaller the target overhead number. Therefore, for the case where the difficulty distribution in the image is uneven, the image compression device provided by the present disclosure can reasonably allocate the code stream space, so that the simpler areas in the image can save some code streams, while the more complex areas can use more code streams, thereby improving the image compression quality of the complex areas and avoiding the waste of code stream space. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure but do not constitute a limitation of the present disclosure. In the accompanying drawings:
[0042] Figure 1It is a schematic diagram of an image compression device provided in an embodiment of the present disclosure.
[0043] Figure 2 It is a schematic diagram of another image compression device provided in an embodiment of the present disclosure.
[0044] Figure 3 A schematic diagram of a compression module provided in some embodiments of the present disclosure.
[0045] Figure 4 A schematic diagram of an image compression method provided in some embodiments of the present disclosure.
[0046] Figure 5 The steps of determining a target overhead number corresponding to an image block are provided in some embodiments of the present disclosure. DETAILED DESCRIPTION
[0047] The specific implementation of the present disclosure is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described herein is only used to illustrate and explain the present disclosure, and is not used to limit the present disclosure.
[0048] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0049] Unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The words "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components.
[0050] Figure 1 is a schematic diagram of an image compression device provided in an embodiment of the present disclosure, such as Figure 1 As shown, the image compression device includes: a data acquisition module 10, an overhead number determination module 20 and a compression module 30.
[0051] The data acquisition module 10 is configured to acquire image data of the image to be compressed.
[0052] The image to be compressed includes image blocks along multiple rows and columns, each image block includes multiple pixels, and the image data of the image to be compressed includes pixel data of each pixel in each image block.
[0053] The overhead number determination module 20 is configured to determine a target overhead number for each of the image blocks.
[0054] Among them, in at least one row of image blocks, the target overhead number corresponding to each image block is obtained based on the compression difficulty level of the image block; and, for two image blocks with different compression difficulty levels in the same row, the target overhead number corresponding to the image block with a relatively higher compression difficulty level is greater than the target overhead number of the image block with a relatively lower compression difficulty level.
[0055] Among them, the compression difficulty level is used to characterize the difficulty of compressing data on an image block. For example, when the pixel data of each pixel in an image block are relatively close, or the pixel data of each pixel are in a trend of smooth transition (that is, the image block is in a smooth position in the entire image), the image block is relatively easy to compress, that is, the compression difficulty level is relatively low; when the pixel data of each pixel in the image block fluctuates greatly, or fluctuates more frequently (that is, the image block is in a texture position in the image or a position with more detailed features), the image block is relatively difficult to compress, that is, the compression difficulty level is relatively high.
[0056] In one example, the compression difficulty levels of the multiple image blocks in the image to be compressed may include two levels: difficult and simple; in another example, the compression difficulty levels of the multiple image blocks in the image to be compressed may include three levels: simple, medium and difficult; in some further embodiments, the compression difficulty levels of the multiple image blocks in the image to be compressed may include five levels: simple, relatively simple, medium, relatively difficult and difficult. Of course, the compression difficulty levels may also be divided in other ways.
[0057] The overhead number refers to the size of the code stream space allocated for the image block. The larger the overhead number, the better the compression effect of the image block; the smaller the overhead number, the worse the compression effect of the image block.
[0058] The compression module 30 is configured to compress and encode the pixel data in the corresponding image block according to the target overhead number of each image block.
[0059] When the image compression device of the embodiment of the present disclosure performs image compression, the target overhead number of at least one row of image blocks is obtained based on the compression difficulty level of the image blocks. The higher the compression difficulty level, the larger the target overhead number; the lower the compression difficulty level, the smaller the target overhead number. Therefore, for the case where the difficulty distribution in the image is uneven, the image compression device provided by the present disclosure can reasonably allocate the code stream space, so that the simpler areas in the image can save some code streams, while the more complex areas can use more code streams, thereby improving the image compression quality of the complex areas and avoiding the waste of code stream space.
[0060] In some embodiments, data compression processing is performed on image blocks row by row.
[0061] In some embodiments, the overhead number determination module 20 is further configured to determine the compression difficulty level of each image block after the first row; set the target overhead number of each image block in the first row to a pre-allocated initial overhead number; and, when the compression difficulty levels of multiple image blocks in the i-th row are not exactly the same, adjust the initial overhead number according to the compression difficulty level of the j-th image block in the i-th row to obtain the target overhead number of the j-th image block in the i-th row.
[0062] Wherein, i and j are both integers, i is greater than 1 and not greater than the total number of rows of pixel blocks, and j is greater than 0 and not greater than the number of pixel blocks in each row.
[0063] In the same row, the sum of the target overhead numbers of the multiple image blocks is 0.9 to 1 times the sum of the initial overhead numbers of the multiple image blocks. That is, after adjusting the initial overhead numbers of the multiple image blocks in the same row, the total amount of the overhead numbers remains unchanged or is slightly less than the overhead number before adjustment.
[0064] In some embodiments, the overhead number determination module 20 may determine the compression difficulty level of the j-th image block in the i-th row through the following steps S211a to S211c:
[0065] S211a, from the image blocks that have completed data compression processing, obtain the cost difference between the actual cost number of each adjacent image block of the jth image block in the i-th row after compression coding and the corresponding target cost number, wherein i and j are both integers, i is greater than 1 and not greater than the total number of groups of pixel blocks, and j is greater than 0 and not greater than the number of pixel blocks in each group.
[0066] In some examples, each image block may have one or more neighboring image blocks. For example, the j-th image block in the i-1-th row may be used as a neighboring image block of the j-th image block in the i-th row; or, the j-1-th, j-th, and j+1-th image blocks in the i-1-th row may all be used as neighboring image blocks of the j-th image block in the i-th row.
[0067] S211b: Determine the compression difficulty level corresponding to the cost difference of each adjacent image block according to the cost difference of each adjacent image block and the mapping relationship between the compression difficulty level and the cost difference range.
[0068] Among them, the mapping relationship between the compression difficulty level and the cost difference range is pre-set, and each compression difficulty level corresponds to a cost difference range; therefore, according to each compression difficulty level and the corresponding cost difference range, the compression difficulty level corresponding to the cost interpolation of each adjacent image block can be determined.
[0069] S211c. Determine the compression difficulty level of the j-th image block in the ith row according to the compression difficulty level corresponding to the cost difference between each adjacent image block.
[0070] Among them, when the jth image block in the i-th row has one adjacent image block, the compression difficulty level corresponding to the overhead difference of the adjacent image block is used as the compression difficulty level of the jth image block in the i-th row. When the jth image block in the i-th row has multiple adjacent image blocks, the compression difficulty level of the jth image block in the i-th row can be determined by weighting.
[0071] In a specific example of the present disclosure, the j-th image block in the i-1-th row is taken as a neighboring image block of the j-th image block in the i-th group. At this time, step S211c includes: taking the compression difficulty level corresponding to the overhead difference of the j-th image block in the i-1-th row as the compression difficulty level of the j-th image block in the i-th row.
[0072] In some embodiments, the overhead number determination module 20 is further configured to determine the target overhead number for each image block in the i-th row in the following manner: when multiple image blocks in the i-th row have multiple different compression difficulty levels, at least the initial overhead number of each image block with the highest compression difficulty level is increased by a first adjustment amount, and the initial overhead number of each image block with the lowest compression difficulty level is reduced by a second adjustment amount, so as to obtain the target overhead number for each image block in the i-th row.
[0073] The initial cost number of each image block may be equal. When the compression difficulty level of the j-th image block in the i-th row is difficult, a certain value may be added to the initial cost number; when the compression difficulty level of the j-th image block in the i-th row is simple, a certain value may be subtracted from the initial cost number.
[0074] In the same row, the initial cost number corresponding to each image block is the same; and the sum of the initial cost numbers of multiple image blocks is equal to the sum of the target cost numbers of multiple image blocks. In other words, the total cost number of multiple image blocks in a group remains unchanged before and after adjustment.
[0075] In one example, for the j-th image block in the i-th row, the adjustment amount of the j-th image block in the i-th row can be determined according to the compression difficulty level of each image block in the same row, and the initial overhead number of the j-th image block in the i-th row can be adjusted according to the adjustment amount to obtain the target overhead number of the j-th image block in the i-th row.
[0076] For example, there are two compression difficulty levels, namely simple and difficult. In the i-th row, there are m image blocks with a simple compression difficulty level and n image blocks with a difficult compression difficulty level; then the initial cost number of each of the m image blocks is subtracted from the second adjustment amount; the initial cost number of each of the n image blocks is increased by the first adjustment amount, the first adjustment amount of the n image blocks is the same, and the sum of the n first adjustment amounts is equal to or slightly less than the sum of the m second adjustment amounts. The second adjustment amount can be preset.
[0077] For another example, there are five compression difficulty levels, namely: simple, relatively simple, general, relatively difficult and difficult. In the i-th row, there are m1 image blocks with a simple compression difficulty level, m2 image blocks with a relatively simple compression difficulty level, m3 image blocks with a general compression difficulty level, m4 image blocks with a relatively difficult compression difficulty level, and m5 image blocks with a difficult compression difficulty level; then the initial overhead number of each image block in the m1 image blocks is subtracted from the second adjustment amount; the initial overhead number of each image block in the m2 image blocks is subtracted from the third adjustment amount; the initial overhead number of each image block in the m4 image blocks is increased by the fourth adjustment amount; the initial overhead amount of each image block in the m5 image blocks is increased by the first adjustment amount. Among them, the second adjustment amount and the third adjustment amount can be preset. In addition, the second adjustment amount is greater than the third adjustment amount, the fourth adjustment amount is less than the first adjustment amount, and the sum of the m4 fourth adjustment amounts and the m5 first adjustment amounts is equal to or slightly less than the sum of the m1 second adjustment amounts and the m2 third adjustment amounts.
[0078] In some embodiments, if the compression difficulty levels of multiple image blocks in the i-th row are the same, the initial overhead number may not be adjusted, and the initial overhead number may be directly used as the target overhead number of each image block in the i-th row.
[0079] In the above embodiment, the compression difficulty level of the image blocks after the first row is determined according to the compression difficulty level corresponding to the cost difference of the adjacent image blocks. In other embodiments, each image block may be pre-compressed, and the compression difficulty level of the image block may be determined according to the result of the pre-compression. Specifically, Figure 2 is a schematic diagram of another image compression device provided in an embodiment of the present disclosure, such as Figure 2 As shown, the image compression device includes not only the above-mentioned data acquisition module 10, overhead number determination module 20 and compression module 30, but also a pre-compression module 40, a difference determination module 50 and a level determination module 60.
[0080] The pre-compression module 40 is configured to pre-compress the pixel data in the image block using the pre-allocated initial overhead numbers, wherein the initial overhead numbers in the image to be compressed may be the same.
[0081] The difference determination module 50 is configured to obtain the cost difference between the actual cost number and the initial cost number of each image block after compression encoding.
[0082] The level determination module 60 is configured to determine the compression difficulty level corresponding to each overhead difference according to the overhead difference of each image block and the mapping relationship between the compression difficulty level and the overhead difference range, and use the determined compression difficulty levels as the compression difficulty levels of each image block.
[0083] The mapping relationship between the compression difficulty level and the cost difference range may be preset.
[0084] When the image compression method includes the above-mentioned pre-compression module 40, difference determination module 50, and level determination module 60, the process of the overhead number determination module 20 determining the target overhead number corresponding to the image block specifically includes: adjusting the initial overhead number according to the compression difficulty level of the image block to obtain the target overhead number of the image block; and, in the same row, the sum of the target overhead numbers of multiple image blocks is 0.9 to 1 times the sum of the initial overhead numbers of the multiple image blocks.
[0085] The process of adjusting the initial cost number can be found in the above description and will not be repeated here.
[0086] Figure 3 A schematic diagram of a compression module provided in some embodiments of the present disclosure, such as Figure 3 As shown, the compression module 30 includes: a prediction encoding unit 31, a data difference determination unit 32, a quantization unit 33 and an encoding unit 34.
[0087] The prediction coding unit 31 is configured to perform prediction coding on each pixel of the image block to obtain prediction data of each pixel in the image block.
[0088] The data difference determination unit 32 is configured to determine a data difference between the pixel data of each pixel in the image block and the prediction data.
[0089] The quantization unit 33 is configured to quantize the data difference of each pixel in the image block according to the target overhead number to obtain a quantized value of each pixel.
[0090] Among them, the quantization accuracy loss is affected by the target overhead number of the image block. When the target overhead number of the image block is large, better quantization parameters can be used for quantization to improve the compression effect; when the target overhead number of the image block is small, worse quantization parameters are used for quantization.
[0091] The encoding unit 34 is configured to encode the quantized value of each pixel in the image block.
[0092] In some embodiments, the encoding unit 34 may use Golomb Rice Coding to encode the quantized value of each pixel. Golomb Rice Coding can greatly save bit streams for geometric distribution, so the use of Golomb Rice Coding in the disclosed embodiment can further compress the bit stream. Of course, the encoding unit 34 may also use other encoding methods for encoding.
[0093] In some embodiments, the compression module 30 may further include a dequantization unit 35, which is configured to dequantize the quantized value of each pixel and reconstruct data based on the dequantization result of each pixel and the prediction data to obtain the reconstructed value of each pixel.
[0094] The data reconstruction of each pixel data is performed sequentially, and the prediction data of at least part of the pixels are determined based on the reconstructed values of the neighboring pixels for which the data reconstruction has been completed.
[0095] For each pixel to be predicted and coded, its neighboring pixels refer to the pixels adjacent to the pixel to be predicted and coded. For example, when predicting and coding the pixel in the rth row and j' column in the image to be compressed, the pixels in the previous r-1 rows and the previous j'-1 columns of the rth row have been reconstructed, and the pixel in the rth row and j' column can be predicted and coded based on the reconstructed value of the pixel in the r-1th row and j' column; or, the pixel in the rth row and j' column can be predicted and coded based on the reconstructed value of the pixel in the rth row and j' column; or, the pixel in the rth row and j' column can be predicted and coded based on the reconstructed value of the pixel in the r-1th row and j'-1 column. r and j' are both integers, r is greater than 1 and not greater than the total number of rows of pixels in the image to be compressed, and j' is greater than 1 and not greater than the total number of columns of pixels in the image to be compressed.
[0096] For example, for the pixel in the 1st row and the pth column (p is an integer, p is greater than 1 and not greater than the total number of pixel columns), the pixel in the 1st row and the pth column can be predictively encoded based on the reconstructed value of the pixel in the 1st row and the p-1th column.
[0097] In addition, for the pixel in the first row and the first column, since the surrounding pixels have not yet obtained the reconstructed values when the pixel is predicted and encoded, the prediction data of the pixel in the first row and the first column can be set to the first preset value. For example, the pixel data of the pixel is between 0 and 255, and the first preset value can be an intermediate value between 0 and 255.
[0098] It should be noted that the pre-compression process used in the above-mentioned embodiment is similar to the compression encoding process of the compression module 30, both of which include prediction, quantization, and encoding processes, which will not be repeated here.
[0099] Figure 4 is a schematic diagram of an image compression method provided in some embodiments of the present disclosure, such as Figure 4 As shown, the image compression method includes:
[0100] S1. Obtain image data of an image to be compressed; the image to be compressed includes image blocks of multiple rows and columns, the image blocks include multiple pixels, and the image data includes pixel data of each pixel in the image to be compressed.
[0101] S2. Perform data compression processing on each image block; wherein the data compression processing includes: determining a target overhead number corresponding to the image block, and compressing and encoding pixel data in the image block according to the target overhead number. wherein, in at least one row of image blocks, the target overhead number corresponding to the image block is obtained based on the compression difficulty level of the image block; and, for two image blocks with different compression difficulty levels in the same row, the target overhead number corresponding to the image block with a relatively higher compression difficulty level is greater than the target overhead number of the image block with a relatively lower compression difficulty level.
[0102] In some embodiments, for the first row of image blocks, the target cost number of each image block is the pre-assigned initial cost number; for the jth image block in the i-th row, the step of determining the target cost number corresponding to the image block is as follows: Figure 5 As shown, the method specifically includes the following steps S211 to S212:
[0103] S211: Determine the compression difficulty level of the jth image block in the i-th row. The specific process is described above and will not be repeated here.
[0104] S212. When the compression difficulty levels of multiple image blocks in the i-th row are not exactly the same, adjust the pre-allocated initial overhead number according to the compression difficulty level of the j-th image block in the i-th row to obtain the target overhead number of the j-th image block in the i-th row.
[0105] The following is an example of an image compression method in which the compression difficulty level includes two levels, difficult and simple. The image compression method includes the following steps:
[0106] S101, obtaining image data of an image to be compressed. The image to be compressed includes multiple rows and columns of image blocks, and each image block includes multiple pixels.
[0107] S102: Allocate an initial overhead number to each image block. Then, process the image blocks row by row.
[0108] S103. For each image block in the first row, the initial overhead number is used as the target overhead number of the image block, and pixel data of each pixel of the image block is compressed and encoded in sequence according to the target overhead number.
[0109] The process of compressing and encoding the pixel data of each pixel includes:
[0110] Predictive coding is performed on the pixel data of the pixel to obtain the predicted data of the pixel. If there is a pixel that has been reconstructed in the neighborhood of the pixel, predictive coding is performed on the pixel to be currently predicted according to the reconstructed value of the pixel that has been reconstructed in the neighborhood. If there is no pixel that has been reconstructed in the neighborhood of the pixel, the predicted data of the pixel is set to a first preset value.
[0111] The data difference between the pixel data of the pixel and the predicted data is determined.
[0112] The data difference corresponding to the pixel is quantized according to the target overhead number to obtain the quantized value of the pixel, and the quantized value of the pixel is encoded.
[0113] The quantized value of the pixel is dequantized, and data is reconstructed based on the dequantized result of the pixel and the predicted data to obtain the reconstructed value of the pixel.
[0114] S104: For each image block in the i-th row, determine the compression difficulty level of each image block, where i is an integer greater than 1 and less than the total number of rows of image blocks.
[0115] The compression difficulty level of the image block in the i-th row and the j-th column is determined according to the following steps.
[0116] S104a, obtaining the cost difference between the actual cost number and the target cost number of the image block in the i-1th row and the jth column.
[0117] S104b, according to the cost difference of the image block in the i-1th row and jth column, and the mapping relationship between the compression difficulty level and the cost difference range, determine the compression difficulty level corresponding to the cost difference of the image block in the i-1th row and jth column; and use the compression difficulty level as the compression difficulty level of the image block in the i-1th row and jth column. j is an integer greater than 0 and not greater than the total number of columns of the pixel block.
[0118] S105 . If the compression difficulty levels of the multiple image blocks in the i-th row are not completely the same, the initial cost number of each image block in the i-th row is adjusted to obtain a target cost number of each image block in the i-th row.
[0119] For example, in the i-th row, the compression difficulty level of x image blocks is simple, and the compression difficulty level of y image blocks is difficult; at this time, the initial cost number of each image block in the x image blocks is subtracted from the second adjustment amount to obtain the target cost number; and the sum of the x second adjustment amounts is distributed to the y image blocks, that is, the initial cost number of each image block in the y image blocks is increased by the first adjustment amount to obtain the target cost number of each image block in the y image blocks. Among them, in the i-th row, the sum of the target cost numbers of multiple image blocks is equal to or slightly less than the sum of the initial cost numbers.
[0120] S106 . For each image block in the i-th row, compress and encode the pixel data of each pixel of the image block in sequence according to the corresponding target overhead number.
[0121] The process of compressing and encoding the pixel data is described in S103 and will not be repeated here.
[0122] The present disclosure also provides an electronic device, comprising:
[0123] one or more processors;
[0124] The memory stores one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors implement the above-mentioned image compression method.
[0125] The electronic device also includes one or more I / O interfaces connected between the processor and the memory and configured to implement information interaction between the processor and the memory.
[0126] Among them, the processor is a device with data processing capabilities, including but not limited to the central processing unit (CPU) and the like; the memory is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory (FLASH); the I / O interface (read-write interface) is connected between the processor and the memory, and can realize information exchange between the processor and the memory, including but not limited to the data bus (Bus) and the like.
[0127] In some embodiments, the processor, memory, and I / O interface are connected to each other and, in turn, to other components of the computing device via a bus.
[0128] This embodiment further provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the image compression method provided by this embodiment is implemented. To avoid repeated description, the specific steps of the method are not repeated here.
[0129] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In hardware implementations, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0130] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0131] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present disclosure, but the present disclosure is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and substance of the present disclosure, and these modifications and improvements are also considered to be within the scope of protection of the present disclosure.
Claims
1. An image compression device, characterized in that: include: A data acquisition module is configured to acquire image data of an image to be compressed; the image to be compressed includes a plurality of rows and columns of image blocks, the image blocks include a plurality of pixels, and the image data includes pixel data of each pixel in the image to be compressed; an overhead number determination module, configured to determine a target overhead number for each of the image blocks; wherein, in at least one row, the target overhead number for the image blocks is obtained based on the compression difficulty level of the image blocks; and, for two image blocks with different compression difficulty levels in the same row, the target overhead number corresponding to the image block with a relatively higher compression difficulty level is greater than the target overhead number for the image block with a relatively lower compression difficulty level; A compression module, configured to compress and encode pixel data in the corresponding image block according to the target overhead number of each image block; The overhead number determination module is further configured as follows: When it is determined that the compression difficulty levels of the plurality of image blocks in the i-th row after the first row are not completely the same, the initial overhead number is adjusted according to the compression difficulty level of the j-th image block in the i-th row to obtain a target overhead number of the j-th image block in the i-th row; Wherein, i and j are both integers, i is greater than 1 and not greater than the total number of rows of the image blocks, j is greater than 0 and not greater than the number of the image blocks in each row; the initial cost number corresponding to each of the image blocks in the image to be compressed is the same; in the same row, the sum of the target cost numbers of the multiple image blocks is 0.9 to 1 times the sum of the initial cost numbers of the multiple image blocks; The overhead number determination module is further configured as follows: When multiple image blocks in the i-th row have multiple different compression difficulty levels, at least the initial overhead number of each image block with the highest compression difficulty level is increased by a first adjustment amount, and the initial overhead number of each image block with the lowest compression difficulty level is reduced by a second adjustment amount to obtain a target overhead number for each image block in the i-th row.
2. The image compression device according to claim 1, characterized in that: The overhead number determination module is further configured as follows: Obtain, from the image blocks that have completed data compression processing, cost differences between actual cost numbers of each adjacent image block of the j-th image block in the i-th row after compression encoding and corresponding target cost numbers; Determine, according to the cost difference of each adjacent image block and the mapping relationship between the compression difficulty level and the cost difference range, the compression difficulty level corresponding to the cost difference of each adjacent image block; And, the compression difficulty level of the j-th image block in the ith row is determined according to the compression difficulty level corresponding to the cost difference of each adjacent image block.
3. The image compression device according to claim 1, characterized in that: The image compression device also includes: A pre-compression module, configured to pre-compress the pixel data in each of the image blocks using the pre-allocated initial overhead number; A difference determination module is configured to obtain a cost difference between an actual cost number of each image block in a pre-compression process and the initial cost number; a level determination module configured to determine the compression difficulty level corresponding to each cost difference according to the cost difference of each image block and the mapping relationship between the compression difficulty level and the cost difference range, and use the determined compression difficulty levels as the compression difficulty levels of each image block; Among them, the overhead number determination module is specifically configured to adjust the initial overhead number according to the compression difficulty level of the image block to obtain the target overhead number of the image block; and, in the same row, the sum of the target overhead numbers of multiple image blocks is 0.9 to 1 times the sum of the initial overhead numbers of the multiple image blocks.
4. The image compression device according to any one of claims 1 to 3, characterized in that: The compression module comprises: A prediction coding unit, configured to perform prediction coding on each pixel of the image block to obtain prediction data of each pixel in the image block; a data difference determination unit, configured to determine a data difference between pixel data of each pixel in the image block and prediction data; a quantization unit, configured to quantize the data difference of each pixel in the image block according to the target overhead number to obtain a quantized value of each pixel; The encoding unit is configured to encode the quantized value of each pixel in the image block.
5. The image compression device according to claim 4, characterized in that: The compression module also includes: a dequantization unit configured to dequantize the quantized value of each pixel in the image block, and reconstruct data according to the dequantization result of each pixel and the prediction data to obtain a reconstructed value of each pixel; The dequantization unit reconstructs the data of each pixel in sequence, and the prediction data of at least part of the pixels are determined based on the reconstructed values of the neighboring pixels for which the data reconstruction has been completed.
6. An image compression method, characterized in that: include: Acquire image data of an image to be compressed; the image to be compressed includes image blocks of multiple rows and columns, the image blocks include multiple pixels, and the image data includes pixel data of each pixel in the image to be compressed; Performing data compression processing on each of the image blocks; wherein the data compression processing includes: determining a target overhead number corresponding to the image block, and compressing and encoding pixel data in the image block according to the target overhead number; Wherein, in at least one row of the image blocks, the target cost number corresponding to the image blocks is obtained based on the compression difficulty level of the image blocks; and, for two image blocks with different compression difficulty levels in the same row, the target cost number corresponding to the image block with a relatively higher compression difficulty level is greater than the target cost number of the image block with a relatively lower compression difficulty level; For the first row of image blocks, the target cost number of each image block is the pre-allocated initial cost number; For the jth image block in the i-th row, the step of determining the target overhead number corresponding to the image block includes: Determining a compression difficulty level of the j-th image block in the i-th row; In a case where the compression difficulty levels of multiple image blocks in the i-th row are not completely the same, adjusting the pre-allocated initial overhead number according to the compression difficulty level of the j-th image block in the i-th row to obtain a target overhead number for the j-th image block in the i-th row; Wherein, i and j are both integers, i is greater than 1 and not greater than the total number of rows of the image blocks, j is greater than 0 and not greater than the number of the image blocks in each row; the initial cost number corresponding to each of the image blocks in the image to be compressed is the same; in the same row, the sum of the initial cost numbers of multiple image blocks is equal to the sum of the target cost numbers of multiple image blocks; According to the compression difficulty level of the j-th image block in the i-th row, the pre-allocated initial overhead number is adjusted, including: When multiple image blocks in the i-th row have multiple different compression difficulty levels, at least the initial overhead number of each image block with the highest compression difficulty level is increased by a first adjustment amount, and the initial overhead number of each image block with the lowest compression difficulty level is reduced by a second adjustment amount to obtain a target overhead number for each image block in the i-th row.
7. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to claim 6 is implemented.
Citation Information
Patent Citations
Macro block group video code rate control method
CN101159871A
Encoding method and device, image processing system, and computer readable storage medium
CN110495174A
Encoding method and encoder
CN113132728A