Image compression method and device and image decompression method and device
By segmenting the original image into initial image blocks and calculating the second and fourth level compression errors respectively, the target compression level is determined. This solves the problems of large computational load and large compression error in the existing technology, and realizes image compression and decompression with high efficiency and low computing power.
Patent Information
- Application Number
- CN202511662534.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-12
- Publication Date
- 2026-02-17
AI Technical Summary
Existing image compression and decompression methods rely on pre-trained algorithms, which involve large computational loads and require high computing power from devices. They are not suitable for lightweight devices, and a single compression level may lead to large compression errors and quality degradation.
The original image is divided into several initial image blocks. The error is calculated using two-level and four-level compression respectively. The target compression level of each initial image block is determined and then stitched together to generate compressed image data.
It reduces compression errors, improves compression efficiency and quality, is suitable for lightweight devices, avoids the complexity of algorithm training and updates, and improves computational efficiency.
Smart Images

Figure CN121547589A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to an image compression method, decompression method, and apparatus. Background Technology
[0002] Currently, image compression and decompression mainly include two methods. The first method relies on pre-trained image compression and decompression algorithms. The algorithm training process is cumbersome, lacks specificity, and can produce large errors. Furthermore, the algorithm needs continuous iterative updates, requires a large amount of data, and places high demands on the computing power of the device, making it unsuitable for lightweight devices.
[0003] In addition, during the compression process, the entire original image is often compressed using a single compression level. This single compression level processing method may increase compression errors and reduce compression quality. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide an image compression method, a decompression method, and an apparatus, which have a simple compression method, low computational load, and can reduce compression errors.
[0005] To achieve the above objectives, according to one aspect of the present invention, an image compression method is provided, comprising:
[0006] The original image is divided into several initial image blocks, and steps A1 to A3 are performed for each of the initial image blocks:
[0007] Step A1: Compress the initial image block using two-stage compression, calculate the two-stage compression error, and generate two-stage compressed image block data;
[0008] Step A2: Compress the initial image block using four-level compression to obtain four-level compressed image block data, and calculate the four-level compression error.
[0009] Step A3: Determine the target compression level of the initial image block based on the above-mentioned level 2 compression error and level 4 compression error;
[0010] By stitching together the compressed image block data corresponding to the target compression level of each of the above initial image blocks, compressed image data corresponding to the above original image is obtained.
[0011] Optionally, determining the target compression level of the initial image patch based on the second-level compression error and the fourth-level compression error includes:
[0012] Calculate the first difference between the second-level compression error and the fourth-level compression error, and the second difference between the fourth-level compression error and the second-level compression error;
[0013] Based on the first comparison result of the first difference and the preset comparison threshold, and the second comparison result of the second difference and the preset comparison threshold, the target compression level of the initial image block is determined.
[0014] Optionally, determining the target compression level of the initial image patch based on the first comparison result of the first difference and a preset comparison threshold, and the second comparison result of the second difference and a preset comparison threshold, includes:
[0015] In response to the first comparison result indicating that the first difference is greater than or equal to the preset comparison threshold, the fourth level of compression is taken as the target compression level of the initial image block.
[0016] In response to the second comparison result indicating that the second difference is greater than or equal to the preset comparison threshold, the second-level compression is taken as the target compression level of the initial image block.
[0017] Optionally, the above method further includes:
[0018] For each pixel, its color components are used to calculate the corresponding representation data.
[0019] Optionally, the calculation of the above-mentioned second-level compression error includes:
[0020] Convert the initial image patch into a binary image patch;
[0021] The first total degree of difference is calculated based on the color component of each pixel and the binary pixel value corresponding to each pixel in the above binary image block;
[0022] The second total degree of difference is calculated based on the above characterization data and color components for each pixel;
[0023] The first total degree of difference and the second total degree of difference are compared, and the second-level compression error is determined based on the comparison results of the first total degree of difference and the second total degree of difference.
[0024] Optionally, the calculation of the above-mentioned four-level compression error includes:
[0025] Reconstruct the above four-level compressed image block data to obtain reconstructed image block data corresponding to the above four-level compressed image block data;
[0026] The above-mentioned four-level compression error is calculated based on the initial image block corresponding to the above-mentioned four-level compressed image block data and the above-mentioned reconstructed image block data.
[0027] Optionally, the calculation of the fourth-level compression error based on the initial image block corresponding to the fourth-level compressed image block data and the reconstructed image block data includes:
[0028] For each pixel, calculate the absolute value of the difference between each color component in the initial image block and each color component in the reconstructed image block data;
[0029] The sum of the absolute values of all pixels in the reconstructed image block data is calculated as the fourth-level compression error.
[0030] To achieve the above objectives, according to another aspect of the present invention, an image decompression method is provided, comprising the following steps for compressed image data obtained by the image compression method of the present invention:
[0031] For each compressed image block in the compressed image data described above, perform the following steps Z1 to Z3:
[0032] Step Z1: Determine the target compression level based on the compressed image block data; the target compression level is either level two or level four compression.
[0033] Step Z2: Determine the number of binary bits to be padded according to the target compression level, and padded the compressed image block data with binary bits based on the number of binary bits to be padded.
[0034] Step Z3: Determine the restored pixel value of each pixel based on the filled compressed image block data, and concatenate the restored pixel values of each pixel to obtain the decompressed image block data;
[0035] The decompressed image block data corresponding to each of the above compressed image block data is stitched together to obtain the original image corresponding to the above compressed image data.
[0036] Optionally, the compressed image block data mentioned above includes feature data, quantization data, and compression type data;
[0037] The above-mentioned determination of the number of binary bits to fill based on the target compression level, and the filling of the compressed image block data with binary bits based on the above-mentioned number of binary bits, includes:
[0038] In response to the target compression level being two-level compression, target reference data with a different bit depth from other reference data is identified in the feature data; binary bits of a preset number of two-level compression are padded for the target reference data.
[0039] In response to the target compression level being four-level compression, a preset number of binary bits are padded for each low-compression mode reference data and each high-compression mode reference data in the above feature data.
[0040] Optionally, determining the restored pixel value for each pixel based on the padded compressed image block data includes:
[0041] Based on the feature data filled with the quantized data, the restored color component of each pixel is generated according to the preset rules associated with the target compression level; for each pixel, the restored pixel value is calculated based on the restored color component.
[0042] To achieve the above objectives, according to another aspect of the present invention, an image compression apparatus is provided, comprising:
[0043] The segmentation module is used to segment the original image into several initial image blocks;
[0044] For each of the aforementioned initial image blocks, the first calculation module, the second calculation module, and the first determination module are executed respectively;
[0045] The first calculation module is used to compress the initial image block using two-stage compression, calculate the two-stage compression error, and generate two-stage compressed image block data.
[0046] The second calculation module is used to compress the initial image block using four-level compression to obtain four-level compressed image block data, and to calculate the four-level compression error.
[0047] The first determining module is used to determine the target compression level of the initial image block based on the second-level compression error and the fourth-level compression error.
[0048] The first stitching module is used to stitch together compressed image block data corresponding to the target compression level of each of the initial image blocks to obtain compressed image data corresponding to the original image.
[0049] To achieve the above objectives, according to another aspect of the present invention, an image decompression apparatus is provided, comprising:
[0050] For each compressed image block in the above compressed image data, the second determination module, the filling module, and the second stitching module are executed:
[0051] The second determining module is used to determine the target compression level based on the compressed image block data; the target compression level is either level two or level four compression.
[0052] The aforementioned filling module is used to determine the number of binary bits to fill based on the target compression level, and to fill the compressed image block data with binary bits based on the number of binary bits to fill.
[0053] The second stitching module described above is used to determine the restored pixel value of each pixel based on the filled compressed image block data, and stitch the restored pixel values of each pixel together to obtain the decompressed image block data;
[0054] The third stitching module is used to stitch together the decompressed image block data corresponding to each of the above-mentioned compressed image block data to obtain the original image corresponding to the above-mentioned compressed image data.
[0055] To achieve the above objectives, according to another aspect of the present invention, an electronic device is provided.
[0056] An electronic device according to an embodiment of the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement an image compression method or an image decompression method according to an embodiment of the present invention.
[0057] To achieve the above objectives, according to another aspect of the present invention, a computer-readable storage medium is provided.
[0058] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements an image compression method or an image decompression method according to an embodiment of the present invention.
[0059] To achieve the above objectives, according to another aspect of the present invention, a computer program product is provided.
[0060] A computer program product according to an embodiment of the present invention includes: a computer program, which, when executed by a processor, implements an image compression method or an image decompression method according to an embodiment of the present invention.
[0061] One embodiment of the above invention has the following advantages or beneficial effects: In the process of compressing the original image to generate compressed image data, the original image is divided into several initial image blocks. Secondary compression error and quaternary compression error are calculated for each initial image block. The target compression level for the initial image block is determined based on the secondary and quaternary compression errors. The compressed image block data corresponding to the target compression level is then stitched together to obtain compressed image data corresponding to the original image. This allows for precise matching of a more suitable compression level for each initial image block based on the errors of the two compression levels, resulting in compressed image blocks with smaller compression errors for each initial image block, further reducing the compression error of the compressed image data corresponding to the original image. Furthermore, during image compression, compressed image block data can be generated based solely on the pixels in the initial image blocks, eliminating the need for image compression algorithms. This reduces the algorithm training and subsequent update processes, simplifies the compression method, greatly improves compression efficiency, reduces computational load, and lowers the computational requirements of the device, allowing deployment in lightweight devices. Simultaneously, it avoids the poor compression quality issues that may arise from using image compression algorithms, thus improving compression quality.
[0062] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0063] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0064] Figure 1 This is a schematic flowchart of an image compression method according to an embodiment of the present invention;
[0065] Figure 2 This is a schematic diagram of a binarized image according to an embodiment of the present invention;
[0066] Figure 3 This is a schematic flowchart of an image decompression method according to an embodiment of the present invention;
[0067] Figure 4 This is a schematic diagram of the main modules of an image compression apparatus according to an embodiment of the present invention;
[0068] Figure 5 This is a schematic diagram of the main modules of an image decompression apparatus according to an embodiment of the present invention;
[0069] Figure 6 This is a schematic diagram of the structure of a computer system suitable for implementing the image compression method, decompression method, or apparatus of the present invention. Detailed Implementation
[0070] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0071] It should be noted that, unless otherwise specified, the embodiments of the present invention and the technical features thereof can be combined with each other.
[0072] like Figure 1 As shown, the image compression method of this invention mainly includes the following steps S101 to S103:
[0073] Step S101: Divide the original image into several initial image blocks;
[0074] Understandably, directly compressing the entire original image would require complex calculations, resulting in significant computational and memory usage, and thus slow compression speed. Therefore, the original image is first divided into several initial image blocks, with each initial image block serving as a compression unit. Compression is then performed on each image block separately. This divides the task of compressing the original image into multiple independent subtasks that compress the initial image blocks, thereby reducing computational complexity and memory usage, and improving compression efficiency. The original image can be an RGB image.
[0075] Furthermore, the original image can be divided into several initial image blocks of x rows × y columns according to the data matrix. Here, x is much smaller than the number of rows in the original image, and y is much smaller than the number of columns in the original image.
[0076] x and y can be the same or different; no specific restrictions are imposed here. As an example, x and y can both be 4. As another example, x can be 8 and y can be 2.
[0077] In addition, the compression ratio needs to be determined before compressing the original image. The compression ratio refers to the ratio of the amount of data in the compressed image to the amount of data in the original image before compression. By determining the compression ratio, the amount of data in the compressed image block corresponding to each initial image block can be determined. As an example, the compression ratio can be 1 / 6. When m and n are both 4, the RGB image includes three color component types: R, G, and B. Each color component of each pixel has a data depth of 8 bits. When the original image is an RGB image, the amount of data in any initial image block is (8×3×4×4) bits, or 384 bits; the amount of data in the compressed image block corresponding to the initial image block is (384×1 / 6) bits, or 64 bits.
[0078] Step S102: For each of the above initial image blocks, execute steps A1 to A3 respectively:
[0079] Step A1: Compress the initial image block using two-stage compression, calculate the two-stage compression error, and generate two-stage compressed image block data;
[0080] The second-level compression error can be calculated during the compression of the initial image block using second-level compression, and then the second-level compressed image block data corresponding to the initial image block can be generated based on the second-level compression error.
[0081] Step A2: Compress the initial image block using four-level compression to obtain four-level compressed image block data, and calculate the four-level compression error.
[0082] After compressing the initial image block into a four-level compressed image block using four-level compression, the four-level compression error is calculated by reconstructing the image block data.
[0083] Step A3: Determine the target compression level of the initial image block based on the above-mentioned level 2 compression error and level 4 compression error;
[0084] Step S103: The compressed image block data corresponding to the target compression level of each initial image block is stitched together to obtain compressed image data corresponding to the original image.
[0085] Compression levels include two-level compression, four-level compression, etc. By compressing the initial image blocks using two-level compression and four-level compression respectively, the compression errors of the two-level compression and the four-level compression are determined. The compression level with the smaller compression error is then selected as the target compression level, and the compressed image block data corresponding to the target compression level is used as the compressed image block data corresponding to the initial image block.
[0086] It should be noted that different initial image blocks can correspond to different target compression levels. That is, each initial image block uses compressed image block data with a smaller compression error, thus obtaining compressed image data corresponding to the original image. The error of this compressed image data is significantly smaller than that obtained by using the same compression level for each initial image block. As an example, the original image is divided into four initial image blocks, where the target compression level of initial image block 1 is level four compression, the target compression level of initial image block 2 is level two compression, the target compression level of initial image block 3 is level two compression, and the target compression level of initial image block 4 is level four compression. Then, according to the respective positions of initial image blocks 1, 2, 3, and 4 in the original image, the level four compressed image block data corresponding to initial image block 1, the level two compressed image block data corresponding to initial image block 2, the level two compressed image block data corresponding to initial image block 3, and the level four compressed image block data corresponding to initial image block 4 are concatenated to obtain the compressed image data corresponding to the original image.
[0087] In an optional embodiment, step S101 specifically includes: dividing the original image into a data matrix of x rows × y columns; in response to the last data matrix of the original image not satisfying the x rows × y columns condition, determining the dimension that is not satisfied; when the dimension that is not satisfied includes rows, copying the data of the last row of the original image to fill the data matrix to x rows; when the dimension that is not satisfied includes columns, copying the data of the last column of the original image to fill the data matrix to y columns.
[0088] As an example, when the original image contains 14 rows and 15 columns of data, dividing it into 4 rows × 4 columns data matrices yields 16 data matrices. The last row of each data matrix contains only 2 rows; this can be done by copying the data from the last row to pad each matrix with 4 rows. Similarly, the last column of each data matrix contains only 3 columns; this can be done by copying the data from the last column to pad each matrix with 4 columns, resulting in 16 4 rows × 4 columns data matrices.
[0089] In an optional embodiment, before step S102, the method further includes: for each pixel, calculating the characterization data corresponding to the pixel using its color components.
[0090] For each pixel in an RGB image, there are three color component types: R, G, and B. Each color component is 8 bits, so the color depth of each pixel is 24 bits.
[0091] To facilitate subsequent calculations, corresponding representation data can be calculated for each pixel. Specifically, the calculation of representation data can include at least the following two methods:
[0092] The first method involves calculating the representation data of each pixel by weighting and summing its color components according to a preset first color component weight.
[0093]
[0094] in, This represents the representation data of the nth pixel in the initial image patch; This indicates the weight of the first color component for color component type R; This represents the weight of the first color component for color component type G; This indicates the weight of the first color component for color component type B. This represents the value of the color component R of the nth pixel; This represents the value of the color component G of the nth pixel; This represents the value of the color component B of the nth pixel. , and The sum of the three is 1.
[0095] As an example, , and Both can be 1 / 3, or they can be 0.299, It is 0.587. It could be 0.114.
[0096] It should be noted that the preset weights of each color component in the process of converting the initial image block into a grayscale image block by weighted averaging the weights of the first color component and the second color component can be the same or different.
[0097] The second method involves identifying the color component with the largest value for each pixel and using that value as the representation data for the corresponding pixel, as shown below.
[0098]
[0099] Where 1≤n≤m, m represents the number of pixels in the initial image block.
[0100] The set of representation data corresponding to all pixels in the initial image patch can be obtained through either the first or second method described above. .
[0101] Furthermore, after determining the representation data for each pixel, the maximum and minimum representation data can be determined for each initial image block.
[0102] Specifically, the representation data of each pixel is compared to determine the maximum and minimum representation data of the initial image block. More specifically, the maximum and minimum representation data can be determined based on the set of representation data corresponding to all pixels in the initial image block, as shown below.
[0103]
[0104]
[0105] in, This represents the maximum representation data of the initial image patch; The minimum representation data representing the initial image patch.
[0106] Furthermore, given that the maximum and minimum representation data in the initial image block have been determined, the representation data segmentation threshold of the initial image block can be further determined, and the pixels in the initial image block can be divided into low-mode pixels and high-mode pixels based on the comparison results of the representation data and the representation data segmentation threshold. The maximum low-mode reference data and the minimum high-mode reference data can also be further determined.
[0107] Specifically, the maximum and minimum representation data are weighted and summed according to preset representation data weights to calculate the representation data segmentation threshold, as shown in the following formula.
[0108]
[0109] in, The segmentation threshold representing the characterization data of the initial image patch; This represents the weight of the representation data that represents the largest representation data. This represents the weight of the representation data that represents the minimum representation data. and The sum of the two is 1.
[0110] For each pixel, its representation data is compared with the aforementioned representation data segmentation threshold; in response to the representation data being less than the aforementioned representation data threshold, initial quantization data with a value of 0 is generated for the pixel; in response to the representation data being greater than or equal to the aforementioned representation data segmentation threshold, initial quantization data with a value of 1 is generated for the pixel, as shown in the following formula.
[0111]
[0112] in, This represents the initial quantization data for the nth pixel in the initial image block.
[0113] For the low-mode pixels in the initial image block whose initial quantization data is 0, determine the largest low-mode representation data among the representation data of these low-mode pixels. For the high-mode pixels in the initial image block whose initial quantization data is 1, determine the minimum high-mode representation data with the smallest value among the representation data of the high-mode pixels. .
[0114] In an optional embodiment, the calculation of the second-level compression error includes the following steps A11 to A14:
[0115] Step A11: Convert the initial image block into a binary image block;
[0116] First, the initial image block is converted into a grayscale image block, and then the grayscale image block is converted into a binary image block.
[0117] Specifically, a simple average or weighted average can be performed on the color components in each pixel, thereby converting the initial image block into a grayscale image block based on the result of the simple average or weighted average. Then, for each pixel in the grayscale image block, the grayscale value is compared with a pre-set binarization threshold, thereby converting the grayscale image block into a binary image block through threshold segmentation.
[0118] The simple average can be represented by the following formula.
[0119]
[0120] G represents the grayscale value; R represents the value of the color component R; G represents the value of the color component G; B represents the value of the color component B.
[0121] The weighted average can be represented by the following formula.
[0122]
[0123] Indicates the preset weight of the color component R; Indicates the preset weight of color component G; This indicates the preset weight of color component B. , and The condition that the sum of all three must be 1 is required.
[0124] In the above binarized image block, each pixel has a binarized pixel value of either 0 or 1. When the result of a simple average or weighted average is greater than or equal to the binarization threshold, the binarized pixel value of that pixel can be determined to be 1; when the result of a simple average or weighted average is less than the binarization threshold, the binarized pixel value of that pixel can be determined to be 0. For example, ... Figure 2 As shown, Figure 2 A schematic diagram of a possible binarized image corresponding to the original image is shown, which includes 18 binarized image blocks, each containing 4 rows × 4 columns of pixels.
[0125] Step A12: Calculate the first total degree of difference based on the color components of each pixel and the binarized pixel value corresponding to each pixel in the above binarized image block;
[0126] Specifically, the first low-mode reference data and the first high-mode reference data, as well as the first total difference degree, can be calculated based on the binarized pixel value and color component of each pixel.
[0127] The first total difference indicates the degree of difference between the initial image block and the secondary compressed image block when the secondary compressed image block corresponding to the initial image block is determined using binarized pixel values and color components.
[0128] Step A13: Calculate the second total degree of difference based on the above-described characterization data and color components for each pixel;
[0129] Specifically, based on the above-mentioned characterization data and color components of each pixel, the second low-mode reference data and the second high-mode reference data corresponding to each color component type, as well as the second total difference degree, can be calculated.
[0130] The second total difference level indicates the degree of difference between the initial image block and the secondary compressed image block when the secondary compressed image block corresponding to the initial image block is determined using characterization data and color components.
[0131] Step A14: Compare the first total difference degree and the second total difference degree, and determine the second-level compression error based on the comparison results of the first total difference degree and the second total difference degree.
[0132] Comparing the first total difference level and the second total difference level mentioned above, the total difference level with the smaller value is taken as the second-level compression error.
[0133] Specifically, when the first total difference is greater than or equal to the second total difference, the second total difference is taken as the second-level compression error; when the first total difference is less than the second total difference, the first total difference is taken as the second-level compression error.
[0134] Optionally, step A12 above may include the following steps A121 to A123:
[0135] Step A121: For the first pixel with a binarized pixel value of 0 in the above binarized image block, calculate the average value of each color component corresponding to the above color component type based on the color component type, and use it as the first low mode reference data of the corresponding color component type.
[0136] The binarized image block includes a first pixel with a binarized pixel value of 0 and a second pixel with a binarized pixel value of 1.
[0137] For each pixel in the initial image block corresponding to the first pixel, the average value of each color component is calculated according to the color component type to serve as the first low mode reference data for the corresponding color type, thereby obtaining three first low mode reference data: the first low mode reference data for R, the first low mode reference data for G, and the first low mode reference data for B.
[0138] Step A122: For the second pixel with a binarized pixel value of 1 in the above-mentioned binarized image block, calculate the average value of each color component corresponding to the above-mentioned color component type, and use it as the first high mode reference data of the corresponding color component type.
[0139] Similar to the calculation process of the first low-mode reference data, for the pixels in the initial image block corresponding to the second pixel, the first high-mode reference data for R, the first high-mode reference data for G, and the first high-mode reference data for B are calculated.
[0140] Specifically, when the binarized image patch includes The first pixel with a binary pixel value of 0 and When the second pixel has a binarized pixel value of 1, for the pixel corresponding to the first pixel in the initial image block, the average value of each color component is calculated based on the color component type and used as the first low-mode reference data, as shown in the following formula.
[0141]
[0142]
[0143]
[0144] in, This represents the first low-mode reference data for color component R; Indicates the number of the first pixel; This represents the value of the color component R of the pixel in the initial image block corresponding to the i-th first pixel; This represents the first low-mode reference data for color component G; This represents the value of the color component G of the pixel in the initial image block corresponding to the i-th first pixel; This represents the first low-mode reference data for color component B; This represents the value of the color component B of the pixel in the initial image block corresponding to the i-th first pixel;
[0145] For the pixel corresponding to the second pixel in the initial image patch, the average value of each color component is calculated based on the color component type and used as the first high-mode reference data, as shown in the following formula.
[0146]
[0147]
[0148]
[0149] in, This represents the first high-mode reference data for color component R; Indicates the number of the second pixel; This represents the value of the color component R of the pixel in the initial image block corresponding to the j-th second pixel; This represents the first high-mode reference data for color component G; This represents the value of the color component G of the pixel in the initial image block corresponding to the j-th second pixel; This represents the first high-mode reference data for color component B; This represents the value of the color component B of the pixel in the initial image block corresponding to the j-th second pixel.
[0150] Step A123: Calculate the first total difference using the first low mode reference data, the first high mode reference data, and the color component of each pixel corresponding to each color component type.
[0151] The greater the degree of the first overall difference, the worse the compression quality of the secondary compressed image block determined by step A12.
[0152] Furthermore, step A123 above may include the following steps A1231 to A1234:
[0153] Step A1231: Calculate the first difference between the color component of each of the first pixels and the first low mode reference data, and sum the absolute values of the first differences of each of the first pixels to calculate the first degree of difference;
[0154] Specifically, for each color component type, the first difference between the color component of the pixel corresponding to the first pixel in the initial image block and the first low-mode reference data is calculated, and the absolute value of each first difference is further determined. The absolute values of the first differences associated with each first pixel are summed to obtain the first degree of difference, as shown in the following formula.
[0155]
[0156]
[0157]
[0158] in, This indicates the first degree of difference for color component R; This indicates the first degree of difference for color component G; This indicates the first degree of difference for color component B.
[0159] Step A1232: Calculate the second difference between the color component of each of the above-mentioned second pixels and the first high mode reference data, and sum the absolute values of the second differences of each of the above-mentioned second pixels to calculate the second degree of difference;
[0160] Similar to the calculation process for the first degree of difference, the calculation method for the second degree of difference is shown in the following formula.
[0161]
[0162]
[0163]
[0164] in, This indicates the second degree of difference for color component R; This indicates the second degree of difference for color component G; This indicates the second degree of difference for color component B.
[0165] Step A1233: For each of the above color component types, sum the first degree of difference and the second degree of difference to obtain the first degree of color component difference for the corresponding color component type;
[0166] For color component types R, G, and B, the formula is as follows:
[0167]
[0168]
[0169]
[0170] in, This indicates the degree of difference in the first color component for color component type R; This indicates the degree of difference in the first color component for color component type G; This indicates the degree of difference in the first color component for color component type B.
[0171] Step A1234: The degree of difference of the first color component corresponding to each of the above color component types is weighted and summed according to the preset second color component weights to calculate the first total degree of difference, as shown in the following formula.
[0172]
[0173] in, Indicates the first overall degree of difference; This indicates the weight of the second color component for color component type R; This indicates the weight of the second color component for color component type G; This represents the weight of the second color component for color component type B. , and The sum of the three is 1.
[0174] Optionally, step A13 above may include the following steps A131 to A134:
[0175] Step A131: For low-mode pixels in the initial image block whose initial quantization data is 0, calculate the average value of each color component corresponding to the color component type based on the color component type, and use it as the second low-mode reference data for the color component type corresponding to the initial image block; For high-mode pixels in the initial image block whose initial quantization data is 1, calculate the average value of each color component corresponding to the color component type based on the color component type, and use it as the second high-mode reference data for the color component type corresponding to the initial image block.
[0176] Specifically, when the initial image patch includes Low-mode pixels and When dealing with a high-mode pixel, for each low-mode pixel, the average value of each color component is calculated based on the color component type and used as the second low-mode reference data, as shown in the following formula.
[0177]
[0178]
[0179]
[0180] in, This represents the second lowest mode reference data for color component R; This represents the value of the color component R of the k-th low-mode pixel in the initial image patch; This represents the second lowest mode reference data for color component G; This represents the value of the color component G of the k-th low-mode pixel in the initial image patch; This represents the second lowest mode reference data for color component B; This represents the value of the color component B of the k-th low-mode pixel in the initial image block.
[0181] For each high-mode pixel, the average value of each color component is calculated based on the color component type and used as the second high-mode reference data, as shown in the following formula.
[0182]
[0183]
[0184]
[0185] in, This represents the second highest mode reference data for color component R; This represents the value of the color component R of the l-th high-mode pixel in the initial image patch; This represents the second highest mode reference data for color component G; This represents the value of the color component G of the l-th high-mode pixel in the initial image patch; This represents the second highest mode reference data for color component B; This represents the value of the color component B of the l-th high-mode pixel in the initial image block.
[0186] Step A132: For each low-mode pixel of the initial image block, calculate the third difference between the second low-mode reference data of each color component type and the color component of the pixel, and perform a weighted sum of the third differences of each color component type based on the preset third difference weight to calculate the third degree of difference of the pixel; For each high-mode pixel, calculate the fourth difference between the second high-mode reference data of each color component type and the color component of the pixel, and perform a weighted sum of the fourth differences of each color component type based on the preset fourth difference weight to calculate the fourth degree of difference of the pixel.
[0187] Specifically, the calculation method for the third degree of difference is shown in the following formula.
[0188]
[0189]
[0190]
[0191] in, This indicates the third degree of difference for a low-mode pixel in the initial image patch; This represents the value of the color component R of the low-mode pixel; This represents the preset third difference weight for color component type R; This represents the value of the color component G of the low-mode pixel; This represents the preset third difference weight for color component type G; This represents the value of the color component B of the low-mode pixel; This represents the preset third difference weight for color component type B.
[0192] The calculation method for the fourth degree of difference is shown in the following formula.
[0193]
[0194]
[0195]
[0196] in, This indicates the fourth degree of difference for a high-mode pixel in the initial image patch; This represents the value of the color component R of the high-mode pixel; This represents the preset fourth difference weight for color component type R; This represents the value of the color component G of the high-mode pixel; This represents the preset fourth difference weight for color component type G; This represents the value of the color component B of the high-mode pixel; This represents the preset fourth difference weight for color component type B.
[0197] It should be noted that, generally, the preset third difference weight for color component type R is the same as the preset fourth difference weight for color component type R; the preset third difference weight for color component type G is the same as the preset fourth difference weight for color component type G; and the preset third difference weight for color component type B is the same as the preset fourth difference weight for color component type B.
[0198] Step A133: For each of the aforementioned low-mode pixels, compare the aforementioned third degree of difference with the aforementioned maximum low-mode characterization data; in response to the aforementioned third degree of difference being greater than or equal to the aforementioned maximum low-mode characterization data, update the initial quantization data of the aforementioned low-mode pixel to 0; for each of the aforementioned high-mode pixels, compare the aforementioned fourth degree of difference with the aforementioned minimum high-mode characterization data; in response to the aforementioned fourth degree of difference being greater than or equal to the aforementioned minimum high-mode characterization data, update the initial quantization data of the aforementioned high-mode pixel to 1;
[0199]
[0200] Step A134: Repeat steps A131 to A133 until the preset iteration end condition is reached. Calculate the second total difference using the second low mode reference data of the last iteration corresponding to each color component type, the second high mode reference data of the last iteration, and the color components of each pixel of the initial image block mentioned above.
[0201] The preset iteration termination condition can be a pre-set number of iterations, or it can be the number of times the initial quantized data has consecutively reached the same value. For example, the preset number of iterations can be set to 6, so the iteration stops after the loop of steps A131 to A133 has been executed 6 times. As another example, the preset number of iterations can be set to 2, so the iteration stops when the initial quantized data has two consecutive identical values.
[0202] Further, step A134 may include the following steps A1341 to A1344:
[0203] Step A1341: Calculate the fifth difference between the color component of each of the above low-mode pixels and the second low-mode reference data of the last iteration, and sum the absolute values of the fifth differences of each of the above low-mode pixels in the above initial image block to calculate the fifth degree of difference;
[0204] Specifically, for each color component type, the absolute value of the fifth difference between the color component of the low-mode pixel and the second low-mode reference data is calculated, and the absolute values of the fifth differences for each low-mode pixel are summed to obtain the fifth degree of difference, as shown in the following formula.
[0205]
[0206]
[0207]
[0208] in, This indicates the fifth degree of difference for color component R; This indicates the fifth degree of difference for color component G; This indicates the fifth degree of difference for color component B; This indicates the number of low-mode pixels after the last iteration; This represents the value of the color component R of the o-th low-mode pixel after the last iteration; This represents the value of the color component G of the o-th low-mode pixel after the last iteration; This represents the value of the color component B of the 0th low-mode pixel after the last iteration; This represents the second lowest mode reference data for color component R after the last iteration; This represents the second lowest mode reference data for color component G after the last iteration; This represents the second lowest mode reference data for color component B after the last iteration.
[0209] Step A1342: Calculate the sixth difference between the color component of each of the above high-mode pixels and the second high-mode reference data of the last iteration, and sum the absolute values of the sixth differences of each of the above high-mode pixels in the above initial image block to calculate the sixth degree of difference;
[0210] Specifically, for each color component type, the absolute value of the sixth difference between the color component of the high-mode pixel and the second high-mode reference data is calculated, and the absolute values of the sixth difference for each high-mode pixel are summed to obtain the sixth degree of difference, as shown in the following formula.
[0211]
[0212]
[0213]
[0214] in, This indicates the sixth degree of difference for color component R; This indicates the sixth degree of difference for color component G; This indicates the sixth degree of difference for color component B; This indicates the number of high-mode pixels in the initial image patch; This represents the value of the color component R of the p-th high-mode pixel; This represents the value of the color component G of the p-th high-mode pixel; This represents the value of the color component p of the p-th low-mode pixel; This represents the second highest mode reference data for color component R after the last iteration; This represents the second highest mode reference data for color component G after the last iteration; This represents the second highest mode reference data for color component B after the last iteration.
[0215] Step A1343: For each of the above color component types, sum the fifth degree of difference and the sixth degree of difference to obtain the second degree of color component difference for the corresponding color component type;
[0216] For color component types R, G, and B, the formula is as follows:
[0217]
[0218]
[0219]
[0220] in, This indicates the degree of difference in the second color component for color component type R; This indicates the degree of difference in the second color component for color component type G; This indicates the degree of difference in the second color component for color component type B.
[0221] Step A1344: Calculate the second total difference degree by weighting and summing the second color component differences corresponding to each of the above color component types according to the preset third color component weights, as shown in the following formula.
[0222]
[0223] in, Indicates the second overall degree of difference; This indicates the weight of the third color component for color component type R; This indicates the weight of the third color component for color component type G; This represents the weight of the third color component for color component type B. , and The sum of the three is 1.
[0224] In an optional embodiment, the above-mentioned generation of secondary compressed image block data corresponding to secondary compression includes: determining secondary feature data and secondary quantization data of the secondary compressed image block corresponding to the above-mentioned initial image block through the low-mode reference data and high-mode reference data associated with the above-mentioned secondary compression error; and concatenating the above-mentioned secondary feature data, secondary quantization data and compression type data indicating secondary compression to obtain secondary compressed image block data.
[0225] Specifically, when the aforementioned secondary compression error is the first total difference level, the seventh difference value of the aforementioned first difference level and the aforementioned second difference level are calculated for each color component type, and the seventh difference value corresponding to each of the aforementioned color component types is compared. The first low mode reference data or first high mode reference data of the target color component type corresponding to the smallest seventh difference value is compressed by a preset number of binary bits for secondary compression. The first low mode reference data, first high mode reference data of other color component types, as well as the uncompressed first low mode reference data or first high mode reference data of the aforementioned target color component type and the compressed first low mode reference data or first high mode reference data are combined as the secondary feature data of the aforementioned secondary compressed image block. The binarized pixel value of each pixel in the aforementioned binarized image block is combined as the secondary quantization data of the aforementioned secondary compressed image block.
[0226] When the second-level compression error is the second total difference level, for each color component type, the eighth difference value of the fifth difference level and the sixth difference level is calculated, and the eighth difference value corresponding to each color component type is compared. The second low mode reference data or second high mode reference data of the target color component type corresponding to the smallest eighth difference value is compressed by a preset number of binary bits for second-level compression. The second low mode reference data, second high mode reference data of other color component types, and the uncompressed second low mode reference data or second high mode reference data of the target color component type, as well as the compressed second low mode reference data or second high mode reference data, are combined as the second-level feature data of the second-level compressed image block. The initial quantization data of the last iteration of each pixel is combined as the second-level quantization data of the second-level compressed image block.
[0227] Compression type data indicates the compression level of the compressed image patch data. Compression levels include level 2 compression, level 4 compression, etc. The meaning of different numbers in the compression type data can be predefined. For example, when the compression type data is 0, it indicates that the compression level of the compressed image patch data is level 2; when the compression type data is 1, it indicates that the compression level of the compressed image data is level 4. The compression type data is 1 bit.
[0228] As an example, when the initial image block is 4 rows × 4 columns and the compression ratio is 1 / 6, the data size of the secondary compressed image block data corresponding to the initial image block is 64 bits. Then, the secondary compressed image block data can include 47 bits of secondary feature data, 16 bits of secondary quantization data and 1 bit of compression type data. The compression type data is preset to indicate the compression level as secondary compression when it is 0 and as 4 compression level when it is 1. When the secondary compression error is at the first total difference level, the first low-mode reference data or first high-mode reference data of the target color component type corresponding to the smallest seventh difference is compressed by 1 bit by shifting it 1 bit to the right. The 47-bit secondary feature data includes the first low-mode reference data, the first high-mode reference data, and the compressed first low-mode reference data or first high-mode reference data. The 16-bit secondary quantization data includes the binarized pixel value of each pixel, and the compression type data is 0. When the secondary compression error is at the second total difference level, the second low-mode reference data or second high-mode reference data of the target color component type corresponding to the smallest eighth difference is compressed by 1 bit by shifting it 1 bit to the right. The 47-bit secondary feature data includes the second low-mode reference data, the second high-mode reference data, and the compressed second low-mode reference data or second high-mode reference data. The 16-bit secondary quantization data includes the initial quantization data of the last iteration of each pixel, and the compression type data is 0.
[0229] In an optional embodiment, the initial image block is compressed using four levels of compression to obtain four-level compressed image block data, mainly including the following steps A21 to A24:
[0230] Step A21: Calculate the compression level based on the maximum and minimum characterization data mentioned above;
[0231] Step A22: Determine the quantization segmentation threshold according to the above compression level, and determine the corresponding fourth-level quantization data for each of the above pixels based on the comparison result of the above quantization segmentation threshold and the above characterization data.
[0232] Step A23: Group the pixels according to the above four-level quantization data, and calculate the corresponding four-level feature data for each group of the above four-level quantization data;
[0233] Step A24: Combine the above-mentioned four-level feature data, the above-mentioned four-level quantization data, and the compression type data to obtain four-level compressed image block data corresponding to the above-mentioned initial image block.
[0234] Furthermore, step A21 above may include the following steps A211 to A212:
[0235] Step A211: Calculate distance representation data and intermediate representation data based on the maximum representation data and the minimum representation data mentioned above;
[0236] Among them, distance representation data and intermediate representation data Please refer to the following formula for calculation:
[0237]
[0238]
[0239] Step A212: Determine the compression level of the initial image patch based on the distance representation data, the intermediate representation data, the maximum low-mode representation data, and the minimum high-mode representation data.
[0240] Specifically, the first difference between the minimum high-mode representation data and the intermediate representation data, and the second difference between the intermediate representation data and the maximum low-mode representation data are calculated; the minimum of the first difference and the second difference is taken as the interval representation data. As shown in the following formula,
[0241]
[0242] The first interval threshold is calculated based on the aforementioned distance representation data. Second interval threshold and the third interval threshold As shown in the following formula,
[0243]
[0244] The compression level of the initial image patch is determined based on the comparison results by comparing the interval characterization data with the first, second, and third interval thresholds mentioned above. Specifically, in response to the interval representation data being less than or equal to the first interval threshold, the compression level is determined to be 0; in response to the interval representation data being greater than the first interval threshold and less than or equal to the second interval threshold, the compression level is determined to be 1; in response to the interval representation data being greater than the second interval threshold and less than or equal to the third interval threshold, the compression level is determined to be 2; and in response to the interval representation data being greater than the third interval threshold, the compression level is determined to be 3. As shown below,
[0245]
[0246] In one optional embodiment, the quantization segmentation thresholds include a first quantization segmentation threshold, a second quantization segmentation threshold, and a third quantization segmentation threshold.
[0247] Step A22 above may include the following steps A221 to A224:
[0248] Step A221: Calculate intermediate parameters based on the distance characterization data and the compression level described above;
[0249] Specifically, we can first calculate half of the distance representation data and the first product of the compression level, and then use one-quarter of the first product as the intermediate parameter D, as shown in the following formula.
[0250]
[0251] Step A222: Determine the first quantization segmentation threshold and the third quantization segmentation threshold based on the aforementioned intermediate parameters, the aforementioned distance representation data, and the aforementioned intermediate representation data, and use the aforementioned intermediate representation data as the aforementioned second quantization segmentation threshold. ;
[0252] Specifically, the first sum of the aforementioned intermediate parameters and half of the distance representation data can be calculated, and the third difference between the aforementioned intermediate representation data and the aforementioned first sum can be used as the aforementioned first quantization segmentation threshold. The aforementioned intermediate representation data can be directly used as the second quantization segmentation threshold. The second sum of the aforementioned intermediate representation data, the aforementioned intermediate parameters, and half of the aforementioned distance representation data can be calculated and used as the aforementioned third quantization segmentation threshold. As shown in the following formula,
[0253]
[0254] Wherein, the first quantization segmentation threshold is less than the second quantization segmentation threshold, and the second quantization segmentation threshold is less than the third quantization segmentation threshold;
[0255] Step A223: For each pixel, compare the above-mentioned characterization data with the above-mentioned first quantization segmentation threshold, the second quantization segmentation threshold and the above-mentioned third quantization segmentation threshold;
[0256] Step A224: In response to the characterization data being less than or equal to the first quantization segmentation threshold, the fourth-level quantization data of the pixel is determined to be 0; in response to the characterization data being greater than the first quantization segmentation threshold and less than or equal to the second quantization segmentation threshold, the fourth-level quantization data of the pixel is determined to be 1; in response to the characterization data being greater than the second quantization segmentation threshold and less than or equal to the third quantization segmentation threshold, the fourth-level quantization data of the pixel is determined to be 2; in response to the characterization data being greater than the third quantization segmentation threshold, the fourth-level quantization data of the pixel is determined to be 3.
[0257] Based on the characterization data and the aforementioned first, second, and third quantization segmentation thresholds, the four-level quantization data of the pixel is determined, as shown in the following formula.
[0258]
[0259] in, This represents the fourth-level quantization data of the nth pixel in the initial image block.
[0260] Each pixel It is 2 bits. As an example, for a 4×4 initial image block, which includes 16 pixels, the corresponding four-level quantization data is 32 bits in total.
[0261] Furthermore, prior to step A23, the method further includes: using the pixel with the fourth-level quantization data of 0 as the third pixel; using the pixel with the fourth-level quantization data of 1 as the fourth pixel; using the pixel with the fourth-level quantization data of 2 as the fifth pixel; and using the pixel with the fourth-level quantization data of 3 as the sixth pixel.
[0262] For the third pixel, the fourth pixel, the fifth pixel, and the sixth pixel respectively, perform the following steps B1 to B3:
[0263] Step B1: Calculate the sum of the characterization data and the sum of the color components for each color component type, and determine the corresponding number of pixels;
[0264] As an example, for an initial 4×4 image block, there are a total of 16 pixels, including 4 third pixels, 7 fourth pixels, 2 fifth pixels and 3 sixth pixels. For the above 4 third pixels, the sum of their characterization data, the sum of the color components R of all third pixels, the sum of the color components G of all third pixels, and the sum of the color classification B of all third pixels are calculated. Similarly, the above calculations are performed for the fourth, fifth and sixth pixels respectively.
[0265] Step B2: For each of the above color component types, calculate the average value of the color components based on the sum of the above color components and the above number of pixels;
[0266] For the third pixel, the average color component is calculated using the following formula:
[0267]
[0268]
[0269]
[0270] in, This represents the average value of the color component R of the third pixel; Indicates the number of pixels in the third pixel; This represents the sum of the color components R of the third pixel; This represents the average value of the color component G of the third pixel; This represents the sum of the color components G of the third pixel; This represents the average value of the color component B of the third pixel; This represents the sum of the color components B of the third pixel.
[0271] Similar to the third pixel, for the fourth pixel, the average color component is calculated using the following formula:
[0272]
[0273]
[0274]
[0275] in, This represents the average value of the color component R of the fourth pixel; Indicates the number of pixels in the fourth pixel; This represents the sum of the color components R of the fourth pixel; This represents the average value of the color component G of the fourth pixel; This represents the sum of the color components G of the fourth pixel; This represents the average value of the color component B of the fourth pixel; This represents the sum of the color components B of the fourth pixel.
[0276] Similarly, for the fifth pixel, the average color component is calculated using the following formula:
[0277]
[0278]
[0279]
[0280] in, This represents the average value of the color component R of the fifth pixel; Indicates the number of pixels in the fifth pixel; This represents the sum of the color components R of the fifth pixel; This represents the average value of the color component G of the fifth pixel; This represents the sum of the color components G of the fifth pixel; This represents the average value of the color component B of the fifth pixel; This represents the sum of the color components B of the fifth pixel.
[0281] Similarly, for the sixth pixel, the average color component is calculated using the following formula:
[0282]
[0283]
[0284]
[0285] in, This represents the average value of the color component R of the sixth pixel; Indicates the number of pixels in the sixth pixel; This represents the sum of the color components R of the sixth pixel; This represents the average value of the color component G of the sixth pixel; This represents the sum of the color components G of the sixth pixel; This represents the average value of the color component B of the sixth pixel; This represents the sum of the color components B of the sixth pixel.
[0286] Step B3: Calculate the average value of the characterization data based on the sum of the above characterization data and the above number of pixels.
[0287] For the third pixel, the average value of the characterizing data is calculated using the following formula:
[0288]
[0289] in, This represents the average value of the characterization data for the third pixel; This represents the sum of the characterization data for the third pixel.
[0290] Similarly, for the fourth pixel, the average value of the characterizing data is calculated using the following formula:
[0291]
[0292] in, This represents the average value of the characterization data for the fourth pixel; This represents the sum of the characterization data for the fourth pixel.
[0293] Similarly, for the fifth pixel, the average value of the characterizing data is calculated using the following formula:
[0294]
[0295] in, This represents the average value of the characterization data for the fifth pixel; This represents the sum of the characterization data for the fifth pixel.
[0296] Similarly, for the sixth pixel, the average value of the characterizing data is calculated using the following formula:
[0297]
[0298] in, This represents the average value of the characterization data for the sixth pixel; This represents the sum of the characterization data for the sixth pixel.
[0299] In an optional embodiment, step A23 above may include the following steps A231 to A234:
[0300] Step A231: Combine the third pixel and the fourth pixel to form the first group of target pixels, and combine the fifth pixel and the sixth pixel to form the second group of target pixels;
[0301] Step A232: For each color component type, calculate the initial low-mode reference data for the first group of target pixels based on the average color component value of the third pixel, the average color component value of the fourth pixel, and the pre-configured weights of the third and fourth pixels. Please refer to the following formula.
[0302]
[0303]
[0304]
[0305] in, This represents the initial low-mode reference data for the color components R of the first group of target pixels; This represents the initial low-mode reference data for the color components G of the first group of target pixels; This represents the initial low-mode reference data for the color component B of the first group of target pixels; This indicates the weight of the third pixel in the first group of target pixels; This indicates the weight of the fourth pixel in the first group of target pixels; .
[0306] Step A233: For each color component type, calculate the initial high-mode reference data for the second group of target pixels based on the average color component value of the fifth pixel, the average color component value of the sixth pixel, and the pre-configured weights of the fifth and sixth pixels. Please refer to the following formula.
[0307]
[0308]
[0309]
[0310] in, This represents the initial low-mode reference data for the color components R of the first group of target pixels; This represents the initial low-mode reference data for the color components G of the first group of target pixels; This represents the initial low-mode reference data for the color component B of the first group of target pixels; This indicates the weight of the fifth pixel in the first group of target pixels; This indicates the weight of the sixth pixel in the first group of target pixels; .
[0311] Step A234: Determine the fourth-level feature data of the compressed image block corresponding to the initial image block using the initial low-mode reference data and the initial high-mode reference data.
[0312] Specifically, the data corresponding to any color component in the initial low-mode reference data or the initial high-mode reference data is compressed by a first preset number of binary bits, and the data corresponding to other color components in the initial low-mode reference data and the initial high-mode reference data are compressed by a second preset number of binary bits; the compressed low-mode reference data and the compressed high-mode reference data are combined as the fourth-level feature data of the compressed image block corresponding to the initial image block.
[0313] Furthermore, the data volume of the fourth-level feature data is determined based on the data volume of the compressed image block corresponding to the initial image block. The data volume of the fourth-level compressed image block can be determined based on the data volume of the initial image block and the compression ratio; that is, the data volume of the fourth-level compressed image block is equal to the product of the data volume of the initial image block and the compression ratio. The fourth-level compressed image block data includes fourth-level feature data, fourth-level quantization data, and compression type data. The compression type data is 1 bit, and the fourth-level quantization data corresponding to each pixel is 2 bits. Therefore, the data volume of the fourth-level quantization data corresponding to the fourth-level compressed image block is twice the number of pixels. After determining the data volume of the fourth-level compressed image block, as well as the data volumes of the compression type data and the fourth-level quantization data, the data volume of the fourth-level feature data can be determined.
[0314] The number of binary bits to be compressed for each initial low-mode reference data or initial high-mode reference data can be further determined based on the amount of data in the fourth-level compressed image block.
[0315] As an example, for a 4×4 initial image block, the initial low-mode reference data or the initial high-mode reference data corresponding to each color component type is 8 bits, the initial low-mode reference data for all color component types is 24 bits, and the initial high-mode reference data for all color component types is 24 bits, resulting in a total of 48 bits for both initial low-mode and initial high-mode reference data corresponding to the initial image block. Since the data size of the four-level compressed image block corresponding to the initial image block is 64 bits, including 1 bit of compression type data and 32 bits of four-level quantization data, the data size of the four-level feature data should be 31 bits. Therefore, it is necessary to compress the aforementioned 48 bits of initial low-mode and initial high-mode reference data to 31 bits. Therefore, the data corresponding to any color component in the initial low-mode or initial high-mode reference data can be right-shifted by 2 bits to achieve a 2-bit compression, and the data corresponding to other color components in the aforementioned initial low-mode and initial high-mode reference data can be right-shifted by 3 bits to achieve a 3-bit compression, resulting in a total of 31 bits of compressed low-mode and compressed high-mode reference data.
[0316] In one optional embodiment, the above calculation of the fourth-level compression error includes: reconstructing the fourth-level compressed image block data to obtain reconstructed image block data corresponding to the fourth-level compressed image block data; and calculating the fourth-level compression error based on the initial image block corresponding to the fourth-level compressed image block data and the reconstructed image block data.
[0317] In an optional embodiment, the reconstruction of the above-mentioned four-level compressed image block data to obtain reconstructed image block data corresponding to the above-mentioned four-level compressed image block data specifically includes the following steps Y1 to Y4:
[0318] Step Y1: Padded with binary bits for a preset four-level compression;
[0319] The four-level compressed image block data includes four-level feature data, four-level quantization data, and compression type data. Binary bit padding is applied to the feature data within the four-level compressed image block. The preset number of four-level compression levels can be the same as either the first or second preset number.
[0320] Step Y2: Calculate temporary data and temporary differences based on the filled feature data;
[0321] Step Y3: Calculate the reconstruction threshold based on the above temporary data and the above temporary difference, and determine the restored pixel value of each pixel based on the above reconstruction threshold and the target quantization data;
[0322] Step Y4: Concatenate the restored pixel values of each of the above pixels to obtain the decompressed reconstructed image block data;
[0323] Optionally, step Y1 may include: for each color component type, filling the compressed low-mode reference data and compressed high-mode reference data in the above four-level feature data with a preset number of binary bits for compression, so that the compressed low-mode reference data is restored to the restored low-mode reference data and the compressed high-mode reference data is restored to the restored high-mode reference data.
[0324] The low-compression mode reference data and the high-compression mode reference data are padded by left-shifting the low-compression mode reference data and the high-compression mode reference data by a preset number of binary bits (four levels of compression).
[0325] Furthermore, after filling, to avoid large errors between the restored low-mode reference data and the initial low-mode reference data, and between the restored high-mode reference data and the initial high-mode reference data, corresponding preset error data can be added after left shifting. This restores the compressed low-mode reference data to the restored low-mode reference data and the compressed high-mode reference data to the restored high-mode reference data. The preset error data can be determined by the following formula:
[0326]
[0327] Where p represents the preset error data; q represents the preset number of four compression levels.
[0328] Optionally, step Y2 above may include: for each color component type, taking half of the sum of the restored low-mode reference data and the restored high-mode reference data as temporary data; and taking the difference between the restored low-mode reference data and the restored high-mode reference data as a temporary difference value, as shown in the following formula.
[0329]
[0330]
[0331] in, This indicates temporary data. This indicates that the high-mode reference data has been restored; This indicates that the low-mode reference data has been restored; This represents a temporary difference.
[0332] Optionally, the above reconstruction thresholds include a first reconstruction threshold, a second reconstruction threshold, a third reconstruction threshold, and a fourth reconstruction threshold.
[0333] Step Y3 above may include: calculating the second product of the temporary difference and the first weight, and using the ninth difference between the temporary data and the second product as the first reconstruction threshold; calculating the third product of the temporary difference and the second weight, and using the tenth difference between the temporary data and the third product as the second reconstruction threshold; using the third sum of the temporary data and the third product as the third reconstruction threshold; and using the fourth sum of the temporary data and the second product as the fourth reconstruction threshold; wherein the second weight is greater than 0 and less than the first weight, and the first weight is less than 1. Please refer to the following formula.
[0334]
[0335]
[0336]
[0337]
[0338] in, Indicates the first reconstruction threshold; Indicates the second reconstruction threshold; Indicates the third reconstruction threshold; This indicates the fourth reconstruction threshold; Indicates the first weight; This indicates the second weight.
[0339] Preferably, the first weight is 1 / 2; the second weight is 1 / 6.
[0340] Optionally, step Y3 above may include: for each color component type, when the four-level quantization data is 0, using the first reconstruction threshold as the restored color component of the corresponding pixel; when the four-level quantization data is 1, using the second reconstruction threshold as the restored color component of the corresponding pixel; when the four-level quantization data is 2, using the third reconstruction threshold as the restored color component of the corresponding pixel; and when the four-level quantization data is 3, using the fourth reconstruction threshold as the restored color component of the corresponding pixel. Please refer to the following formula.
[0341]
[0342] in, This represents the reconstructed color component of the nth pixel in the reconstructed image patch data. When the reconstruction threshold represents a threshold for the reconstruction of color components R, G, or B, the corresponding... This represents the value of the restored color components R, G, or B of the nth pixel;
[0343] Then, for each pixel, the restored pixel value is calculated based on the restored color components mentioned above. Specifically, for each pixel, the product of the preset restored color component weight and the corresponding restored color component is summed to obtain the restored pixel value, which is the product of the preset restored color component R weight and the restored color component R, plus the product of the preset restored color component G weight and the restored color component G, plus the product of the preset restored color component B weight and the restored color component B.
[0344] In an optional embodiment, the calculation of the four-level compression error based on the initial image block corresponding to the four-level compressed image block data and the reconstructed image block data includes: for each pixel, calculating the absolute value of the difference between each color component in the initial image block and each color component in the reconstructed image block data; calculating the sum of the absolute values corresponding to all pixels in the reconstructed image block data as the four-level compression error, as shown in the following formula.
[0345]
[0346] in, Indicates level four compression error; This indicates the number of pixels in the reconstructed image patch, which is equivalent to the number of pixels in the initial image patch; This represents the pixel value of the nth pixel in the initial image block.
[0347] In an optional embodiment, determining the target compression level of the initial image block based on the second-level compression error and the fourth-level compression error includes: calculating a first difference between the second-level compression error and the fourth-level compression error, and a second difference between the fourth-level compression error and the second-level compression error; and determining the target compression level of the initial image block based on a first comparison result of the first difference and a preset comparison threshold, and a second comparison result of the second difference and a preset comparison threshold.
[0348] Specifically, determining the target compression level of the initial image block based on the first comparison result of the first difference and the preset comparison threshold and the second comparison result of the second difference and the preset comparison threshold includes: in response to the first comparison result indicating that the first difference is greater than or equal to the preset comparison threshold, taking the fourth-level compression as the target compression level of the initial image block; and in response to the second comparison result indicating that the second difference is greater than or equal to the preset comparison threshold, taking the second-level compression as the target compression level of the initial image block.
[0349] Once the target compression level is determined, the compressed image block data corresponding to the target compression level can be selected when stitching compressed image data, as shown in the following formula.
[0350]
[0351] in, This represents compressed image block data corresponding to the target compression level of the initial image block; This represents level four compressed image block data; This represents secondary compressed image block data; Indicates the second-order compression error; This indicates the preset comparison threshold.
[0352] By presetting a preset comparison threshold and determining the target compression level through the comparison results of the first difference and the preset comparison threshold, as well as the comparison results of the second difference and the preset comparison threshold, the difference between the second-level compression error and the fourth-level compression error is quantified. This can clearly identify the compression method with smaller error and better compression quality, making the finally selected compressed image block data more in line with actual needs and reducing the probability of being misled by random errors.
[0353] According to the image compression method of this invention, during the process of compressing the original image into compressed image data, the original image is divided into several initial image blocks. Secondary compression error and quaternary compression error are calculated for each initial image block. The target compression level of the initial image block is determined based on the secondary and quaternary compression errors. The compressed image block data corresponding to the target compression level is then stitched together to obtain compressed image data corresponding to the original image. This method can accurately match a more suitable compression level for each initial image block based on the errors of the two compression levels, thereby obtaining compressed image blocks with smaller compression errors for each initial image block, further reducing the compression error of the compressed image data corresponding to the original image. Furthermore, during the image compression process, compressed image block data can be generated based solely on the pixels in the initial image blocks, eliminating the need for image compression algorithms. This reduces the algorithm training and subsequent update processes, simplifies the compression method, greatly improves compression efficiency, reduces computational load, and lowers the computational requirements of the device, allowing deployment in lightweight devices. Simultaneously, it avoids the poor compression quality problems that may arise from using image compression algorithms, thus improving the overall compression quality.
[0354] like Figure 3 As shown, the image decompression method of this invention is mainly used for decompressing compressed image data obtained by the image compression method of this invention, and mainly includes the following steps S301 to S302:
[0355] Step S301: For each compressed image block in the compressed image data described above, perform the following steps Z1 to Z3:
[0356] The compressed image block data mentioned above includes feature data, quantization data, and compression type data;
[0357] Step Z1: Determine the target compression level based on the compressed image block data; the target compression level is either level two or level four compression.
[0358] The target compression level for a compressed image patch can be determined based on the compression type data within the compressed image patch data. The target compression level is determined according to the meaning of different numbers in the predefined compression type data. For example, when the compression type data is 0, it indicates that the target compression level for the compressed image patch data is level two compression; when the compression type data is 1, it indicates that the target compression level for the compressed image patch data is level four compression.
[0359] Step Z2: Determine the number of binary bits to be padded according to the target compression level, and padded the compressed image block data with binary bits based on the number of binary bits to be padded.
[0360] It is understandable that the number of binary bits padded for the feature data is different for different target compression levels. That is, when the target compression level is level 2 compression, the number of binary bits padded is the preset number of level 2 compression; when the target compression level is level 4 compression, the number of binary bits padded is the preset number of level 4 compression.
[0361] Once the number of binary bits to be padded is determined, binary bits can be padded to the feature data in the compressed image block data based on this.
[0362] Step Z3: Determine the restored pixel value of each pixel based on the filled compressed image block data, and concatenate the restored pixel values of each pixel to obtain the decompressed image block data corresponding to the above compressed image block data;
[0363] Step S302: The decompressed image block data corresponding to each of the above compressed image block data is stitched together to obtain the original image corresponding to the above compressed image data.
[0364] In an optional embodiment of the present invention, step Z2 includes: in response to the target compression level being level 2 compression, identifying target reference data in the feature data whose bit depth is different from that of other reference data; performing binary bit padding for the target reference data with a preset number of level 2 compressions; and in response to the target compression level being level 4 compression, performing binary bit padding for each low-compression mode reference data and each high-compression mode reference data in the feature data with a preset number of level 4 compressions.
[0365] Specifically, when the target compression level is level two compression, target reference data with a bit depth different from the bit depth of other reference data is identified in the feature data; the target reference data is padded with a preset number of binary bits for level two compression so that its bit depth is the same as the bit depth of other reference data, thus obtaining the padded feature data.
[0366] As an example, when the bit depth of other reference data in the feature data is 8 bits and the bit depth of the target reference data is 7 bits, the target reference data can be padded with 1 bit by shifting it left by 1 bit.
[0367] Optionally, to reduce errors, the target reference data can be incremented by 1 after the binary bits are filled.
[0368] When the target compression level is level four compression, for each color component type, the compressed low-mode reference data and compressed high-mode reference data in the above feature data are padded with a preset number of binary bits for level four compression, so that the compressed low-mode reference data is restored to the restored low-mode reference data and the compressed high-mode reference data is restored to the restored high-mode reference data.
[0369] The low-compression mode reference data and the high-compression mode reference data are padded by left-shifting the low-compression mode reference data and the high-compression mode reference data by a preset number of binary bits (four levels of compression).
[0370] Optionally, after filling, to avoid large errors between the restored low-mode reference data and the initial low-mode reference data, and between the restored high-mode reference data and the initial high-mode reference data, corresponding preset error data can be added after left shifting. This restores the compressed low-mode reference data to the restored low-mode reference data and the compressed high-mode reference data to the restored high-mode reference data. The preset error data can be determined by the following formula:
[0371]
[0372] Where p represents the preset error data; q represents the preset number of four compression levels.
[0373] In an optional embodiment of the present invention, step Z3 includes: generating the restored color component of each pixel according to the feature data filled with the quantized data and the preset rules associated with the target compression level; and calculating the restored pixel value for each pixel based on the restored color component.
[0374] When the target compression level is level 2 compression, the restored color components of each pixel are generated according to preset rules based on the quantized data and the padded feature data; the padded feature data includes the restored high mode reference data and restored low mode reference data corresponding to each color component type;
[0375] Specifically, for each pixel, the following steps are performed: In response to the quantization data being 1, the high-mode reference data for each color component type is used as the restored color component of the corresponding color component type in the pixel; in response to the quantization data being 0, the low-mode reference data for each color component type is used as the restored color component of the corresponding color component type in the pixel, as shown in the following formula.
[0376]
[0377] in, This represents the pixel value after the nth pixel has been restored. This represents the high-mode reconstruction data of the nth pixel; This represents the restored low-mode data for the nth pixel; This represents the quantized data of the nth pixel.
[0378] when This represents the high-mode data for the color components R, G, or B of the nth pixel. When representing the low-mode data of the color components R, G, or B of the nth pixel, correspondingly, This represents the numerical value of the restored color components R, G, or B of the nth pixel;
[0379] Then, for each pixel, the restored pixel value is calculated based on its corresponding restored color component. Specifically, for each pixel, the product of the preset restored color component weight and the corresponding restored color component is summed to obtain the restored pixel value, which is the product of the preset restored color component R weight and the restored color component R, plus the product of the preset restored color component G weight and the restored color component G, plus the product of the preset restored color component B weight and the restored color component B.
[0380] When the target compression level is level four compression, temporary data and temporary differences are calculated based on the padded feature data; a reconstruction threshold is calculated based on the temporary data and temporary differences, and the restored pixel value of each pixel is determined based on the reconstruction threshold and quantization data.
[0381] Specifically, for each color component type of each pixel, half of the sum of the restored low-mode reference data and the restored high-mode reference data is used as temporary data; the difference between the restored low-mode reference data and the restored high-mode reference data is used as a temporary difference value, as shown in the following formula.
[0382]
[0383]
[0384] in, This indicates temporary data. This indicates that the high-mode reference data has been restored; This indicates that the low-mode reference data has been restored; This represents a temporary difference.
[0385] Calculate the second product of the aforementioned temporary difference and the first weight, and use the ninth difference between the aforementioned temporary data and the aforementioned second product as the first reconstruction threshold; calculate the third product of the aforementioned temporary difference and the second weight, and use the tenth difference between the aforementioned temporary data and the aforementioned third product as the second reconstruction threshold; use the third sum of the aforementioned temporary data and the aforementioned third product as the third reconstruction threshold; use the fourth sum of the aforementioned temporary data and the aforementioned second product as the fourth reconstruction threshold; wherein, the aforementioned second weight is greater than 0 and less than the aforementioned first weight, and the aforementioned first weight is less than 1, please refer to the following formula.
[0386]
[0387]
[0388]
[0389]
[0390] in, Indicates the first reconstruction threshold; Indicates the second reconstruction threshold; Indicates the third reconstruction threshold; This indicates the fourth reconstruction threshold; Indicates the first weight; This indicates the second weight.
[0391] Preferably, the first weight is 1 / 2; the second weight is 1 / 6.
[0392] For each color component type, when the quantization data is 0, the first reconstruction threshold is used as the restored color component of the corresponding pixel; when the quantization data is 1, the second reconstruction threshold is used as the restored color component of the corresponding pixel; when the quantization data is 2, the third reconstruction threshold is used as the restored color component of the corresponding pixel; and when the quantization data is 3, the fourth reconstruction threshold is used as the restored color component of the corresponding pixel. Please refer to the following formula.
[0393]
[0394] in, This represents the reconstructed color component of the nth pixel in the reconstructed image patch data. When the reconstruction threshold represents the reconstruction threshold for the color components R, G, or B of the nth pixel, accordingly, This represents the value of the restored color components R, G, or B of the nth pixel;
[0395] Then, for each pixel, the restored pixel value is calculated based on its corresponding restored color component. Specifically, for each pixel, the product of the preset restored color component weight and the corresponding restored color component is summed to obtain the restored pixel value, which is the product of the preset restored color component R weight and the restored color component R, plus the product of the preset restored color component G weight and the restored color component G, plus the product of the preset restored color component B weight and the restored color component B.
[0396] According to the image decompression method of the present invention, for each compressed image block data in the compressed image data, the target compression level is determined, and the number of binary bits to be padded is determined based on the target compression level to padded the compressed image block data with binary bits, thereby determining the restored pixel value of each pixel, and obtaining the decompressed image block data corresponding to the compressed image block data. After the decompressed image block data is stitched together, the restored image corresponding to the above compressed image data can be obtained. The image decompression method is simple, requires less computation, improves decompression efficiency, can be deployed in lightweight devices, and does not require the use of compression algorithms during the decompression process, reducing the process of algorithm training and subsequent updates.
[0397] like Figure 4 As shown, the image compression device 400 of this embodiment mainly includes: a segmentation module 401, used to segment the original image into several initial image blocks; for each of the initial image blocks, a first calculation module 402, a second calculation module 403, and a first determination module 404 are executed; the first calculation module 402 is used to compress the initial image block using two-level compression, calculate the two-level compression error, and generate two-level compressed image block data; the second calculation module 403 is used to compress the initial image block using four-level compression to obtain four-level compressed image block data, and calculate the four-level compression error; the first determination module 404 is used to determine the target compression level of the initial image block based on the two-level compression error and the four-level compression error; and a first stitching module 405 is used to stitch together the compressed image block data corresponding to the target compression level of each initial image block to obtain compressed image data corresponding to the original image.
[0398] In an optional embodiment of the present invention, the first determining module 404 is further configured to: calculate a first difference between the second-level compression error and the fourth-level compression error, and a second difference between the fourth-level compression error and the second-level compression error; and determine the target compression level of the initial image block based on a first comparison result of the first difference and a preset comparison threshold, and a second comparison result of the second difference and a preset comparison threshold.
[0399] In an optional embodiment of the present invention, the first determining module 404 is further configured to: in response to the first comparison result indicating that the first difference is greater than or equal to the preset comparison threshold, use the fourth-level compression as the target compression level of the initial image block; and in response to the second comparison result indicating that the second difference is greater than or equal to the preset comparison threshold, use the second-level compression as the target compression level of the initial image block.
[0400] In an optional embodiment of the present invention, the image compression device 400 further includes a third calculation module, used to calculate the characterization data corresponding to each pixel using its color components.
[0401] In an optional embodiment of the present invention, the first calculation module 402 is further configured to: convert the initial image block into a binary image block; calculate a first total difference degree based on the color component of each pixel and the binary pixel value corresponding to each pixel in the binary image block; calculate a second total difference degree based on the characterization data of each pixel and the color component; compare the first total difference degree and the second total difference degree, and determine the second-level compression error based on the comparison result of the first total difference degree and the second total difference degree.
[0402] In an optional embodiment of the present invention, the second calculation module 403 is further configured to: reconstruct the four-level compressed image block data to obtain reconstructed image block data corresponding to the four-level compressed image block data; and calculate the four-level compression error based on the initial image block corresponding to the four-level compressed image block data and the reconstructed image block data.
[0403] In an optional embodiment of the present invention, the second calculation module 403 is further configured to: calculate, for each pixel, the absolute value of the difference between each color component in the initial image block and each color component in the reconstructed image block data; and calculate the sum of the absolute values corresponding to all pixels in the reconstructed image block data as the fourth-level compression error.
[0404] The image compression apparatus according to embodiments of the present invention, during the process of compressing the original image to generate compressed image data, divides the original image into several initial image blocks, calculates a second-level compression error and a fourth-level compression error for each initial image block, determines the target compression level of the initial image block based on the second-level and fourth-level compression errors, and stitches together the compressed image block data corresponding to the target compression level to obtain compressed image data corresponding to the original image. It can accurately match a more suitable compression level for each initial image block based on the errors of the two compression levels, thereby obtaining a compressed image block with a smaller compression error for each initial image block, further reducing the compression error of the compressed image data corresponding to the original image. Furthermore, during the image compression process, compressed image block data can be generated based solely on the pixels in the initial image blocks, eliminating the need for image compression algorithms. This reduces the algorithm training and subsequent update processes, simplifies the compression method, greatly improves compression efficiency, reduces computational load, and lowers the computational requirements of the device, allowing deployment in lightweight devices. Simultaneously, it avoids the poor compression quality problems that may arise from using image compression algorithms, thus improving compression quality.
[0405] like Figure 5 As shown, the image decompression apparatus 500 of this embodiment mainly includes: for each compressed image block data in the compressed image data, executing a second determining module 501, a filling module 502, and a second stitching module 503: the second determining module 501 is used to determine its target compression level according to the compressed image block data; the target compression level is level two compression or level four compression; the filling module 502 is used to determine the number of binary bits to fill according to the target compression level, and fill the compressed image block data with binary bits based on the number of binary bits to fill; the second stitching module 503 is used to determine the restored pixel value of each pixel according to the filled compressed image block data, and stitch the restored pixel values of each pixel to obtain decompressed image block data; the third stitching module 504 is used to stitch the decompressed image block data corresponding to each of the compressed image block data to obtain the original image corresponding to the compressed image data.
[0406] In an optional embodiment of the present invention, the compressed image block data includes feature data, quantization data, and compression type data.
[0407] The filling module 502 is further configured to: in response to the target compression level being level two compression, identify target reference data in the feature data whose bit depth differs from that of other reference data; fill the target reference data with a preset number of binary bits for level two compression; and in response to the target compression level being level four compression, fill each low-compression mode reference data and each high-compression mode reference data in the feature data with a preset number of binary bits for level four compression.
[0408] In an optional embodiment of the present invention, the second stitching module 503 is further configured to: generate the restored pixel value of each pixel according to the feature data filled with the quantized data and the preset rules associated with the target compression level.
[0409] According to the image decompression apparatus of the present invention, for each compressed image block data in the compressed image data, the target compression level is determined, and the number of binary bits to be padded is determined based on the target compression level to padded the compressed image block data with binary bits, thereby determining the restored pixel value of each pixel, and obtaining the decompressed image block data corresponding to the compressed image block data. After the decompressed image block data is stitched together, the restored image corresponding to the above-mentioned compressed image data can be obtained. The image decompression method is simple, requires less computation, improves decompression efficiency, can be deployed in lightweight devices, and does not require the use of compression algorithms during the decompression process, reducing the process of algorithm training and subsequent updates.
[0410] The following is for reference. Figure 6 It shows a schematic diagram of the structure of a computer system 600 suitable for implementing the image compression method, image decompression method, image compression apparatus or image decompression apparatus of the present invention. Figure 6 The computer system 600 shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
[0411] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 602 or programs loaded from storage section 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of the computer system 600. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0412] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.
[0413] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit (CPU) 601, it performs the functions defined above in the system of this invention.
[0414] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0415] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0416] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor. For example, a processor can be described as including a segmentation module, a first calculation module, a second calculation module, a first determination module, and a first stitching module. Another example is a processor including a second determination module, a filling module, a second stitching module, and a third stitching module. The names of these modules do not necessarily limit the module itself; for example, a segmentation module can also be described as "a module that segments the original image into several initial image blocks."
[0417] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: dividing an original image into several initial image blocks, and for each initial image block, performing steps A1 to A5: Step A1, compressing the initial image block using two-level compression, calculating the two-level compression error, and generating two-level compressed image block data; Step A2, compressing the initial image block using four-level compression to obtain four-level compressed image block data, and calculating the four-level compression error; Step A3, determining a target compression level for the initial image block based on the two-level compression error and the four-level compression error; and concatenating the compressed image block data corresponding to the target compression level for each initial image block to obtain compressed image data corresponding to the original image. Alternatively, when one or more of the above procedures are executed by a device, the device includes: performing the following steps Z1 to Z3 for each compressed image block data in the compressed image data: Step Z1: Determine the target compression level of the compressed image block data; the target compression level is level 2 compression or level 4 compression; Step Z2: Determine the number of binary bits to fill based on the target compression level, and fill the compressed image block data with binary bits based on the number of binary bits to fill; Step Z3: Determine the restored pixel value of each pixel based on the filled compressed image block data, and concatenate the restored pixel values of each pixel to obtain decompressed image block data; concatenate the decompressed image block data corresponding to each of the above compressed image block data to obtain the original image corresponding to the compressed image data.
[0418] According to the technical solution of this invention, during the process of compressing the original image to generate compressed image data, the original image is divided into several initial image blocks. Secondary compression error and quaternary compression error are calculated for each initial image block. The target compression level of the initial image block is determined based on the secondary and quaternary compression errors. The compressed image block data corresponding to the target compression level is then stitched together to obtain compressed image data corresponding to the original image. This allows for precise matching of a more suitable compression level for each initial image block based on the errors of the two compression levels, resulting in compressed image blocks with smaller compression errors for each initial image block, further reducing the compression error of the compressed image data corresponding to the original image. Furthermore, during image compression, compressed image block data can be generated based solely on the pixels in the initial image blocks, eliminating the need for image compression algorithms. This reduces the need for algorithm training and subsequent updates, simplifies the compression method, significantly improves compression efficiency, reduces computational load, and lowers the computational requirements of the device, allowing deployment in lightweight devices. Simultaneously, it avoids the poor compression quality issues that may arise from using image compression algorithms, thus improving overall compression quality.
[0419] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
[0420] This invention provides the following technical solutions:
[0421] Technical Solution 1. An image compression method, comprising:
[0422] The original image is divided into several initial image blocks, and steps A1 to A3 are performed for each of the initial image blocks:
[0423] Step A1: Compress the initial image block using two-stage compression, calculate the two-stage compression error, and generate two-stage compressed image block data;
[0424] Step A2: Compress the initial image block using four-level compression to obtain four-level compressed image block data, and calculate the four-level compression error;
[0425] Step A3: Determine the target compression level of the initial image block based on the second-level compression error and the fourth-level compression error;
[0426] The compressed image block data corresponding to the target compression level of each initial image block is stitched together to obtain compressed image data corresponding to the original image.
[0427] Technical Solution 2. The image compression method according to Technical Solution 1, wherein determining the target compression level of the initial image block based on the second-level compression error and the fourth-level compression error includes:
[0428] Calculate the first difference between the second-level compression error and the fourth-level compression error, and the second difference between the fourth-level compression error and the second-level compression error;
[0429] The target compression level of the initial image block is determined based on the first comparison result of the first difference and the preset comparison threshold, and the second comparison result of the second difference and the preset comparison threshold.
[0430] Technical Solution 3. The image compression method according to Technical Solution 2, wherein determining the target compression level of the initial image block based on a first comparison result of the first difference and a preset comparison threshold and a second comparison result of the second difference and a preset comparison threshold includes:
[0431] In response to the first comparison result indicating that the first difference is greater than or equal to the preset comparison threshold, the fourth level of compression is taken as the target compression level of the initial image block;
[0432] In response to the second comparison result indicating that the second difference is greater than or equal to the preset comparison threshold, the secondary compression is taken as the target compression level of the initial image block.
[0433] Technical Solution 4. The image compression method according to Technical Solution 1, the method further includes:
[0434] For each pixel, its color components are used to calculate the corresponding representation data.
[0435] Technical Solution 5. According to the image compression method described in Technical Solution 4, the calculation of the second-level compression error includes:
[0436] Convert the initial image block into a binary image block;
[0437] The first total degree of difference is calculated based on the color component of each pixel and the binary pixel value corresponding to each pixel in the binarized image block;
[0438] A second total degree of difference is calculated based on the characterization data and color components of each pixel;
[0439] The first total difference degree and the second total difference degree are compared, and the second-level compression error is determined based on the comparison result of the first total difference degree and the second total difference degree.
[0440] Technical Solution 6. According to the image compression method described in Technical Solution 1, the calculation of the four-level compression error includes:
[0441] The four-level compressed image block data is reconstructed to obtain reconstructed image block data corresponding to the four-level compressed image block data.
[0442] The fourth-level compression error is calculated based on the initial image block corresponding to the fourth-level compressed image block data and the reconstructed image block data.
[0443] Technical Solution 7. The image compression method according to Technical Solution 6, wherein calculating the fourth-level compression error based on the initial image block corresponding to the fourth-level compressed image block data and the reconstructed image block data includes:
[0444] For each pixel, calculate the absolute value of the difference between each color component in the initial image block and each color component in the reconstructed image block data;
[0445] The sum of the absolute values of all pixels in the reconstructed image block data is calculated as the fourth-level compression error.
[0446] Technical Solution 8. An image decompression method for compressed image data obtained by compressing using any one of the image compression methods described in Technical Solutions 1 to 7, comprising:
[0447] For each compressed image block in the compressed image data, perform the following steps Z1 to Z3:
[0448] Step Z1: Determine the target compression level based on the compressed image block data; the target compression level is either level two or level four compression.
[0449] Step Z2: Determine the number of binary bits to be padded according to the target compression level, and padded the compressed image block data with binary bits based on the number of binary bits to be padded.
[0450] Step Z3: Determine the restored pixel value of each pixel based on the filled compressed image block data, and concatenate the restored pixel values of each pixel to obtain the decompressed image block data;
[0451] The decompressed image block data corresponding to each compressed image block data is stitched together to obtain the original image corresponding to the compressed image data.
[0452] Technical Solution 9. The image decompression method according to Technical Solution 8, wherein the compressed image block data includes feature data, quantization data, and compression type data;
[0453] The step of determining the number of binary bit paddings based on the target compression level, and padding the compressed image block data with binary bits based on the number of binary bit paddings, includes:
[0454] In response to the target compression level being two-level compression, target reference data with a different bit depth from other reference data is identified in the feature data; binary bits are padded for the target reference data to a preset number of two-level compression operations.
[0455] In response to the target compression level being level four compression, a preset number of binary bits are padded for each low-compression mode reference data and each high-compression mode reference data in the feature data, corresponding to the four-level compression requirement.
[0456] Technical Solution 10. The image decompression method according to Technical Solution 9, wherein determining the restored pixel value of each pixel based on the padded compressed image block data includes:
[0457] Based on the feature data filled with the quantized data, the restored color component of each pixel is generated according to the preset rules associated with the target compression level; for each pixel, the restored pixel value is calculated based on the restored color component.
[0458] Technical Solution 11. An image compression device, comprising:
[0459] The segmentation module is used to segment the original image into several initial image blocks;
[0460] For each of the initial image blocks, the first calculation module, the second calculation module, and the first determination module are executed respectively;
[0461] The first calculation module is used to compress the initial image block using two-stage compression, calculate the two-stage compression error, and generate two-stage compressed image block data;
[0462] The second calculation module is used to compress the initial image block using four-level compression to obtain four-level compressed image block data, and to calculate the four-level compression error;
[0463] The first determining module is used to determine the target compression level of the initial image block based on the second-level compression error and the fourth-level compression error;
[0464] The first stitching module is used to stitch together compressed image block data corresponding to the target compression level of each initial image block to obtain compressed image data corresponding to the original image.
[0465] Technical Solution 12. An image decompression apparatus, comprising:
[0466] For each compressed image block in the compressed image data, the second determination module, the filling module, and the second stitching module are executed:
[0467] The second determining module is used to determine the target compression level based on the compressed image block data; the target compression level is either level two compression or level four compression.
[0468] A padding module is used to determine the number of binary bits to pad based on the target compression level, and to pad the compressed image block data with binary bits based on the number of binary bits to pad.
[0469] The second stitching module is used to determine the restored pixel value of each pixel based on the filled compressed image block data, and stitch the restored pixel values of each pixel together to obtain the decompressed image block data.
[0470] The third stitching module is used to stitch together the decompressed image block data corresponding to each of the compressed image block data to obtain the original image corresponding to the compressed image data.
[0471] Technical Solution 13. An electronic device, comprising:
[0472] One or more processors;
[0473] A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the image compression method as described in any of technical solutions 1 to 7 or the image decompression method as described in any of technical solutions 8 to 10.
[0474] Technical Solution 14. A computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the image compression method as described in any one of Technical Solutions 1 to 7 or the image decompression method as described in any one of Technical Solutions 8 to 10.
[0475] Technical Solution 15. A computer program product, comprising:
[0476] A computer program, when executed by a processor, implements the image compression method as described in any one of technical solutions 1 to 7 or the image decompression method as described in any one of technical solutions 8 to 10.
Claims
1. An image compression method characterized by, The method comprises the following steps: segmenting an original image into a plurality of initial image blocks, and performing steps A1-A3 on each initial image block respectively: Step A1: compressing the initial image block by using two-level compression, calculating a two-level compression error, and generating two-level compressed image block data; Step A2: compressing the initial image block by using four-level compression to obtain four-level compressed image block data, and calculating a four-level compression error; Step A3: determining a target compression level of the initial image block according to the two-level compression error and the four-level compression error; splicing the compressed image block data corresponding to the target compression level of each initial image block to obtain compressed image data corresponding to the original image.
2. The image compression method of claim 1, wherein, The method comprises the following steps: calculating a first difference between the two-level compression error and the four-level compression error, and a second difference between the four-level compression error and the two-level compression error; determining the target compression level of the initial image block according to a first comparison result of the first difference and a preset comparison threshold, and a second comparison result of the second difference and the preset comparison threshold.
3. An image decompression method characterized by, The method comprises the following steps: performing steps Z1-Z3 on each compressed image block data in the compressed image data obtained by using the image compression method of any one of claims 1-2: Step Z1: determining a target compression level of the compressed image block data according to the compressed image block data; the target compression level is two-level compression or four-level compression; Step Z2: determining a number of binary bits to be filled according to the target compression level, and filling the compressed image block data with the number of binary bits; Step Z3: determining a restored pixel value of each pixel according to the filled compressed image block data, and splicing the restored pixel value of each pixel to obtain decompressed image block data; splicing the decompressed image block data corresponding to each compressed image block data to obtain an original image corresponding to the compressed image data.
4. The image decompression method of claim 3, wherein, The compressed image block data comprises feature data, quantization data, and compression type data; The method comprises the following steps: in response to the target compression level being two-level compression, identifying target reference data in the feature data whose bit depth is different from that of other reference data, and filling the target reference data with a preset number of binary bits for two-level compression; in response to the target compression level being four-level compression, filling each compressed low mode reference data and each compressed high mode reference data in the feature data with a preset number of binary bits for four-level compression.
5. The image decompression method of claim 4, wherein, The method comprises the following steps: According to the quantized feature data after the filling, a restored color component of each pixel is generated according to a preset rule associated with the target compression level; and for each pixel, a restored pixel value is calculated based on the restored color component.
6. An image compression apparatus characterized by comprising: The method comprises: a segmentation module configured to segment an original image into a plurality of initial image blocks; for each of the initial image blocks, a first calculation module, a second calculation module and a first determination module are executed; the first calculation module is configured to compress the initial image block using a two-level compression, calculate a two-level compression error, and generate two-level compressed image block data; the second calculation module is configured to compress the initial image block using a four-level compression, obtain four-level compressed image block data, and calculate a four-level compression error; the first determination module is configured to determine a target compression level of the initial image block according to the two-level compression error and the four-level compression error; a first splicing module is configured to splice the compressed image block data corresponding to the target compression level of each of the initial image blocks to obtain compressed image data corresponding to the original image.
7. An image decompression apparatus characterized by comprising: The method comprises: for each of the compressed image block data in the compressed image data, a second determination module, a filling module and a second splicing module are executed: the second determination module is configured to determine a target compression level of the compressed image block data according to the compressed image block data; the target compression level is two-level compression or four-level compression; the filling module is configured to determine a number of binary bit fillings according to the target compression level, and fill the compressed image block data with the binary bit fillings based on the number of binary bit fillings; the second splicing module is configured to determine a restored pixel value of each pixel according to the filled compressed image block data, splice the restored pixel value of each pixel, and obtain decompressed image block data; a third splicing module is configured to splice the decompressed image block data corresponding to each of the compressed image block data to obtain an original image corresponding to the compressed image data.
8. An electronic device, comprising: The method comprises: one or more processors; a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the image compression method of any one of claims 1-2 or implement the image decompression method of any one of claims 3-5.
9. A computer-readable storage medium, characterized in that, A computer program is stored thereon, when the program is executed by a processor, the image compression method of any one of claims 1-2 is implemented or the image decompression method of any one of claims 3-5 is implemented.
10. A computer program product, characterised in that, The method comprises: a computer program, when the computer program is executed by a processor, the image compression method of any one of claims 1-2 is implemented or the image decompression method of any one of claims 3-5 is implemented.