Image compression method, device, equipment and storage medium

By dividing the image into macroblocks and sub-macroblocks, and dynamically adjusting the compression method, the computing power and data flow management challenges faced by HDR encoding in hardware implementation are solved, and a more efficient and flexible image compression effect is achieved.

CN119155455BActive Publication Date: 2025-02-11禹创半导体(深圳)有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411661858.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2025-02-11
Estimated Expiration
2044-11-20

AI Technical Summary

Technical Problem

High Dynamic Range (HDR) encoding faces challenges in computing power and data flow management in hardware implementation, and requires support for flexible parameter adjustment and configuration, increasing the complexity of hardware implementation.

Method used

By dividing the original image into macroblocks and sub-macroblocks, image feature data is extracted, and the expected compression specifications and distortion degree of various compression methods are determined based on the preset compression effect analysis method, and the compression method of sub-macroblocks is dynamically adjusted to reduce hardware implementation Difficulty.

Benefits of technology

While maintaining image quality, the difficulty of implementing the image compression algorithm is reduced, the compression efficiency and flexibility are improved, the image content in different regions is adapted to the overall compression effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119155455B_ABST
    Figure CN119155455B_ABST
Patent Text Reader

Abstract

The present application provides an image compression method, apparatus, device and storage medium, the method comprising: extracting image feature data of each sub-macroblock of an original image; based on a preset compression effect analysis method, determining the expected compression specifications and compression distortion degrees of a plurality of preset first compression methods respectively according to the image feature data; determining a second compression method from the plurality of first compression methods according to the image feature data, determining a specification difference according to the expected compression specifications corresponding to the second compression method and a preset fixed compression specification, if it is detected that the specification difference is less than zero, determining the first sub-macroblock and the second sub-macroblock based on the expected compression specifications; determining a third compression method from the first compression method according to the expected compression specifications, the specification difference and the compression distortion degree corresponding to the first sub-macroblock; compressing the second sub-macroblock according to the second compression method, and compressing the first sub-macroblock according to the third compression method to obtain compressed image data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image compression technology, and in particular to an image compression method, device, equipment and storage medium. Background Art

[0002] At present, the development of image compression technology aims to store or transmit image data at a lower bit rate while maintaining image quality as much as possible. High dynamic range (HDR) coding is an advanced image compression method that can reduce the amount of data while retaining more details. However, although high dynamic range coding compression can save bits and maintain low distortion in theory, it faces a series of challenges in hardware implementation. First, high dynamic range coding usually requires processing complex algorithms, which places higher requirements on the computing power of hardware. Traditional codec hardware design is often based on relatively simple algorithms, while high dynamic range coding requires stronger computing power and faster processing speed to process large amounts of data in real time, which may lead to increased hardware costs. Secondly, the high dynamic range coding compression process involves a lot of data flow management and optimization, which not only requires an efficient memory management system, but also requires the integration of more cache mechanisms at the hardware level to support fast reading and writing, which is a huge challenge for hardware design. In addition, since different application scenarios have different requirements for image quality and compression efficiency, high dynamic range coding compression technology needs to support flexible parameter adjustment and configuration, which also increases the complexity of hardware implementation. Summary of the invention

[0003] The present application provides an image compression method, apparatus, device and storage medium, which are used to reduce the difficulty of implementing an image compression algorithm while maintaining image quality.

[0004] In a first aspect, an embodiment of the present application provides an image compression method, the method comprising:

[0005] Dividing the original image into a plurality of macroblocks, and dividing each macroblock into a plurality of sub-macroblocks, extracting image features of each sub-macroblock, and obtaining image feature data;

[0006] Based on a preset compression effect analysis method, respectively determining the expected compression specifications and compression distortion degrees of a plurality of preset first compression methods according to the image feature data;

[0007] Determine, according to the image feature data, a second compression method corresponding to the sub-macroblock from a plurality of the first compression methods, and determine a specification difference according to an expected compression specification corresponding to the second compression method and a preset fixed compression specification;

[0008] If it is detected that the specification difference is less than zero, the sub-macroblocks are sorted from large to small based on the expected compression specification to obtain a sub-macroblock sorting, wherein the sub-macroblock located before a preset sequence in the sub-macroblock sorting is a first sub-macroblock, and the other sub-macroblocks are second sub-macroblocks;

[0009] Determining a third compression method from the first compression methods according to the specification difference, the expected compression specification corresponding to the first sub-macroblock, and the degree of compression distortion;

[0010] The second sub-macroblock is compressed according to the second compression method, and the first sub-macroblock is compressed according to the third compression method to obtain compressed image data.

[0011] In a second aspect, an embodiment of the present application provides an image compression device, the device comprising:

[0012] An image segmentation module is used to divide the original image into a plurality of macroblocks, and to divide each macroblock into a plurality of sub-macroblocks, and to extract image features of each sub-macroblock to obtain image feature data;

[0013] A compression analysis module, used to determine the expected compression specifications and compression distortion degrees of a plurality of preset first compression methods respectively according to the image feature data based on a preset compression effect analysis method;

