Image compression method, device, medium and computer program product
By dynamically updating the quantization table to adapt to the characteristics of the current frame image, the problem of image details loss caused by a fixed quantization table is solved, and the effect of improving image display quality without increasing the compressed volume is achieved.
Patent Information
- Application Number
- CN202510221605.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2045-02-27
AI Technical Summary
The prior art uses a fixed quantization table during image compression, resulting in the image with more icons and text details filtering out more high-frequency components, resulting in loss of image details and low display quality.
By obtaining the frequency coefficient of the current frame image, quantization is performed using the target quantization table, the similarity between the current frame image and the restored image is calculated, and if it is less than the preset threshold, the quantization table is updated to re-quantize and encode, ensuring that the most suitable quantization table is used.
While ensuring that the image compression volume increment is not large, the detailed information of the image is further preserved to improve the image display quality.
Smart Images

Figure CN119728973B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an image compression method, device, medium and computer program product. Background Art
[0002] In addition to supporting local display, general servers also support remote desktop management functions, which can remotely control the server host through the network. The server remote desktop redirection function is processed by the internal image processing engine of the BMC (Baseboard Management Controller) and sent to the remote client through network transmission. Since direct transmission of original images will occupy a large amount of bandwidth and consume network resources, the images are often transmitted after compression to reduce the network bandwidth usage. The more common practice is to use JPEG (Joint Photographic Experts Group) algorithm compression.
[0003] Currently, in the entire JPEG compression process, except for the color space sampling and quantization part, all other steps are reversible. However, the quantization part directly affects the compression ratio and imaging quality of the entire compression algorithm. If the quantization step size is large, more high-frequency coefficients will be filtered out, resulting in lower image quality, unclear details, and lower image quality; on the contrary, if the quantization step size is small, the image quality is higher, but the volume is larger. Related technical solutions often use a fixed quantization table when compressing images. However, for some icons and images with more text details, the use of a fixed quantization table will filter out more high-frequency components, causing the image to lose a lot of details, which is not friendly to the display of image text.
[0004] In summary, for images of different styles, how to use a more appropriate quantization table to compress the image so as to further retain the image details and improve the image display quality while ensuring that the image compression volume increase is not large is a problem that needs to be solved. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide an image compression method, device, medium and computer program product, which can use a more appropriate quantization table to compress images of different styles, so as to further retain the image details and improve the image display quality under the premise of ensuring that the image compression volume increment is not large. The specific scheme is as follows:
[0006] In a first aspect, the present application discloses an image compression method, comprising:
[0007] Obtain the frequency coefficients corresponding to each image block after performing discrete cosine transform on the current frame image;
[0008] The target quantization table is used to quantize the frequency coefficients corresponding to each image block to obtain an initial quantization result; the target quantization table is the quantization table used when obtaining the compression result of the previous frame of image;
[0009] Performing inverse quantization and inverse discrete cosine transformation on the initial quantization result to obtain a restored image corresponding to the current frame image, and calculating the similarity between the current frame image and the restored image;
[0010] If the similarity is less than a preset threshold, the target quantization table is updated to use the updated quantization table to re-quantize the frequency coefficients corresponding to each image block to obtain a final quantization result, and the final quantization result is encoded based on a preset encoding rule to obtain a compression result.
[0011] Optionally, the similarity between the current frame image and the restored image is calculated, including:
[0012] For each first block in the current frame image, determine a second block corresponding to the first block from the restored image, and calculate the similarity between the first block and the second block to obtain the similarity corresponding to each image block;
[0013] Based on the row numbers and column numbers corresponding to the image blocks, the similarities corresponding to the image blocks are summed in the horizontal direction based on the first accumulation rule to obtain a first result, and the similarities corresponding to the image blocks are summed in the vertical direction based on the second accumulation rule to obtain a second result;
[0014] The first result and the second result are weighted by using a first preset weight coefficient to obtain the similarity between the current frame image and the restored image.
[0015] Optionally, calculating the similarity between the first block and the second block includes:
[0016] For each group of pixel points corresponding to the first block and the second block, calculate a first absolute difference value of the corresponding pixel value on the first color channel, calculate a second absolute difference value of the corresponding pixel value on the second color channel, and calculate a third absolute difference value of the corresponding pixel value on the third color channel;
[0017] Determine a first difference set for each group of pixel points on the first color channel based on the first difference absolute value, determine a second difference set for each group of pixel points on the second color channel based on the second difference absolute value, and determine a third difference set for each group of pixel points on the third color channel based on the third difference absolute value;
[0018] The first difference value set, the second difference value set and the third difference value set are weightedly calculated based on the second preset weight coefficient to obtain the similarity between the first block and the second block.
[0019] Optionally, summing the similarities corresponding to the image blocks in a horizontal direction based on the first accumulation rule to obtain a first result includes:
[0020] For each row in the horizontal direction, the absolute value of the difference is calculated for the similarities corresponding to each two adjacent column-numbered image blocks, and the absolute values of the differences are summed to obtain a first result.
[0021] Optionally, summing the similarities corresponding to the image blocks in the vertical direction based on the second accumulation rule to obtain a second result includes:
[0022] The similarities corresponding to each image block on each row are summed to obtain the target sum value;
[0023] In the vertical direction, a difference operation is performed on the target sum values corresponding to two adjacent rows to obtain a difference result, and each difference result is summed to obtain a second result.
[0024] Optionally, after calculating the similarity between the current frame image and the restored image, the following steps are further included:
[0025] If the similarity is not less than a preset threshold, the initial quantization result is directly used as the final quantization result, and the final quantization result is encoded based on a preset encoding rule to obtain compressed data.
[0026] Optionally, encoding the final quantization result based on a preset encoding rule to obtain a compression result includes:
[0027] The final quantization result is rearranged using a Z-shaped arrangement algorithm to obtain an arrangement result;
[0028] Compressing the arrangement result by using a run length encoding algorithm to obtain initial compressed data;
[0029] The Huffman coding algorithm is used to compress the initial compressed data to obtain a compressed result.
[0030] Optionally, the frequency coefficients corresponding to each image block are quantized using a target quantization table to obtain an initial quantization result, including:
[0031] Performing a ratio operation on the frequency coefficient corresponding to each image block and the quantization coefficient at the corresponding position in the target quantization table, and rounding the result of the ratio operation to obtain an initial quantization result; wherein the frequency coefficient includes a DC coefficient and an AC coefficient;
[0032] Accordingly, the target quantization table is updated, including:
[0033] Performing statistics on the quantized frequency coefficients corresponding to each image block determined from the initial quantization result to obtain a statistical result;
[0034] The quantization coefficients corresponding to the AC coefficients in the target quantization table are updated based on the statistical results to obtain an updated quantization table.
[0035] Optionally, statistics are performed on the quantized frequency coefficients corresponding to each image block determined from the initial quantization result to obtain statistical results, including:
[0036] Obtaining the quantized frequency coefficients corresponding to each image block from the initial quantization result;
[0037] Count the number of consecutive zero values in each quantized frequency coefficient, and count the number of occurrences of each number;
[0038] The number of targets with the largest number of occurrences is determined from each quantized frequency coefficient to obtain a statistical result.
[0039] Optionally, based on the statistical result, the quantization coefficient corresponding to the AC coefficient in the target quantization table is updated to obtain an updated quantization table, including:
[0040] The AC coefficients in the frequency coefficients corresponding to each image block are counted, and the average value of each AC coefficient is calculated;
[0041] The quantization coefficients corresponding to the AC coefficients in the target quantization table are updated based on the average values of the AC coefficients and the target number to obtain an updated quantization table.
[0042] Optionally, updating the quantization coefficient corresponding to the AC coefficient in the target quantization table based on the average value of each AC coefficient and the target number includes:
[0043] quantizing the average value of each AC coefficient using the quantization coefficient corresponding to the AC coefficient in the target quantization table;
[0044] It is determined whether the rounded result of the ratio of the average value of each AC coefficient to the corresponding quantization coefficient is less than a preset ratio threshold, and whether to update the corresponding quantization coefficient based on the determination result and the target number.
[0045] Optionally, determining whether to update the corresponding quantization coefficient based on the judgment result and the target number includes:
[0046] If the rounded result of the ratio of the average value of any AC coefficient to the corresponding quantization coefficient is greater than the preset ratio threshold, it is determined that the corresponding quantization coefficient is not updated;
[0047] If the rounding result of the ratio of the average value of any AC coefficient to the corresponding quantization coefficient is not greater than the preset ratio threshold, the preset value is added by one, and it is determined whether the preset value is greater than the target number; wherein the preset value is used to record the number of times the rounding result of the ratio of the average value of a continuous number of AC coefficients to the corresponding quantization coefficient is not greater than the preset ratio threshold;
[0048] If the preset value is greater than the target number, it is determined that the corresponding quantization coefficient will not be updated. If the preset value is not greater than the target number, and the rounded result of the ratio of the average value of the next AC coefficient to the corresponding quantization coefficient is greater than the preset ratio threshold, the corresponding quantization coefficient is updated based on the preset compensation coefficient.
[0049] In a second aspect, the present application discloses an electronic device, comprising:
[0050] Memory, used to store computer programs;
[0051] The processor is used to execute the computer program to implement the steps of the aforementioned disclosed image compression method.
[0052] In a third aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the aforementioned disclosed image compression method are implemented.
[0053] In a fourth aspect, the present invention discloses a computer program product, comprising a computer program / instruction, which implements the steps of the aforementioned disclosed image compression method when executed by a processor.
[0054] It can be seen that the present application first needs to obtain the frequency coefficients corresponding to each image block after the current frame image is subjected to discrete cosine transform; the frequency coefficients corresponding to each of the image blocks are quantized using a target quantization table to obtain an initial quantization result; the target quantization table is a quantization table used when obtaining the compression result of the previous frame image; the initial quantization result is inversely quantized and inversely discrete cosine transformed to obtain a restored image corresponding to the current frame image, and the similarity between the current frame image and the restored image is calculated; if the similarity is less than a preset threshold, the target quantization table is updated to use the updated quantization table to re-quantize the frequency coefficients corresponding to each of the image blocks to obtain a final quantization result, and the final quantization result is encoded based on a preset encoding rule to obtain a compression result.
[0055] Beneficial effect: The present application first obtains the frequency coefficients corresponding to each image block after the current frame image is subjected to discrete cosine transform, and then uses the target quantization table to quantize the frequency coefficients corresponding to each image block to obtain the initial quantization result. The target quantization table is the quantization table used when obtaining the compression result of the previous frame image, that is, the quantization table used in the compression process of each frame image in the present application is not fixed, and the quantization table used when compressing the previous frame image needs to be used. Further, the present application needs to inverse quantize and inverse discrete cosine transform the initial quantization result to obtain the restored image corresponding to the current frame image, and its purpose is to calculate the similarity between the current frame image and the restored image, so as to judge whether the target quantization table currently used is appropriate according to the similarity between the two, that is, to confirm whether the display quality of the image processed by the target quantization table meets certain requirements. If the similarity is less than the preset threshold, it means that the target quantization table currently used is not appropriate, and the processed image does not meet the higher display quality, so it is necessary to update the target quantization table, so as to use the updated quantization table to re-quantize the frequency coefficients corresponding to each image block to obtain the final quantization result, and finally encode the final quantization result based on the preset encoding rule to obtain the compression result. In this way, when processing each frame of the image, the final quantization table used is adaptively adjusted according to the characteristics of the current frame of the image, so that the most appropriate quantization table can be used to quantize the current frame of the image, rather than using a fixed quantization table. In this way, the image details can be further retained and the image display quality can be improved without ensuring that the image compression volume increment is small. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0057] Figure 1 A flow chart of an image compression method disclosed in this application;
[0058] Figure 2 A schematic diagram of an image compression step disclosed in this application;
[0059] Figure 3 A schematic diagram of a current frame image and a restored image disclosed in this application;
[0060] Figure 4 A flowchart of a specific image compression method disclosed in this application;
[0061] Figure 5A flowchart of an image compression application in a baseboard management controller disclosed in the present application;
[0062] Figure 6 A schematic diagram of a coded binary number disclosed in the present application;
[0063] Figure 7 A schematic diagram of the distribution of frequency coefficients disclosed in this application;
[0064] Figure 8 A schematic diagram of frequency distribution of all image blocks disclosed in this application;
[0065] Fig. 9 A schematic diagram of a brightness quantization table and a chromaticity quantization table disclosed in the present application;
[0066] Fig.10 A schematic diagram of a target quantization table and an updated quantization table disclosed in the present application;
[0067] Fig.11 This is a schematic diagram of the structure of an image compression device disclosed in this application;
[0068] Fig.12 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0069] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0070] Currently, in the entire JPEG compression process, except for the color space sampling and quantization part, all other steps are reversible. However, the quantization part directly affects the compression ratio and imaging quality of the entire compression algorithm. If the quantization step size is large, more high-frequency coefficients will be filtered out, resulting in lower image quality, less obvious details, and lower image quality; on the contrary, if the quantization step size is small, the image quality is higher, but the volume occupied is larger. Related technical solutions often use a fixed quantization table when compressing images. However, for some icons and images with more text details, the use of a fixed quantization table will filter out more high-frequency components, resulting in the loss of many details in the image, which is very unfriendly to the display of image text. To this end, the embodiment of the present application discloses an image compression method, device, medium and computer program product. When targeting images of different styles, a more suitable quantization table can be used to compress the image, so as to further retain the image detail information and improve the image display quality while ensuring that the image compression volume increment is not large.
[0071] See also Figure 1 and Figure 2 As shown, the embodiment of the present application discloses an image compression method, which includes:
[0072] Step S11: Obtain the frequency coefficients corresponding to each image block after performing discrete cosine transform on the current frame image.
[0073] In this embodiment, the overall process of the JPEG compression algorithm is first introduced, which mainly includes color mode conversion, pixel block padding, DCT (Discrete Cosine Transform) transformation, quantization, Z-stack, run-length encoding, Huffman coding, and data packaging. Among them, color mode conversion is to convert the RGB color mode into the YCbCr (Y refers to the brightness component, Cb refers to the blue chrominance component, and Cr refers to the red chrominance component) color mode; pixel block padding divides the image data input in rows and columns into several 8×8 pixel blocks. If the image is less than a multiple of 8×8 pixel blocks, it needs to be padded to an integer multiple of 8×8 before operation; DCT transformation is to process the entire image according to 8×8 small blocks, and the three color channels of each small block are DCT transformed respectively; quantization is to round and quantize the frequency coefficients after DCT change according to the specified quantization table, which is a lossy data processing algorithm; Z-shaped arrangement is to rearrange the coefficients of DCT transformation in a Z-shaped walking manner; run-length encoding is to run-length encode the non-zero coefficient value according to the number of non-zeros in front of the coefficient value to obtain higher compressed data; Huffman coding is to perform Huffman coding on the data in the previous step; finally, the data is packaged and filled with JPEG file header and tail data.
[0074] Therefore, after the current frame image is subjected to color space sampling, pixel block padding, and DCT transformation in sequence, the frequency coefficients corresponding to each image block of the current frame image can be obtained.
[0075] Step S12: quantizing the frequency coefficients corresponding to each image block using a target quantization table to obtain an initial quantization result; the target quantization table is the quantization table used when obtaining the compression result of the previous frame of image.
[0076] In this embodiment, the target quantization table is used to quantize the frequency coefficients corresponding to each image block to obtain an initial quantization result. The target quantization table is the quantization table used when obtaining the compression result of the previous frame of image. That is, the quantization table used in the compression process of each frame of image in this application is not fixed, and the quantization table used when compressing the previous frame of image needs to be used. It should be pointed out that when quantizing the frequency coefficients corresponding to each image block of the first frame of image, a preset default quantization table is used.
[0077] Step S13: performing inverse quantization and inverse discrete cosine transformation on the initial quantization result to obtain a restored image corresponding to the current frame image, and calculating the similarity between the current frame image and the restored image.
[0078] In this embodiment, the initial quantization result needs to be inverse quantized and inverse discrete cosine transformed to obtain a restored image corresponding to the current frame image. The purpose is to calculate the similarity between the current frame image and the restored image, and then judge whether the target quantization table currently used is appropriate based on the similarity between the two, that is, to confirm whether the display quality of the image processed by the target quantization table meets certain requirements.
[0079] In a specific implementation, the above-mentioned calculation of the similarity between the current frame image and the restored image includes: for each first block in the current frame image, determining a second block corresponding to the first block from the restored image, and calculating the similarity between the first block and the second block to obtain the similarity corresponding to each image block; based on the row number and column number corresponding to the image block, summing the similarities corresponding to each image block in the horizontal direction based on the first accumulation rule to obtain a first result, and summing the similarities corresponding to each image block in the vertical direction based on the second accumulation rule to obtain a second result; using a first preset weight coefficient to perform weighted calculation on the first result and the second result to obtain the similarity between the current frame image and the restored image.
[0080] It can be understood that, from the above content, before the DCT transformation, each frame image has been divided into several small blocks of 8×8 pixels. Therefore, when calculating the similarity between the current frame image and the restored image, the present application calculates according to the 8×8 blocks. Specifically, for each first block in the current frame image, it is necessary to determine the second block corresponding to the first block from the restored image, and calculate the similarity between the first block and the second block, so as to obtain the similarity corresponding to each image block. Figure 3 As shown, it is necessary to calculate the similarity between the block b11 in the current frame image P1 and the block b11 in the restored image P2 in turn and record it as D1, calculate the similarity between the block b12 in P1 and the block b12 in the restored image P2 and record it as D2, and so on. Furthermore, since the correlation between the horizontal blocks after 8×8 blocking is large, and the correlation between the vertical blocks is relatively low, the application needs to sum the similarities corresponding to each image block in the horizontal direction based on the first accumulation rule to obtain a first result based on the row number and column number corresponding to the image block, and sum the similarities corresponding to each image block in the vertical direction based on the second accumulation rule to obtain a second result, and finally use the first preset weight coefficient to perform weighted calculation on the first result and the second result to obtain the similarity between the current frame image and the restored image.
[0081] In a specific embodiment, calculating the similarity between the first block and the second block includes: for each corresponding group of pixel points in the first block and the second block, calculating the first difference absolute value of the corresponding pixel value on the first color channel, calculating the second difference absolute value of the corresponding pixel value on the second color channel, and calculating the third difference absolute value of the corresponding pixel value on the third color channel; determining a first difference set of each group of pixel points on the first color channel based on the first difference absolute value, determining a second difference set of each group of pixel points on the second color channel based on the second difference absolute value, and determining a third difference set of each group of pixel points on the third color channel based on the third difference absolute value; performing weighted calculation on the first difference set, the second difference set and the third difference set based on a second preset weight coefficient to obtain the similarity between the first block and the second block.
[0082] That is, since there are 8×8 (i.e., 64) pixels in each block, this embodiment needs to calculate the absolute difference of the corresponding pixel values on three color channels (Y, U, V) for each group of pixels corresponding to the first block and the second block. Specifically, the first absolute difference of the corresponding pixel value is calculated on the first color channel Y, which is recorded as AAyn-BByn, where AAyn is the pixel value of the nth pixel on the Y channel of the first block, and BByn is the pixel value of the nth pixel on the y channel of the second block; the second absolute difference of the corresponding pixel value is calculated on the second color channel U, which is recorded as AAun-BBun, where AAun is the pixel value of the nth pixel on the U channel of the first block, and BBun is the pixel value of the nth pixel on the U channel of the second block; the third absolute difference of the corresponding pixel value is calculated on the third color channel V, which is recorded as AAvn-BBvn, where AAvn is the pixel value of the nth pixel on the V channel of the first block, and BBvn is the pixel value of the nth pixel on the V channel of the second block. Then, the first difference set of each group of pixels on the first color channel is determined based on the absolute value of the first difference, the second difference set of each group of pixels on the second color channel is determined based on the absolute value of the second difference, and the third difference set of each group of pixels on the third color channel is determined based on the absolute value of the third difference, that is, the absolute values of the differences corresponding to the 64 pixels on each block are summed. Finally, the first difference set, the second difference set, and the third difference set are weighted based on the second preset weight coefficient to obtain the similarity between the first block and the second block. The specific calculation formula is as follows:
[0083] ;
[0084] Among them, y, u, and v are the second preset weight coefficients, which represent the weight coefficients of the image RGB to YUV color space conversion respectively. The three parameters y, u, and v are configurable, and y+u+v=1; that is, the similarity of any block is to calculate the absolute value of the difference between the corresponding pixels and then multiply it by the corresponding y, u, and v channel coefficients and then accumulate them.
[0085] In a specific implementation, the first result is obtained by summing the similarities corresponding to each image block in the horizontal direction based on the first accumulation rule, including: for each row in the horizontal direction, calculating the absolute value of the difference between the similarities corresponding to each two adjacent column numbers of the image blocks, and summing the absolute values of the differences to obtain the first result. Assuming that Dpq represents the similarity of the image blocks in the pth row and qth column, the first accumulation rule is used for calculation in the horizontal direction, specifically, for each row in the horizontal direction, calculating the absolute value of the difference between the similarities corresponding to each two adjacent column numbers of the image blocks, and summing the absolute values of the differences to obtain the first result, which can be expressed as:
[0086] .
[0087] In a specific implementation, the similarities corresponding to each image block are summed up in the vertical direction based on the second accumulation rule to obtain the second result, including: summing up the similarities corresponding to each image block on each row to obtain a target sum value; performing a difference operation on the target sum values corresponding to two adjacent rows in the vertical direction to obtain a difference result, and summing up the difference results to obtain the second result. Assuming that Dpq represents the similarity of the image blocks in the pth row and qth column, the second accumulation rule is used for calculation in the vertical direction, specifically, the similarities corresponding to each image block on each row are summed up to obtain a target sum value, and then in the vertical direction, the target sum values corresponding to two adjacent rows are differenced to obtain a difference result, and finally the difference results are summed up to obtain the second result, that is, the difference between the upper and lower rows is calculated, and then the second result in the vertical direction is obtained after all rows are calculated, which can be expressed as:
[0088] .
[0089] Specifically, the first result and the second result are weighted by using the first preset weight coefficient to obtain the similarity between the current frame image and the restored image, that is, the total similarity D of the entire image is calculated as follows:
[0090] ;
[0091] Among them, C0 and C1 are first preset weight coefficients, C0 is specifically a weight coefficient for horizontal calculation, and C1 is specifically a weight coefficient for vertical calculation.
[0092] Step S14: If the similarity is less than the preset threshold, the target quantization table is updated to use the updated quantization table to re-quantize the frequency coefficients corresponding to each image block to obtain a final quantization result, and the final quantization result is encoded based on a preset encoding rule to obtain a compression result.
[0093] In a specific implementation, if the similarity between the current frame image and the restored image is less than a preset threshold, it means that the target quantization table currently used is not appropriate, and the processed image does not meet the high display quality. Therefore, it is necessary to update the quantization coefficients in the target quantization table, so as to use the updated quantization table to re-quantize the frequency coefficients corresponding to each image block to obtain the final quantization result, and finally encode the final quantization result based on the preset coding rules to obtain the compression result. In this way, when processing each frame image, the quantization table finally used is adaptively adjusted according to the characteristics of the current frame image, so that the most appropriate quantization table can be used to quantize the current frame image, rather than using a fixed quantization table. In this way, the image details can be further retained and the image display quality can be improved while ensuring that the image compression volume increment is not large.
[0094] In a specific implementation, after calculating the similarity between the current frame image and the restored image, it also includes: if the similarity is not less than a preset threshold, directly using the initial quantization result as the final quantization result, and encoding the final quantization result based on a preset encoding rule to obtain compressed data. That is, if the similarity between the current frame image and the restored image is not less than the preset threshold, it means that the quantization coefficient in the target quantization table currently used is within a reasonable range, and there is no need to update the target quantization table, so the initial quantization result can be directly used as the final quantization result, and then the final quantization result is encoded based on the preset encoding rule to obtain a compressed result.
[0095] It should be further pointed out that encoding the final quantization result based on the preset encoding rule to obtain the compression result includes: rearranging the final quantization result using a Z-shaped arrangement algorithm to obtain an arrangement result; compressing the arrangement result using a run length coding algorithm to obtain initial compressed data; and compressing the initial compressed data using a Huffman coding algorithm to obtain a compression result. That is, after obtaining the final quantization result, the process of encoding it includes Z-shaped arrangement, run length coding and Huffman coding in sequence, and the compression result is obtained after completing the above coding.
[0096] In addition, it should be pointed out that after compressing the original image data, the compressed data needs to be transmitted to the remote client. During this transmission process, in order to ensure the security of the image data, the compression result can be encrypted by a preset encryption method and then transmitted to the remote client. Encryption can not only protect data privacy, but also prevent the data from being tampered with during transmission. When the image is transmitted, encryption will add mechanisms such as digital signatures or hash checks to the data. If an attacker attempts to tamper with the image data, the receiving end can find that the data has been tampered with by decrypting and verifying the digital signature or hash value, ensuring that the image received by the remote client is consistent with the image sent by the server, ensuring the integrity and reliability of the data, and avoiding operational errors or decision-making errors caused by data tampering. In a specific implementation method, the compression result can be encrypted by using a symmetric encryption algorithm, an asymmetric encryption algorithm, and a hash algorithm.
[0097] It can be seen that the present application first obtains the frequency coefficients corresponding to each image block after the current frame image is subjected to discrete cosine transform, and then uses the target quantization table to quantize the frequency coefficients corresponding to each image block to obtain the initial quantization result. The target quantization table is the quantization table used when obtaining the compression result of the previous frame image, that is, the quantization table used in the compression process of each frame image in the present application is not fixed, and the quantization table used when compressing the previous frame image needs to be used. Further, the present application needs to inverse quantize and inverse discrete cosine transform the initial quantization result to obtain the restored image corresponding to the current frame image, and its purpose is to calculate the similarity between the current frame image and the restored image, so as to judge whether the target quantization table currently used is appropriate according to the similarity between the two, that is, to confirm whether the display quality of the image processed by the target quantization table meets certain requirements. If the similarity is less than the preset threshold, it means that the target quantization table currently used is not appropriate, and the processed image does not meet the higher display quality, so it is necessary to update the target quantization table, so as to use the updated quantization table to re-quantize the frequency coefficients corresponding to each image block to obtain the final quantization result, and finally encode the final quantization result based on the preset encoding rule to obtain the compression result. In this way, when processing each frame of the image, the final quantization table used is adaptively adjusted according to the characteristics of the current frame of the image, so that the most appropriate quantization table can be used to quantize the current frame of the image, rather than using a fixed quantization table. In this way, the image details can be further retained and the image display quality can be improved without ensuring that the image compression volume increment is small.
[0098] See also Figure 4 and Figure 5 As shown, the embodiment of the present application discloses a specific image compression method. Compared with the previous embodiment, this embodiment further explains and optimizes the technical solution. Specifically, it includes:
[0099] Step S21: Obtain the frequency coefficients corresponding to each image block after performing discrete cosine transform on the current frame image.
[0100] Step S22: perform a ratio operation on the frequency coefficient corresponding to each image block and the quantization coefficient at the corresponding position in the target quantization table, and round the result of the ratio operation to obtain an initial quantization result; wherein the frequency coefficient includes a DC coefficient and an AC coefficient, and the target quantization table is the quantization table used when obtaining the compression result of the previous frame of the image.
[0101] In this embodiment, the size of the quantization table is the same as the size of the image block, both of which are 8×8. The process of quantizing the frequency coefficient corresponding to each image block using the target quantization table is specifically to divide the frequency coefficient corresponding to each image block by the quantization coefficient of the corresponding position in the target quantization table, and then perform a rounding operation. For example, if the original frequency coefficient is 252 and the quantization coefficient is 8, the initial quantization result obtained after quantization is 252 / 8=31 (rounding operation). In addition, it should be pointed out that the frequency coefficients in the quantization table include DC coefficients and AC coefficients, among which the first coefficient located in the upper left corner of the quantization table is the DC coefficient, which mainly reflects the average brightness information of the small image block, represents the low-frequency component of the image, and reflects the general outline and main energy of the image. The remaining 63 are AC coefficients, which mainly represent the high-frequency information of the image. Features such as edges, textures, and details in the image are all reflected through AC coefficients, such as text edges and icon details in the server display screen.
[0102] Step S23: performing inverse quantization and inverse discrete cosine transformation on the initial quantization result to obtain a restored image corresponding to the current frame image, and calculating the similarity between the current frame image and the restored image.
[0103] In this embodiment, the initial quantization result is inversely quantized and inversely discrete cosine transformed to obtain a restored image corresponding to the current frame image. If the original data is 252 and the quantization coefficient is 8, the data obtained after quantization is 252 / 8=31 (rounding operation), and the inversely quantized data is 31×8=248, which means that during the JPEG compression and decompression process, errors are generated through the quantization and inverse quantization processes, which affects the clarity of the image, while the discrete cosine transform is reversible and will not generate errors.
[0104] Step S24: If the similarity is less than a preset threshold, statistics are performed on the quantized frequency coefficients corresponding to each image block determined from the initial quantization result to obtain a statistical result.
[0105] In this embodiment, if the similarity is less than a preset threshold, the target quantization table needs to be updated. First, statistics need to be performed on the quantized frequency coefficients corresponding to each image block determined from the initial quantization result to obtain a statistical result.
[0106] First of all, it should be pointed out that when the quantized zigzag data is run-length encoded and Huffman encoded, the following phenomenon will occur. According to the run-length encoding and Huffman coding rules, the coefficient C
[64] after a DCT transformation is as follows: 35,7,0,0,0,-6,-2,0,0,-9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,…,0. Then the final encoded binary number after run-length encoding and Huffman coding is as follows Figure 6 As shown. By analyzing the above compression coding process, for some quantized coefficients, by modifying the 0-value coefficient between two non-0 coefficients, the final coding length can be guaranteed to be unchanged to a certain extent. For example, the original data -2,0,0,-2 is encoded as 0101 1111 1001 0100 (16 bits), and after being modified to -2,-2,-2,-2, it is encoded as 0101 0101 0101 0101 (16 bits).
[0107] Therefore, the main purpose of this application is to modify the quantization coefficient table and change the original quantization result of 0 to a non-zero value, thereby retaining the high-frequency coefficients in the quantization coefficient, and optimizing the image display details without affecting the image compression volume, thereby improving the image display effect.
[0108] Since the image is processed and quantized in 8×8 blocks, one channel Y is analyzed here, and the other U and V channels are analyzed by analogy. The DCT transformation of each block will obtain 64 frequency coefficients of the corresponding block, which are distributed as follows Figure 7 When counting the frequency coefficient distribution, it is necessary to count the frequency distribution of all block data, such as Figure 8 As shown, when counting, the absolute value of each coefficient is added together. For example, the first 8×8 block is b1, the second is b2, and the 64th is b64. The statistical rules are as follows:
[0109] C1=|b1[1]|+|b2[1]|+|b3[1]|+…|b64[1]|;
[0110] C2=|b1[2]|+|b2[2]|+|b3[2]|+…|b64[2]|;
[0111] Ci=|b1[i]|+|b2[i]|+|b3[i]|+…|b64[i]|.
[0112] Among them, |b1[i] is the i-th frequency coefficient of block b1, |b2[n]| is the i-th frequency coefficient of block b1, and so on. Figure 8 It can be seen that the strength of each coefficient is large or small. When quantizing, the quantization step size is reduced for places with lower coefficient strength to ensure that the lossy quantization of the coefficient is reduced, thereby ensuring that some high-frequency components in the image are not removed and improving the display details of the image.
[0113] Therefore, in a specific implementation, the quantized frequency coefficients corresponding to each image block determined from the initial quantization result are counted to obtain statistical results, including: obtaining the quantized frequency coefficients corresponding to each image block from the initial quantization result; counting the number of consecutive zero values in each quantized frequency coefficient, and counting the number of occurrences of each number; determining the target number with the largest number of occurrences from each quantized frequency coefficient to obtain statistical results. That is, after obtaining the initial quantization result, it is necessary to obtain the quantized frequency coefficients corresponding to each image block, and then count the number of consecutive zero values in each quantized frequency coefficient, and count the number of occurrences of each number. For example, for the coefficient C
[64] mentioned above, the distribution of the consecutive zero values therein is obtained by calculation as shown in the following table:
[0114] Table 1 Continuous zero value distribution table
[0115]
[0116] Therefore, it can be seen that there are 2 consecutive 0 values, 3 consecutive 0 values, and 18 consecutive 0 values in this 8×8 pixel block, and the number of occurrences is 1. The quantized frequency coefficients corresponding to each image block are counted, and the target number with the largest number of occurrences is determined from each quantized frequency coefficient to obtain the statistical result. That is, this embodiment first quantizes the data according to the target quantization table, and then counts the distribution of the number of consecutive 0 values in all 8×8 pixel blocks, finds the value with the largest number of consecutive 0 values and sets it as the threshold value H. If a frame of image is transformed by DCT, quantized using the target quantization table, and all 8×8 pixel blocks are counted, it is found that 3 consecutive 0s appear the most times, then the target number 3 is obtained and set as the threshold value H, and the statistical result is obtained.
[0117] Step S25: based on the statistical results, the quantization coefficients corresponding to the AC coefficients in the target quantization table are updated to obtain an updated quantization table.
[0118] In this embodiment, the principle of updating the target quantization table based on the obtained statistical results is to keep the DC coefficient of the quantization table unchanged, modify the quantization table corresponding to the AC coefficient in the quantization table, and thus obtain an updated quantization table. In a specific embodiment, the quantization coefficient corresponding to the AC coefficient in the target quantization table is updated based on the statistical results to obtain an updated quantization table, including: performing statistics on the AC coefficients in the frequency coefficients corresponding to each image block, and calculating the average value of each AC coefficient; based on the average value of each AC coefficient and the target number, the quantization coefficient corresponding to the AC coefficient in the target quantization table is updated to obtain an updated quantization table.
[0119] It is understandable that if a picture is divided into N 8×8 pixel blocks, then each pixel block has 63 AC coefficients, then C1 1 represents the first AC coefficient of the first pixel block, and CNi represents the i-th AC coefficient of the N-th (assuming N=100)-th pixel block. In this embodiment, the AC coefficients in the frequency coefficients corresponding to each image block are counted to calculate the average value of each AC coefficient, and the expression is as follows:
[0120] ;
[0121] Among them, Ayi (i ranges from 1 to 63) is the average AC coefficient intensity of all 8×8 pixel blocks in the Y channel of the entire image, Ay1 is the average value of the first AC coefficient of all 8×8 pixel blocks on the Y channel, and so on.
[0122] In a specific implementation, the quantization coefficients corresponding to the AC coefficients in the target quantization table are updated based on the average values and target numbers of the AC coefficients, including: quantizing the average values of the AC coefficients using the quantization coefficients corresponding to the AC coefficients in the target quantization table; determining whether the rounded result of the ratio of the average value of each AC coefficient to the corresponding quantization coefficient is less than a preset ratio threshold, and determining whether to update the corresponding quantization coefficients based on the determination result and the target number.
[0123] First of all, it should be pointed out that there are two default quantization tables in JPEG, one is the brightness quantization table and the other is the chrominance quantization table, such as Fig. 9 As shown. Using the brightness quantization table Q y For example, first use the quantization table Q y The quantization coefficient corresponding to the AC coefficient quantizes the average value of each AC coefficient, and determines whether the rounded result of the ratio of the average value of each AC coefficient to the corresponding quantization coefficient is less than the preset ratio threshold 1, thereby determining whether to update the corresponding quantization coefficient based on the judgment result and the target number.
[0124] Specifically, determining whether to update the corresponding quantization coefficient based on the judgment result and the target number includes: if the integer result of the ratio of the average value of any AC coefficient to the corresponding quantization coefficient is greater than the preset ratio threshold, it is determined not to update the corresponding quantization coefficient; if the integer result of the ratio of the average value of any AC coefficient to the corresponding quantization coefficient is not greater than the preset ratio threshold, perform an increment operation on the preset value, and determine whether the preset value is greater than the target number; where the preset value is used to record the number of times that the integer result of the ratio of the average value of consecutive AC coefficients to the corresponding quantization coefficient is not greater than the preset ratio threshold; if the preset value is greater than the target number, it is determined not to update the corresponding quantization coefficient, and if the preset value is not greater than the target number and the integer result of the ratio of the average value of the next AC coefficient to the corresponding quantization coefficient is greater than the preset ratio threshold, update the corresponding quantization coefficient based on the preset compensation coefficient.
[0125] That is, use the quantization table to calculate the quantization value of the average quantization table of AC coefficients Byi = Ayi / Qyi, where Qyi is the i-th value in the luminance quantization table Qy. If |Ayi / Qyi| > 1, it is considered that the quantization result is greater than 0 and the value of the quantization table does not need to be modified; if |Ayi / Qyi| ≤ 1, perform an increment operation on the preset value m, that is, m++, and determine whether the preset value m is greater than the target number H; where the preset value m is used to record the number of times that the integer result of the ratio of the average value of consecutive AC coefficients to the corresponding quantization coefficient is not greater than the preset ratio threshold. If m > H, it is considered that there are more data quantized to 0, and the result of the data after run-length coding is shorter, so the value of the quantization table does not need to be modified. If the preset value m is not greater than the target number H and the integer result of the ratio of the average value of the next AC coefficient to the corresponding quantization coefficient is greater than the preset ratio threshold 1, it is considered that there are m consecutive data quantized to 0, that is, the data to be modified. Therefore, it is necessary to reduce the quantization step of these m data, that is, modify the value in the quantization table to a certain extent so that the absolute value of the quantized number is not 0 as much as possible. In this embodiment, the corresponding quantization coefficient needs to be updated based on the preset compensation coefficient, and its specific expression is:
[0126] Qqyi = round((Qyi - (1 - |Ayi / Qyi|)×Qyi) + C0);
[0127] where C0 is the compensation coefficient, -1 < C0 < 0, Ayi is the quantization coefficient in the target quantization table, and Qqyi is the quantization coefficient in the optimized quantization table, as Fig.10 shown.
[0128] In this way, the final optimized brightness quantization table Qqy is obtained, and the chromaticity quantization table Qqc is obtained in the same way. Since the U and V channels share a chromaticity quantization table, the average value of Aui and Avi is used during calculation, that is, Qqci=1 / 2(Qqui+Qqvi).
[0129] Step S26: re-quantizing the frequency coefficients corresponding to each image block using the updated quantization table to obtain a final quantization result, and encoding the final quantization result based on a preset encoding rule to obtain a compression result.
[0130] For more specific processing procedures of the above steps S21 and S26, reference may be made to the corresponding contents disclosed in the above embodiments, which will not be described in detail here.
[0131] It can be seen that the present application adaptively and dynamically adjusts the quantization table by counting the average value of the AC coefficient and the number of occurrences of consecutive zero values in the frequency coefficient. Under the premise of ensuring that the image compression volume increment is not large, it can ensure to a certain extent that some high-frequency coefficients of the image will not be optimized, thereby enriching the image display details, improving the image display quality, and improving product performance and robustness.
[0132] See also Fig.11 As shown, the embodiment of the present application discloses an image compression device, which includes:
[0133] The frequency coefficient acquisition module 11 is used to acquire the frequency coefficient corresponding to each image block after performing discrete cosine transform on the current frame image;
[0134] The first quantization module 12 is used to quantize the frequency coefficients corresponding to each of the image blocks using a target quantization table to obtain an initial quantization result; the target quantization table is a quantization table used when obtaining the compression result of the previous frame of image;
[0135] A similarity calculation module 13 is used to perform inverse quantization and inverse discrete cosine transformation on the initial quantization result to obtain a restored image corresponding to the current frame image, and calculate the similarity between the current frame image and the restored image;
[0136] The second quantization module 14 is used to update the target quantization table if the similarity is less than a preset threshold, so as to use the updated quantization table to re-quantize the frequency coefficients corresponding to each image block to obtain a final quantization result, and encode the final quantization result based on a preset encoding rule to obtain a compression result.
[0137] It can be seen that the present application first obtains the frequency coefficients corresponding to each image block after the current frame image is subjected to discrete cosine transform, and then uses the target quantization table to quantize the frequency coefficients corresponding to each image block to obtain the initial quantization result. The target quantization table is the quantization table used when obtaining the compression result of the previous frame image, that is, the quantization table used in the compression process of each frame image in the present application is not fixed, and the quantization table used when compressing the previous frame image needs to be used. Further, the present application needs to inverse quantize and inverse discrete cosine transform the initial quantization result to obtain the restored image corresponding to the current frame image, and its purpose is to calculate the similarity between the current frame image and the restored image, so as to judge whether the target quantization table currently used is appropriate according to the similarity between the two, that is, to confirm whether the display quality of the image processed by the target quantization table meets certain requirements. If the similarity is less than the preset threshold, it means that the target quantization table currently used is not appropriate, and the processed image does not meet the higher display quality, so it is necessary to update the target quantization table, so as to use the updated quantization table to re-quantize the frequency coefficients corresponding to each image block to obtain the final quantization result, and finally encode the final quantization result based on the preset encoding rule to obtain the compression result. In this way, when processing each frame of the image, the final quantization table used is adaptively adjusted according to the characteristics of the current frame of the image, so that the most appropriate quantization table can be used to quantize the current frame of the image, rather than using a fixed quantization table. In this way, the image details can be further retained and the image display quality can be improved without ensuring that the image compression volume increment is small.
[0138] Since the embodiments of the device part correspond to the above embodiments, please refer to the description of the embodiments of the method part for the embodiments of the device part, and will not be repeated here.
[0139] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the image compression method performed by the electronic device disclosed in any of the aforementioned embodiments.
[0140] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0141] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0142] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon include an operating system 221, a computer program 222 and data 223, etc. The storage method can be temporary storage or permanent storage.
[0143] Among them, the operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, so as to realize the operation and processing of the massive data 223 in the memory 22 by the processor 21, which can be Windows, Unix, Linux, etc. In addition to including a computer program that can be used to complete the image compression method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks. In addition to data transmitted from an external device received by the electronic device, the data 223 can also include data collected by its own input and output interface 25, etc.
[0144] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium, in which a computer program is stored. When the computer program is loaded and executed by a processor, the steps of the image compression method disclosed in any of the aforementioned embodiments are implemented.
[0145] Furthermore, an embodiment of the present invention also discloses a computer program product, including a computer program / instruction, which implements the steps of the image compression method disclosed in any of the aforementioned embodiments when executed by a processor.
[0146] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0147] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0148] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a compact disc read-only memory (CD-ROM), or any other form of storage medium known in the art.
[0149] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0150] The above is a detailed introduction to an image compression method, device, medium and computer program product provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for a person skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. An image compression method, characterized in that: include: Obtain the frequency coefficients corresponding to each image block after performing discrete cosine transform on the current frame image; quantizing the frequency coefficients corresponding to each of the image blocks using a target quantization table to obtain an initial quantization result; The target quantization table is a quantization table used when obtaining the compression result of the previous frame image; Performing inverse quantization and inverse discrete cosine transformation on the initial quantization result to obtain a restored image corresponding to the current frame image, and calculating the similarity between the current frame image and the restored image; If the similarity is less than a preset threshold, the target quantization table is updated to re-quantize the frequency coefficients corresponding to each of the image blocks using the updated quantization table to obtain a final quantization result, and the final quantization result is encoded based on a preset encoding rule to obtain a compression result; Wherein, the frequency coefficient includes a DC coefficient and an AC coefficient; Accordingly, the updating of the target quantization table includes: Obtaining the quantized frequency coefficients corresponding to each image block from the initial quantization result, and counting the number of consecutive zero values in each of the quantized frequency coefficients, and counting the number of occurrences of each of the number conditions, and then determining the target number with the largest number of occurrences from each of the quantized frequency coefficients; Performing statistics on the AC coefficients in the frequency coefficients corresponding to each image block, and calculating the average value of each of the AC coefficients, and then quantizing the average values of each of the AC coefficients using the quantization coefficients corresponding to the AC coefficients in the target quantization table; It is determined whether a rounded result of the ratio of the average value of each AC coefficient to the corresponding quantization coefficient is less than a preset ratio threshold, and whether to update the corresponding quantization coefficient based on the determination result and the target number.
2. The image compression method according to claim 1, characterized in that: The calculating the similarity between the current frame image and the restored image includes: For each first block in the current frame image, determine a second block corresponding to the first block from the restored image, and calculate the similarity between the first block and the second block to obtain the similarity corresponding to each image block; Based on the row numbers and column numbers corresponding to the image blocks, the similarities corresponding to the image blocks are summed in the horizontal direction based on the first accumulation rule to obtain a first result, and the similarities corresponding to the image blocks are summed in the vertical direction based on the second accumulation rule to obtain a second result; The first result and the second result are weightedly calculated using a first preset weight coefficient to obtain a similarity between the current frame image and the restored image.
3. The image compression method according to claim 2, characterized in that: The calculating the similarity between the first block and the second block includes: For each group of pixel points corresponding to the first block and the second block, calculate a first absolute difference value of the corresponding pixel value on a first color channel, calculate a second absolute difference value of the corresponding pixel value on a second color channel, and calculate a third absolute difference value of the corresponding pixel value on a third color channel; Determine a first difference set for each group of pixel points on the first color channel based on the first difference absolute value, determine a second difference set for each group of pixel points on the second color channel based on the second difference absolute value, and determine a third difference set for each group of pixel points on the third color channel based on the third difference absolute value; The first difference set, the second difference set and the third difference set are weightedly calculated based on a second preset weight coefficient to obtain the similarity between the first block and the second block.
4. The image compression method according to claim 2, characterized in that: The step of summing the similarities corresponding to the image blocks in the horizontal direction based on the first accumulation rule to obtain the first result includes: For each row in the horizontal direction, the absolute value of the difference is calculated for the similarities corresponding to the image blocks of every two adjacent columns, and the absolute values of the difference are summed to obtain a first result.
5. The image compression method according to claim 2, characterized in that: The step of summing the similarities corresponding to the image blocks in the vertical direction based on the second accumulation rule to obtain the second result includes: The similarities corresponding to each image block on each row are summed to obtain the target sum value; In the longitudinal direction, a difference operation is performed on the target sum values corresponding to two adjacent rows to obtain a difference result, and the difference results are summed to obtain a second result.
6. The image compression method according to claim 1, characterized in that: After calculating the similarity between the current frame image and the restored image, the method further includes: If the similarity is not less than the preset threshold, the initial quantization result is directly used as the final quantization result, and the final quantization result is encoded based on a preset encoding rule to obtain compressed data.
7. The image compression method according to claim 1, characterized in that: The step of encoding the final quantization result based on a preset encoding rule to obtain a compression result includes: Rearranging the final quantization result using a Z-shaped arrangement algorithm to obtain an arrangement result; Compressing the arrangement result by using a run length encoding algorithm to obtain initial compressed data; The initial compressed data is compressed using a Huffman coding algorithm to obtain a compression result.
8. The image compression method according to any one of claims 1 to 7, characterized in that: The step of using the target quantization table to quantize the frequency coefficients corresponding to each of the image blocks to obtain an initial quantization result includes: A ratio operation is performed on the frequency coefficient corresponding to each of the image blocks and the quantization coefficient at the corresponding position in the target quantization table, and an initial quantization result is obtained by rounding the ratio operation result.
9. The image compression method according to claim 8, characterized in that: The determining whether to update the corresponding quantization coefficient based on the judgment result and the target number includes: If the rounded result of the ratio of the average value of any of the AC coefficients to the corresponding quantization coefficient is greater than the preset ratio threshold, determining not to update the corresponding quantization coefficient; If the rounding result of the ratio of the average value of any of the AC coefficients to the corresponding quantization coefficient is not greater than the preset ratio threshold, the preset value is incremented by one, and it is determined whether the preset value is greater than the target number; wherein the preset value is used to record the number of times the rounding result of the ratio of the average value of a continuous number of the AC coefficients to the corresponding quantization coefficient is not greater than the preset ratio threshold; If the preset value is greater than the target number, it is determined that the corresponding quantization coefficient will not be updated. If the preset value is not greater than the target number, and the rounded result of the ratio of the average value of the next AC coefficient to the corresponding quantization coefficient is greater than the preset ratio threshold, the corresponding quantization coefficient is updated based on the preset compensation coefficient.
10. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the image compression method according to any one of claims 1 to 9.
11. A computer-readable storage medium, characterized in that: Used to store computer programs; wherein, when the computer program is executed by a processor, the steps of the image compression method according to any one of claims 1 to 9 are implemented.
12. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the image compression method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Image coding method based on JND model
CN103297773A
Quantization table and image compression processing methods and devices, terminal and image searching system
CN104581158A
Quantization factor adjustment method and device, electronic equipment and storage medium
CN114727108A