A picture coding method, apparatus, device and computer readable storage medium
Patent Information
- Application Number
- CN202211448084.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-18
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2042-11-18
AI Technical Summary
并且在实际应用中,图片中的一些不影响图片质量的数据采用无损压缩会造成时间与空间上的浪费
[0038] As can be seen, the image encoding method provided in this application divides the image to be compressed into multiple data blocks and classifies each data block. Different compression methods are used for different categories of data blocks, and the compression methods corresponding to different categories are not all lossless compression. That is, not all data blocks are compressed using lossless compression. In this way, while ensuring image quality, storage space is reduced and encoding and decoding efficiency is improved.
Smart Images

Figure CN115713567B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of encoding technology, and in particular to an image encoding method; it also relates to an image encoding apparatus, device, and computer-readable storage medium. Background Technology
[0002] PNG (Portable Network Graphics) is a widely used bitmap format that uses the lossless LZ77 algorithm for data compression. Lossless compression means that the decompressed file is identical to the original file. Lossless compressed PNG images tend to be larger, requiring more storage resources. Larger images open and save more slowly, as encoding and decoding consume more CPU or hardware resources. Faster processing of large PNG images requires superior CPU performance or hardware resources. Furthermore, in practical applications, lossless compression of data that doesn't affect image quality can lead to wasted time and space.
[0003] In view of this, how to save resources and costs while ensuring image quality has become a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0004] The purpose of this application is to provide an image encoding method that can save resource consumption and reduce costs while ensuring image quality. Another purpose of this application is to provide an image encoding device, apparatus, and computer-readable storage medium, all of which have the above-mentioned technical effects.
[0005] To address the aforementioned technical problems, this application provides an image encoding method, comprising:
[0006] Obtain the image to be compressed, divide the image to be compressed into multiple data blocks, and determine the category of each data block;
[0007] Based on the category of each data block, the compression method corresponding to the category is used to compress each data block to obtain compressed data; the compression methods corresponding to different categories are not all lossless compression;
[0008] The compressed data is then integrated to obtain a compressed image.
[0009] Optionally, determining the category of each of the data blocks includes:
[0010] Based on the content of each data block, the category of each data block is determined, and the categories of data blocks include unimportant data blocks, reusable data blocks, and important data blocks.
[0011] Optionally, compressing each data block according to its category using the compression method corresponding to that category includes:
[0012] If the data block is an unimportant data block, then lossy compression is used to compress the data block;
[0013] If the data block is a reusable data block, then the sliding window size of the lossless compression algorithm is set to the size of the reusable data, the reusable data block is losslessly compressed, and the data block that is the same as the reusable data block is represented by an index value;
[0014] If the data block is an important data block, then the data block is compressed according to a preset compression strategy.
[0015] Optionally, compressing the data block according to a preset compression strategy includes:
[0016] The important data blocks are divided into preset sizes, and the similarity between the data blocks of the preset sizes is determined;
[0017] Based on the similarity between the data blocks of the preset size, the corresponding compression method is adopted to compress the data blocks of the preset size.
[0018] Optionally, determining the similarity between the data blocks of the preset size includes:
[0019] Calculate the preset feature values of the data block of the preset size;
[0020] Calculate the Hamming distance between data blocks of the preset size based on the preset feature values;
[0021] Calculate the ratio of the Hamming distance to the preset size;
[0022] The similarity between the data blocks of the preset size is determined based on the ratio.
[0023] Optionally, compressing the data blocks of the preset size according to the similarity between the data blocks of the preset size includes:
[0024] If the similarity between the current data block of the preset size and the previous data block of the preset size is greater than a first preset threshold, then the compression result of the previous data block of the preset size is used; wherein, the compression method of the first data block of the preset size is lossless compression;
[0025] If the similarity between the current data block of the preset size and the previous data block of the preset size is greater than the second preset threshold and less than the first preset threshold, then lossy compression is used to compress the current data block of the preset size.
[0026] If the similarity between the current data block of the preset size and the previous data block of the preset size is less than the second preset threshold, then lossless compression is used to compress the current data block of the preset size.
[0027] Optionally, integrating the compressed data to obtain a compressed image includes:
[0028] The compressed data and image data blocks are integrated to obtain the compressed image; wherein, the image data blocks record the category, compression method, similarity, and length of the compressed data.
[0029] To address the aforementioned technical problems, this application also provides an image encoding device, comprising:
[0030] The category determination module is used to obtain the image to be compressed, divide the image to be compressed into multiple data blocks, and determine the category of each data block;
[0031] The data compression module is used to compress each data block according to its category and using the compression method corresponding to that category to obtain compressed data; the compression methods corresponding to different categories are not all lossless compression;
[0032] The data integration module is used to integrate the compressed data to obtain a compressed image.
[0033] To address the aforementioned technical problems, this application also provides an image encoding device, comprising:
[0034] Memory, used to store computer programs;
[0035] A processor for executing the computer program to implement the steps of the image encoding method as described in any of the preceding claims.
[0036] To address the aforementioned technical problems, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the image encoding method described in any of the preceding claims.
[0037] The image encoding method provided in this application includes: acquiring an image to be compressed; dividing the image to be compressed into multiple data blocks and determining the category of each data block; compressing each data block according to the category of each data block using the compression method corresponding to the category to obtain compressed data; the compression methods corresponding to different categories are not all lossless compression; and integrating the compressed data to obtain a compressed image.
[0038] As can be seen, the image encoding method provided in this application divides the image to be compressed into multiple data blocks and classifies each data block. Different compression methods are used for different categories of data blocks, and the compression methods corresponding to different categories are not all lossless compression. That is, not all data blocks are compressed using lossless compression. In this way, while ensuring image quality, storage space is reduced and encoding and decoding efficiency is improved.
[0039] The image encoding device, equipment, and computer-readable storage medium provided in this application all have the aforementioned technical effects. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the prior art and embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is a flowchart illustrating an image encoding method provided in an embodiment of this application.
[0042] Figure 2 This is a schematic diagram of data block classification provided in an embodiment of this application;
[0043] Figure 3 This is a schematic diagram of a data representation provided in an embodiment of this application;
[0044] Figure 4 This is a schematic diagram of an encoding output result provided in an embodiment of this application;
[0045] Figure 5 This is a schematic diagram of an image encoding device provided in an embodiment of this application;
[0046] Figure 6 This is a schematic diagram of an image encoding device provided in an embodiment of this application. Detailed Implementation
[0047] The core of this application is to provide an image encoding method that can save resource consumption and reduce costs while ensuring image quality. Another core aspect of this application is to provide an image encoding device, apparatus, and computer-readable storage medium, all of which achieve the aforementioned technical effects.
[0048] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0049] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating an image encoding method provided in an embodiment of this application. (Refer to...) Figure 1 As shown, the method includes:
[0050] S101: Obtain the image to be compressed, divide the image to be compressed into multiple data blocks, and determine the category of each data block;
[0051] After obtaining the data to be compressed, it can first be divided into data blocks of different sizes, and the category of each data block can be determined. Then, appropriate compression methods can be applied to the data blocks of different categories. The category of the data block reflects its importance to the image display.
[0052] In some embodiments, determining the category of each data block includes:
[0053] Based on the content of each data block, the category of each data block is determined, and the categories of data blocks include unimportant data blocks, reusable data blocks, and important data blocks.
[0054] In this embodiment, data blocks are categorized into three types: unimportant data blocks, reusable data blocks, and important data blocks. Unimportant data blocks refer to data blocks that do not affect image display or are not noticeable to the human eye. Reusable data blocks refer to consecutive identical data blocks. Important data blocks refer to key data blocks in the image, data blocks that are of high visual interest during image display.
[0055] For example, if the data to be compressed contains both background and other content, the background is considered an unimportant data block, while the other content is considered important data. If the data to be compressed contains a large amount of data with consistent ARGB values, it is considered a reusable data block. It should be noted that the categories of the data blocks divided from the entire image may not necessarily include all categories; it may contain only one, two, or all three. For example, see reference... Figure 2 The data block partitioning shown includes three categories.
[0056] S102: Based on the category of each data block, compress each data block using the compression method corresponding to the category to obtain compressed data; the compression methods corresponding to different categories are not all lossless compression;
[0057] This embodiment pre-defines the correspondence between data block categories and compression methods. Based on the classification of data blocks, the corresponding compression method for each data block category can be used to compress the data blocks. Note that not all compression methods corresponding to different categories are lossless compression.
[0058] In some embodiments, compressing each data block according to its category using a compression method corresponding to that category includes:
[0059] If the data block is an unimportant data block, then lossy compression is used to compress the data block;
[0060] If the data block is a reusable data block, then the sliding window size of the lossless compression algorithm is set to the size of the reusable data, the reusable data block is losslessly compressed, and the data block that is the same as the reusable data block is represented by an index value;
[0061] If the data block is an important data block, then the data block is compressed according to a preset compression strategy.
[0062] This embodiment addresses the three categories of data blocks: unimportant data blocks, reusable data blocks, and important data blocks. Different compression methods are applied to each category. If a data block is unimportant, a lossy compression method is used. For example, after sampling the data, one pixel may represent multiple pixels, or the average of multiple pixels may be used to represent multiple pixels.
[0063] If the data block is reusable, it is compressed using a lossless compression method. In this lossless compression algorithm, the sliding window size is equal to the size of the data block. Subsequent data blocks identical to this one are represented directly using their index values.
[0064] For example, given m pixels, the subsequent (N-1)*m pixels are identical to these m pixels. During channel compression, the sliding window size in the LZ77 algorithm is first adjusted to m. The subsequent (N-1)*m pixels are directly represented by the index value (1, m), indicating they are identical to the first row. The first row has m pixels. In the uncompressed data block, its storage format is as follows: Figure 3 As shown in Table 1, the results of updating and saving reusable data blocks using STATUS CHUNK are shown in Table 1.
[0065] Table 1
[0066]
[0067] If the data block is an important data block, then the important data block will be compressed according to the preset compression strategy, namely the preset compression strategy mentioned above.
[0068] In some embodiments, compressing the data block according to a preset compression strategy includes:
[0069] The important data blocks are divided into preset sizes, and the similarity between the data blocks of the preset sizes is determined;
[0070] Based on the similarity between the data blocks of the preset size, the corresponding compression method is adopted to compress the data blocks of the preset size.
[0071] In this embodiment, the compression strategy is to further divide important data blocks, determine the similarity between the pre-defined size data blocks, and then take corresponding compression methods for data blocks of different similarities.
[0072] By dividing important data blocks and compressing them based on their similarity, storage space can be further reduced.
[0073] It is clear that, in addition to the compression strategies mentioned above, other compression strategies can be adopted. For example, to accelerate the compression rate of important data blocks, lossless compression can be applied directly to the entire important data block.
[0074] In some embodiments, determining the similarity between the data blocks of the preset size includes:
[0075] Calculate the preset feature values of the data block of the preset size;
[0076] Calculate the Hamming distance between data blocks of the preset size based on the preset feature values;
[0077] Calculate the ratio of the Hamming distance to the preset size;
[0078] The similarity between the data blocks of the preset size is determined based on the ratio.
[0079] The preset feature value can be either the pixel difference of the data block or the hash value of the data block.
[0080] When the preset feature value is the hash value of the data block, the important data block can be further divided into m*n (n rows and m columns) data blocks. The difference between adjacent rows of pixels is then calculated within each m*n data block. The following explanation uses a single channel as an example:
[0081] Subtract the pixel value of the previous row from the pixel value of the current row. Repeat this process n-1 times from row 2 to row n, resulting in an m*n difference matrix N. Calculate the average value a of this difference matrix.
[0082] Traverse each pixel in the difference matrix N from left to right and from top to bottom. If the element n in the i-th row and j-th column of the difference matrix is greater than or equal to a, then mark the pixel value at that position as 1; otherwise, mark it as 0. Finally, obtain the hash value of the current data block, which has a length of m*n.
[0083] Similarly, the hash value of the next data block can be obtained. By comparing the hash values of the two data blocks, the Hamming distance x between the two data blocks of size m*n can be calculated, and x / (m*n) can be calculated.
[0084] For example, the hash value of data block 1 is: 1001 1100 1111 1000 1011 0010 1001 0100;
[0085] The hash value of data block 2 is: 1001 1100 1111 1000 1011 0110 1001 0000;
[0086] Therefore, the Hamming distance between data block 1 and data block 2 is 2.
[0087] x / (m*n) = 2 / 32 = 6.25%.
[0088] When the preset feature value is the pixel difference of a data block, the important data block can be further divided into m*n data blocks. The difference between adjacent pixels is calculated within each m*n data block, resulting in (m-1)*n differences. If the preceding pixel is greater than the following pixel, it is recorded as 1; otherwise, it is recorded as 0.
[0089] Calculate the Hamming distance x between data blocks of size m*n, and calculate x / (m*n).
[0090] For example, the difference between adjacent pixels in data block 1 is: 1001 1100 1111 1000 1011 0010 10010100;
[0091] The difference between adjacent pixels in data block 2 is: 1001 1100 1111 1000 1011 0110 1001 0000;
[0092] Therefore, the Hamming distance between data block 1 and data block 2 is 2.
[0093] x / (m*n) = 2 / 32 = 6.25%.
[0094] An interval that reflects the similarity between data blocks can be preset. After calculating the ratio, the similarity between data blocks of the preset size is determined based on the ratio.
[0095] In a specific embodiment, the similarity between the data blocks of the preset size can be determined by subtracting the ratio from 1 to obtain the similarity, i.e., similarity = 1 - ratio.
[0096] In the example above, the ratio is 6.25%, so the similarity is 1 minus 6.25%, which equals 93.75%. This indicates that data block 1 and data block 2 are consistent, and data block 2 can be directly represented by data block 1. In other words, the smaller the ratio, the greater the similarity, indicating that the data block data is more consistent.
[0097] In some embodiments, compressing the data blocks of the preset size according to the similarity between the data blocks of the preset size includes:
[0098] If the similarity between the current data block of the preset size and the previous data block of the preset size is greater than a first preset threshold, then the compression result of the previous data block of the preset size is used; wherein, the compression method of the first data block of the preset size is lossless compression;
[0099] If the similarity between the current data block of the preset size and the previous data block of the preset size is greater than the second preset threshold and less than the first preset threshold, then lossy compression is used to compress the current data block of the preset size.
[0100] If the similarity between the current data block of the preset size and the previous data block of the preset size is less than the second preset threshold, then lossless compression is used to compress the current data block of the preset size.
[0101] For example, the first preset threshold can be set to 90%, and the second preset threshold can be set to 50%.
[0102] If the similarity between the current data block of the preset size and the previous data block of the preset size is greater than 90%, that is, 0 ≤ x / (m*n) ≤ 10%, it indicates that the current data block of the preset size is highly similar to the previous data block of the preset size, and the two are basically repeated data. In this case, the current data block of the preset size may not be subjected to compression processing, and the compression result of the previous data block of the preset size is used instead.
[0103] If the similarity between the current data block of the preset size and the previous data block of the preset size is less than 90% and greater than 50%, that is, 10% < x / (m*n) ≤ 50%, it indicates that the current data block of the preset size is partially similar to the previous data block of the preset size, and a lossy compression method is used to compress the current data block of the preset size.
[0104] If the similarity between the current data block of the preset size and the previous data block of the preset size is less than 50%, that is, 50% < x / (m*n) < 1, the similarity between the current data block of the preset size and the previous data block of the preset size is low, and the changes between the data blocks are drastic, so a lossless compression method is used to compress the current data block of the preset size.
[0105] S103: integrating the compressed data to obtain a compressed image.
[0106] This step aims to, after compression is completed, integrate the compressed data to obtain the final compressed image.
[0107] Wherein, said integrating the compressed data to obtain a compressed image comprises:
[0108] integrating the compressed data and image data blocks to obtain the compressed image; wherein the image data blocks record the category of the data block, the compression method, the similarity, and the length of the compressed data.
[0109] Specifically, with reference to Figure 4 , a custom status marker block can be defined ( Figure 4 STATUS CHUNK shown therein), which is used to record category information of data blocks, compression method information and the length of compressed data. After data compression is completed, insert an image data block ( Figure 4 IDAT CHUNK shown therein). One image data block may contain 0, 1, or two or more status marker blocks. The IHDR of the image, that is, the file header data, is added with a marker for mixed coding, that is, the adopted coding method, and the IEND of the image, that is, the image end data, remains unchanged. For the composition of the status marker block, please refer to Table 2:
[0110] Table 2
[0111]
[0112] The decompression process for compressed images is the reverse of the compression process; it can be deduced by working backward from the compression process, so it will not be elaborated here.
[0113] In summary, the image encoding method provided in this application divides the image to be compressed into multiple data blocks and classifies each data block. Different compression methods are used for different categories of data blocks, and the compression methods corresponding to different categories are not all lossless compression. That is, not all data blocks are compressed using lossless compression. In this way, while ensuring image quality, storage space is reduced and encoding / decoding efficiency is improved.
[0114] This application also provides an image encoding device, which is described below and can be referred to in conjunction with the method described above. Please refer to... Figure 5 , Figure 5 This is a schematic diagram of an image encoding device provided in an embodiment of this application, combined with... Figure 5 As shown, the device includes:
[0115] The category determination module 10 is used to acquire the image to be compressed, divide the image to be compressed into multiple data blocks, and determine the category of each data block;
[0116] The data compression module 20 is used to compress each data block according to its category and using the compression method corresponding to that category to obtain compressed data; the compression methods corresponding to different categories are not all lossless compression;
[0117] The data integration module 30 is used to integrate the compressed data to obtain a compressed image.
[0118] Based on the above embodiments, as a specific implementation method, the category determination module 10 is specifically used for:
[0119] Based on the content of each data block, the category of each data block is determined, and the categories of data blocks include unimportant data blocks, reusable data blocks, and important data blocks.
[0120] Based on the above embodiments, as a specific implementation method, the data compression module 20 includes:
[0121] The first compression unit is used to compress the data block using a lossy compression method if the data block is an unimportant data block.
[0122] The second compression unit is configured to, if the data block is a reusable data block, set the sliding window size of the lossless compression algorithm to the size of the reusable data block, perform lossless compression on the reusable data block, and represent the same data block as the reusable data block using an index value.
[0123] The third compression unit is used to compress the data block according to a preset compression strategy if the data block is an important data block.
[0124] Based on the above embodiments, as a specific implementation method, the third compression unit includes:
[0125] A similarity determination unit is used to divide the important data blocks into preset sizes and determine the similarity between the data blocks of the preset sizes;
[0126] The data compression unit is used to compress the data blocks of the preset size by adopting an appropriate compression method based on the similarity between the data blocks of the preset size.
[0127] Based on the above embodiments, as a specific implementation method, the similarity determination unit includes:
[0128] The feature value calculation subunit is used to calculate the preset feature value of the data block of the preset size;
[0129] Hamming distance calculation subunit is used to calculate the Hamming distance between data blocks of the preset size based on the preset feature value;
[0130] A ratio calculation subunit is used to calculate the ratio of the Hamming distance to the preset size;
[0131] The similarity determination subunit is used to determine the similarity between the data blocks of the preset size based on the ratio.
[0132] Based on the above embodiments, as a specific implementation method, the data compression unit includes:
[0133] The first processing subunit is configured to use the compression result of the previous data block if the similarity between the current data block of the preset size and the previous data block of the preset size is greater than a first preset threshold; wherein the compression method of the first data block of the preset size is lossless compression.
[0134] The second processing subunit is used to compress the current data block of the preset size using a lossy compression method if the similarity between the current data block of the preset size and the previous data block of the preset size is greater than a second preset threshold and less than a first preset threshold.
[0135] The third processing subunit is used to compress the current data block of the preset size using a lossless compression method if the similarity between the current data block of the preset size and the previous data block of the preset size is less than the second preset threshold.
[0136] Based on the above embodiments, as a specific implementation method, the data integration module 30 is specifically used for:
[0137] The compressed data and image data blocks are integrated to obtain the compressed image; wherein, the image data blocks record the category, compression method, similarity, and length of the compressed data.
[0138] The image encoding device provided in this application divides the image to be compressed into multiple data blocks and classifies each data block. Different compression methods are used for different categories of data blocks, and the compression methods corresponding to different categories are not all lossless compression. That is, not all data blocks are compressed using lossless compression. In this way, while ensuring image quality, storage space is reduced and encoding and decoding efficiency is improved.
[0139] This application also provides an image encoding device, for reference. Figure 6 As shown, the device includes a memory 1 and a processor 2.
[0140] Memory 1 is used to store computer programs;
[0141] Processor 2 is used to execute computer programs to perform the following steps:
[0142] Obtain the image to be compressed, divide the image into multiple data blocks, and determine the category of each data block; compress each data block according to its category using the compression method corresponding to that category to obtain compressed data; not all compression methods corresponding to different categories are lossless compression; integrate the compressed data to obtain a compressed image.
[0143] For a description of the equipment provided in this application, please refer to the above method embodiments; further details will not be provided here.
[0144] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can perform the following steps:
[0145] Obtain the image to be compressed, divide the image into multiple data blocks, and determine the category of each data block; compress each data block according to its category using the compression method corresponding to that category to obtain compressed data; not all compression methods corresponding to different categories are lossless compression; integrate the compressed data to obtain a compressed image.
[0146] The computer-readable storage medium may include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0147] For a description of the computer-readable storage medium provided in this application, please refer to the above method embodiments; further details will not be repeated here.
[0148] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatuses, devices, and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant details can be found in the method section.
[0149] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0150] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0151] The image encoding method, apparatus, device, and computer-readable storage medium provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. An image encoding method, characterized in that, include: Obtain the image to be compressed, divide the image to be compressed into multiple data blocks, and determine the category of each data block; Based on the category of each data block, the data blocks are compressed using the compression method corresponding to the category to obtain compressed data; Not all of the different categories correspond to lossless compression. By integrating the compressed data, a compressed image is obtained; The determination of the category of each data block includes: Based on the content of each data block, the category of each data block is determined, and the categories of data blocks include unimportant data blocks, reusable data blocks, and important data blocks; The step of compressing each data block according to its category using the compression method corresponding to that category includes: If the data block is an unimportant data block, then lossy compression is used to compress the data block; If the data block is a reusable data block, then the sliding window size of the lossless compression algorithm is set to the size of the reusable data, the reusable data block is losslessly compressed, and the data block that is the same as the reusable data block is represented by an index value; If the data block is an important data block, then the data block is compressed according to a preset compression strategy.
2. The image encoding method according to claim 1, characterized in that, The step of compressing the data block according to a preset compression strategy includes: The important data blocks are divided into preset sizes, and the similarity between the data blocks of the preset sizes is determined; Based on the similarity between the data blocks of the preset size, the corresponding compression method is adopted to compress the data blocks of the preset size.
3. The image encoding method according to claim 2, characterized in that, Determining the similarity between the data blocks of the preset size includes: Calculate the preset feature values of the data block of the preset size; Calculate the Hamming distance between data blocks of the preset size based on the preset feature values; Calculate the ratio of the Hamming distance to the preset size; The similarity between the data blocks of the preset size is determined based on the ratio.
4. The image encoding method according to claim 3, characterized in that, The step of compressing the data blocks of the preset size according to the similarity between the data blocks of the preset size includes: If the similarity between the current data block of the preset size and the previous data block of the preset size is greater than a first preset threshold, then the compression result of the previous data block of the preset size is used; wherein, the compression method of the first data block of the preset size is lossless compression; If the similarity between the current data block of the preset size and the previous data block of the preset size is greater than the second preset threshold and less than the first preset threshold, then lossy compression is used to compress the current data block of the preset size. If the similarity between the current data block of the preset size and the previous data block of the preset size is less than the second preset threshold, then lossless compression is used to compress the current data block of the preset size.
5. The image encoding method according to claim 1, characterized in that, The process of integrating the compressed data to obtain the compressed image includes: The compressed data and image data blocks are integrated to obtain the compressed image; wherein, the image data blocks record the category, compression method, similarity, and length of the compressed data.
6. An image encoding device, characterized in that, include: The category determination module is used to obtain the image to be compressed, divide the image to be compressed into multiple data blocks, and determine the category of each data block; The data compression module is used to compress each data block according to its category and using the compression method corresponding to that category to obtain compressed data; the compression methods corresponding to different categories are not all lossless compression; The data integration module is used to integrate the compressed data to obtain a compressed image; The category determination module is specifically used for: Based on the content of each data block, the category of each data block is determined, and the categories of data blocks include unimportant data blocks, reusable data blocks, and important data blocks; The data compression module includes: The first compression unit is used to compress the data block using a lossy compression method if the data block is an unimportant data block. The second compression unit is configured to, if the data block is a reusable data block, set the sliding window size of the lossless compression algorithm to the size of the reusable data block, perform lossless compression on the reusable data block, and represent the same data block as the reusable data block using an index value. The third compression unit is used to compress the data block according to a preset compression strategy if the data block is an important data block.
7. An image encoding device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the image encoding method as described in any one of claims 1 to 5 when executing the computer program.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the image encoding method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
JADE-JPEG based adaptive document compression engine
US20020176632A1