[0014] a specification calculation module, configured to determine a second compression method corresponding to the sub-macroblock from a plurality of the first compression methods according to the image feature data, and determine a specification difference according to an expected compression specification corresponding to the second compression method and a preset fixed compression specification;

[0015] A macroblock sorting module, configured to sort the sub-macroblocks from large to small based on the compression expected specification if it is detected that the specification difference is less than zero, to obtain a sub-macroblock sorting, wherein the sub-macroblock located before a preset sequence in the sub-macroblock sorting is a first sub-macroblock, and the other sub-macroblocks are second sub-macroblocks;

[0016] an algorithm determination module, configured to determine a third compression method from the first compression methods according to the specification difference, the expected compression specification corresponding to the first sub-macroblock, and the degree of compression distortion;

[0017] An image compression module is used to compress the second sub-macroblock according to the second compression method, and to compress the first sub-macroblock according to the third compression method to obtain compressed image data.

[0018] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising a memory and a processor;

[0019] The memory is used to store computer programs;

[0020] The processor is used to execute the computer program and implement the image compression method as described in any one of the embodiments of the present application when executing the computer program.

[0021] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor enables the processor to implement an image compression method as described in any one of the embodiments of the present application.

[0022] The embodiment of the present application provides an image compression method, which includes: dividing an original image into multiple macroblocks, and dividing each macroblock into multiple sub-macroblocks, extracting image features of each sub-macroblock, and obtaining image feature data; based on a preset compression effect analysis method, respectively determining the compression expected specifications and compression distortion degrees of multiple preset first compression methods according to the image feature data; determining a second compression method corresponding to the sub-macroblock from the multiple first compression methods according to the image feature data, and determining a specification difference according to the compression expected specification corresponding to the second compression method and the preset compression fixed specification; if it is detected that the specification difference is less than zero, sorting the sub-macroblocks from large to small based on the compression expected specification to obtain a sub-macroblock sorting, wherein the sub-macroblock located before the preset sequence in the sub-macroblock sorting is the first sub-macroblock, and the other sub-macroblocks are the second sub-macroblocks; determining a third compression method from the first compression method according to the specification difference, the compression expected specification and the compression distortion degree corresponding to the first sub-macroblock; compressing the second sub-macroblock according to the second compression method, and compressing the first sub-macroblock according to the third compression method to obtain compressed image data. Through the above method, the original image is divided into multiple macroblocks, each macroblock is compressed according to a preset fixed compression specification, and then refined into multiple sub-macroblocks. The compression method is adjusted at the sub-macroblock level, which reduces the complexity of hardware practice and does not cause the compression algorithm to pay too much attention to the pixel changes of small blocks, but focuses on macroblocks in a larger range. In the process of adjusting the compression method, the second compression algorithm with the smallest compression distortion for each sub-macroblock is first determined, and then it is evaluated whether these second compression algorithms will cause the overall remaining compression specification to exceed the preset fixed compression specification. The second compression algorithm with a larger expected compression specification is replaced with a third compression algorithm, and the expected compression specification of the third compression algorithm is smaller than the expected compression specification of the second compression algorithm, thereby reducing the overall remaining compression specification, achieving more flexible adaptation to image content in different areas, and improving the overall compression effect of the image, while maintaining image quality, reducing the difficulty of implementing the image compression algorithm. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0024] Figure 1 A schematic flow chart of an image compression method provided in an embodiment of the present application;

[0025] Figure 2 A schematic block diagram of an image compression device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are 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 creative work are within the scope of protection of the present invention.

[0027] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0028] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0029] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0030] See also Figure 1 , Figure 1 The embodiment of the present application also provides a schematic flow chart of an image compression method. Figure 1 As shown, the specific steps of the image compression method include: S101-S106.

[0031] S101, dividing an original image into a plurality of macroblocks, and dividing each macroblock into a plurality of sub-macroblocks, extracting image features of each sub-macroblock, and obtaining image feature data.

[0032] Exemplarily, the original image includes: picture data, video data and 3D modeling data. The data size of the original image data is relatively large and needs to be split into multiple macroblocks for compression, and then each macroblock is split into multiple sub-macroblocks. By dynamically adjusting the compression method for the sub-macroblock, different compression forms and remaining compression specifications (number of bits) are flexibly selected to compress the sub-macroblock to adapt to the content complexity of the sub-macroblock and the corresponding compression effect requirements.

[0033] S102: Based on a preset compression effect analysis method, respectively determine the expected compression specifications and compression distortion degrees of a plurality of preset first compression methods according to the image feature data.

[0034] Exemplarily, the preset compression effect analysis method includes: "sum of absolute difference, SAD". SAD is used to measure the difference between the compressed image and the original image, that is, the degree of compression distortion. The smaller the SAD value, the closer the compressed image is to the original image, and the better the compression effect.

[0035] Next, evaluate the compression expected specifications required for each compression method. Different compression methods consume different numbers of bits during the compression process and occupy different compression expected specifications. Therefore, it is necessary to calculate the compression expected specifications occupied by each compression method to ensure the highest compression ratio while maintaining image quality.

