CN118283279A - Image compression method, system, electronic device and storage medium - Google Patents

Image compression method, system, electronic device and storage medium Download PDF

Info

Publication number
CN118283279A
CN118283279A CN202410615156.4A CN202410615156A CN118283279A CN 118283279 A CN118283279 A CN 118283279A CN 202410615156 A CN202410615156 A CN 202410615156A CN 118283279 A CN118283279 A CN 118283279A
Authority
CN
China
Prior art keywords
residual
huffman table
huffman
preset
image
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410615156.4A
Other languages
Chinese (zh)
Inventor
邵云峰
殷亚祥
曹桂平
董宁
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hefei Eko Photoelectric Technology Co ltd
Original Assignee
Hefei Eko Photoelectric Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hefei Eko Photoelectric Technology Co ltd filed Critical Hefei Eko Photoelectric Technology Co ltd
Priority to CN202410615156.4A priority Critical patent/CN118283279A/en
Publication of CN118283279A publication Critical patent/CN118283279A/en
Pending legal-status Critical Current

Links

Landscapes

  • Compression Or Coding Systems Of Tv Signals (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

The application discloses an image compression method, an image compression system, electronic equipment and a storage medium, and belongs to the field of image processing. The method comprises the following steps: acquiring a residual error value set of an image to be compressed; respectively calculating the coding lengths of the residual error value sets under a plurality of fixed Huffman tables, and selecting the fixed Huffman table with the shortest coding length as the optimal Huffman table; and carrying out coding processing on the residual value set based on the optimal Huffman table to obtain coded data corresponding to the image to be compressed. The fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function. Based on the processing, the application not only avoids the problem in dynamic coding and reduces the gap between the image compression rate provided by the fixed Huffman table and the optimal image compression rate, but also can save the resource space of the coding end and the decoding end, thereby improving the working efficiency of image compression.

Description

Image compression method, system, electronic device and storage medium
Technical Field
The present invention relates to the field of image processing, and in particular, to an image compression method, an image compression system, an electronic device, and a storage medium.
Background
Image compression refers to a technique of representing an original pixel matrix with fewer bits in a lossy or lossless manner, also called image coding. The basic principle of image compression is that there is redundancy in the original image data. The lossless compression algorithm based on residual coding achieves the purpose of image compression by reducing spatial redundancy through utilizing correlation among adjacent pixels.
In the encoding work after completion of the residual calculation, huffman encoding is generally selected as the encoding scheme. However, in the existing huffman coding scheme, a huffman tree is often required to be dynamically built, which increases the processing time of the coding end and the decoding end and affects the working efficiency of image compression.
Therefore, there is a need for an image compression method for solving the above-mentioned problems.
Disclosure of Invention
The application provides an image compression method, an image compression system, electronic equipment and a storage medium, which are used for improving the working efficiency of image compression.
In order to achieve the above purpose, the present application proposes the following technical solutions:
In a first aspect of the present application, there is provided an image compression method, the method comprising:
acquiring a residual error value set of an image to be compressed;
Respectively calculating the coding lengths of the residual error value sets under a plurality of fixed Huffman tables, and selecting the fixed Huffman table with the shortest coding length as the optimal Huffman table; the fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function;
And carrying out coding processing on the residual value set based on the optimal Huffman table to obtain coded data corresponding to the image to be compressed.
Optionally, the residual values of the set of residual values are calculated by an arithmetic coding method.
Optionally, the residual probability distribution function includes a first distribution function:
Wherein y represents the distribution probability of the residual value; b represents a preset parameter, and b is more than or equal to 0.5 and less than or equal to 100; x represents the residual value, and x is more than or equal to 0 and less than or equal to 255.
Optionally, the method further comprises:
in a preset data range, carrying out interval sampling on the b values to obtain a plurality of groups of residual error distribution sequences;
And generating a Huffman table of a corresponding b value based on the residual error distribution sequence so as to form a preset Huffman table set.
Optionally, the residual probability distribution function further includes a second distribution function;
The second distribution function includes: p (0) =α·p (1), P (1) =β·p (2), P (2) =θ·p (c), P (d) =γ·p (d+1), and
Wherein, P (0) represents the probability of the residual value being 0, P (c) represents the probability of the residual value being c, P (d) represents the probability of the residual value being d, and 3.ltoreq.c.ltoreq.7, 8.ltoreq.d.ltoreq.255;
Alpha, beta, theta and gamma represent preset multiplying power parameters, and alpha is more than or equal to 1 and less than or equal to 4, beta is more than or equal to 1 and less than or equal to 2, theta is more than or equal to 1 and less than or equal to 8, and gamma is more than or equal to 1 and less than or equal to 1.1.
Optionally, the method further comprises:
and constructing a residual sequence conforming to the second distribution function, and generating a corresponding Huffman table based on the residual sequence to form a preset Huffman table set.
Optionally, the process of screening to obtain multiple fixed huffman tables based on the preset huffman table set includes:
Selecting Huffman tables generated based on a first distribution function, and replacing Huffman table sets corresponding to b <2 and b > 70 by first Huffman tables in the sets respectively;
Constructing a Huffman table set with probability ratio between the residual values 0 and 7 being close, and respectively replacing the Huffman table set by any Huffman table in the set; the judging condition of the probability ratio approaching is as follows: the probability ratio error of the same residual value is not more than 10%;
Aiming at the residual Huffman tables, huffman table sets with the same coding length of residual values 0-7 are constructed, and any Huffman table in the sets is selected to replace the Huffman table set.
In a second aspect of the present application, there is provided an image compression system, the system comprising:
The residual value set acquisition module is used for acquiring a residual value set of the image to be compressed;
The code table selection module is used for respectively calculating the coding lengths of the residual error value sets under a plurality of sets of fixed Huffman tables and selecting the fixed Huffman table with the shortest coding length as the optimal Huffman table; the fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function;
And the encoding processing module is used for encoding the residual value set based on the optimal Huffman table to obtain encoded data corresponding to the image to be compressed.
In a third aspect of the present application, there is provided an electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
a memory for storing a computer program;
And a processor for implementing the image compression method according to any one of the above-described methods when executing the program stored in the memory.
In a fourth aspect of the present application, there is provided a computer-readable storage medium having stored therein a computer program which, when executed by a processor, implements the image compression method of any one of the above.
The beneficial effects of the application are as follows:
The application provides an image compression method, which comprises the following steps: acquiring a residual error value set of an image to be compressed; respectively calculating the coding lengths of the residual error value sets under a plurality of fixed Huffman tables, and selecting the fixed Huffman table with the shortest coding length as the optimal Huffman table; and carrying out coding processing on the residual value set based on the optimal Huffman table to obtain coded data corresponding to the image to be compressed. The fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function.
Based on the processing, the method and the device carry out coding processing on the image to be compressed through the fixed Huffman table, do not need to carry out dynamic coding, and can effectively save coding time and network resources of a coding end. Meanwhile, in the dynamic coding process, the generated Huffman table needs to be transmitted to a decoding end along with the coded data, so that the transmission bandwidth is additionally occupied, and the image compression rate is reduced. Accordingly, the present application avoids the above-described dynamic encoding problem.
On the other hand, in the scheme provided by the application, after the optimal Huffman table is selected from the fixed Huffman tables, the residual value set is processed by encoding, and the fixed Huffman tables are obtained by screening the Huffman table set generated based on the residual probability distribution function. Therefore, the application increases the number of the fixed Huffman tables, improves the application range of the fixed Huffman tables, and avoids the defect of larger deviation from the optimal image compression ratio because the single fixed Huffman table has no universality. In addition, the fixed Huffman table is generated based on the residual probability distribution function, so that the universality of the fixed Huffman table in a residual coding scene can be ensured, the risk that the occurrence frequency of characters in data to be compressed is inconsistent with the distribution condition of the fixed coding table is effectively reduced, and the gap between the image compression rate and the optimal image compression rate provided by the fixed Huffman table is reduced. The subsequent multiple experimental results show that the difference between the image compression rate provided by the application and the optimal compression rate obtained by dynamic coding is very small, and the effectiveness of the image compression scheme provided by the application is verified.
In addition, the application reduces the number of the fixed Huffman tables on the basis of ensuring the application range of the fixed Huffman tables by screening the Huffman table set, thereby reducing the time for acquiring the optimal Huffman table, saving the resource space of a coding end and a decoding end and improving the working efficiency of image compression.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute a limitation on the application. In the drawings:
FIG. 1 is a schematic flow chart of an image compression method provided by the application;
FIG. 2 is a probability distribution diagram of a residual value R P according to the present application;
FIG. 3 is a probability distribution diagram of a residual value R m according to the present application;
FIG. 4 is a probability distribution diagram of a residual value R provided by the present application;
FIG. 5 is a schematic diagram showing the relationship between the value of a parameter b and the compression rate according to the present application;
FIG. 6 is a schematic diagram of a residual actual probability distribution and a residual theoretical probability distribution provided by the present application;
FIG. 7 is a flow chart of another image compression method provided by the application;
FIG. 8 is a schematic diagram showing a comparison of compression ratios of an optimal Huffman table and a fixed Huffman table provided by the application;
FIG. 9 is a schematic diagram of an image compression system provided by the present application;
Fig. 10 is a block diagram of an electronic device provided by the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application.
The basic principle of image compression is that there is redundancy in the original image data. The redundancy types mainly include: spatial redundancy: representing information correlation between adjacent pixels in the image; time redundancy: representing the correlation between different frames in the image sequence; spectral redundancy: which is manifested as a correlation of different color planes or spectral bands.
Methods of image compression are mainly classified into two types, lossy compression and lossless compression. Wherein the compression rate of lossy compression is typically high, but image details are lost; the compression rate of lossless compression is relatively low but the integrity of the image information can be ensured.
The application mainly provides an image compression scheme based on residual error coding, which belongs to the lossless compression type, and the purpose of image compression is achieved by reducing spatial redundancy by utilizing correlation between adjacent pixels.
In the actual working process, the camera shoots an image of the real world, and the adjacent pixel information has certain relevance and is generally represented by the gradual change characteristic of the gray value of the adjacent pixel; i.e. its image data is spatially redundant. Instead of directly encoding the gray value of each pixel, the residual encoding is performed by encoding the gray data differences between adjacent pixels. In the residual coding process, a symbol with high occurrence probability (namely a residual value in the application) is coded by a shorter code word, and a symbol with low occurrence probability is coded by a longer code word, so that the spatial redundancy of image data is reduced, and the compression of the image data is realized.
After the residual value is calculated, the coding work can be carried out. The basic principle of coding is to reduce the overall image size as much as possible without losing any information during the coding process, and methods conforming to this principle are collectively referred to as entropy coding. There are many schemes for existing entropy coding, such as golomb coding, huffman coding and arithmetic coding. The Huffman coding is selected in the image compression scheme provided by the application by comprehensively considering the coding complexity and the decoding efficiency.
For the encoding process, after the Huffman table (or Huffman tree) is constructed, a table look-up process from symbol to code stream data is performed. However, since the image content is in dynamic change, the entropy of the image to be compressed is always changed, and the generated huffman table is also changed along with the image content of the image to be compressed. The coding mode of the Huffman table is called dynamic coding, and the generated Huffman table is called dynamic Huffman table.
In the dynamic coding process, different Huffman tables are required to be respectively constructed for different images to be compressed, so that the processing time of a coding end is increased. Meanwhile, the constructed Huffman table needs to be sent to a decoding end along with the coded data, so that not only is the transmission bandwidth occupied, but also the occupancy rate of a CPU (Central Processing Unit ) in the decoding end is influenced. Based on the above factors, there is room for further improvement in the working efficiency of the existing image compression method.
In order to solve the above problems, the present application proposes an image compression method, as shown in fig. 1, comprising the steps of:
S1, acquiring a residual error value set of an image to be compressed.
S2, calculating the coding lengths of the residual error value sets under the fixed Huffman tables, and selecting the fixed Huffman table with the shortest coding length as the optimal Huffman table.
The fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function.
And S3, carrying out coding processing on the residual value set based on the optimal Huffman table to obtain coded data corresponding to the image to be compressed.
Based on the processing, the method and the device carry out coding processing on the image to be compressed through the fixed Huffman table, do not need to carry out dynamic coding, and can effectively save coding time and network resources of a coding end. Meanwhile, in the dynamic coding process, the generated Huffman table needs to be transmitted to a decoding end along with the coded data, so that the transmission bandwidth is additionally occupied, and the image compression rate is reduced. Accordingly, the present application avoids the above-described dynamic encoding problem.
The application increases the number of the fixed Huffman tables, improves the application range of the fixed Huffman tables, and avoids the defect of larger deviation from the optimal image compression ratio because the single fixed Huffman table has no universality. In addition, the fixed Huffman table is generated based on the residual probability distribution function, so that the universality of the fixed Huffman table in a residual coding scene can be ensured, the risk that the occurrence frequency of characters in data to be compressed is inconsistent with the distribution condition of the fixed coding table is effectively reduced, and the gap between the image compression rate and the optimal image compression rate provided by the fixed Huffman table is reduced. The subsequent experimental result shows that the difference between the image compression rate provided by the application and the optimal compression rate obtained by dynamic coding is very small, and the effectiveness of the image compression scheme is verified.
In addition, the application reduces the number of the fixed Huffman tables on the basis of ensuring the application range of the fixed Huffman tables by screening the Huffman table set, thereby reducing the time for acquiring the optimal Huffman table, saving the resource space of a coding end and a decoding end and improving the working efficiency of image compression.
For step S1, the residual value set represents a data set containing a corresponding residual value for each pixel in the image to be compressed. Wherein the residual value is calculated by an arithmetic coding method. Specifically, the residual value obtaining process includes the following steps:
s101, predicting a value to be encoded based on the pixel position encoded on the image to be compressed by adopting a linear model to obtain a predicted value pred (X) of the pixel to be encoded. X represents the original pixel value of the pixel to be encoded.
S102, calculating the residual value of each pixel point in the image to be compressed according to the predicted value pred (X) of the pixel to be encoded and the pixel value X of the pixel to be encoded.
For step S101, in the process of predicting the value to be encoded by the linear model, according to the difference of the positions of the pixels to be encoded, the following 3 cases are classified:
1) If the pixel to be encoded is the first pixel of the first line of pixels of the image to be compressed, the predicted value pred (X) =0 of the pixel to be encoded.
2) If the pixel to be encoded is the first pixel of the non-first line pixel of the image to be compressed, the predicted value pred (X) =b of the pixel to be encoded, where B is the nearest neighbor pixel value of the last line of the pixel to be encoded (i.e., the first pixel value of the last line).
3) If the pixel to be encoded is the remaining position pixel of the image to be compressed, the predicted value pred (X) =a of the pixel to be encoded, where a is the left nearest neighbor pixel value of X, i.e. the pixel value to the left of the current pixel value. Typically, a pixel has 4 neighboring pixels, which are located above, below, left, and right of the current pixel, and the nearest left pixel refers to the pixel on the left.
In one implementation, step S102 includes the following:
s10201, subtracting the predicted value of the pixel to be encoded from the true value of the pixel to be encoded to obtain an initial residual value R P of the image to be compressed. Wherein R P = X-pred (X).
S10202, converting the initial residual value R P of the image to be compressed into a residual value R m to be transformed. Wherein, R m=[X-pred(X)]mod2N.
S10203, adjusting the residual value R m to be converted into a final residual value R,
So that the residual meets the exponential decay profile.
Where N is the Bit number of each pixel of the image, i.e., the image Bit depth, and n=8 in the present application.
It should be noted that, as can be known from the calculation formula of the residual R P, the range of R P is
To continue to encode this range using Nbits, let R m=[X-pred(X)]mod2N be the equation that if the residual is negative then 2 N is added and if it is positive then the value is unchanged. Such a transformation would change the probability distribution of the residual such that the probability distribution no longer satisfies the exponential dip, as shown in fig. 2,3 below, where fig. 2 shows the probability distribution of residual R P and fig. 3 shows the probability distribution of residual R m. For the decompression process, the original pixel values are restored using x= [ R m+pred(X)]mod2N.
Since the residual value R m no longer satisfies the exponential-down probability distribution after the residual transformation, in order to enable the residual to continue to satisfy the exponential-down distribution, the right part of the mirror image of 2 N-1 in fig. 3 is moved to the left, and after the transformation, the probability distribution is changed, namely, the following:
So that the final residual value R satisfies the probability distribution shown in fig. 4 below, it can be seen from fig. 4 that the probability distribution of R clearly conforms to the exponential drop law. Wherein 2 N-1 represents the demarcation point during the calculation of R based on R m, and 2 N -1 represents the maximum residual value of the present application, specifically 255.
In some embodiments, the types of images to be compressed include, but are not limited to, continuous gray, true color, and Bayer pseudo-color images, etc.
And (2) aiming at the step (S2), respectively compressing the residual value sets by utilizing a plurality of fixed Huffman tables, and selecting the Huffman table with the shortest coded data length as the optimal Huffman table. The coding length represents the total length of the coded data after the residual value set is compressed by the Huffman table.
In the actual working process, a plurality of fixed Huffman tables are sent to an FPGA (Field Programmable GATE ARRAY ) after the camera is electrified by an MCU (MicroController Unit, a micro control unit). In the application, the image depth of the image to be compressed is 8 bits, each set of Huffman table has 256 lines of data, and the corresponding residual value is 0-255. Each row of data comprises two columns, wherein the first column is a code word, and 14bit is an unsigned integer; the second column is a code length, ranging from 1-14,4bit unsigned integer. As shown in table 1 below, table 1 discloses the first 4 rows of the fixed huffman table set provided by the present application.
Table 1 the first 4 symbols of the huffman table
It is noted that in the image compression scheme provided by the application, the encoding and decoding processes can be performed in the FPGA.
The residual probability distribution function represents a functional expression of a relationship between a distribution probability of a residual value and the residual value. In one implementation, the predetermined residual probability distribution function includes a first distribution function:
Wherein y represents the distribution probability of the residual value; b represents a preset parameter, and b is more than or equal to 0.5 and less than or equal to 100; x represents the residual value, and x is more than or equal to 0 and less than or equal to 255. The first distribution function is obtained through fitting experimental image data.
Based on the first distribution function, a theoretical fixed code table set can be obtained as a part of a preset huffman table set. The corresponding y value sequence (namely, the residual probability distribution sequence) can be obtained by selecting different b values, and then the corresponding Huffman table is generated by the y value sequence.
In one implementation, the type of the Huffman table preset in the application is a length-limited normal Huffman table. The use of the Haffman table not only shortens the encoding length and reduces the encoding time, but also shortens the decoding time, thereby improving the working efficiency of image compression.
Considering that the compression ratio of the image is basically between 1 and 4 in actual work, the value range of the value b in the first distribution function is set to be 0.5-100. Specifically, the compression rate of the residual coding is 6.95 when b=0.5, and 1.04 when b=100. It is clear that the value range of the above-mentioned b value is reasonable and effective.
In some embodiments, the process of generating the set of fixed code tables based on the first distribution function includes the steps of:
And a, in a preset data range, sampling the b values at intervals to obtain a plurality of groups of residual error distribution sequences.
And b, generating a Huffman table of a corresponding b value based on the residual error distribution sequence so as to form a preset Huffman table set.
For step a, it is considered that the first distribution function belongs to an exponential distribution function, so that in the process of obtaining the theoretical fixed code complex set, the value of the b value is nonlinear. Specifically, when b is 0.5.ltoreq.b < 10, the sampling interval of the b value is 0.1, and when 10.ltoreq.b.ltoreq.100, the sampling interval is 1.
For each b value, a set of sequences of residual distributions are generated, and a normal huffman tree and a corresponding compression rate are generated, as shown in fig. 5, and fig. 5 is a schematic diagram of the relationship between different b values and compression rates. It can be seen that the compression rate is large and the change is fast when the value b is smaller; the compression ratio is small and the conversion is slow when the b value is large. Since the smaller the b value is, the more concentrated the residual distribution is at 0 point, the more information can be compressed, and the smaller the gray value transformation is, the more the flat area is on the image; the larger the b value is, the more scattered the residual distribution is, and the larger the gray value transformation is, the more the image edges are or the noise is large.
In the actual working process, the Huffman table set obtained by using the first distribution function has a good compression effect on 80% of real images, but still cannot achieve good compression rate on partial images. As shown in fig. 6, for a real image with a poor compression ratio, the real residual probability distribution and the theoretical residual probability distribution of the real image cannot be well fitted, so that the optimal compression ratio cannot be obtained by using a theoretical huffman table.
The first distribution function analysis shows that the first distribution function belongs to an exponential distribution curve, and if the interval of sampling the residual value x is 0-255, the sampling interval is 1, namely, all sampling is performed on integer points. The residual sequence is an equal ratio series related to the value b, and the ratio is exp (1/b). Assuming that b is 1, the ratio of the residual sequence 1 st item (symbol 0) and the residual sequence 2 nd item (symbol 1) is e. It can be seen that the fixed huffman table set generated based on the first distribution function still has a certain lifting space for the compression ratio of the partial image.
In order to further improve the compression rate of the preset Huffman table set when being applied to the real image, the application obtains a second distribution function by further fitting after analyzing a large number of real images with residual distribution which does not meet the equal ratio sequence on the basis of the first distribution function.
The second distribution function includes: p (0) =α·p (1), P (1) =β·p (2), P (2) =θ·p (c), P (d) =γ·p (d+1), and
Wherein, P (0) represents the probability of the residual value being 0, P (c) represents the probability of the residual value being c, P (d) represents the probability of the residual value being d, and 3.ltoreq.c.ltoreq.7, 8.ltoreq.d.ltoreq.255;
Alpha, beta, theta and gamma represent preset multiplying power parameters, and alpha is more than or equal to 1 and less than or equal to 4, beta is more than or equal to 1 and less than or equal to 2, theta is more than or equal to 1 and less than or equal to 8, and gamma is more than or equal to 1 and less than or equal to 1.1.
In some embodiments, the process of generating the set of fixed code tables based on the second distribution function includes the steps of:
and c, constructing a residual sequence conforming to the second distribution function, and generating a corresponding Huffman table based on the residual sequence to form a preset Huffman table set.
Specifically, a plurality of residual sequences are pre-constructed, so that the probability distribution of each residual accords with the second distribution function, and a corresponding Huffman table is generated. And combining the Huffman table generated based on the second distribution function and the Huffman table generated according to the first distribution function into a total code table set to be used as a preset Huffman table set.
If the number of code tables in the preset Huffman table set is large, the coding speed of the coding end can be greatly influenced if the optimal Huffman table is directly searched, and the preset Huffman table set needs to be screened. In addition, in actual work, although most of the image contents are different, the probability distribution of the residual values is similar, and the residual values can be processed by the same Huffman table. Therefore, the application can screen the preset Huffman table set, and replace a plurality of Huffman tables by one Huffman table.
In one implementation, a process of screening to obtain a plurality of fixed huffman tables based on a preset huffman table set includes the following steps:
Selecting a Huffman table generated based on a first distribution function, and replacing Huffman table sets corresponding to b <2 and b > 70 by first Huffman tables in the sets. And in the Huffman table set, after the Huffman tables are orderly ordered according to the sequence from the big value to the small value of b, selecting a first Huffman table set as a screened fixed code table.
Step two, constructing a Huffman table set with probability ratio between residual values 0-7 being close, and replacing the Huffman table set by any Huffman table in the set. The judging criterion of the probability ratio approaching is as follows: the probability ratio error of the same residual value is not more than 10%. Specifically, in the process of comparing probability ratio values, each huffman table takes the first character (i.e., residual value 0) as a reference number (i.e., the ratio of residual value 0 is 1), and then successively compares the probability ratio errors of the remaining residual values. If there is a certain probability ratio error greater than 10% (or the probability ratio error may also be set to be fixed at 0.1), then the two compared Huffman tables cannot be incorporated into the same set. In actual operation, the first set of Huffman tables in the Huffman table set is usually selected as the fixed code table after screening.
Thirdly, constructing a Huffman table set with the same coding length of residual values 0-7 aiming at the residual Huffman tables, and respectively selecting any Huffman table in the set to replace the Huffman table set. In actual operation, the first set of Huffman tables in the Huffman table set is usually selected as the fixed code table after screening.
As for the first step, it is known based on practical experience that the variation of the residual compression rate in this section is small when the b value is small (b < 2) or when the b value is small (b > 70), as shown in fig. 5. Therefore, after the same code table (i.e. Huffman table in the application) is used for replacing the corresponding code table set, the influence on the final image compression rate of the scheme of the application is small.
For step two, in the residual coding based image compression scheme, since 80% -90% of residual values are distributed in the first 8 symbols (i.e., residual values 0-7), the final image compression rate is mainly determined by the first 8 symbols. Therefore, the Huffman table set with the probability ratio between the residual values of 0 and 7 being close is replaced by a set of Huffman tables, and the influence on the final image compression rate is small.
Aiming at the third step, the Huffman tree structures corresponding to the Huffman tables are compared for the last residual Huffman tables, and the Huffman tables with similar structures are combined. The structural similarity of the huffman tree is considered from the coding length of the previous 8 symbol nodes, namely, the coding length of each symbol is counted, and if the coding lengths of the same symbol are different, the tree structure is considered to be different.
Taking the image depth of 8 bits as an example in the application, the number of code tables in a preset Huffman table set is 240, and after the screening of the first step to the third step, 8 Huffman tables can be finally obtained. As shown in table 2, the code length of the first 8 symbols of the 8 sets of huffman tables are disclosed.
TABLE 2 fixed Huffman table first 8 symbols code length
Aiming at the step S3, the optimal Huffman table is utilized to encode the residual value set according to the sequence from front to back, and the encoded data corresponding to the image to be compressed, namely the code stream data, is obtained. If the data amount of the encoded data is less than 64 bits, 0 compensation processing is performed on the insufficient data.
In some embodiments, after step S3, as shown in fig. 7, the image compression scheme submitted by the present application further includes the steps of:
and S4, decoding the coded data based on a preset decoding table to obtain a residual value set.
S5, converting each residual value in the residual value set into an original pixel value of the image to be compressed, and finishing decoding.
In some embodiments, after the set of residual values is obtained, the set of residual values may be subjected to a blocking process, so that the subsequent decoding end decodes the multiple blocks of data in parallel. Taking a linear camera as an example, after a residual value set is obtained, residual value data corresponding to each row of pixels can be equally divided into 8 blocks and then separately encoded. The subsequent decoding end FPGA can decode 8 blocks of data in parallel so as to improve the decoding speed.
In addition, the application compares the image compression rate difference of two image compression modes of the optimal Huffman table (namely dynamic Huffman coding) and the fixed Huffman table. As shown in FIG. 8, the compression rate realized by the fixed Huffman table provided by the application has a small loss value compared with the optimal Huffman table, and can meet the actual working requirement.
Based on the same inventive concept, the present application also provides an image compression system, as shown in fig. 9, comprising:
The residual value set obtaining module 901 is configured to obtain a residual value set of an image to be compressed.
The code table selection module 902 is configured to calculate the coding lengths of the residual value set under the multiple sets of fixed huffman tables, and select the fixed huffman table with the shortest coding length as the optimal huffman table. The fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function.
The encoding processing module 903 is configured to perform encoding processing on the residual value set based on the optimal huffman table, so as to obtain encoded data corresponding to the image to be compressed.
The embodiment of the application also provides an electronic device, as shown in fig. 10, which comprises a processor 1001, a communication interface 1002, a memory 1003 and a communication bus 1004, wherein the processor 1001, the communication interface 1002 and the memory 1003 complete communication with each other through the communication bus 1004,
A memory 1003 for storing a computer program;
The processor 1001 is configured to implement any of the above-described image compression methods when executing a program stored in the memory 1003.
The communication bus mentioned above for the electronic device may be a Peripheral component interconnect standard (Peripheral ComponentInterconnect, PCI) bus or an extended industry standard architecture (Extended Ind ustry StandardArchitecture, EISA) bus, or the like. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the electronic device and other devices.
The Memory may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but may also be a Digital signal processor (Digital SignalProcessor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components.
In yet another embodiment of the present application, there is also provided a computer readable storage medium having stored therein a computer program which, when executed by a processor, implements any of the above-described image compression method steps.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (10)

1. An image compression method, the method comprising:
acquiring a residual error value set of an image to be compressed;
Respectively calculating the coding lengths of the residual error value sets under a plurality of fixed Huffman tables, and selecting the fixed Huffman table with the shortest coding length as the optimal Huffman table; the fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function;
And carrying out coding processing on the residual value set based on the optimal Huffman table to obtain coded data corresponding to the image to be compressed.
2. The method according to claim 1, wherein the residual values of the set of residual values are calculated by an arithmetic coding method.
3. The method of claim 1, wherein the residual probability distribution function comprises a first distribution function:
Wherein y represents the distribution probability of the residual value; b represents a preset parameter, and b is more than or equal to 0.5 and less than or equal to 100; x represents the residual value, and x is more than or equal to 0 and less than or equal to 255.
4. A method according to claim 3, characterized in that the method further comprises:
in a preset data range, carrying out interval sampling on the b values to obtain a plurality of groups of residual error distribution sequences;
And generating a Huffman table of a corresponding b value based on the residual error distribution sequence so as to form a preset Huffman table set.
5. The method of claim 1, wherein the residual probability distribution function further comprises a second distribution function;
The second distribution function includes: p (0) =α·p (1), P (1) =β·p (2), P (2) =θ·p (c), P (d) =γ·p (d+1), and
Wherein, P (0) represents the probability of the residual value being 0, P (c) represents the probability of the residual value being c, P (d) represents the probability of the residual value being d, and 3.ltoreq.c.ltoreq.7, 8.ltoreq.d.ltoreq.255;
Alpha, beta, theta and gamma represent preset multiplying power parameters, and alpha is more than or equal to 1 and less than or equal to 4, beta is more than or equal to 1 and less than or equal to 2, theta is more than or equal to 1 and less than or equal to 8, and gamma is more than or equal to 1 and less than or equal to 1.1.
6. The method of claim 5, wherein the method further comprises:
and constructing a residual sequence conforming to the second distribution function, and generating a corresponding Huffman table based on the residual sequence to form a preset Huffman table set.
7. The method according to any one of claims 1-6, wherein the process of screening a plurality of fixed huffman tables based on a preset set of huffman tables comprises:
Selecting Huffman tables generated based on a first distribution function, and replacing Huffman table sets corresponding to b <2 and b > 70 by first Huffman tables in the sets respectively;
Constructing a Huffman table set with probability ratio between the residual values 0 and 7 being close, and respectively replacing the Huffman table set by any Huffman table in the set; the judging condition of the probability ratio approaching is as follows: the probability ratio error of the same residual value is not more than 10%;
Aiming at the residual Huffman tables, huffman table sets with the same coding length of residual values 0-7 are constructed, and any Huffman table in the sets is selected to replace the Huffman table set.
8. An image compression system, the system comprising:
The residual value set acquisition module is used for acquiring a residual value set of the image to be compressed;
The code table selection module is used for respectively calculating the coding lengths of the residual error value sets under a plurality of sets of fixed Huffman tables and selecting the fixed Huffman table with the shortest coding length as the optimal Huffman table; the fixed Huffman tables are obtained by screening a preset Huffman table set, and the preset Huffman table set is generated based on a preset residual probability distribution function;
And the encoding processing module is used for encoding the residual value set based on the optimal Huffman table to obtain encoded data corresponding to the image to be compressed.
9. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
A processor for implementing the image compression method according to any one of claims 1-7 when executing a program stored on a memory.
10. A computer readable storage medium, characterized in that a computer program is stored in the computer readable storage medium, which computer program, when being executed by a processor, implements the image compression method according to any one of claims 1-7.
CN202410615156.4A 2024-05-17 2024-05-17 Image compression method, system, electronic device and storage medium Pending CN118283279A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410615156.4A CN118283279A (en) 2024-05-17 2024-05-17 Image compression method, system, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410615156.4A CN118283279A (en) 2024-05-17 2024-05-17 Image compression method, system, electronic device and storage medium

Publications (1)

Publication Number Publication Date
CN118283279A true CN118283279A (en) 2024-07-02

Family

ID=91645291

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410615156.4A Pending CN118283279A (en) 2024-05-17 2024-05-17 Image compression method, system, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN118283279A (en)

Similar Documents

Publication Publication Date Title
US10819367B2 (en) Guaranteed data compression
WO2020253828A1 (en) Coding and decoding method and device, and storage medium
US11509330B2 (en) Guaranteed data compression
US8767823B2 (en) Method and apparatus for frame memory compression
US10812101B2 (en) Guaranteed data compression
US11716094B2 (en) Guaranteed data compression using intermediate compressed data
CN115150612A (en) Image encoding and decoding method, encoder, decoder, and storage medium
CA2537629A1 (en) Fast loss less image compression system based on neighborhood comparisons
US20220232217A1 (en) Guaranteed Data Compression
JP2798172B2 (en) Image encoding / decoding device
CN114222129A (en) Image compression encoding method, image compression encoding device, computer equipment and storage medium
CN113630125A (en) Data compression method, data encoding method, data decompression method, data encoding device, data decompression device, electronic equipment and storage medium
US10609382B2 (en) Method and apparatus for compressing video data
JP3593884B2 (en) Encoding device and decoding device
CN118283279A (en) Image compression method, system, electronic device and storage medium
JP2022522487A (en) Image component prediction method, encoder, decoder and storage medium
CN103428502B (en) Decoding method and decoding system
US7477787B2 (en) Image compression device and method
WO2011162964A2 (en) System and method and computer program product for parameter estimation for lossless video compression
CN110739974B (en) Data compression method and device and computer readable storage medium
US20110051802A1 (en) System and method for video compression using non-linear quantization and modular arithmetic computation
CN108810556B (en) Method, device and chip for compressing reference frame
CN109040520B (en) Motion estimation storage architecture design method based on data compression and search range prediction
CN115865098A (en) Data compression method based on Huffman coding
KR20240108463A (en) Picture decoding method and device, picture encoding method and device

Legal Events

Date Code Title Description
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination