An image compression method and apparatus
By using adaptive scaling and optimization of the quantization matrix, the problem of frequency-indiscriminate compression in JPEG compression technology is solved, achieving more efficient image compression, reducing block artifacts and ringing artifacts, and improving image quality.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG QIANCONG TECH CO LTD
- Filing Date
- 2025-09-19
- Publication Date
- 2026-07-17
Smart Images

Figure CN121000882B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and more specifically to an image compression method and apparatus. Background Technology
[0002] Image compression is a technique that reduces the amount of image data, aiming to reduce storage space or transmission bandwidth requirements while maintaining the visual quality of the image as much as possible.
[0003] With the widespread application of digital images, JPEG compression technology based on discrete cosine transform has become a mainstream solution due to its high compression efficiency. Its core process includes: converting the RGB image to the YCbCr color space and performing chromaticity downsampling; dividing it into pixel blocks and generating a frequency domain coefficient matrix through discrete cosine transform; using a standard quantization matrix to significantly reduce or reduce high-frequency coefficients to zero to achieve key data compression; and finally generating an efficient bitstream through zigzag scanning, run-length encoding, and Huffman coding.
[0004] However, in existing technologies, common global uniform scaling schemes generate a standard quantization matrix by multiplying a single scaling factor by a standard quantization table, and then use this matrix to divide the frequency domain coefficient matrix element by element to complete the quantization. This method leads to indiscriminate compression of frequency points, with each frequency point being compressed to the same degree. This can easily cause loss of high-frequency details or over-quantization in low-frequency regions, resulting in quality problems such as blockiness and ringing artifacts. Furthermore, the standard quantization table does not consider the characteristics of image content, and the distribution of frequency domain coefficients varies significantly in different scenes, making it difficult for a uniform quantization strategy to balance compression rate and fidelity. Summary of the Invention
[0005] This invention addresses the problems existing in the prior art by providing an image compression method and apparatus that can achieve adaptive scaling based on frequency intensity.
[0006] The specific technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows: an image compression method, comprising the following steps:
[0007] S1. Obtain the frequency domain coefficient matrix generated by the discrete cosine transform of the image to be compressed;
[0008] S2. Compare the threshold matrix with the frequency domain coefficient matrix, count the number of effective frequency points at each frequency position in the frequency domain coefficient matrix, and form an effective coefficient matrix; the threshold matrix is generated by the standard quantization matrix of the standard method according to preset coefficients. Scaling, preset coefficients The value is 0.5;
[0009] S3. Calculate the scaling ratio for each frequency point based on the effective coefficient matrix, and form the corresponding scaling ratio matrix;
[0010] S4. Substitute the standard quantization table, scaling factor, and scaling ratio matrix into the optimized quantization matrix calculation formula to generate the optimized quantization matrix; the specific calculation formula for the optimized quantization matrix is as follows:
[0011]
[0012] in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension. This is the standard quantization table, which is the default quantization table provided for the luma and chroma channels in the JPEG standard. The scaling factor is obtained by converting the quality factor provided by the user using a conversion formula. This is the scaling matrix;
[0013] S5. Quantize the frequency domain coefficient matrix using the optimized quantization matrix to generate the quantized frequency domain coefficient matrix;
[0014] S6. Scan the quantized frequency domain coefficient matrix, rearrange the data, and entropy encode to complete image compression.
[0015] Preferably, during the comparison of the threshold matrix and the frequency domain coefficient matrix, if the absolute value of the value at any frequency point in the frequency domain coefficient matrix is greater than or equal to the value at the corresponding position in the threshold matrix, then 1 is set at the corresponding position in the effective coefficient source matrix; otherwise, 0 is set. The above comparison and discrimination process is repeated until the comparison of values at all frequency points is completed, so as to form an effective coefficient source matrix with values determined at each position. The above process is repeated again until the comparison of all frequency domain coefficient matrices is completed, forming multiple effective coefficient source matrices. The multiple effective coefficient source matrices are then summed to form an effective coefficient matrix that can reflect the characteristics of image content.
[0016] Preferably, by splitting the effective coefficient matrix into four effective coefficient sub-matrices, and calculating the scaling ratio corresponding to each frequency point position based on the split effective coefficient sub-matrices data and scaling ratio calculation formula, a scaling ratio sub-matrice corresponding to each effective coefficient sub-matrices is formed. The multiple scaling ratio sub-matrices are then juxtaposed to reconstruct a scaling ratio matrix, thereby achieving adaptive scaling while avoiding problems such as over-quantization.
[0017] Preferably, the scaling ratio is calculated based on the relative intensity of each frequency point in its respective effective coefficient submatrix, combined with the constraint that the mean of the scaling ratio submatrix is 1, and the constraint that the value of the scaling ratio is limited to the interval (0, 2). The scaling ratio is calculated as follows:
[0018]
[0019] in, , , For the scaling matrix located at the th Line 1 The scaling value of the column. For the effective coefficient matrix located at the th Line 1 The number of effective coefficients in the column The index number in the effective coefficient matrix is ( , The mean of the number of effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The maximum value of the number of all effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The minimum number of all effective coefficients within the effective coefficient submatrix. For the effective frequency point deviation from the mean, This represents the effective frequency range.
[0020] Preferably, the relative intensity of each frequency point in its respective effective coefficient submatrix is determined by dividing the effective frequency point's deviation from the mean by the effective frequency point's range.
[0021] Preferably, based on S3, a correction coefficient matrix is determined according to the quality factor and frequency domain coefficient distribution characteristics to form step T3;
[0022] T3. On the one hand, the scaling ratio is calculated and a scaling ratio matrix is constructed based on the effective coefficient matrix at each frequency point; on the other hand, the correction coefficient matrix is determined based on the quality factor and the frequency domain coefficient distribution characteristics; the correction coefficient matrix... ,in, This is the first correction factor. This is the second correction factor. This is the third correction factor. This is the fourth correction factor; It is a 4x4 matrix with all 1s, and through multi-level control, the visual perception quality is significantly optimized.
[0023] Preferably, the first correction coefficient is set as a function of the quality factor, and the first correction coefficient... The specific calculation formula is as follows: ,in, For quality factor, ; the second correction factor and the third correction factor All are set to a constant of 1; the fourth correction factor is also set as a function of the quality factor, the fourth correction factor... The specific calculation formula is as follows: ,in, For quality factor, This enables differentiated control of the quantization step size across different frequency bands.
[0024] Preferably, after forming the correction coefficient matrix, step S4 is changed to step T4:
[0025] T4. Substitute the standard quantization table, scaling factor, scaling ratio matrix, and correction coefficient matrix into the matrix containing the correction coefficient matrix. The optimized quantization matrix calculation formula is used to generate the optimized quantization matrix, which includes the correction coefficient matrix. The specific formula for calculating the optimized quantization matrix is as follows:
[0026]
[0027] in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension. It is the matrix dot product symbol, which refers to the element-wise multiplication operation on two matrices of the same dimension.
[0028] The present invention also provides an image compression apparatus, comprising:
[0029] The receiving module acquires the frequency domain coefficient matrix generated by the discrete cosine transform of the image to be compressed, and transmits the frequency domain coefficient matrix data to the statistics module and the quantization calculation module; and acquires the quality factor provided by the user configuration, and transmits the quality factor to the scaling factor calculation module.
[0030] The scaling factor calculation module has a built-in conversion formula. The scaling factor calculation module calculates the corresponding scaling factor from the received quality factor through the conversion formula, and the scaling factor data is transmitted to the threshold matrix calculation module and the quantization calculation module.
[0031] The threshold matrix calculation module has a built-in standard quantization table, standard quantization matrix calculation formula and threshold matrix calculation formula. The threshold matrix calculation module calculates the corresponding standard quantization matrix by using the standard quantization matrix calculation formula to obtain the received scaling factor, and then calculates the corresponding threshold matrix by using the threshold matrix calculation formula and the standard quantization matrix. The threshold matrix data is then transmitted to the statistics module.
[0032] The statistics module compares the received multiple frequency domain coefficient matrices with the threshold matrix in turn, counts the number of effective coefficients at each frequency point in each frequency domain coefficient matrix, and forms an effective coefficient matrix. The effective coefficient matrix data is then transmitted to the scaling calculation module and the quantization calculation module.
[0033] The scaling ratio calculation module has a built-in scaling ratio calculation formula. It splits the received effective coefficient matrix into four effective coefficient sub-matrices, and calculates the scaling ratio corresponding to each frequency point position according to the split effective coefficient sub-matrices data and the scaling ratio calculation formula, forming a scaling ratio sub-matrices corresponding to each effective coefficient sub-matrices. It then juxtaposes multiple scaling ratio sub-matrices to reconstruct a scaling ratio matrix, and transmits the scaling ratio matrix data to the quantization calculation module.
[0034] The quantization calculation module has a built-in standard quantization table and an optimized quantization matrix calculation formula. It takes the received scaling factor and scaling ratio matrix, as well as the built-in standard quantization table, and substitutes them into the optimized quantization matrix calculation formula to calculate the corresponding optimized quantization matrix. The quantization calculation module also uses the optimized quantization matrix to quantize the received frequency domain coefficient matrix to generate a quantized frequency domain coefficient matrix. The quantized frequency domain coefficient matrix data is then transmitted to the sorting and encoding module.
[0035] The sorting and encoding module is used to scan the quantized frequency domain coefficient matrix, rearrange the data, and entropy encode it.
[0036] Preferably, the image compression device further includes a correction coefficient module, which has a built-in correction coefficient matrix. Correction coefficient matrix ,in, This is the first correction factor. , This is the second correction factor. , This is the third correction factor. , This is the fourth correction factor. ; It is a 4x4 matrix of all 1s; the correction coefficient module directly calculates the corresponding correction coefficient value based on the quality factor provided by the user, and then determines the corresponding correction coefficient matrix. Correction coefficient matrix The data is transmitted to the quantization calculation module, where the built-in optimized quantization matrix calculation formula is changed to include a correction coefficient matrix. The calculation formula.
[0037] The beneficial effects of the present invention are as follows: The present invention provides an image compression method and apparatus that achieves adaptive scaling based on frequency point intensity. It uses a threshold matrix and compares it with the frequency domain coefficient matrix to count the number of effective coefficients at each frequency point in each frequency domain coefficient matrix, thereby forming an effective coefficient matrix that can reflect the characteristics of image content.
[0038] Then, based on the effective coefficient matrix and scaling ratio calculation formula, the scaling ratio of each frequency point is calculated separately. The scaling ratio of each frequency point is not the same. The scaling ratio of each frequency point is precisely matched with the ideal quantization step size of each frequency point. Through data-driven dynamic adjustment and constraint optimization, adaptive scaling by frequency point is realized, achieving a triple balance between compression ratio, quality and computational efficiency. Then, based on the scaling ratio matrix, an optimized quantization matrix is generated, and corresponding quantization, encoding and other operations are performed to complete image compression.
[0039] The present invention also provides a correction coefficient matrix, wherein the first and fourth correction coefficients in the correction coefficient matrix are both set as functions of the quality factor, and the second and third correction coefficients are both set as constants of 1, thereby achieving differentiated control without changing the overall magnitude, narrowing the gap between subjective perceived quality and statistical optimal solution, and achieving a better comprehensive balance between image volume and visual quality. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. 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 of the steps of an image compression method according to the present invention;
[0042] Figure 2 This is a flowchart of another image compression method according to the present invention;
[0043] Figure 3 This is a schematic diagram of the module composition of an image compression device according to the present invention;
[0044] Figure 4 This is a schematic diagram of the module composition of another image compression device according to the present invention. Detailed Implementation
[0045] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments.
[0046] Example 1
[0047] Figure 1A flowchart illustrating the steps of an image compression method according to Embodiment 1 of the present invention is shown. Based on this flowchart, the specific steps of the image compression method in this embodiment are as follows:
[0048] In step S1, the frequency domain coefficient matrix generated by the discrete cosine transform of the image to be compressed is obtained. In this step, the image to be compressed is divided into 8×8 pixel blocks, and the entire image is divided into multiple blocks. The two-dimensional discrete cosine transform formula is used to perform discrete cosine transform on each block, transforming each block from the spatial domain to the frequency domain, and finally forming multiple frequency domain coefficient matrices. Based on the color space division, the frequency domain coefficient matrix can be the frequency domain coefficient matrix of the independent luminance component (Y) and / or the frequency domain coefficient matrix of the chrominance component (Cb, Cr). The method of the present invention is applicable to both luminance and chrominance components, and both follow a unified processing flow.
[0049] For example, the frequency domain coefficient matrix of the luminance component generated from a single block after discrete cosine transform processing. It can be a matrix with the following values:
[0050]
[0051] In existing image compression strategies, due to the use of a globally uniform scaling method, the scaling factor is directly multiplied by the standard quantization table to obtain the standard quantization matrix. Then, each frequency coefficient in the frequency domain coefficient matrix is divided by the corresponding value in the standard quantization matrix to complete the quantization of each coefficient and form the quantized frequency domain coefficient matrix. The globally uniform scaling method will lead to indiscriminate compression of frequency points, which can easily cause loss of high-frequency details or over-quantization in low-frequency regions, resulting in quality problems such as block artifacts and ringing artifacts.
[0052] To avoid the above problems, the image compression method proposed in this invention filters out the number of effective frequency points at each frequency point position in the frequency domain coefficient matrix based on the threshold matrix, sets a dynamic scaling ratio matrix according to the number of effective frequency points at each frequency point position, combines the standard quantization table and the scaling ratio matrix to generate an optimized quantization matrix that adapts to each frequency point and has adaptive scaling characteristics; and then uses the optimized quantization matrix to complete the quantization of the frequency domain coefficient matrix.
[0053] After obtaining the frequency domain coefficient matrix, step S2 is executed. In step S2, the threshold matrix is compared with the frequency domain coefficient matrix. Based on the threshold matrix, the number of effective frequency points at each frequency point position in the frequency domain coefficient matrix is screened and counted, i.e., the number of effective coefficients, and an effective coefficient matrix is formed. Based on the effective coefficient matrix, the compression degree corresponding to each frequency point in the frequency domain coefficient matrix is accurately calculated. The threshold matrix is generated by the standard quantization matrix of the standard method according to preset coefficients. Scaling yields the standard quantization matrix obtained in the standard method. By scaling factor With standard quantification table The product is multiplied, the result is divided by 100 and rounded off. The specific calculation formula is as follows: Among them, standard quantification table The default quantization tables provided for the luma and chroma channels in the JPEG standard are used, and the default quantization table of the corresponding component is selected according to the luma / chroma component to which the frequency domain coefficient matrix belongs. Rounding operator; scaling factor From quality factor The quality factor is obtained through conversion using the conversion formula. Provided by user configuration. The conversion formula is as follows:
[0054] Determine the standard quantization matrix Then, the standard quantization matrix According to preset coefficients Scaling to obtain the threshold matrix Preset coefficients The value is 0.5, and the threshold matrix is... The calculation formula is as follows:
[0055] Preset coefficients When the value is 0.5, each element in the threshold matrix is exactly the retention threshold for the corresponding frequency domain coefficient. The retention threshold is the minimum value of the frequency point position corresponding to the frequency point position whose absolute value is divided by the corresponding value in the standard quantization matrix and rounded to the nearest integer. If the absolute value of any frequency point position in the frequency domain coefficient matrix is less than the corresponding retention threshold, the result of dividing it by the corresponding value in the standard quantization matrix is zero after rounding. This means that the frequency point contributes little to the image quality or information transmission and can be compressed. It can be recorded as an invalid frequency point. Conversely, it is recorded as an effective frequency point. By using the retention threshold as the element value in the threshold matrix, the effectiveness of each frequency point in the frequency domain coefficient matrix can be efficiently distinguished, and data support can be provided for generating an effective coefficient matrix that reflects the characteristics of image content. This makes compression more reasonable and the compression accuracy can be allocated as needed.
[0056] After obtaining the threshold matrix, multiple frequency domain coefficient matrices are compared sequentially with the threshold matrix to count the number of effective coefficients at each frequency point in each frequency domain coefficient matrix, forming an effective coefficient matrix. More specifically, a frequency domain coefficient matrix is first selected and compared with the threshold matrix to form an effective coefficient source matrix. During this comparison, if the absolute value of the value at any frequency point in the frequency domain coefficient matrix is greater than or equal to the value at the corresponding position in the threshold matrix, then the corresponding position in the effective coefficient source matrix is set to 1; otherwise, it is set to 0. This comparison and discrimination process is repeated until the comparison of values at all frequency points is completed, forming an effective coefficient source matrix with values determined at each position. This process is repeated until the comparison of all frequency domain coefficient matrices is completed, resulting in multiple effective coefficient source matrices. These multiple effective coefficient source matrices are then summed to form the effective coefficient matrix.
[0057] For example, when the quality factor At that time, the luminance standard quantization matrix is calculated based on the JPEG standard luminance quantization table. As shown below:
[0058] At this point, according to the method of the present invention, a brightness standard quantization matrix is used. Based on the preset coefficients Scaling yields the brightness threshold matrix Brightness threshold matrix As shown below:
[0059]
[0060] In the above brightness standard quantization matrix In the matrix, the value at the frequency point position in the first row and first column is 16. In the aforementioned brightness threshold matrix... In the frequency coefficient matrix of the luminance component, the value at the first frequency point position in the first row and first column is 8. If the absolute value of the value at the first frequency point position in the first row and first column of the luminance component's frequency coefficient matrix is 7, and this absolute value is less than the corresponding retention threshold of 8, the result of dividing it by the corresponding value of 16 in the standard quantization matrix is zero after rounding. If the absolute value of the value at the first frequency point position in the first row and first column of the luminance component's frequency coefficient matrix is 8, and this absolute value is not less than the corresponding retention threshold of 8, the result of dividing it by the corresponding value of 16 in the standard quantization matrix is not zero after rounding. Therefore, based on the threshold matrix, by directly comparing the numerical values of the frequency point positions in the frequency coefficient matrix and the corresponding frequency point positions in the threshold matrix, the effectiveness of each frequency point in the frequency coefficient matrix can be efficiently distinguished, thereby achieving the screening and retention of effective frequency points and improving the targeting and effectiveness of the compression strategy.
[0061] The above brightness threshold matrix The frequency domain coefficient matrix of the luminance component as shown in the example above Perform numerical comparisons at each frequency point to form the effective coefficient source matrix. As shown below:
[0062]
[0063] Multiple effective coefficient source matrices The effective coefficient matrix formed by summing It can be a matrix with the following values:
[0064]
[0065] In the effective coefficient matrix, the more effective frequency points at the same frequency position, the larger the corresponding value. This corresponding value can be recorded as the number of effective coefficients, reflecting that the frequency point is more important in vision, and the compression amount for that frequency point can be reduced. Similarly, the fewer effective frequency points at the same frequency position, the smaller the corresponding value, reflecting that the frequency point contributes less to vision, and the compression amount for that frequency point can be increased or quantized significantly. The effective coefficient matrix provides data support for achieving a fine balance between compression accuracy and subjective quality, making subsequent image compression more flexible and targeted, thereby achieving adaptive image compression.
[0066] In obtaining the effective coefficient matrix Then, proceed to step S3; in step S3, based on the effective coefficient matrix... Calculate the scaling ratio for each frequency point and form the corresponding scaling ratio matrix. .
[0067] In determining the scaling ratio for each frequency point, the effective coefficient matrix is split based on the distribution characteristics of the frequency domain coefficients within the frequency domain coefficient matrix. In the frequency domain coefficient matrix, the coefficients in the upper left corner are low-frequency coefficients, the coefficients in the upper right and lower left corners are mid-frequency coefficients, and the coefficients in the lower right corner are high-frequency coefficients. Different frequency domain coefficients correspond to different image features. For example, low-frequency coefficients mainly correspond to global brightness / color gradations and main structures, while high-frequency coefficients mainly correspond to details and fine lines. Under the same image feature type, the difference in the number of effective coefficients at each frequency point accurately reflects the relative importance of each frequency point in representing that type of image feature. Furthermore, if different image features are... When the number of effective coefficients for a given frequency type is included in the same whole for comparison, the difference comparison results can only reflect the differences in the corresponding values of each frequency point, but cannot reflect the actual contribution of each frequency point to the image quality. In particular, the mid-frequency coefficients correspond to the outline of the subject and structural texture, which are crucial to the sharpness and continuity of the image. However, the number of effective coefficients corresponding to the mid-frequency coefficients is usually far less than the number of effective coefficients for the low-frequency coefficients. This difference in the number of effective coefficients does not match the actual contribution of the mid-frequency and low-frequency coefficients to the image quality, and the scaling ratio of each frequency point determined according to this method will cause a loss of accuracy, resulting in image distortion or loss of detail.
[0068] Therefore, in this invention, based on the distribution characteristics of frequency domain coefficients in the frequency domain coefficient matrix, the effective coefficient matrix is divided into four effective coefficient sub-matrices, and for each effective coefficient sub-matrice, a scaling ratio is assigned to each frequency point according to the difference in the number of effective coefficients between frequency points.
[0069] The effective coefficient matrix is split into the following four effective coefficient submatrices, as shown below:
[0070]
[0071] in, ~ This represents the number of effective coefficients at each frequency point, with its subscript indicating its row and column position in the effective coefficient matrix. Each effective coefficient submatrix after splitting is a 4×4 matrix, containing 16 effective coefficients. , , , There are four distinct effective coefficient submatrices.
[0072] The above-mentioned effective coefficient matrix with specific numerical values For example, the four effective coefficient submatrices after splitting are shown below:
[0073]
[0074] After obtaining the effective coefficient submatrix, the scaling ratio corresponding to each frequency point in each submatrix is calculated.
[0075] Because the difference in the number of effective coefficients between some frequency points in the effective coefficient submatrix may be large, for example, in the effective coefficient submatrix... In the image, the number of effective coefficients in the first row and first column is 136, while the number of effective coefficients in the fourth row and fourth column is 1. The difference between the two values is two orders of magnitude. Similarly, the scaling ratios determined directly based on the number of effective frequency points will also have the problem of excessively large differences in values. If the scaling ratios differ too much, the frequency point compression intensity will be unbalanced, resulting in a huge difference in the preservation intensity of different regions and textures in the image, which will destroy the visual balance of the image. For example, it will make some parts of the image clear while the rest is blurry, resulting in visual fragmentation and chaotic sense of layering.
[0076] To rationally determine the scaling ratio corresponding to each frequency point position, this invention proposes to base the scaling ratio on the effective frequency point deviation from the mean. and effective frequency range Calculate the scaling ratio, the effective frequency point deviation from the mean. That is, the difference between the number of effective coefficients at a frequency point and the mean of the effective coefficient submatrix, wherein the effective frequency point range is... That is, the difference between the maximum and minimum number of effective coefficients in the effective coefficient submatrix, expressed as the effective frequency point deviation from the mean. and effective frequency range Divide to determine the relative intensity of each frequency point in its respective effective coefficient submatrix, and then determine the scaling ratio corresponding to each frequency point position. The scaling ratios corresponding to each frequency point position can be combined to form a scaling ratio matrix. The scaling ratio matrix can be split into four scaling ratio submatrices according to the relationship between the effective coefficient matrix and the effective coefficient submatrix.
[0077] During image compression, although the initial quality factor is provided by the user, the scaling ratio of each frequency point is subsequently incorporated into the calculation of the optimized quantization matrix. The frequency domain coefficient matrix is then quantized using the optimized quantization matrix to generate the quantized frequency domain coefficient matrix. After this process, the actual compressed image quality factor may change due to the incorporation of the scaling ratio. For image compression, the compressed image quality factor should ideally be the same as or nearly identical to the quality factor provided by the user. To ensure that the compressed image quality factor is the same as or nearly identical to the quality factor provided by the user, in this embodiment, the scaling ratio is limited. The mean of each scaling ratio submatrix is limited to 1, and the value of each scaling ratio is limited to the interval (0, 2). When the mean of each scaling ratio submatrix is limited to 1, the values of each scaling ratio will be evenly distributed around 1, which can eliminate the systematic deviation of the global quantization intensity caused by unbalanced scaling ratios, avoid the drift of the overall scale, and make the quantization intensity when adaptively customizing the scaling ratio of each frequency point close to the original quantization intensity.
[0078] For example, when most of the scaling values in the scaling submatrix are greater than 1 or less than 1, causing the quantization intensity to be biased upwards or downwards, this is an unbalanced scaling situation, which will increase image distortion or cause compression artifacts, thus leading to a decrease in image quality.
[0079] By setting the values of each scaling factor within the range of (0, 2), reasonable upper and lower limits are ensured for the scaling factors at all frequency points. This constraint ensures that the scaling factor does not cause extreme increases or decreases during quantization adjustments, keeping the entire quantization process balanced and avoiding extreme error amplification or information loss.
[0080] Therefore, in this embodiment of the invention, based on the relative intensity of each frequency point in its respective effective coefficient submatrix, and combined with the mean constraint of the scaling submatrix and the value constraint of the scaling ratio, the formula for calculating the scaling ratio is determined as follows:
[0081]
[0082] in, , , For the scaling matrix located at the th Line 1 The scaling value of the column. For the effective coefficient matrix located at the th Line 1 The number of effective coefficients in the column The index number in the effective coefficient matrix is ( , The mean of the number of effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The maximum value of the number of all effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The minimum number of all valid coefficients in the valid coefficient submatrix.
[0083] For the above effective coefficient submatrix , , , The scaling ratio is calculated separately according to the scaling ratio formula, and the following scaling ratio submatrix is finally formed. , , , .
[0084]
[0085] Based on the relative positions of the effective coefficient submatrices, the above scaling submatrices are... , , , The juxtaposition and reconstruction results in the following scaling matrix. :
[0086]
[0087] As shown in the scaling matrix above As shown, in the upper left region, the scaling ratios of each frequency point are not exactly the same. The scaling ratio of each frequency point is precisely matched with the ideal quantization step size of each frequency point, which can more fully preserve the detailed information of the low frequency region. In contrast, in the lower right region, the scaling ratios of each frequency point are selected with similar or consistent values. This not only matches the number of effective coefficients relative to the position in the effective coefficient matrix, but also achieves efficient compression. This scaling ratio calculation method, through data-driven dynamic adjustment and constraint optimization, achieves adaptive scaling by frequency point, achieving a triple balance between compression ratio, quality, and computational efficiency. It becomes a key hub connecting frequency domain analysis and quantization execution, significantly improving the algorithm's adaptability to complex image content.
[0088] Obtaining the scaling matrix Then, proceed to step S4; in step S4,
[0089] Standard quantification table Scaling factor and scaling matrix Substitute the values into the formula for calculating the optimized quantization matrix to generate the optimized quantization matrix. The optimized quantization matrix calculation formula is as follows:
[0090]
[0091] in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension.
[0092] Based on the JPEG standard luminance quantization table used in this embodiment of the invention, and in terms of quality factor... (corresponding scaling factor) Under these conditions, and in conjunction with the aforementioned scaling matrix Substituting into the formula for calculating the optimized quantization matrix, the resulting optimized quantization matrix is... Specifically as follows:
[0093]
[0094] After obtaining the optimized quantization matrix, step S5 is executed. In step S5, the frequency domain coefficient matrix is quantized using the optimized quantization matrix to generate the quantized frequency domain coefficient matrix. The quantization of each coefficient is completed by dividing each frequency domain coefficient in the frequency domain coefficient matrix by the corresponding value in the optimized quantization matrix and rounding it to the nearest integer.
[0095] After obtaining the quantized frequency domain coefficient matrix, step S6 is executed. In step S6, the quantized frequency domain coefficient matrix is scanned, rearranged, and entropy encoded. First, for each 8×8 quantized frequency domain coefficient matrix, it is scanned from the upper left corner to the lower right corner in a zigzag path, traversing layer by layer along the diagonal direction, so that low-frequency coefficients are concentrated at the front and high-frequency zero values are concentrated at the back. Then, data preprocessing is performed, and the continuous zero values and non-zero values are converted in format and rearranged to further reduce redundancy. Finally, entropy encoding is performed, for example, Huffman coding can be used to allocate short codes according to the frequency of symbol occurrence, and finally a compact binary code stream is generated to complete image compression.
[0096] The image compression method of this invention has also been tested and compared with existing standard methods, and the data is shown in the table below.
[0097] Table 1. Comparison of the objective quality PSNR of reconstructed images using different compression methods
[0098]
[0099] The images used for testing the objective PSNR of each method in the table above were all encoded, decoded, and reconstructed under the same quality factor. The PSNR was then calculated using the original image as a reference and the reconstructed image. The test data is shown in Table 1. Currently, the existing standard methods... The objective quality PSNRs at the specified times were 40.03 / 40.58 / 41.35 / 42.59 / 44.64 dB. When PSNR ≈ 40 dB, it already falls within the high-fidelity threshold, and at normal viewing distances, the overall distortion is barely perceptible to the naked eye. When PSNR ≥ 45 dB, it approaches the near-lossless range. In comparison, the method of this invention achieves PSNRs of 40.37 / 41.02 / 41.82 / 42.97 / 45.13 dB at the corresponding quality factors, an average improvement of approximately 0.42 dB. After the objective quality PSNR reaches 40 dB, each 0.42 dB improvement is equivalent to further reducing the average error amplitude per pixel (RMSE) by approximately 4.7%. Achieving this technical effect is not easy; it can further converge edge ringing and block effects, enhance the continuity of fine textures, and make the layer transitions in low-contrast areas smoother. Therefore, the image compression method of this invention achieves stable and significant objective quality gains while maintaining image size.
[0100] Example 2
[0101] Although the frequency-domain statistical allocation in Example 1 can adapt to the complexity of image content and produce compression results that are close to subjective quality, there is still room for improvement between subjective perceived quality and the statistically optimal solution. To further narrow this gap and obtain a compression effect that is closer to subjective perception, this example introduces a correction coefficient matrix. Based on the image compression quantization using the scaling matrix in Example 1, a perception-driven correction is performed to optimize the compression process.
[0102] like Figure 2 The image compression method shown in Embodiment 2 of the present invention has the same steps S1 and S2 as Embodiment 1. In subsequent processing, based on step S3 of Embodiment 1, a correction coefficient matrix is further determined according to the quality factor and the frequency domain coefficient distribution characteristics. Specifically, after completing step S2, on the one hand, the scaling ratio is calculated and a scaling ratio matrix is constructed based on the effective coefficient matrix at each frequency point; on the other hand, the correction coefficient matrix is determined according to the quality factor and the frequency domain coefficient distribution characteristics. The above two processes are independent of each other and are preferably executed in parallel. For ease of description, the original step S3 and the process of determining the correction coefficient matrix are combined and referred to as step T3.
[0103] During step T3, the process of calculating the scaling ratio and constructing the scaling ratio matrix based on the effective coefficient matrix at each frequency point is detailed in Example 1 and will not be repeated here. The following mainly describes the process of determining the correction coefficient matrix based on the quality factor and the distribution characteristics of the frequency domain coefficients. To facilitate understanding of the setting of the correction coefficient matrix, the structure and distribution characteristics of the frequency domain coefficient matrix are explained first. The frequency domain coefficient matrix is an 8×8 matrix. According to the distribution characteristics of the frequency domain coefficients in the frequency domain coefficient matrix, the frequency domain coefficients in the upper left corner are low-frequency coefficients, the frequency domain coefficients in the upper right and lower left corners are mid-frequency coefficients, and the frequency domain coefficients in the lower right corner are high-frequency coefficients.
[0104] Correspondingly, the correction coefficient matrix Set as an 8×8 matrix, the correction coefficient matrix It can be divided into four 4×4 correction coefficient submatrices. The correction coefficient submatrix located in the upper left corner can be denoted as the first correction coefficient submatrix, which is used to finely adjust the quantization step size of the low-frequency coefficients. The correction coefficient submatrix located in the upper right corner can be denoted as the second correction coefficient submatrix. The correction coefficient submatrix located in the lower left corner can be denoted as the third correction coefficient submatrix. The second and third correction coefficient submatrices are both used to finely adjust the quantization step size of the mid-frequency coefficients. The correction coefficient submatrix located in the lower right corner can be denoted as the fourth correction coefficient submatrix. The fourth correction coefficient submatrix is used to finely adjust the quantization step size of the high-frequency coefficients.
[0105] In each correction coefficient submatrix, all elements are numerically equal. Therefore, the correction coefficient submatrix can be represented by multiplying the coefficients by a matrix of all ones. That is, the first correction coefficient submatrix can be represented as... ,in, This is the first correction factor. It is a 4x4 matrix of all 1s; the second correction coefficient submatrix can be represented as ,in, The second correction coefficient is given; the third correction coefficient submatrix can be represented as follows: ,in, The third correction coefficient; the fourth correction coefficient submatrix can be represented as ,in, This is the fourth correction factor; subsequently, the correction factor matrix is formed by combining the above correction factor submatrices. .
[0106] The correction coefficient matrix in this embodiment This is a perception-driven correction used to narrow the gap between subjectively perceived quality and the statistically optimal solution. At the subjective perception level, low-frequency coefficients mainly correspond to global brightness / color gradations and subject structure, to which the human eye is highly sensitive. To enhance the fidelity of the low-frequency coefficient region and make the overall image presentation smoother and more natural, in this embodiment, compared to other correction coefficient values, the first correction coefficient value is increased, and the first correction coefficient is set as a function of the quality factor. The specific calculation formula is as follows: ,in, For quality factor, While ensuring the aforementioned advantages of low-frequency fidelity, the first correction coefficient is... With quality factor Related to the quality factors provided by the user configuration. To match the corresponding correction coefficient value, when the quality factor The smaller the value, the higher the first correction factor. The larger the quality factor, the less compression is needed in the low-frequency regions of the image compared to when no correction factor is added. While meeting the upper limit of image size constraints, the limited sharpness quota is preferentially allocated to low-frequency coefficients to ensure the fidelity and sharpness of the visual effects corresponding to low-frequency coefficients, achieving a balance between image quality and size. When it is larger, the first correction factor The smaller the value, the more minor adjustments are made to the low-frequency coefficients without over-enhancing their structural components, thus preserving the naturalness and consistency of the low-frequency coefficient region.
[0107] At the subjective perception level, the mid-frequency coefficients correspond to the main outline and structural texture, and the human eye is extremely sensitive to their sharpness and continuity. Given a scaling matrix, by setting the correction coefficient corresponding to the mid-frequency coefficients to a constant 1, i.e., the second correction coefficient... and the third correction factor Setting all values to a constant of 1 avoids repeated interference and erosion of the real texture, suppresses ringing amplification caused by overlay adjustment, stabilizes the non-zero distribution, and ensures that the subject's edges and textures maintain reliable visual presentation while ensuring clarity.
[0108] At the subjective perception level, high-frequency coefficients mainly correspond to details and fine lines, and the human eye is highly sensitive to artifacts such as ringing, noise, and texture flicker caused by them. To suppress high-frequency artifacts and improve detail rendering, in this embodiment, the value of the fourth correction coefficient is reduced compared to other correction coefficient values. The fourth correction coefficient is also set as a function of the quality factor. The specific calculation formula is as follows: ,in, For quality factor, ; the fourth correction factor With quality factor Correlated, when quality factor The smaller the value, the more important the fourth correction factor. The smaller the value, the larger the corresponding frequency value in the optimized quantization matrix, which can effectively suppress edge ringing, texture flickering, and noise amplification caused by over-sharpening, and stabilize the non-zero distribution; when the quality factor is smaller... When the frequency is high, only mild suppression is applied to maintain the cleanliness of details without excessive suppression, thus preserving the natural sharpness and consistency of the high-frequency range.
[0109] Furthermore, by the first correction coefficient Second correction factor Third correction factor Fourth correction factor The correction coefficient matrix formed The mean is exactly 1, and the values of each correction coefficient will be evenly distributed around 1, which can eliminate the systematic deviation of the global quantization intensity caused by unbalanced correction coefficients and avoid the drift of the overall scale.
[0110] Based on the calculation formula and settings of the above correction coefficients, and with the user providing specific quality factors... Then, the quality factor Substituting the values into the above formula for calculating the correction coefficients allows for the direct calculation of the corresponding correction coefficient values, thereby determining the corresponding correction coefficient matrix. For example, when the user provides a quality factor When, the corresponding correction coefficient matrix Specifically as follows:
[0111]
[0112] in, It is a 4x4 matrix consisting entirely of 1s.
[0113] like Figure 2 The image compression method shown in Embodiment 2 of the present invention has a step T4 that is similar to step S4 in Embodiment 1. Step T4 introduces a correction coefficient matrix to optimize the calculation of the quantization matrix based on step S4.
[0114] More specifically, in determining the correction coefficient matrix and scaling matrix Then, proceed to step T4; in step T4, the standard quantization table is... Scaling factor Scaling matrix With the correction coefficient matrix Substitute into the matrix containing the correction coefficients The optimized quantization matrix calculation formula is used to generate the optimized quantization matrix. This embodiment includes a correction coefficient matrix. The specific formula for calculating the optimized quantization matrix is as follows:
[0115]
[0116] in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension. It is the matrix dot product symbol, which refers to the element-wise multiplication operation on two matrices of the same dimension.
[0117] With the above quality factors Correction coefficient matrix at time and the JPEG standard luminance quantization table and scaling matrix used in Example 1. Scaling factor For example, substituting the above parameters into the optimized quantization matrix calculation formula of this embodiment, we obtain the corresponding optimized quantization matrix. The results are as follows:
[0118]
[0119] In this embodiment, compared to the case without the introduction of the correction coefficient matrix (i.e., Embodiment 1), the introduction of the correction coefficient matrix enables differentiated control of the quantization step size across different frequency bands. The quantization step size in the low-frequency region is relatively reduced to maintain the stability and smoothness of the main outline and large-scale color gradations; the quantization step size in the high-frequency region is relatively increased to suppress weak noise and invalid textures, reducing the probability of block artifacts and ringing artifacts; simultaneously, the correction coefficient in the mid-frequency region is set to 1 to maintain quantization neutrality, thereby maintaining the continuity and clarity of structural textures and edge sharpness. Under the global constraint that the mean of the correction coefficient matrix is 1, the differentiated control, without changing the overall magnitude, narrows the gap between subjectively perceived quality and the statistically optimal solution, achieving a better overall balance between image volume and visual quality.
[0120] After determining the optimized quantization matrix, step S5 is executed. In step S5, as in Example 1, the frequency domain coefficient matrix is quantized using the optimized quantization matrix to generate the quantized frequency domain coefficient matrix. The quantization of each coefficient is completed by dividing each frequency domain coefficient in the frequency domain coefficient matrix by the corresponding value in the optimized quantization matrix and rounding it to the nearest integer.
[0121] After obtaining the quantized frequency domain coefficient matrix, step S6 is executed. In step S6, the quantized frequency domain coefficient matrix is scanned, rearranged, and entropy encoded. First, for each 8×8 quantized frequency domain coefficient matrix, it is scanned from the upper left corner to the lower right corner in a zigzag path, traversing layer by layer along the diagonal direction, so that low-frequency coefficients are concentrated at the front and high-frequency zero values are concentrated at the back. Then, data preprocessing is performed, and the continuous zero values and non-zero values are converted in format and rearranged to further reduce redundancy. Finally, entropy encoding is performed, for example, Huffman coding can be used to allocate short codes according to the frequency of symbol occurrence, and finally a compact binary code stream is generated to complete image compression.
[0122] Example 3
[0123] See Figure 3 This embodiment provides an image compression device, including a receiving module 101, a scaling factor calculation module 102, a threshold matrix calculation module 103, a statistics module 104, a scaling ratio calculation module 105, a quantization calculation module 106, and a sorting and encoding module 107.
[0124] The receiving module 101 acquires the frequency domain coefficient matrix generated by the discrete cosine transform of the image to be compressed, and transmits the frequency domain coefficient matrix data to the statistics module 104 and the quantization calculation module 106, wherein there are multiple frequency domain coefficient matrices; and acquires the quality factor provided by the user configuration. and quality factor The data is transmitted to the scaling factor calculation module 102.
[0125] The scaling factor calculation module 102 has a built-in conversion formula. The scaling factor calculation module 102 will calculate the received quality factor. The corresponding scaling factor is obtained by calculating using the conversion formula. The conversion formula is as follows:
[0126] Determining the scaling factor Then, scaling factor The data is transmitted to the threshold matrix calculation module 103 and the quantization calculation module 106.
[0127] Threshold matrix calculation module 103, which has a built-in standard quantization table The standard quantization matrix calculation formula and the threshold matrix calculation formula are used. The threshold matrix calculation module 103 will receive the scaling factor. The corresponding standard quantization matrix is obtained by calculating the standard quantization matrix using the standard quantization matrix calculation formula. Then, through the threshold matrix calculation formula and the standard quantization matrix Then, the corresponding threshold matrix is calculated. The threshold matrix Standard quantization matrix generated by standard methods According to preset coefficients Scaling, preset coefficients The value is 0.5; threshold matrix The calculation formula is as follows:
[0128] In the standard method, the standard quantization matrix By scaling factor With standard quantification table Substituting into the standard quantization matrix calculation formula, we obtain the standard quantization matrix calculation formula as follows: Among them, standard quantification table It includes the default quantization tables provided for the luma and chroma channels in the JPEG standard, and selects the default quantization table for the corresponding luma / chroma component based on the luma / chroma component to which the frequency domain coefficient matrix belongs; This is the rounding operator.
[0129] In determining the threshold matrix Then, the threshold matrix The data is transmitted to the statistics module 104.
[0130] The statistics module 104 receives a frequency domain coefficient matrix and a threshold matrix, wherein there are multiple frequency domain coefficient matrices. The statistics module 104 compares the multiple frequency domain coefficient matrices with the threshold matrix in turn, counts the number of effective coefficients at each frequency point in each frequency domain coefficient matrix, and forms an effective coefficient matrix.
[0131] In the process of comparing multiple frequency domain coefficient matrices sequentially with a threshold matrix, first, a frequency domain coefficient matrix is selected and compared with the threshold matrix. If the absolute value of the value at any frequency point in the frequency domain coefficient matrix is greater than or equal to the value at the corresponding position in the threshold matrix, then the corresponding position in the effective coefficient source matrix is set to 1; otherwise, it is set to 0. This comparison and discrimination process is repeated until the values at all frequency points are compared, thus forming an effective coefficient source matrix with values determined at each position. This process is repeated again until the comparison of all frequency domain coefficient matrices is completed, resulting in multiple effective coefficient source matrices. Finally, these multiple effective coefficient source matrices are summed to form the effective coefficient matrix. .
[0132] Determining the effective coefficient matrix Then, the effective coefficient matrix The data is transmitted to the scaling calculation module 105 and the quantization calculation module 106.
[0133] The scaling ratio calculation module 105 has a built-in scaling ratio calculation formula, which will receive the effective coefficient matrix. The system is divided into four effective coefficient sub-matrices. Based on the effective coefficient sub-matrices data and the scaling formula, the scaling ratio corresponding to each frequency point is calculated to form a scaling ratio sub-matrix corresponding to each effective coefficient sub-matrix. The multiple scaling ratio sub-matrices are then juxtaposed to reconstruct the scaling ratio matrix Scale.
[0134] The scaling factor is calculated based on the relative intensity of each frequency point in its respective effective coefficient submatrix, combined with the constraint that the mean of the scaling factor submatrix is 1, and the constraint that the scaling factor value is limited to the interval (0, 2). The scaling factor is calculated as follows:
[0135]
[0136] in, , , For the scaling matrix located at the th Line 1 The scaling value of the column. For the effective coefficient matrix located at the th Line 1 The number of effective coefficients in the column The index number in the effective coefficient matrix is ( , The mean of the number of effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The maximum value of the number of all effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The minimum number of all valid coefficients in the valid coefficient submatrix.
[0137] After the scaling matrix Scale is determined, the scaling matrix Scale is transmitted to the quantization calculation module 106.
[0138] Quantization calculation module 106, which has a built-in standard quantization table And the optimized quantization matrix calculation formula, which will receive the scaling factor And the scaling matrix Scale, as well as the built-in standard quantization table Substituting the values into the formula for calculating the optimized quantization matrix yields the corresponding optimized quantization matrix. The optimized quantization matrix calculation formula is as follows:
[0139]
[0140] in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension.
[0141] The quantization calculation module 106 also uses the optimized quantization matrix to quantize the received frequency domain coefficient matrix to generate a quantized frequency domain coefficient matrix. By dividing each frequency domain coefficient in the frequency domain coefficient matrix by the corresponding value in the optimized quantization matrix and rounding it to the nearest integer, the quantization of each coefficient is completed, forming the quantized frequency domain coefficient matrix.
[0142] After the quantized frequency domain coefficient matrix is formed, the quantized frequency domain coefficient matrix data is transmitted to the sorting and encoding module 107.
[0143] The sorting and encoding module 107 is used to scan and rearrange the quantized frequency domain coefficient matrix and perform entropy encoding. First, for each 8×8 quantized frequency domain coefficient matrix, it is scanned from the upper left corner to the lower right corner in a zigzag path, traversing layer by layer along the diagonal direction, so that low-frequency coefficients are concentrated at the front and high-frequency zero values are concentrated at the back. Then, data preprocessing is performed to convert the format of continuous zero values and non-zero values and rearrange the data distribution to further reduce redundancy. Finally, entropy encoding is performed, for example, Huffman coding can be used to allocate short codes according to the frequency of symbol occurrence, and finally a compact binary code stream is generated to complete image compression.
[0144] Example 4
[0145] See Figure 4 Based on Embodiment 3, the image compression device provided in this embodiment further includes a correction coefficient module 109, which has a built-in correction coefficient matrix. Correction coefficient matrix It is a perception-driven correction used to narrow the gap between subjectively perceived quality and the statistically optimal solution; correction coefficient matrix. Set as an 8×8 matrix, the correction coefficient matrix It can be divided into four 4×4 correction coefficient submatrices, where each element in the correction coefficient submatrix is a numerical value of the same size. The first correction coefficient submatrix can be represented as follows: ,in, This is the first correction factor. It is a 4x4 matrix of all 1s; the second correction coefficient submatrix can be represented as ,in, The second correction coefficient is given; the third correction coefficient submatrix can be represented as follows: ,in, The third correction coefficient; the fourth correction coefficient submatrix can be represented as ,in, This is the fourth correction factor; subsequently, the correction factor matrix is formed by combining the above correction factor submatrices. .
[0146] In this embodiment, the first correction coefficient is set as a function of the quality factor. The specific calculation formula is as follows: ,in, For quality factor, ; the second correction factor and the third correction factor All are set to a constant of 1; the fourth correction factor is also set as a function of the quality factor, the fourth correction factor... The specific calculation formula is as follows: ,in, For quality factor, .
[0147] Based on the calculation formula and settings of the aforementioned correction coefficient, after the user provides a specific quality factor and it is received by the receiving module 101, the receiving module 101 will convert the quality factor into... Simultaneously with the transmission to the scaling factor calculation module 102, the quality factor is also... The data is transmitted to the correction factor module 109, which then converts the quality factor. Substituting the values into the above formula for calculating the correction coefficients allows for the direct calculation of the corresponding correction coefficient values, thereby determining the corresponding correction coefficient matrix. .
[0148] Determining the correction coefficient matrix Then, the correction coefficient matrix The data is transmitted to the quantization calculation module 106.
[0149] The quantization calculation module 106 receives the correction coefficient matrix. After the data is processed, its built-in optimized quantization matrix calculation formula is changed to include the correction coefficient matrix as follows. The optimized quantization matrix calculation formula is as follows:
[0150]
[0151] in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension. It is the matrix dot product symbol, which refers to the element-wise multiplication operation on two matrices of the same dimension.
[0152] Quantization calculation module 106 will use the standard quantization table Scaling factor Scaling matrix With the correction coefficient matrix Substituting the modified optimized quantization matrix into the calculation formula, the corresponding optimized quantization matrix is obtained. .
[0153] The quantization calculation module 106 also utilizes the newly obtained optimized quantization matrix. The received frequency domain coefficient matrix is quantized to generate a quantized frequency domain coefficient matrix. The quantization of each coefficient is completed by dividing each frequency domain coefficient in the frequency domain coefficient matrix by the corresponding value in the optimized quantization matrix and rounding it to the nearest integer.
[0154] After the quantized frequency domain coefficient matrix is formed, the quantized frequency domain coefficient matrix data is transmitted to the sorting and encoding module 107.
[0155] The sorting and encoding module 107 is used to scan and rearrange the quantized frequency domain coefficient matrix and perform entropy encoding. First, for each 8×8 quantized frequency domain coefficient matrix, it is scanned from the upper left corner to the lower right corner in a zigzag path, traversing layer by layer along the diagonal direction, so that low-frequency coefficients are concentrated at the front and high-frequency zero values are concentrated at the back. Then, data preprocessing is performed to convert the format of continuous zero values and non-zero values and rearrange the data distribution to further reduce redundancy. Finally, entropy encoding is performed, for example, Huffman coding can be used to allocate short codes according to the frequency of symbol occurrence, and finally a compact binary code stream is generated to complete image compression.
[0156] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made by those skilled in the art to the technical solutions of the present invention without departing from the spirit of the present invention should fall within the protection scope of the present invention.
Claims
1. An image compression method, characterized in that, Includes the following sequential steps: S1. Obtain the frequency domain coefficient matrix generated by the discrete cosine transform of the image to be compressed; S2. Compare the threshold matrix with the frequency domain coefficient matrix, count the number of effective frequency points at each frequency position in the frequency domain coefficient matrix, and form an effective coefficient matrix; the threshold matrix is generated by the standard quantization matrix of the standard method according to preset coefficients. Scaling, preset coefficients The value is 0.5; S3. Calculate the scaling ratio for each frequency point based on the effective coefficient matrix, and form the corresponding scaling ratio matrix; S4. Substitute the standard quantization table, scaling factor, and scaling ratio matrix into the optimized quantization matrix calculation formula to generate the optimized quantization matrix; the specific calculation formula for the optimized quantization matrix is as follows: in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension. This is the standard quantization table, which is the default quantization table provided for the luma and chroma channels in the JPEG standard. The scaling factor is obtained by converting the quality factor provided by the user using a conversion formula. This is the scaling matrix; S5. Quantize the frequency domain coefficient matrix using the optimized quantization matrix to generate the quantized frequency domain coefficient matrix; S6. Scan the quantized frequency domain coefficient matrix, rearrange the data, and entropy encode to complete image compression.
2. The image compression method according to claim 1, characterized in that, During the comparison of the threshold matrix and the frequency domain coefficient matrix, if the absolute value of the value at any frequency point in the frequency domain coefficient matrix is greater than or equal to the value at the corresponding position in the threshold matrix, then 1 is set at the corresponding position in the effective coefficient source matrix; otherwise, 0 is set. The above comparison and discrimination process is repeated until the comparison of values at all frequency points is completed, so as to form an effective coefficient source matrix with values determined at each position. The above process is repeated again until the comparison of all frequency domain coefficient matrices is completed, resulting in multiple effective coefficient source matrices. The multiple effective coefficient source matrices are then summed to form an effective coefficient matrix.
3. The image compression method according to claim 1, characterized in that, By splitting the effective coefficient matrix into four effective coefficient sub-matrices, and calculating the scaling ratio corresponding to each frequency point position based on the split effective coefficient sub-matrices data and scaling ratio calculation formula, a scaling ratio sub-matrix corresponding to each effective coefficient sub-matrix is formed, and multiple scaling ratio sub-matrices are juxtaposed to reconstruct a scaling ratio matrix.
4. The image compression method according to claim 3, characterized in that, The scaling ratio is calculated based on the relative intensity of each frequency point in its respective effective coefficient submatrix, combined with the constraint that the mean of the scaling ratio submatrix is 1, and the constraint that the scaling ratio value is limited to the interval (0, 2). The scaling ratio is calculated as follows: in, , , For the scaling matrix located at the th Line 1 The scaling value of the column. For the effective coefficient matrix located at the th Line 1 The number of effective coefficients in the column The index number in the effective coefficient matrix is ( , The mean of the number of effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The maximum value of the number of all effective coefficients within the effective coefficient submatrix. The index number in the effective coefficient matrix is ( , The minimum number of effective coefficients within the effective coefficient submatrix. For the effective frequency point deviation from the mean, This represents the effective frequency range.
5. The image compression method according to claim 4, characterized in that, The relative intensity of each frequency point in its respective effective coefficient submatrix is determined by dividing the effective frequency point's deviation from the mean by the effective frequency point's range.
6. The image compression method according to claim 1, characterized in that, Based on S3, the correction coefficient matrix is determined according to the quality factor and frequency domain coefficient distribution characteristics, forming step T3; T3. On the one hand, the scaling ratio is calculated and a scaling ratio matrix is constructed based on the effective coefficient matrix at each frequency point; on the other hand, the correction coefficient matrix is determined based on the quality factor and the frequency domain coefficient distribution characteristics. Correction coefficient matrix ,in, The first correction factor is... This is the second correction factor. This is the third correction factor. This is the fourth correction factor; It is a 4x4 matrix consisting entirely of 1s.
7. The image compression method according to claim 6, characterized in that, The first correction factor is defined as a function of the quality factor. The specific calculation formula is as follows: ,in, For quality factor, ; the second correction factor and the third correction factor All are set to a constant of 1; the fourth correction factor is also defined as a function of the quality factor, the fourth correction factor The specific calculation formula is as follows: ,in, For quality factor, .
8. An image compression method according to claim 6 or 7, characterized in that, After forming the correction coefficient matrix, step S4 is changed to step T4: T4. Substitute the standard quantization table, scaling factor, scaling ratio matrix, and correction coefficient matrix into the matrix containing the correction coefficient matrix. The optimized quantization matrix calculation formula is used to generate the optimized quantization matrix, which includes the correction coefficient matrix. The specific formula for calculating the optimized quantization matrix is as follows: in, This is the rounding operator; It is the matrix dot division operator, which refers to performing element-wise division on two matrices of the same dimension. It is the matrix dot product symbol, which refers to the element-wise multiplication operation on two matrices of the same dimension.
9. An image compression apparatus for performing an image compression method as described in any one of claims 1-8, characterized in that, include: The receiving module acquires the frequency domain coefficient matrix generated by the discrete cosine transform of the image to be compressed, and transmits the frequency domain coefficient matrix data to the statistics module and the quantization calculation module. And obtain the quality factor provided by the user configuration, and transfer the quality factor to the scaling factor calculation module; The scaling factor calculation module has a built-in conversion formula. The scaling factor calculation module calculates the corresponding scaling factor from the received quality factor through the conversion formula, and the scaling factor data is transmitted to the threshold matrix calculation module and the quantization calculation module. The threshold matrix calculation module has a built-in standard quantization table, standard quantization matrix calculation formula and threshold matrix calculation formula. The threshold matrix calculation module calculates the corresponding standard quantization matrix by using the standard quantization matrix calculation formula to obtain the received scaling factor, and then calculates the corresponding threshold matrix by using the threshold matrix calculation formula and the standard quantization matrix. The threshold matrix data is then transmitted to the statistics module. The statistics module compares the received multiple frequency domain coefficient matrices with the threshold matrix in turn, counts the number of effective coefficients at each frequency point in each frequency domain coefficient matrix, and forms an effective coefficient matrix. The effective coefficient matrix data is then transmitted to the scaling calculation module and the quantization calculation module. The scaling ratio calculation module has a built-in scaling ratio calculation formula. It splits the received effective coefficient matrix into four effective coefficient sub-matrices, and calculates the scaling ratio corresponding to each frequency point position according to the split effective coefficient sub-matrices data and the scaling ratio calculation formula, forming a scaling ratio sub-matrices corresponding to each effective coefficient sub-matrices. It then juxtaposes multiple scaling ratio sub-matrices to reconstruct a scaling ratio matrix, and transmits the scaling ratio matrix data to the quantization calculation module. The quantization calculation module has a built-in standard quantization table and an optimized quantization matrix calculation formula. It takes the received scaling factor and scaling ratio matrix, as well as the built-in standard quantization table, and substitutes them into the optimized quantization matrix calculation formula to calculate the corresponding optimized quantization matrix. The quantization calculation module also uses the optimized quantization matrix to quantize the received frequency domain coefficient matrix, generating a quantized frequency domain coefficient matrix, which is then transmitted to the sorting and encoding module. The sorting and encoding module is used to scan the quantized frequency domain coefficient matrix, rearrange the data, and entropy encode it.
10. An image compression device according to claim 9, characterized in that, It also includes a correction coefficient module, which contains a built-in correction coefficient matrix. Correction coefficient matrix ,in, The first correction factor is... , This is the second correction factor. , This is the third correction factor. , This is the fourth correction factor. ; It is a 4x4 matrix of all 1s; the correction coefficient module directly calculates the corresponding correction coefficient value based on the quality factor provided by the user, and then determines the corresponding correction coefficient matrix. Correction coefficient matrix The data is transmitted to the quantization calculation module, where the built-in optimized quantization matrix calculation formula is changed to include a correction coefficient matrix. The calculation formula.