[0036] S103, determining a second compression method corresponding to the sub-macroblock from a plurality of first compression methods according to the image feature data, and determining a specification difference according to an expected compression specification corresponding to the second compression method and a preset fixed compression specification.

[0037] Exemplarily, the expected compression specifications corresponding to the second compression method are accumulated to obtain the compression accumulated specifications, and the overall remaining compression specifications of the compressed image data are preliminarily evaluated. The preset compression fixed specifications are subtracted from the compression accumulated specifications to obtain the specification difference. In this way, it is evaluated whether the compressed image data is greater than the set compression fixed specifications. The preset compression fixed specifications are set for macroblocks.

[0038] In this way, different macroblocks can be compressed within a preset specification and achieve a preset compression ratio. This is not only suitable for traditional image compression applications, but also can be applied to various fields that require high-efficiency compression, such as video encoding, remote image transmission, etc.

[0039] S104. If it is detected that the specification difference is less than zero, the sub-macroblocks are sorted from large to small based on the expected compression specification to obtain a sub-macroblock sorting, wherein the sub-macroblock located before the preset sequence in the sub-macroblock sorting is the first sub-macroblock, and the other sub-macroblocks are the second sub-macroblocks.

[0040] Exemplarily, when the specification difference is less than zero, it indicates that after the sub-macroblock is compressed by the second compression method, the specification of the compressed image data generated is greater than expected, and the preset compression ratio is not achieved. Therefore, it is necessary to select a part from the sub-macroblock to adjust the compression ratio. When selecting, the priority is higher for the expected compression specification. The larger the expected compression specification, the worse the compression effect of the sub-macroblock. Therefore, the sub-macroblocks are sorted according to the expected compression specification, and the sub-macroblock ranked before the preset sequence is used as the first sub-macroblock. For example, the preset sequence is 15, and the first sub-macroblock needs to change the corresponding second compression method to the third compression method, thereby reducing the expected compression specification and improving the compression ratio. The second sub-macroblock is temporarily left unchanged.

[0041] S105 . Determine a third compression method from the first compression methods according to the specification difference, the expected compression specification corresponding to the first sub-macroblock, and the degree of compression distortion.

[0042] Exemplarily, if the specification difference is greater than zero, it needs to be apportioned to each first sub-macroblock. When apportioning, it can be proportioned according to the ratio of the expected compression specifications of the first sub-macroblock, or evenly apportioned to each first sub-macroblock. Then, the expected compression specifications corresponding to the first sub-macroblock are subtracted from the apportioned specification difference to obtain the compression optimization specification, and then the appropriate third compression algorithm is re-matched in the first compression method according to the compression optimization specification and the degree of compression distortion. First, the pre-selected compression algorithm that meets the compression optimization specification is selected from the first compression algorithm, and then the pre-selected compression algorithm with the smallest degree of compression distortion is used as the third compression algorithm.

[0043] S106. Compress the second sub-macroblock according to the second compression method, and compress the first sub-macroblock according to the third compression method to obtain compressed image data.

[0044] Exemplarily, when compressing an image, the corresponding sub-macroblocks are compressed respectively according to a determined compression algorithm.

[0045] In this way, the complexity of hardware implementation is significantly reduced, avoiding the adjustment of dynamic compression expected specifications on each pixel or small block, and focusing on a larger range of sub-macroblocks. Secondly, this dynamically switched compression expected specification strategy can more flexibly adapt to the image content of different areas, thereby improving the overall compression effect, especially when processing images with rich details or irregular textures.

[0046] The embodiment of the present application provides an image compression method, which includes: dividing an original image into multiple macroblocks, and dividing each macroblock into multiple sub-macroblocks, extracting image features of each sub-macroblock, and obtaining image feature data; based on a preset compression effect analysis method, respectively determining the compression expected specifications and compression distortion degrees of multiple preset first compression methods according to the image feature data; determining a second compression method corresponding to the sub-macroblock from the multiple first compression methods according to the image feature data, and determining a specification difference according to the compression expected specification corresponding to the second compression method and the preset compression fixed specification; if it is detected that the specification difference is less than zero, sorting the sub-macroblocks from large to small based on the compression expected specification to obtain a sub-macroblock sorting, wherein the sub-macroblock located before the preset sequence in the sub-macroblock sorting is the first sub-macroblock, and the other sub-macroblocks are the second sub-macroblocks; determining a third compression method from the first compression method according to the specification difference, the compression expected specification and the compression distortion degree corresponding to the first sub-macroblock; compressing the second sub-macroblock according to the second compression method, and compressing the first sub-macroblock according to the third compression method to obtain compressed image data. Through the above method, the original image is divided into multiple macroblocks, each macroblock is compressed according to a preset fixed compression specification, and then refined into multiple sub-macroblocks. The compression method is adjusted at the sub-macroblock level, which reduces the complexity of hardware practice and does not cause the compression algorithm to pay too much attention to the pixel changes of small blocks, but focuses on macroblocks in a larger range. In the process of adjusting the compression method, the second compression algorithm with the smallest compression distortion for each sub-macroblock is first determined, and then it is evaluated whether these second compression algorithms will cause the overall remaining compression specification to exceed the preset fixed compression specification. The second compression algorithm with a larger expected compression specification is replaced with a third compression algorithm, and the expected compression specification of the third compression algorithm is smaller than the expected compression specification of the second compression algorithm, thereby reducing the overall remaining compression specification, achieving more flexible adaptation to image content in different areas, and improving the overall compression effect of the image, while maintaining image quality, reducing the difficulty of implementing the image compression algorithm.

