Picture compression method and system and storage medium

Through dynamic compression rate and optimization algorithm, the image is partitioned and compressed, and combined with the storage decision value optimization upload method, the problem of poor image compression quality and unoptimized cost in the existing technology is solved, and a more efficient image compression and storage solution is achieved .

CN119180875APending Publication Date: 2024-12-24UNICLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411213328.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-24

AI Technical Summary

Technical Problem

Existing image compression methods tend to lead to poor image quality after compression when processing large images, and fail to effectively balance the differences between image size and quality, and storage and upload costs are not optimized.

Method used

The image is partitioned by dynamic compression ratio (CRi=Ai/(Ai+Ci), and the compression parameters are determined through an optimization algorithm to achieve a balance of quality and size, while the storage decision value is calculated based on the storage medium and network latency to reduce costs.

Benefits of technology

Improved image compression quality, ensured image quality at a given size and resolution, and balanced cost and efficiency by dynamically selecting storage media and upload time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119180875A_ABST
    Figure CN119180875A_ABST
Patent Text Reader

Abstract

The invention discloses a picture compression method and system and a storage medium, and the method comprises the steps: receiving a picture uploaded by a user, and carrying out the judgment of the picture; if the size of the picture is smaller than a preset picture size threshold value, directly pre-compressing the picture to generate a pre-compressed picture; if the size of the picture is greater than a preset picture size threshold value, calculating to obtain a dynamic compression ratio according to the picture, pre-compressing the picture according to the dynamic compression ratio, generating a pre-compressed picture, checking the pre-compressed picture, and if the size and the resolution of the pre-compressed picture are greater than a preset picture size threshold value and a preset picture resolution threshold value, generating a pre-compressed picture; if not, determining a compression parameter through an optimization algorithm, compressing the pre-compressed picture according to the compression parameter, repeatedly executing the step until the pre-compressed picture meets the size and resolution requirements, and taking the pre-compressed picture as a final compressed picture; and the final compressed picture is stored, so that the relationship among the picture quality, the compression efficiency and the cost is balanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software development, and in particular to a picture compression method, system and storage medium. Background Art

[0002] Nowadays, there are generally two scenarios and processing methods for uploading pictures: The first system limits the image size and pixels, and the system does not support automatic compression. In this case, the front-end service often directly forces a limit on the image size.

[0003] The second type is that the system only limits the image size without requiring the image resolution, and the system supports automatic compression of a certain size ratio. Users can directly upload images of a certain size, and the system service automatically compresses the image within a certain range according to the requirements.

[0004] In the above-mentioned prior art, the existing image compression and storage methods often use a fixed compression ratio or a simple algorithm, which may cause the key points of the compressed image to be unclear when the image is too large. Summary of the invention

[0005] To achieve the above purpose and other related purposes, the present invention discloses a picture compression method, comprising: Receive pictures uploaded by users and make judgments on them; If the image size is smaller than the preset image size threshold, the image is directly pre-compressed to generate a pre-compressed image; If the image size is larger than the preset image size threshold, a dynamic compression rate is calculated based on the image, and the image is pre-compressed based on the dynamic compression rate to generate a pre-compressed image, wherein the dynamic compression rate is: CRi=Ai / (Ai+Ci); Among them, CRi is the dynamic compression rate of the i-th region, Ai is the importance weight of the i-th region in the image, and Ci is the complexity index of the i-th region; The pre-compressed image is inspected. If its size and resolution are greater than the preset image size threshold and image resolution threshold, compression parameters are determined by an optimization algorithm, and the pre-compressed image is compressed according to the compression parameters. This step is repeated until the pre-compressed image meets the size and resolution requirements. At this time, the pre-compressed image is used as the final compressed image. The final compressed image is stored.

[0006] Furthermore, determining the compression parameters by using an optimization algorithm includes: P=arg min p (QLoss(P)+λ⋅SizeDiff(P)); Where P is the compression parameter, QLoss(P) is the quality loss function with P as the independent variable, SizeDiff(P) is the difference between the compressed image size and the target size, and λ is the regularization parameter. The above formula indicates that the P value must satisfy QLoss(P)+λ⋅SizeDiff(P) to be the minimum value.

[0007] Furthermore, storing the final compressed image includes: Calculate storage decision values ​​based on different storage media and network latency: D = S (r) * T / X; Where S(r) is the cost function that depends on the storage medium r, T is the network delay time under the current network environment, and X is the size of the picture uploaded by the user; Select the storage medium and upload time with the lowest value based on the decision value, and upload the image to the object storage system for persistent storage.

[0008] Furthermore, the quality loss function is a function that measures the degree of loss of the compressed image relative to the original image, and is defined based on the peak signal-to-noise ratio or the structural similarity index.

[0009] On the other hand, the present invention also provides a picture compression system, comprising: The picture receiving module is used to receive pictures uploaded by users; Preprocessing module, used to judge and preprocess the image; If the image size is smaller than the preset image size threshold, the image is directly pre-compressed to generate a pre-compressed image; If the image size is larger than the preset image size threshold, a dynamic compression rate is calculated based on the image, and the image is pre-compressed based on the dynamic compression rate to generate a pre-compressed image, wherein the dynamic compression rate is: CRi=Ai / (Ai+Ci); Among them, CRi is the dynamic compression rate of the i-th region, Ai is the importance weight of the i-th region in the image, and Ci is the complexity index of the i-th region; The image compression module is used to check the pre-compressed image. If its size and resolution are greater than the preset image size threshold and image resolution threshold, the compression parameters are determined by the optimization algorithm, and the pre-compressed image is compressed according to the compression parameters. This step is repeated until the pre-compressed image meets the size and resolution requirements. At this time, the pre-compressed image is used as the final compressed image. The storage module is used to store the final compressed image.

[0010] On the other hand, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which implements the above-described method when the program is executed by a processor.

[0011] By adopting the above technical solution, when receiving a picture uploaded by a user, the size of the picture is first determined. If the picture size is smaller than the preset picture size threshold, the picture is directly pre-compressed to generate a pre-compressed picture. If the picture size is larger than the preset picture size threshold, the dynamic compression rate is calculated based on the picture, and the picture is pre-compressed according to the dynamic compression rate to generate a pre-compressed picture, thereby protecting areas of higher importance. The pre-compressed picture is then compressed so that the picture, while meeting the size and resolution requirements, balances the difference between quality and image size as much as possible, thereby improving the overall compression quality. The storage cost and the time cost of uploading are then considered, and a suitable storage medium and upload time are selected to upload the picture, thereby dynamically balancing the relationship between picture quality, compression efficiency and cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, among which:

[0013] Figure 1 The figure is a flow chart of a picture compression method. DETAILED DESCRIPTION

[0014] 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 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 those skilled in the art without creative work are within the scope of protection of the present invention.

[0015] Reference Figure 1 , an embodiment of the present invention provides a method for compressing an image, comprising the following steps: S1: Receive pictures uploaded by users and make judgments on them; S11: If the image size is smaller than a preset image size threshold, the image is directly pre-compressed to generate a pre-compressed image; As mentioned above, the preset image size threshold is set by those skilled in the art according to specific circumstances, and will not be described in detail here.

[0016] As mentioned above, when the image size is smaller than the preset image size threshold, the image size is small at this time, and directly compressing it will not cause the loss of important information of the image, so the image is first pre-compressed at this time.

[0017] S12: If the image size is greater than a preset image size threshold, a dynamic compression rate is calculated based on the image, and the image is pre-compressed based on the dynamic compression rate to generate a pre-compressed image, wherein the dynamic compression rate is: CRi=Ai / (Ai+Ci); Among them, CRi is the dynamic compression rate of the i-th region, Ai is the importance weight of the i-th region in the image, and Ci is the complexity index of the i-th region.

[0018] As mentioned above, when the image is larger than the preset image size threshold, if conventional compression methods are used for the image at this time, the important part of the information in the image may be lost. At this time, the image is divided into multiple regions, and the specific region segmentation method and the number of segmentations are set by the technicians in this field. Then, the importance weight of each region is calculated by an image recognition algorithm (such as a deep learning model). The higher the weight value of the region, the more protection the region should receive during the recompression process to reduce the impact of compression on the region. The complexity index is a calculated value based on the image content, which can usually be measured by calculating the local variance, edge density or structural similarity index (SSIM) of the image. Regions with higher complexity contain more details and textures, so more retention may be required during compression. Compressing the image according to the dynamic compression rate of each region can retain more features in the region with higher importance. Using different compression strategies on the same image is a prior art that can be mastered by technicians in this field, and will not be repeated here.

[0019] S2: Check the pre-compressed image. If its size and resolution are greater than a preset image size threshold and image resolution threshold, determine the compression parameters through an optimization algorithm, compress the pre-compressed image according to the compression parameters, and repeat this step until the pre-compressed image meets the size and resolution requirements. At this time, the pre-compressed image is used as the final compressed image. As mentioned above, the image resolution threshold is set by those skilled in the art according to specific requirements, which will not be described in detail here.

[0020] Wherein, determining the compression parameters by using an optimization algorithm comprises: P=arg min p (QLoss(P)+λ⋅SizeDiff(P)).

[0021] Where P is the compression parameter, QLoss(P) is the quality loss function with P as the independent variable, SizeDiff(P) is the difference between the compressed image size and the target size, and λ is the regularization parameter, which is set by technical personnel in this field. The above formula shows that the P value must satisfy QLoss(P)+λ⋅SizeDiff(P) to be the minimum value.

[0022] The quality loss function is a function that measures the degree of loss of the compressed image relative to the original image, and is defined based on the peak signal-to-noise ratio or the structural similarity index or other evaluation indicators. It is a technical means that can be consulted by technicians in this field and will not be repeated here.

[0023] As described above, when the pre-compressed image is recompressed, the compression parameter is obtained by the above formula. The compression parameter needs to minimize the sum of the quality loss of the image and the difference between the compressed image size and the target size, so that the image quality and the compressed size can achieve a dynamic balance.

[0024] S3: Store the final compressed image.

[0025] Specifically include: An embodiment of the present invention further provides a system, comprising: Calculate storage decision values ​​based on different storage media and network latency: D = S (r) * T / X; Where S(r) is a cost function that depends on the storage medium r. The storage medium includes but is not limited to cloud storage services, local hard disks, etc. It takes into account factors such as the price, persistence, and reliability of storage space, which will not be repeated here. T is the network delay time in the current network environment, and X is the size of the picture uploaded by the user; Select the storage medium and upload time with the lowest value based on the decision value, and upload the image to the object storage system for persistent storage.

[0026] As described above, when storing the final compressed image, the cost and time are also comprehensively considered, and the storage method and upload time with the lowest time cost and storage cost are selected, thereby further reducing the cost.

[0027] This embodiment provides a picture compression method. When receiving a picture uploaded by a user, the size of the picture is first determined. If the picture size is smaller than a preset picture size threshold, the picture is directly pre-compressed to generate a pre-compressed picture. If the picture size is larger than the preset picture size threshold, a dynamic compression rate is calculated based on the picture, and the picture is pre-compressed based on the dynamic compression rate to generate a pre-compressed picture, thereby protecting areas of higher importance. The pre-compressed picture is then compressed to balance the difference between quality and image size as much as possible while meeting the size and resolution requirements, thereby improving the overall compression quality. The storage cost and the time cost of uploading are then considered, and a suitable storage medium and upload time are selected to upload the picture, thereby dynamically balancing the relationship between picture quality, compression efficiency and cost.

[0028] The embodiment of the present invention further provides a picture compression system, including: The picture receiving module is used to receive pictures uploaded by users; Preprocessing module, used to judge and preprocess the image; If the image size is smaller than the preset image size threshold, the image is directly pre-compressed to generate a pre-compressed image; If the image size is larger than the preset image size threshold, a dynamic compression rate is calculated based on the image, and the image is pre-compressed based on the dynamic compression rate to generate a pre-compressed image, wherein the dynamic compression rate is: CRi=Ai / (Ai+Ci); Among them, CRi is the dynamic compression rate of the i-th region, Ai is the importance weight of the i-th region in the image, and Ci is the complexity index of the i-th region; The image compression module is used to check the pre-compressed image. If its size and resolution are greater than the preset image size threshold and image resolution threshold, the compression parameters are determined by the optimization algorithm, and the pre-compressed image is compressed according to the compression parameters. This step is repeated until the pre-compressed image meets the size and resolution requirements. At this time, the pre-compressed image is used as the final compressed image. The storage module is used to store the final compressed image.

[0029] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.

[0030] Those skilled in the art will appreciate that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art in the art to which the present invention belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined.

[0031] For the method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0032] It can be known from the description of the above implementation modes that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc.) to execute the methods described in the various implementation modes of the present application or certain parts of the implementation modes.

