METHOD FOR COMPRESSING IMAGE DATA AND IMAGE DATA COMPRESSING SYSTEM
20170353728 · 2017-12-07
Inventors
Cpc classification
H04N19/132
ELECTRICITY
H04N19/184
ELECTRICITY
International classification
Abstract
A method for compressing image data is provided. The image data includes a file to be compressed, which includes N blocks to be compressed. The method includes: setting a target data increment of each of the N blocks of the file according to a 0.sup.th accumulated target data size and an N.sup.th accumulated target data size; before compressing an n.sup.th block, calculating an (n−1).sup.th accumulated target data size of an (n−1).sup.th block according to the 0.sup.th accumulated target data size and the target data increment; when a difference between an (n−1).sup.th accumulated compressed data size and the (n−1).sup.th accumulated target data size is smaller than a predetermined threshold, removing X least significant bit(s) of a plurality of sets of data in the n.sup.th block to generate an updated n.sup.th block; and compressing the updated n.sup.th block to generate a compressed n.sup.th block.
Claims
1. A method for compressing image data, comprising: setting a target data increment of each of N blocks that need to be compressed of an image to be compressed according to a 0.sup.th accumulated target data size and an N.sup.th accumulated target data size; before compressing an n.sup.th block among the N blocks, calculating an (n−1).sup.th accumulated compressed data size of an (n−1).sup.th block among the N blocks; calculating an (n−1).sup.th accumulated target data size of the (n−1).sup.th block according to the 0.sup.th accumulated target data size and the target data increment; removing X least significant bit(s) of a plurality of sets of data in the n.sup.th block when a difference between the (n−1).sup.th accumulated compressed data size and the (n−1).sup.th accumulated target data size is smaller than a first predetermined threshold to generate a updated n.sup.th block; and compressing the updated n.sup.th block to generate a compressed n.sup.th block; wherein, N and X are finite positive integers, and n is a finite positive integer not greater than N.
2. The method according to claim 1, further comprising: before an m.sup.th block among the N blocks is compressed, calculating an (m−1).sup.th accumulated compressed data size of an (m−1).sup.th block among the N blocks; calculating an (m−1).sup.th accumulated target data size of the (m−1).sup.th block according to the 0.sup.th accumulated target data size and the target data increment; removing Y least significant bit(s) of a plurality of sets of data in the m.sup.th block when a difference between the (m−1).sup.th accumulated compressed data size and the (m−1).sup.th accumulated target data size is greater than the first threshold but smaller than a second threshold to generate an updated m.sup.th block; and compressing the updated m.sup.th block to generate a compressed m.sup.th block. wherein, the second predetermined threshold is greater than the first predetermined threshold, Y is a finite positive integer smaller than X, and m is a finite positive integer not greater than N and different from n.
3. The method according to claim 1, wherein X is 2 and Y is 1.
4. The method according to claim 1, wherein 0.sup.th accumulated target data size is greater than the first predetermined threshold.
5. The method according to claim 1, further comprising updating the 0.sup.th accumulated target data size according to compression archives of each of the blocks that needs to be compressed.
6. The method according to claim 1, wherein the N.sup.th accumulated target data size is a total data size divided by a target compression rate.
7. An image data compressing system, comprising: a compressing module, compressing an image to be compressed according to a predetermined compression algorithm, wherein data of the image comprises N blocks that need to be compressed; and a compression rate control circuit, coupled to the compressing module, comprising: a compressed data accumulating module, calculating an (n−1).sup.th accumulated compressed data size of an (n−1).sup.th block among the N blocks before an n.sup.th block among the N blocks is compressed according to a block compressed data size that the compressing module generates after compressing the (n−1).sup.th block; a target data accumulating module, calculating an (n−1).sup.th accumulated target data size of the (n−1).sup.th block according to a 0.sup.th accumulated target data size and a target data increment of each of the blocks; and a comparing module, outputting a first compression control signal to the compressing module when a difference between the (n−1).sup.th accumulated compressed data size and the (n−1).sup.th accumulated target data size is smaller than a first predetermined threshold; wherein, the compressing module further removes X least significant bit(s) of a plurality of sets of data in the n.sup.th block to generate an updated n.sup.th block when receiving the first compression control signal, and compresses the updated n.sup.th block to generate a compressed n.sup.th block; and N and X are finite positive integers, and n is a finite positive integer not greater than N.
8. The image data compressing system according to claim 7, wherein: the compressed data accumulating module further calculates an (m−1).sup.th accumulated compressed data size of an (m−1).sup.th block among the N blocks before an m.sup.th block among the N blocks is compressed; the target data accumulating module further calculates an (m−1).sup.th accumulated target data size of the (m−1).sup.th block according to the 0.sup.th accumulated target data size and the target data increment; the comparing module further outputs a second compression control signal to the compressing module when a difference between the (m−1).sup.th accumulated compressed data size and the (m−1).sup.th accumulated target data size is greater than the first threshold but smaller than a second threshold; the compressing module further removes Y least significant bit(s) of a plurality of sets of data in the m.sup.th block when the second compression control signal is received to generate an updated m.sup.th block, and compresses the updated m.sup.th block to generate an compressed m.sup.th block; and the second predetermined threshold is greater than the first predetermined threshold, m is a finite positive integer not greater than N and different from n, and Y is a finite positive integer smaller than X.
9. The image data compressing system according to claim 8, wherein X is 2 and Y is 1.
10. The image data compressing system according to claim 7, wherein 0.sup.th accumulated target data size is greater than the first predetermined threshold.
11. The image data compressing system according to claim 7, wherein the compression rate control circuit further updates the 0.sup.th accumulated target data size according to compression archives of each of the blocks that needs to be compressed.
12. The image data compressing system according to claim 7, wherein the N.sup.th accumulated target data size is a total data size divided by a target compression rate.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
DETAILED DESCRIPTION OF THE INVENTION
[0016]
[0017] The compressing module 110 compresses image data according to a predetermined compression algorithm. In one preferred embodiment of the present invention, the compressing module 110 may select a lossless compression algorithm to compress image data. However, the present invention does not limit the compressing module 110 to compressing image data by a lossless compression algorithm, and image data may also be compressed by a lossy compression algorithm that possibly causes distortion.
[0018] The compression rate control circuit 120, coupled to the compressing module 110, includes a compressed data accumulating module 122, a target data size accumulating module 124, and a comparing module 126. In some embodiments of the present invention, the image data compressing system 100 may be applied to compress image data IMG0 in
[0019]
[0020] In some embodiments of the present invention, assuming that the compression rate is a ratio of a total data size before compression to a total data size after compression, the N.sup.th accumulated target data size T.sub.N may be a total data size of the file to be compressed divided by the target compression rate. For example, assuming that the total data size of the image data IMG0 is 1 MB and the target compression rate is 1.25, the N.sup.th accumulated target data size T.sub.N is 1 MB divided by 1.25, i.e., 0.8 MB. The target compression rate may be user-defined or system-predetermined.
[0021] To ensure that a final N.sup.th accumulated compressed data size C.sub.N of the N image blocks B.sub.1 to B.sub.N compressed by the compressing module 110 does not exceed the N.sup.th accumulated target data size T.sub.N, before an n.sup.th block among the N blocks is compressed, e.g., before the image block B.sub.n (where n is a finite positive integer not greater than N) is compressed, the compressed data accumulating module 122 may calculate an (n−1).sup.th accumulated compressed data size C.sub.n-1 of an (n−1).sup.th block, i.e., the actual compressed data size after the image blocks B.sub.1 to B.sub.n-1 have been compressed. The comparing module 126 may further compare the (n−1).sup.th accumulated compressed data size C.sub.n-1 with an (n−1).sup.th accumulated target data size T.sub.n-1 corresponding to the (n−1).sup.th block in the compression rate control curve RCC1, and determine a difference between the two.
[0022] The (n−1).sup.th accumulated target data size T.sub.n-1 may be obtained through calculating the N blocks of the image data IMG0, i.e., a target data increment ΔT of each of the image blocks B.sub.1 to B.sub.N, and the 0.sup.th accumulated target data size T.sub.0, by the target data accumulating module 124. Wherein, the target data increment ΔT is a slope
of the compression rate control curve RCC1. In the above situation, the (n−1).sup.th accumulated target data size T.sub.n-1 may be represented by equation (1):
[0023] In some embodiments of the present invention, the target data accumulating module 124 is limited to directly obtaining the (n−1).sup.th accumulated target data size T.sub.n-1 by equation (1). Alternatively, the target data accumulating module 124 may also calculate the (n−1).sup.th accumulated target data size T.sub.n-1 through adding up the target data increment ΔT, so as to reduce the computation amount of multiplication and to simplify hardware. In
[0024] In the above situation, the comparing module 124 may output a first compression control signal SIG1 to the compressing module 110. When the first compression control signal SIG1 is received, the compressing module 110 removes X least significant bit(s) (LSB) of a plurality of sets of data in the n.sup.th block, i.e., the image block B.sub.n, to generate an updated n.sup.th block, compresses the updated n.sup.th block to generate a compressed n.sup.th block, and stores the compressed n.sup.th block to a memory. Wherein, X may be a user-defined or system-predetermined positive integer. In some embodiments of the present invention, X may be 1 or 2. Because the LSB less affects the overall value of data, no significant influence is produced on the image quality.
[0025] As such, the bit count of each set of data in the updated n.sup.th block is smaller than the bit count of each set of data in the original n.sup.th block, and the compressed data size after compressing the updated n.sup.th block is also smaller than the compressed data size of directly compressing the original n.sup.th block. Thus, the N.sup.th accumulated compressed data size C.sub.N is prevented from becoming greater than the N.sup.th accumulated target data size T.sub.N, and the effect of controlling the compression rate is achieved.
[0026] In some applications of image compression, it is possible that the LSB of each set of data in an image block be used as reserved reference bits, which influence the final image quality only in certain special circumstances. Values of such type of reserved reference bits are usually difficult to predict, and frequently cause compression complications and thus a reduced compression rate. In the above situation, by removing the X LSB of a plurality of sets of data in the image block B.sub.n, not only the data size of data that needs to be compressed is decreased, but also correlation levels among the plurality of sets of data in the image block B.sub.n are increased, which helps the compressing module 110 perform the compression, hence further enhancing the compression rate.
[0027] In other embodiments of the present invention, when the difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 and the (n−1).sup.th accumulated target data size T.sub.n-1 is greater than the predetermined threshold TH1, it means that the current accumulated compressed data size is not close to the current accumulated target data size, and so maintaining image quality may still be prioritized. At this point, the comparing module 126 does not output the first control signal SIG1 to the compressing module or it outputs other control signals different from the first control signal SIG1, such that the compressing module 110 may directly compress the n.sup.th block without removing any data bits.
[0028] Further, to prevent the compressing module 110 from removing a part of the LSB of each of a plurality of sets of data in the image block B.sub.1 at the beginning and from unnecessarily compromising the image quality, the image data compressing system 100 may set the 0.sup.th accumulated target data amount T.sup.0 to be greater than the first threshold TH1.
[0029] As described, the image data compressing system 100 is capable of adjusting the compression rate of the image block B.sub.n according to the difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 of the (n−1).sup.th image block B.sub.n-1 and the (n−1).sup.th accumulated target data size T.sub.n-1 of the (n−1).sup.th image block B.sub.n-1 corresponding to the compression rate control curve RCC1, and first removes a part of the LSB of each set of data in the image block B.sub.n in a situation where the compression rates of the previous (n−1) number of image blocks B.sub.1 to B.sub.n-1 are rather low. Therefore, the image data compressing system 100 is capable of adaptively adjusting the compression rate while maintaining image quality at the same time.
[0030] Further, in some embodiments of the present invention, the compression rate control circuit 120 may adjust the number of LSB that the compressing module 110 removes from each set of data in the image blocks. For example, in
[0031] In the embodiment in
[0032] For example, X may be 2 and Y may be 1. Thus, when the comparing module 126 determines that the difference between the current accumulated compressed data size and the current accumulated target data size is greater than the first predetermined threshold TH1 but smaller than the second predetermined threshold TH2, the comparing module 126 outputs the second compression control signal SIG2 to cause the compressing module 1120 to first remove the 1 LSB of each set of data in the image block before the image block is compressed. In contrast, when the difference between the current accumulated compressed data size and the current accumulated target data size is smaller than the first predetermined threshold, the comparing module 126 may output the first compression control signal SIG1 to cause the compressing module 110 to first remove 2 LSBs of each set of data in the image block before the image block is compressed.
[0033] As such, the image data compressing system 100 may adaptively determine whether to remove the LSB of each set of data in an image block that needs to be compressed, and the number of LSB to be removed if so, thereby more accurately controlling the compression rate and image quality. In some embodiments of the present invention, the image data compressing system 100 may set more predetermined thresholds based on system requirements to allow the image data compressing system 100 to be better in fine-tuning the compression rate. One person skilled in the art may implement the foregoing embodiments in form of digital circuits in the compression rate control circuit 120, and associated details are omitted herein.
[0034]
[0035] In comparison, taking the compression rate control curve RCC3 in
[0036] That is to say, the selection of the 0.sup.th accumulated target data size may affect the timing at which the compression rate control circuit 120 removes the LSB of block data that needs to be compressed. In the image data IMG0, only a part of the image blocks that are first compressed and cannot be easily compressed may lead to a low compression rate, whereas a part of the image blocks that are later compressed may still maintain a high compression rate. In the above situation, if a smaller 0.sup.th accumulated target data size T.sub.0 is selected, the compression rate control circuit 120 may be caused to inappropriately remove LSB of block data that needs to be compressed and unnecessarily reduce image quality.
[0037] Due to different characteristics of data of different images, in some embodiments of the present invention, the compression rate control circuit 120 may also update the 0.sup.th accumulated target data size according to compression archives or compression trends of compressed blocks of previously compressed files. Thus, the image data compressing system 100 may be prevented from inappropriately removing the LSB of a part of the block data and hence from unnecessarily lowering the image quality. One person skilled in the art can implement the foregoing embodiments by digital circuits in the compression rate control circuit 120, and associated details are omitted herein.
[0038]
[0039] In step S610, a target data increment ΔT of each of N blocks that need to be compressed in a file to be compressed is calculated according to a 0.sup.th accumulated target data size T.sub.0 and an N.sup.th accumulated target data size T.sub.N.
[0040] In step S620, before an n.sup.th block among the N blocks is compressed, an (n−1).sup.th accumulated compressed data size C.sub.n-1 is calculated.
[0041] In step S630, an accumulated target data size T.sub.n-1 of an (n−1).sup.th block among the N blocks is calculated according to the 0.sup.th accumulated target data size T.sub.0 and the target data increment ΔT.
[0042] In step S640, it is determined whether a difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 and the accumulated target data size T.sub.n-1 is smaller than a first predetermined threshold TH1. Step S650 is performed if so, otherwise step S660 is performed if not.
[0043] In step S650, X least significant bit(s) of a plurality of sets of data of the n.sup.th block that needs to be compressed is/are removed to generate an updated n.sup.th block.
[0044] In step S652, the updated n.sup.th block is compressed to generate a compressed n.sup.th block, followed by performing step S690.
[0045] In step S660, it is determined whether the difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 and the (n−1).sup.th accumulated target data size T.sub.n-1 is greater than the first predetermined threshold TH1 but smaller than a second predetermined threshold TH2. Step S670 is performed if so, otherwise step S680 is performed if not.
[0046] In step S670, Y least significant bit(s) of a plurality of sets of data of the n.sup.th block that needs to be compressed is/are removed to generate an updated n.sup.th block.
[0047] In step S672, the updated n.sup.th block is compressed to generate a compressed n.sup.th block, followed by performing step S690.
[0048] In step 680, the original n.sup.th block is compressed to generate a compressed n.sup.th block.
[0049] In step S690, the compressed n.sup.th block is stored in a memory.
[0050] The method 600 is applicable to compress the image data IMG0. In step S610, the file that needs to be compressed at this point is the image data IMG0, and the N blocks that need to be compressed in the file are N image blocks B.sub.1 to B.sub.N of the image data IMG0. It should be noted that, the method for compressing image data and the image data compressing system of the present invention are not limited to compressing image data. In other embodiments, the method for compressing image data and the image data compressing system of the present invention may be applied to compress data of other types of files.
[0051] In some embodiments of the present invention, instead of comparing the difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 and the (n−1).sup.th accumulated target data size T.sub.n-1 only with the first predetermined threshold TH1 and the second predetermined threshold TH2, the method 600 may also compare the difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 and the (n−1).sup.th accumulated target data size T.sub.n-1 with other predetermined thresholds, and accordingly determine the number of LSB to be removed, so that the method 600 can more accurately control the compression rate and image quality.
[0052] In some embodiments, step S660 to S672 of the method 600 may be omitted. In step S640, when the difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 and the (n−1).sup.th accumulated target data size T.sub.n-1 is greater than the first predetermined threshold TH1, step S680 is directly performed instead of comparing the difference between the (n−1).sup.th accumulated compressed data size C.sub.n-1 and the (n−1).sup.th accumulated target data size T.sub.n-1 with the second predetermined threshold TH2, thus simplifying the process of the method 600.
[0053] The method 600 is capable of adaptively determining whether to remove the LSB of each set of data in a block that needs to be compressed, and the number of LSB to be removed if so, and is therefore capable of accurately controlling the compression rate and image quality.
[0054] In conclusion, the method for compressing image data and the image data compressing system of the present invention are capable of dynamically determining whether to remove the LSB of each set of data in a block that needs to be compressed, and the number of LSB to be removed if so, and are therefore capable of more accurately controlling the compression rate compared to the prior art while also maintaining image quality.
[0055] While the invention has been described by way of example and in terms of the preferred embodiments, it is to be understood that the invention is not limited thereto. On the contrary, it is intended to cover various modifications and similar arrangements and procedures, and the scope of the appended claims therefore should be accorded the broadest interpretation so as to encompass all such modifications and similar arrangements and procedures.