[0047] In order to more clearly introduce the technical solution of the present application, the technical solution of the present application will be introduced through specific embodiments below. It should be noted that the specific embodiments are used to expand the technical solution of the present application, but are not intended to limit the present application.

[0048] In some embodiments, image features of each sub-macroblock are extracted to obtain image feature data, including: reading pixel value data of each sub-macroblock; performing progressive detection on the pixel value data, and generating pixel gradient features if it is detected that the pixel value data has a regular increase or decrease in one or more directions; performing range detection on the pixel value data, and obtaining pixel value domain features based on the maximum pixel value and the minimum pixel value in the pixel value data; performing periodic detection on the pixel value data, and generating color distribution features if it is detected that the pixel value data has periodic color changes; and generating image feature data based on the pixel gradient features, the pixel value domain features, and the color distribution features.

[0049] Exemplarily, the pixel value data of the sub-macroblock is usually stored in a matrix form, and each element represents the grayscale value or color value of a pixel. The pixel value data of the sub-macroblock is read and progressively detected. The purpose of progressive detection is to identify whether there is a regular change in the pixel value in one or more directions. If it is detected that the pixel value data has a regular increasing or decreasing trend in the horizontal direction, vertical direction or diagonal line, a corresponding pixel gradient feature is generated. This feature can reveal the existence of a gradient area in the image, such as the color gradient of the sky or the light and shadow changes on the surface of an object.

[0050] Then, the pixel value data is range-checked. The specific method is to calculate the maximum pixel value and the minimum pixel value in the sub-macroblock, and determine the range of the pixel value by the difference between the two. The obtained pixel value domain feature is used to describe the distribution range and dynamic change degree of the pixel value in the sub-macroblock. This feature helps to identify high-contrast areas or low-contrast areas in the image, thereby providing a reference for subsequent compression strategies.

[0051] In addition, the pixel value data is subjected to periodicity detection. The purpose of periodicity detection is to identify whether there is a pattern of periodic color changes in the pixel value data. If it is detected that the pixel values ​​within the sub-macroblock have periodic color changes, a corresponding color distribution feature is generated. This feature is very useful for identifying image areas with periodic patterns, such as checkerboards, stripe patterns, or other periodically repeated patterns.

[0052] Finally, based on the extracted pixel gradient features, pixel value range features and color distribution features, the image feature data is comprehensively generated. These feature data not only provide a detailed description of the pixel values ​​in the sub-macroblock, but also reveal the change pattern and structural characteristics of the image in a specific area. Through these feature data, image compression and reconstruction can be better performed, improving the efficiency of the compression algorithm and the quality of the compressed image.

[0053] In some embodiments, the first compression method includes: a gradient compression method, a range compression method, a color compression method and a distribution compression method. According to the image feature data, a second compression method corresponding to the sub-macroblock is determined from a plurality of first compression methods, including: respectively calculating a first proportion coefficient of a pixel gradient feature, a second proportion coefficient of a pixel gradient feature and a third proportion coefficient of a color distribution feature; if the first proportion coefficient is greater than a preset coefficient, the gradient compression method is determined as the second compression method; if the second proportion coefficient is greater than the preset coefficient, the range compression method is determined as the second compression method; if the third proportion coefficient is greater than the preset coefficient, the color compression method is determined as the second compression method; if the first proportion coefficient, the second proportion coefficient and the third proportion coefficient are all less than the preset coefficient, the distribution compression method is determined as the second compression method.

[0054] Exemplarily, when calculating the proportion coefficients of different image features, the calculation can be performed based on the number of pixel values ​​corresponding to each image feature. The preset coefficient is 60%. If an image feature, for example, a pixel gradient feature, has a first proportion coefficient of 80%, 80%>50%, indicating that the pixel gradient feature is the main image feature of this sub-macroblock. When compressing, selecting the compression algorithm corresponding to the pixel gradient feature can achieve a better compression effect. When the first proportion coefficient, the second proportion coefficient, and the third proportion coefficient are all less than the preset coefficient, it means that the main image features in the sub-macroblock are not obvious, and the preset allocation compression method can be used for compression. The allocation compression method is a method based on Block Truncation Coding (BTC), and adjusts the number of cut blocks according to the available remaining compression specifications to achieve the best compression effect.

[0055] Specifically, the distribution compression method processes each 2x8 pixel block. First, the number of cuts is determined based on the distribution characteristics of the pixel values ​​within the block and the residual compression specifications set in advance. Block Truncation Coding is a simple and effective image compression technology that achieves compression by dividing the pixel values ​​of a block into two main parts (e.g., parts above and below the average). In this method, the application of BTC is further expanded to make it more flexible to adapt to different residual compression specifications.