[0033] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for compressing an image, characterized in that: include: Receive pictures uploaded by users and make judgments on them; If the image size is smaller than the preset image size threshold, the image is directly pre-compressed to generate a pre-compressed image; If the image size is larger than the preset image size threshold, a dynamic compression rate is calculated based on the image, and the image is pre-compressed based on the dynamic compression rate to generate a pre-compressed image, wherein the dynamic compression rate is: CRi=Ai / (Ai+Ci); Among them, CRi is the dynamic compression rate of the i-th region, Ai is the importance weight of the i-th region in the image, and Ci is the complexity index of the i-th region; The pre-compressed image is inspected. If its size and resolution are greater than the preset image size threshold and image resolution threshold, compression parameters are determined by an optimization algorithm, and the pre-compressed image is compressed according to the compression parameters. This step is repeated until the pre-compressed image meets the size and resolution requirements. At this time, the pre-compressed image is used as the final compressed image. The final compressed image is stored.

2. The method according to claim 1, characterized in that Determining the compression parameters by using an optimization algorithm includes: P=arg min p (QLoss(P)+λ⋅SizeDiff(P)); Where P is the compression parameter, QLoss(P) is the quality loss function with P as the independent variable, SizeDiff(P) is the difference between the compressed image size and the target size, and λ is the regularization parameter. The above formula indicates that the P value must satisfy QLoss(P)+λ⋅SizeDiff(P) to be the minimum value.