[0056] In specific implementation, when the available remaining compression specifications are large, more cuts can be made, so that the block can be divided into more small blocks. This can improve the accuracy of compression, because the pixel values ​​in each sub-block vary less and can more accurately reflect the details of the original image. Each cut will be made according to the pixel distribution in the current block to ensure that the pixel values ​​of each sub-block can better conform to the actual distribution. For example, if the pixel value range in a block is very wide and there are enough remaining compression specifications for fine processing, then the block can be cut multiple times, and the pixel value distribution in the block after each cut will be more uniform, thereby improving the overall compression effect and restoration quality.

[0057] In some embodiments, if the second compression method is a gradient compression method, the second sub-macroblock is compressed according to the second compression method, including: determining a gradient direction according to a pixel gradient feature; determining an initial compression position in the sub-macroblock according to the gradient direction, and recording an initial pixel value corresponding to the initial compression position; based on the gradient direction, calculating a gradient value of the initial pixel value and other pixel values ​​on the second sub-macroblock; and obtaining a compressed second sub-macroblock according to the initial pixel value and the gradient value.

[0058] Exemplarily, the gradient compression method performs special processing on the gradient areas in the sub-macroblock. These gradient areas are usually formed by the pixel values ​​gradually changing from left to right or from top to bottom. When compressing by the gradient compression method, the starting value of each gradient area is first recorded, and then the pixel values ​​in the gradient direction are restored by interpolation and recording delta, and it is recorded whether these areas have increasing or decreasing gradient characteristics, so that a signed bit of space can be saved when recording delta values.

[0059] The key to gradient compression is how to effectively represent and restore gradient areas to achieve efficient compression. When a gradient area is found, its starting value is recorded and stored. Based on each pixel or block, the difference between it and the pixel value in the gradient direction is calculated, and these differences are stored in a simplified form, such as using variable-length coding to represent delta values, thereby reducing the overall storage space required.

[0060] The gradient compression method helps to reduce the remaining compression specifications after compression, thereby saving storage space or reducing the bitwidth requirements during data transmission. In applications, the gradient compression method is particularly suitable for processing images with large-area gradient effects, such as pictures of the sky, ocean, or large buildings.

[0061] Through the above method, the gradient characteristics in the image can be efficiently captured and restored without consuming a large amount of residual compression specifications on each pixel or small block. By recording the starting value of the area and the direction of increase or decrease, this information is used during decoding to quickly restore the content of the entire gradient area, thereby maintaining the visual quality and details of the image.

[0062] In some embodiments, if the second compression method is a value range compression method, the second sub-macroblock is compressed according to the second compression method, including: determining the pixel value range corresponding to each second sub-macroblock according to the maximum pixel value corresponding to each second sub-macroblock and the minimum pixel value corresponding to the sub-macroblock; determining the expected compression specification corresponding to each second sub-macroblock according to the pixel value range corresponding to each sub-macroblock; and compressing the second sub-macroblock according to the expected compression specification corresponding to each second sub-macroblock.

[0063] Exemplarily, the range compression method is a general compression method applicable to a variety of different image contents. The core of the range compression method is to analyze the pixel value range of each block, specifically including finding the maximum and minimum values ​​within the block, so as to more effectively allocate and use the remaining compression specifications, thereby improving the overall compression efficiency.

[0064] Specifically, the pixels in each sub-macroblock are counted to determine the maximum and minimum pixel values. This information is used to estimate the range of pixel values ​​within the sub-macroblock, thereby determining the remaining compression specification required. At the macro level, since a remaining compression specification has been fixed for the macroblock, adjustments are made within this range based on the needs of each sub-macroblock. For a specific example, suppose that each sub-macroblock can be compressed using 64 bits. If, when processing a specific sub-macroblock, it is found that a large number of bits are left in the previous block, then these bits can be fully utilized to reduce the quantization level.

[0065] In this way, the accuracy of compression restoration can be improved, because a smaller quantization level means a more refined representation of each pixel value, which can retain more image details. On the contrary, if a large number of bits are used in the previous block, which makes the number of bits available for the subsequent block smaller, the quantization level needs to be adjusted to increase. Such an adjustment will reduce the accuracy of compression restoration, but it can effectively save the number of bits, thereby achieving a higher compression ratio. This flexible bit allocation and quantization level adjustment strategy achieves a balance between different sub-macroblocks to ensure the best overall compression effect. In addition, when the difference between the maximum and minimum values ​​in a sub-macroblock is very small or even equal, this feature can be used to significantly reduce the number of bits required. This is because when the value range is narrow, the range of pixel values ​​is limited, so there is no need to use too many bits to represent these values. Such blocks can usually be compressed by a simpler encoding method, thereby further improving compression efficiency.

[0066] The advantage of the general compression method is that it is highly flexible and adaptable, and can adjust the compression strategy according to the different characteristics of the image content. Whether it is processing areas with drastic color changes or areas with gentle color changes, it can be optimized according to the specific situation. By accurately controlling the number of bits and quantization level of each block, a higher compression ratio can be achieved while ensuring image quality, which is an important improvement for image storage and transmission.

[0067] In some embodiments, if the second compression method is a color compression method, the second sub-macroblock is compressed according to the second compression method, including: determining the color type and the partition ratio of the color type of the second sub-macroblock according to the pixel value data; determining the target color type from the color type according to the partition ratio; and compressing and mapping the second sub-macroblock according to the target color type.

[0068] Exemplarily, the color compression method is used to compress specific types of image patterns, especially artificial images, such as checkerboards or pictures with fixed periodic changes in a small range. In these images, pixel values ​​usually have repeated patterns and colors, so efficient compression can be performed by selecting four representative color categories. Based on the color compression method, the pixel values ​​in each sub-macroblock are analyzed, and the four most representative target color categories are selected according to the distribution of pixel values ​​and the periodic characteristics of the image. These target color categories can fully express the main color information in the block, thereby greatly reducing the amount of color information that needs to be stored.

[0069] Color compression methods not only reduce data storage requirements, but also enable fast color mapping and restoration during decoding. For example, in a checkerboard image, the alternating pattern of colors makes four colors sufficient to cover all possible color variations of the entire block. This method can effectively compress images with regular and repetitive color distribution, improve compression efficiency, and ensure that the visual effect of the image remains consistent.

[0070] In some embodiments, a third compression method is determined from the first compression method based on the specification difference, the expected compression specification corresponding to the first sub-macroblock, and the degree of compression distortion, including: determining the compression reduction specification of the first sub-macroblock based on the specification difference; determining the compression target specification based on the expected compression specification and the compression reduction specification; sorting the first compression methods based on the degree of compression distortion to obtain a compression method ranking, wherein the smaller the degree of compression distortion corresponding to the first compression method, the higher it ranks in the compression method ranking; according to the compression target specification, comparing the expected compression specifications corresponding to the first compression methods one by one according to the compression method ranking, and determining the first compression method whose corresponding expected compression specification is smaller than the compression target specification as the third compression method.

[0071] By comprehensively comparing the degree of compression distortion and the expected compression specifications, the third compression method that is most suitable for the first sub-macroblock can be selected. This method can flexibly adjust the compression strategy according to the specific image content and the remaining compression specifications, thereby achieving the best compression effect and resource utilization efficiency. Finally, a method with a small degree of compression distortion and a suitable expected compression specification is selected and applied to the actual image compression process, ensuring that the visual quality of the image is maintained while improving the compression efficiency.

[0072] See also Figure 2 , Figure 2 The embodiment of the present application further provides a schematic block diagram of an image compression device, wherein the image compression device 200 is used to execute the aforementioned image compression method. The image compression device 200 may be configured in a server.

[0073] Among them, the server can be an independent server or a server cluster, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN) and big data and artificial intelligence platforms.

[0074] like Figure 2 As shown, the image compression device 200 includes: an image segmentation module 201, a compression analysis module 202, a specification calculation module 203, a macroblock sorting module 204, an algorithm determination module 205 and an image compression module 206.

[0075] The image segmentation module 201 is used to divide the original image into a plurality of macroblocks, and to divide each macroblock into a plurality of sub-macroblocks, and to extract the image feature of each sub-macroblock to obtain image feature data.

[0076] In some embodiments, when the image segmentation module 201 is used to extract the image features of each sub-macroblock and obtain the image feature data, it is specifically used to implement: reading the pixel value data of each sub-macroblock; performing progressive detection on the pixel value data, and generating a pixel gradient feature if it is detected that there is a regular increase or regular decrease in one or more directions of the pixel value data; performing range detection on the pixel value data, and obtaining a pixel value domain feature based on the maximum pixel value and the minimum pixel value in the pixel value data; performing periodic detection on the pixel value data, and generating a color distribution feature if it is detected that there is a periodic color change in the pixel value data; and generating image feature data based on the pixel gradient feature, the pixel value domain feature, and the color distribution feature.

[0077] The compression analysis module 202 is used to determine the expected compression specifications and compression distortion degrees of multiple preset first compression methods respectively according to the image feature data based on the preset compression effect analysis method.

[0078] The specification calculation module 203 is used to determine the second compression method corresponding to the sub-macroblock from multiple first compression methods according to the image feature data, and determine the specification difference according to the expected compression specification corresponding to the second compression method and the preset fixed compression specification.

[0079] In some embodiments, the first compression method includes: a gradient compression method, a range compression method, a color compression method and an allocation compression method. When the specification calculation module 203 is used to determine the second compression method corresponding to the sub-macroblock from a plurality of first compression methods according to image feature data, it is specifically used to implement: respectively calculating the first proportion coefficient of the pixel gradient feature, the second proportion coefficient of the pixel gradient feature and the third proportion coefficient of the color distribution feature; if the first proportion coefficient is greater than the preset coefficient, the gradient compression method is determined as the second compression method; if the second proportion coefficient is greater than the preset coefficient, the range compression method is determined as the second compression method; if the third proportion coefficient is greater than the preset coefficient, the color compression method is determined as the second compression method; if the first proportion coefficient, the second proportion coefficient and the third proportion coefficient are all less than the preset coefficient, the allocation compression method is determined as the second compression method.