3. The method according to claim 1, characterized in that The storing of the final compressed image comprises: Calculate storage decision values ​​based on different storage media and network latency: D = S (r) * T / X; Where S(r) is the cost function that depends on the storage medium r, T is the network delay time under the current network environment, and X is the size of the picture uploaded by the user; Select the storage medium and upload time with the lowest value based on the decision value, and upload the image to the object storage system for persistent storage.

4. The method according to claim 2, characterized in that: The quality loss function is a function that measures the degree of loss of a compressed image relative to the original image, and is defined based on a peak signal-to-noise ratio or a structural similarity index.

5. A picture compression system, characterized in that: include: The picture receiving module is used to receive pictures uploaded by users; Preprocessing module, used to judge and preprocess the image; If the image size is smaller than the preset image size threshold, the image is directly pre-compressed to generate a pre-compressed image; If the image size is larger than the preset image size threshold, a dynamic compression rate is calculated based on the image, and the image is pre-compressed based on the dynamic compression rate to generate a pre-compressed image, wherein the dynamic compression rate is: CRi=Ai / (Ai+Ci); Among them, CRi is the dynamic compression rate of the i-th region, Ai is the importance weight of the i-th region in the image, and Ci is the complexity index of the i-th region; The image compression module is used to check the pre-compressed image. If its size and resolution are greater than the preset image size threshold and image resolution threshold, the compression parameters are determined by the optimization algorithm, and the pre-compressed image is compressed according to the compression parameters. This step is repeated until the pre-compressed image meets the size and resolution requirements. At this time, the pre-compressed image is used as the final compressed image. The storage module is used to store the final compressed image.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method described in any one of claims 1 to 4 is implemented.