[0080] The macroblock sorting module 204 is used to sort the sub-macroblocks from large to small based on the compression expected specification if it is detected that the specification difference is less than zero, so as to obtain a sub-macroblock sorting, wherein the sub-macroblock located before the preset sequence in the sub-macroblock sorting is the first sub-macroblock, and the other sub-macroblocks are the second sub-macroblocks.

[0081] The algorithm determination module 205 is used to determine a third compression method from the first compression methods according to the specification difference, the expected compression specification corresponding to the first sub-macroblock and the degree of compression distortion.

[0082] In some embodiments, when the algorithm determination module 205 is used to determine the third compression method from the first compression method based on the specification difference, the expected compression specification corresponding to the first sub-macroblock and the degree of compression distortion, it is specifically used to implement: determining the compression reduction specification of the first sub-macroblock based on the specification difference; determining the compression target specification based on the expected compression specification and the compression reduction specification; sorting the first compression methods based on the degree of compression distortion to obtain a compression method ranking, wherein the smaller the degree of compression distortion corresponding to the first compression method is, the higher it is in the compression method ranking; according to the compression target specification, comparing the expected compression specifications corresponding to the first compression methods one by one according to the compression method ranking, and determining the first compression method whose corresponding expected compression specification is smaller than the compression target specification as the third compression method.

[0083] The image compression module 206 is used to compress the second sub-macroblock according to the second compression method, and to compress the first sub-macroblock according to the third compression method to obtain compressed image data.

[0084] In some embodiments, if the second compression method is a gradient compression method, the image compression module 206, when used to compress the second sub-macroblock according to the second compression method, is specifically used to implement: determining a gradient direction according to a pixel gradient feature; determining an initial compression position in the sub-macroblock according to the gradient direction, and recording an initial pixel value corresponding to the initial compression position; calculating a gradient value of the initial pixel value and other pixel values ​​on the second sub-macroblock based on the gradient direction; and obtaining a compressed second sub-macroblock according to the initial pixel value and the gradient value.

[0085] In some embodiments, if the second compression method is a value range compression method, the image compression module 206, when used to compress the second sub-macroblock according to the second compression method, is specifically used to implement: determining the pixel value range corresponding to each second sub-macroblock according to the maximum pixel value corresponding to each second sub-macroblock and the minimum pixel value corresponding to the sub-macroblock; determining the expected compression specification corresponding to each second sub-macroblock according to the pixel value range corresponding to each sub-macroblock; and compressing the second sub-macroblock according to the expected compression specification corresponding to each second sub-macroblock.

[0086] In some embodiments, if the second compression method is a color compression method, the image compression module 206, when used to compress the second sub-macroblock according to the second compression method, is specifically used to implement: determining the color type and the partition ratio of the color type of the second sub-macroblock according to the pixel value data; determining the target color type from the color type according to the partition ratio; and compressing and mapping the second sub-macroblock according to the target color type.

[0087] An embodiment of the present application provides an electronic device, which includes a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program and implement an image compression method as described in any one of the embodiments of the present application when executing the computer program.

[0088] An embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the processor implements any image compression method in the embodiments of the present application.

[0089] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. An image compression method, characterized in that: The method comprises: The original image is divided into a plurality of macroblocks, and each macroblock is divided into a plurality of sub-macroblocks, and the pixel value data of each sub-macroblock is read; the pixel value data is progressively detected, and if it is detected that the pixel value data has a regular increase or regular decrease in one or more directions, a pixel gradient feature is generated; the pixel value data is range detected, and a pixel value domain feature is obtained according to the maximum pixel value and the minimum pixel value in the pixel value data; the pixel value data is periodically detected, and if it is detected that the pixel value data has a periodic color change, a color distribution feature is generated; image feature data is generated according to the pixel gradient feature, the pixel value domain feature and the color distribution feature; Based on a preset compression effect analysis method, the expected compression specifications and compression distortion degrees of a plurality of preset first compression methods are respectively determined according to the image feature data, wherein the first compression methods include: a gradient compression method, a range compression method, a color compression method, and a distribution compression method; The first proportion coefficient of the pixel gradient feature, the second proportion coefficient of the pixel value range feature and the third proportion coefficient of the color distribution feature are calculated respectively; if the first proportion coefficient is greater than the preset coefficient, the gradient compression method is determined as the second compression method; if the second proportion coefficient is greater than the preset coefficient, the value range compression method is determined as the second compression method; if the third proportion coefficient is greater than the preset coefficient, the color compression method is determined as the second compression method; if the first proportion coefficient, the second proportion coefficient and the third proportion coefficient are all less than the preset coefficient, the distribution compression method is determined as the second compression method; the specification difference is determined according to the compression expected specification corresponding to the second compression method and the preset compression fixed specification; If it is detected that the specification difference is less than zero, the sub-macroblocks are sorted from large to small based on the expected compression specification to obtain a sub-macroblock sorting, wherein the sub-macroblock located before a preset sequence in the sub-macroblock sorting is a first sub-macroblock, and the other sub-macroblocks are second sub-macroblocks; Determining a third compression method from the first compression methods according to the specification difference, the expected compression specification corresponding to the first sub-macroblock, and the degree of compression distortion; The second sub-macroblock is compressed according to the second compression method, and the first sub-macroblock is compressed according to the third compression method to obtain compressed image data.

2. The image compression method according to claim 1, characterized in that: If the second compression method is the gradual compression method, compressing the second sub-macroblock according to the second compression method includes: Determining a gradient direction according to the pixel gradient feature; Determine an initial compression position in the sub-macroblock according to the gradient direction, and record an initial pixel value corresponding to the initial compression position; Based on the gradient direction, calculating a gradient value of the initial pixel value and other pixel values ​​on the second sub-macroblock; The compressed second sub-macroblock is obtained according to the initial pixel value and the gradient value.

3. The image compression method according to claim 1, wherein: If the second compression method is the value range compression method, compressing the second sub-macroblock according to the second compression method includes: Determine a pixel value range corresponding to each second sub-macroblock according to a maximum pixel value corresponding to each second sub-macroblock and a minimum pixel value corresponding to the sub-macroblock; Determine the expected compression specification corresponding to each of the second sub-macroblocks according to the pixel value range corresponding to each of the sub-macroblocks; The second sub-macroblocks are compressed according to the expected compression specification corresponding to each of the second sub-macroblocks.

4. The image compression method according to claim 1, wherein: If the second compression method is a color compression method, compressing the second sub-macroblock according to the second compression method includes: Determine, according to the pixel value data, a color type of the second sub-macroblock and a partition ratio of the color type; Determine a target color category from the color categories according to the partition proportions; The second sub-macroblock is compressed and mapped according to the target color category.

5. The image compression method according to claim 1, wherein: The determining a third compression method from the first compression method according to the specification difference, the expected compression specification corresponding to the first sub-macroblock, and the degree of compression distortion includes: Determining a compression reduction specification of the first sub-macroblock according to the specification difference; Determine a compression target specification according to the expected compression specification and the compression reduction specification; Sorting the first compression methods according to the compression distortion degree to obtain a compression method ranking, wherein the smaller the compression distortion degree corresponding to the first compression method is, the higher it ranks in the compression method ranking; According to the compression target specification, the compression expected specifications corresponding to the first compression methods are compared one by one according to the compression method sorting, and the first first compression method whose corresponding compression expected specification is smaller than the compression target specification is determined as the third compression method.

6. An image compression device, characterized in that: The image compression device comprises: An image segmentation module is used to divide an original image into a plurality of macroblocks, and to divide each macroblock into a plurality of sub-macroblocks, and to read the pixel value data of each sub-macroblock; to perform progressive detection on the pixel value data, and to generate pixel gradient features if it is detected that the pixel value data has a regular increase or regular decrease in one or more directions; to perform range detection on the pixel value data, and to obtain pixel value domain features according to the maximum pixel value and the minimum pixel value in the pixel value data; to perform periodic detection on the pixel value data, and to generate color distribution features if it is detected that the pixel value data has a periodic color change; and to generate image feature data according to the pixel gradient features, the pixel value domain features, and the color distribution features; A compression analysis module, for determining the expected compression specifications and compression distortion degrees of a plurality of preset first compression methods according to the image feature data based on a preset compression effect analysis method, wherein the first compression methods include: a gradient compression method, a range compression method, a color compression method, and a distribution compression method; A specification calculation module, used to respectively calculate the first proportion coefficient of the pixel gradient feature, the second proportion coefficient of the pixel value range feature and the third proportion coefficient of the color distribution feature; if the first proportion coefficient is greater than a preset coefficient, the gradient compression method is determined as the second compression method; if the second proportion coefficient is greater than the preset coefficient, the value range compression method is determined as the second compression method; if the third proportion coefficient is greater than the preset coefficient, the color compression method is determined as the second compression method; if the first proportion coefficient, the second proportion coefficient and the third proportion coefficient are all less than the preset coefficient, the distribution compression method is determined as the second compression method; determine the specification difference according to the compression expected specification corresponding to the second compression method and the preset compression fixed specification; A macroblock sorting module, configured to sort the sub-macroblocks from large to small based on the compression expected specification if it is detected that the specification difference is less than zero, to obtain a sub-macroblock sorting, wherein the sub-macroblock located before a preset sequence in the sub-macroblock sorting is a first sub-macroblock, and the other sub-macroblocks are second sub-macroblocks; an algorithm determination module, configured to determine a third compression method from the first compression methods according to the specification difference, the expected compression specification corresponding to the first sub-macroblock, and the degree of compression distortion; An image compression module is used to compress the second sub-macroblock according to the second compression method, and to compress the first sub-macroblock according to the third compression method to obtain compressed image data.

7. An electronic device, characterized in that: The electronic device comprises a memory and a processor; The memory is used to store computer programs; The processor is used to execute the computer program and implement the image compression method according to any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the image compression method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Video data encoding and decoding method and device, computer device and storage medium

    CN111212288A

  • Image compression method, device and equipment and computer readable storage medium

    CN114374847A