CN115037937B - Image compression method, apparatus, device and medium - Google Patents

Image compression method, apparatus, device and medium Download PDF

Info

Publication number
CN115037937B
CN115037937B CN202210626130.0A CN202210626130A CN115037937B CN 115037937 B CN115037937 B CN 115037937B CN 202210626130 A CN202210626130 A CN 202210626130A CN 115037937 B CN115037937 B CN 115037937B
Authority
CN
China
Prior art keywords
image
compression
target
compressed image
proportion
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210626130.0A
Other languages
Chinese (zh)
Other versions
CN115037937A (en
Inventor
李海阳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Xintang Sichuang Educational Technology Co Ltd
Original Assignee
Beijing Xintang Sichuang Educational Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Xintang Sichuang Educational Technology Co Ltd filed Critical Beijing Xintang Sichuang Educational Technology Co Ltd
Priority to CN202210626130.0A priority Critical patent/CN115037937B/en
Publication of CN115037937A publication Critical patent/CN115037937A/en
Application granted granted Critical
Publication of CN115037937B publication Critical patent/CN115037937B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/134Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/102Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/17Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object
    • H04N19/172Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object the region being a picture, frame or field

Abstract

The present disclosure provides an image compression method, apparatus, device and medium, wherein the method comprises: acquiring an original image to be compressed; acquiring a target class to which the original image belongs, a compression loss threshold value and a plurality of image compression ratios corresponding to the target class from a plurality of preset image classes; sequentially compressing the original images according to the sequence of the image compression ratios from small to large until a target compressed image is obtained; the target compressed image is a compressed image of which the compression loss is closest to the compression loss threshold and is not greater than the compression loss threshold in a plurality of compressed images corresponding to the image compression ratios. The method and the device can compress the original image to the greatest extent on the basis of meeting the image requirements (not greater than the compression loss threshold), and can well improve the image compression effect on the basis of saving the labor cost.

Description

Image compression method, apparatus, device and medium
Technical Field
The present disclosure relates to the field of image processing, and in particular, to an image compression method, apparatus, device, and medium.
Background
Image compression is an application of data compression technology to digital images, and in many occasions, images need to be compressed, and the space required by storing the images is saved or the time required by transmitting the images is shortened by compressing the images. In platforms such as Unity, a user is usually required to manually set a compression ratio of an image by experience, and then perform image compression based on the compression ratio set by the user, but this method is prone to problems such as too large compressed image or distortion, and therefore, the user is also required to repeatedly adjust and modify the compression ratio of the image, which is time-consuming and labor-consuming, and high labor cost is required.
Disclosure of Invention
To solve the above technical problem or at least partially solve the above technical problem, the present disclosure provides an image compression method, apparatus, device, and medium.
According to an aspect of the present disclosure, there is provided a method of acquiring an original image to be compressed; acquiring a target class to which the original image belongs, a compression loss threshold value and a plurality of image compression ratios corresponding to the target class from a plurality of preset image classes; sequentially compressing the original images according to the sequence of the image compression ratios from small to large until a target compressed image is obtained; the target compressed image is a compressed image of which the compression loss is closest to the compression loss threshold and is not greater than the compression loss threshold among the compressed images corresponding to the image compression ratios.
According to another aspect of the present disclosure, there is provided an image compression apparatus including: the original image acquisition module is used for acquiring an original image to be compressed; the threshold and proportion acquisition module is used for acquiring a target class to which the original image belongs, a compression loss threshold corresponding to the target class and a plurality of image compression proportions from a plurality of preset image classes; the image compression module is used for sequentially compressing the original images according to the sequence from small to large by the image compression ratios until a target compressed image is obtained; the target compressed image is a compressed image of which the compression loss is closest to the compression loss threshold and is not greater than the compression loss threshold among the compressed images corresponding to the image compression ratios.
According to another aspect of the present disclosure, there is provided an electronic device including: a processor; and a memory storing a program, wherein the program comprises instructions which, when executed by the processor, cause the processor to perform the image compression method described above.
According to another aspect of the present disclosure, there is provided a computer-readable storage medium storing a computer program for executing the above-described image compression method.
According to the technical scheme provided by the embodiment of the disclosure, the target category to which the original image belongs, and the compression loss threshold and the image compression ratios corresponding to the target category are obtained from the preset multiple image categories, so that the compression loss threshold more suitable for the original image and the image compression ratios capable of being used for compressing the original image can be obtained, and then the image compression ratios are sequentially used for compressing the original image according to the sequence from small to large until the target compressed image with the compression loss closest to the compression loss threshold and not greater than the compression loss threshold is obtained; according to the method, the compression ratio does not need to be manually set through experience and adjusted repeatedly, the compression can be tried from small to large by adopting a plurality of image compression ratios suitable for the original image until the target compressed image is obtained, and the target compressed image is closest to and not larger than the compression loss threshold, so that the original image can be compressed to the greatest extent as possible on the basis of meeting the image requirements (not larger than the compression loss threshold), and the image compression effect is also well improved on the basis of saving the labor cost.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure.
In order to more clearly illustrate the embodiments or technical solutions in the prior art of the present disclosure, the drawings used in the description of the embodiments or prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 is a schematic flowchart of an image compression method according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of an image compression method according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of an image compression apparatus according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and its variants as used in this disclosure are intended to be inclusive, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description. It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
In order that the above objects, features and advantages of the present disclosure may be more clearly understood, aspects of the present disclosure will be further described below. It should be noted that the embodiments and features of the embodiments of the present disclosure may be combined with each other without conflict.
In platforms such as Unity, which generally require a user to manually set a compression ratio of an image by experience, the compressed image may not be as desired (still too large or distorted), if the compressed image is still too large, image storage or transmission is inconvenient, and if the compressed image is distorted, subsequent image applications may be seriously affected. Moreover, in a Unity content development platform, each development project may involve a large number of pictures, and if each picture needs to be manually compressed by a user, and the compressed image needs to be manually checked to meet the requirement, the labor cost is very high. In order to at least partially improve the above problems, embodiments of the present disclosure provide an image compression method, apparatus, device and medium, which are described in detail below.
Fig. 1 is a schematic flowchart of an image compression method provided in an embodiment of the present disclosure, where the method may be executed by an image compression apparatus, where the apparatus may be implemented by software and/or hardware, and may be generally integrated in an electronic device, where the electronic device includes, but is not limited to, a mobile phone, a computer, a server, a portable wearable device, a robot, and other devices with image processing capability, as shown in fig. 1, the method mainly includes the following steps S102 to S106:
step S102, obtaining an original image to be compressed.
The content and the purpose of the original image are not limited in the embodiment of the disclosure, the original image may be an image selected locally by a user, uploaded by an external device, or downloaded through a network.
And step S104, acquiring a target class to which the original image belongs, a compression loss threshold corresponding to the target class and a plurality of image compression ratios from a plurality of preset image classes.
The image compression ratio is the ratio of the size of the original image to the size of the compressed image. The larger the image compression ratio, the smaller the compressed image. In the embodiment of the present disclosure, a plurality of image categories may be set in advance based on image contents and/or image usages. For example, a plurality of image categories such as a personal image category, a landscape image category, a night view image category, and the like may be set based on image content; a plurality of image categories may also be set based on image usage, such as an image category for sticker, an image category for background, an image category for target object recognition, and the like; a variety of image categories, such as a texture map category, a normal map category, and the like, may also be set based on image content and image usage. The embodiment of the present disclosure does not limit the manner of dividing the image categories.
In some embodiments, the compression loss threshold is different for different image classes, and/or the compression ratio of the plurality of images is different for different image classes. That is, a corresponding compression loss threshold and/or a plurality of image compression ratios may be set for each image class according to the characteristics of each image class. Image categories such as a person image category or an image category for face recognition mostly require higher definition, so a relatively smaller compression loss threshold (i.e. an acceptable degree of compression is lower) can be set to ensure that the compressed image still has better definition; as another example, the sharpness requirement for the image class as background is generally not high, and therefore a relatively large compression loss threshold (i.e., a high degree of acceptable compression) may be set to compress such images as much as possible. Similarly, the number of available image compression ratios corresponding to different image categories may be different, such as setting 2 image compression ratios for the personal image category, setting 3 image compression ratios for the landscape image category, and the like, and specific values of the image compression ratios corresponding to different image categories may be the same or different, and may be flexibly set according to actual situations, which is not limited herein.
After the original image is obtained, the target type to which the original image belongs can be determined according to the content of the original image or the use of the original image based on the existing multiple image types, and then the compression loss threshold and the multiple image compression ratios corresponding to the target type are obtained.
Step S106, sequentially compressing the original images according to the sequence of the compression ratios of the plurality of images from small to large until a target compressed image is obtained; the target compressed image is a compressed image of which the compression loss is closest to the compression loss threshold value and is not greater than the compression loss threshold value among the compressed images corresponding to the plurality of image compression ratios.
The compression processing is sequentially carried out on the original image according to the sequence from small to large by the compression ratios of the plurality of images, namely the compression ratios of the compressed image are gradually increased until the target compressed image is obtained, the compression loss of the target compressed image is closest to a compression loss threshold, and the compression loss of the target compressed image is not more than the compression loss threshold.
In practical application, the minimum proportion of a plurality of image compression proportions is used as the current image compression proportion one by one, and an original image is compressed; if the compression loss of the compressed image corresponding to the current image compression ratio is smaller than the compression loss threshold, the original image can be further compressed by adopting the next image compression ratio according to the ratio sequence until the image compression ratio which can be ended (hereinafter referred to as the ending ratio) is tried. The compression loss value of the compressed image obtained by the end ratio is greater than or equal to a compression loss threshold value, or the end ratio is the largest image compression ratio (hereinafter referred to as the largest ratio) among the plurality of image compression ratios. And then, the target compressed image can be obtained according to the comparison result between the compression loss of the compressed image corresponding to the ending proportion and the compression loss threshold value. For example, when the compression loss of the compressed image corresponding to the ending proportion is equal to the compression loss threshold, the compressed image corresponding to the ending proportion is used as the target compressed image, when the compression loss of the compressed image corresponding to the ending proportion is greater than the compression loss threshold, the compressed image corresponding to the image compression proportion before the ending proportion is used as the target compressed image, and when the ending proportion is the maximum proportion and the compression loss of the compressed image of the maximum proportion is less than the compression loss threshold, the compressed image of the maximum proportion is directly used as the target compressed image.
According to the method, the compression ratio does not need to be manually set through experience and adjusted repeatedly, the target compressed image which is closest to and not larger than the compression loss threshold value (determined based on the image category of the original image) can be obtained by adopting a plurality of image compression ratios suitable for the original image through trial compression from small to large, so that the original image can be compressed to the greatest extent as possible on the basis of meeting the image requirement (not larger than the compression loss threshold value), and the image compression effect is also better improved on the basis of saving the labor cost.
In some implementation examples, sequentially performing compression processing on the original image according to a plurality of image compression ratios in the order from small to large until the target compressed image is acquired may be performed by referring to the following manner: firstly, sequentially taking a plurality of image compression ratios as target ratios from small to large, and performing compression processing on an original image by adopting the target ratios to obtain a compressed image corresponding to the target ratios; then, obtaining a compression loss value of a compressed image corresponding to the target proportion; and then updating the target proportion based on the comparison result of the compression loss value and the compression loss threshold value until a target compressed image is obtained. In this way, it is helpful to gradually find a target compressed image that can compress the image to the maximum extent and meets the requirements (not greater than the compression loss threshold).
Specifically, the step of updating the target ratio based on the comparison result between the compression loss value and the compression loss threshold until the target compressed image is acquired may be performed with reference to the following (1) to (4) based on the specific cases of the target ratio and the compression loss value corresponding to the target ratio:
(1) And under the condition that the target proportion is not the maximum proportion in the plurality of image compression proportions and the compression loss value corresponding to the target proportion is smaller than the compression loss threshold, updating the target proportion until the maximum proportion is adopted as the target proportion or until the compression loss value corresponding to the target proportion is larger than or equal to the compression loss threshold.
Specifically, the next image compression ratio arranged at the target ratio is used as the updated target ratio, and then the updated target ratio is used for image compression on the original image until the maximum ratio is used as the target ratio or until the compression loss value corresponding to the target ratio is greater than or equal to the compression loss threshold value, and at this time, the target ratio is stopped from being updated.
(2) And under the condition that the target proportion is the maximum proportion and the compression loss value corresponding to the target proportion is less than or equal to the compression loss threshold, adopting the compressed image corresponding to the maximum proportion as the target compressed image. That is, if the maximum ratio is tried, and the original image is compressed by the maximum ratio to obtain a compressed image, and the compression loss value of the compressed image is still not greater than the compression loss threshold, the compressed image corresponding to the maximum ratio is directly used as the target compressed image, and at this time, the maximum image compression effect is achieved.
(3) And when the compression loss value corresponding to the target proportion is larger than the compression loss threshold value, taking the compressed image corresponding to the image compression proportion one bit before the target proportion as the target compressed image. That is, when the original images are compressed in the sequence of the smaller image compression ratios to the larger image compression ratios until the image compression ratio (i.e., the ending ratio) with the compression loss value larger than the compression loss threshold is tried, the previous image compression ratio of the ending ratio is the ratio capable of compressing the original images to the maximum extent, and the compressed image obtained by the previous image compression ratio on the original image meets the requirement that the compressed image is closest to the compression loss threshold and not larger than the compression loss threshold.
(4) And taking the compressed image corresponding to the target proportion as the target compressed image under the condition that the compression loss value corresponding to the target proportion is equal to the compression loss threshold value. When the compression loss value of the target proportion is equal to the compression loss threshold, the compressed image corresponding to the target proportion just meets the requirement that the compressed image is closest to the compression loss threshold and is not greater than the compression loss threshold.
For convenience of understanding, for example, the compression ratios of the plurality of images are, from small to large, ratio 1, ratio 2, and ratio 3, respectively, up to ratio N (that is, the maximum ratio among the compression ratios of the plurality of images), and then compression processing is performed on the original image by using ratio 1 (at this time, ratio 1 is the target ratio), so as to obtain a compressed image corresponding to ratio 1; if the compression loss of the compressed image is smaller than the compression loss threshold, continuing to perform compression processing on the original image by adopting the ratio 2 (at the moment, the ratio 2 is taken as a target ratio, namely the target ratio is updated), and obtaining a compressed image corresponding to the ratio 2; if the compression loss of the compressed image corresponding to the ratio 2 is smaller than the compression loss threshold, the compressed image is continuously executed on the original image by adopting the ratio 3 (at this time, the ratio 3 is taken as the target ratio, that is, the target ratio is updated), and so on until the target compressed image with the compression loss which is closest to the compression loss threshold and not larger than the compression loss threshold is obtained. Such as, if the compression loss of the compressed image corresponding to the ratio 3 is greater than the compression loss threshold, regarding the compressed image corresponding to the ratio 2 as the target compressed image that is closest to the compression loss threshold and is not greater than the compression loss threshold, or if the compression loss of the compressed image corresponding to the ratio 3 is equal to the compression loss threshold, regarding the compressed image corresponding to the ratio 3 as the target compressed image; then, image compression attempts at ratio 4 to ratio N are not performed, because the compression loss of the compressed image corresponding to ratio 4 to ratio N is inevitably greater and greater than the compression loss threshold. Of course, if the compressed images corresponding to the ratios before the ratio N are all smaller than the compression loss threshold, the compressed image corresponding to the ratio N is taken as the target compressed image when the compressed image corresponding to the ratio N is smaller than or equal to the compression loss threshold, and the compressed image corresponding to the ratio N-1 is taken as the target compressed image when the compressed image corresponding to the ratio N is greater than the compression loss threshold. By the method, the target compressed image can be efficiently acquired.
The embodiment of the present disclosure provides a specific implementation example for obtaining a compression loss value of a compressed image corresponding to a target proportion, including the following steps a to C:
and step A, determining a pixel loss value of the compressed image corresponding to the target proportion based on the pixel value of the original image and the pixel value of the compressed image corresponding to the target proportion.
In some embodiments, the loss value may be calculated based on each pixel value in the original image and the corresponding pixel value in the compressed image corresponding to the target ratio, and the loss values corresponding to all the pixel values may be weighted and averaged to obtain the pixel loss value of the compressed image. The method can reasonably and objectively evaluate the pixel loss of the compressed image.
And B, determining a smoothness loss value of the compressed image corresponding to the target proportion according to the line smoothness of the original image and the line smoothness of the compressed image corresponding to the target proportion.
In some embodiments, the line smoothness is characterized based on the number of jaggies of the line; and the number of serrations is inversely related to the line smoothness, i.e., the greater the number of serrations, the lower the line smoothness. On this basis, when determining the smoothness loss value of the compressed image corresponding to the target proportion according to the line smoothness of the original image and the line smoothness of the compressed image corresponding to the target proportion, determining the line sawtooth increment of the compressed image corresponding to the target proportion according to the number of line sawteeth in the original image and the number of line sawteeth in the compressed image corresponding to the target proportion; then determining a target increment interval to which the line sawtooth increment of the compressed image belongs according to a plurality of preset sawtooth increment intervals; and finally, acquiring a smooth loss value corresponding to the target increment interval according to the preset corresponding relation between each sawtooth increment interval and the smooth loss value, and taking the acquired smooth loss value as the smooth loss value corresponding to the line sawtooth increment of the compressed image. In practical application, the range of the increment interval can be flexibly set according to requirements, and is not limited herein. By the method, the line smoothness of the image can be conveniently and accurately estimated.
And C, generating a compression loss value of the compressed image corresponding to the target proportion according to the pixel loss value and the smooth loss value.
In some specific implementation examples, a first weight corresponding to a pixel loss value and a second weight corresponding to a smoothing loss value may be first obtained, and the pixel loss value and the smoothing loss value may be normalized; and then carrying out weighted average operation on the normalized pixel loss value and the normalized smooth loss value according to the first weight and the second weight, and taking the operation result as the compression loss value of the compressed image corresponding to the target proportion. In practical application, the first weight and the second weight can be flexibly set according to requirements, and the numerical values of the first weight and the second weight can be the same or different, so that the influence of pixel loss and smoothing loss on the whole compression loss of the compressed image can be adjusted.
The method provided by the embodiment of the disclosure can comprehensively measure the pixel loss and the smoothing loss so as to objectively evaluate the compression loss of the compressed image, thereby ensuring the accuracy of the compression loss value.
On the basis of the foregoing embodiment, for easy understanding, reference may also be made to the flowchart of the image compression method shown in fig. 2, which mainly includes the following steps S202 to S216:
in step S202, an original image is acquired.
Step S204, a target class to which the original image belongs, a compression loss threshold value corresponding to the target class and a plurality of image compression ratios are obtained from a plurality of preset image classes.
And S206, sequencing the compression ratios of the plurality of images from small to large to obtain a sequencing result.
Step S208, determining the current target proportion from the plurality of image compression proportions according to the sorting result. The initial target scale is the minimum of the multiple image compression scales, and then the target scales can be updated sequentially until the target scales do not need to be updated.
Step S210, a compression loss value of the compressed image corresponding to the target proportion is obtained.
In step S212, the compression loss value is compared with the compression loss threshold value to obtain a comparison result.
Step S214, judging whether to update the target proportion according to the comparison result, if so, executing step S208; if not, step S216 is performed. Specifically, when the target ratio is not the maximum ratio among the plurality of image compression ratios and the compression loss value corresponding to the target ratio is smaller than the compression loss threshold, it is determined that the target ratio needs to be updated.
And step S216, acquiring a target compressed image according to the comparison result. Specifically, when the target proportion is the maximum proportion and the compression loss value corresponding to the target proportion is less than or equal to the compression loss threshold, the compressed image corresponding to the maximum proportion is adopted as the target compressed image; under the condition that the compression loss value corresponding to the target proportion is larger than the compression loss threshold value, taking the compressed image corresponding to the image compression proportion one bit before the target proportion as a target compressed image; and taking the compressed image corresponding to the target proportion as the target compressed image under the condition that the compression loss value corresponding to the target proportion is equal to the compression loss threshold value.
Through the mode, the compression ratio does not need to be set manually through experience and adjusted repeatedly, the target compressed image can be obtained by trying to compress the plurality of image compression ratios suitable for the original image from small to large, and the target compressed image is closest to and not larger than the compression loss threshold value, so that the original image can be compressed to the greatest extent possible on the basis of meeting the image requirements (not larger than the compression loss threshold value), the compressed image does not need to be checked manually, and the image compression effect is improved well on the basis of saving the labor cost.
It should be noted that, the image compression scenario is not limited in the embodiment of the present disclosure, for example, the image compression method provided in the embodiment of the present disclosure may be applied to a Unity content development platform, the Unity content development platform may be widely applied to various fields such as games, automobiles, architectural engineering, movie animation, and the like, and may be used to create, operate, and transform any real-time interactive 2D and 3D content, where a large number of images that need to be processed are usually involved in the Unity content development platform, manual compression is usually required, and it is also required to manually check whether the obtained compressed image meets requirements (such as whether distortion or not).
Corresponding to the foregoing image compression method, an embodiment of the present disclosure further provides an image compression apparatus, and fig. 3 is a schematic structural diagram of an image compression apparatus provided in an embodiment of the present disclosure, which may be implemented by software and/or hardware and may be generally integrated in an electronic device. As shown in fig. 3, the image compression apparatus 300 includes:
an original image obtaining module 302, configured to obtain an original image to be compressed;
a threshold and ratio obtaining module 304, configured to obtain, from multiple preset image categories, a target category to which an original image belongs, and a compression loss threshold and multiple image compression ratios corresponding to the target category;
the image compression module 306 is configured to sequentially perform compression processing on the original image according to a sequence from small to large according to a plurality of image compression ratios until a target compressed image is obtained; the target compressed image is a compressed image of which the compression loss is closest to the compression loss threshold value and is not greater than the compression loss threshold value among the compressed images corresponding to the plurality of image compression ratios.
The device does not need to manually set the compression ratio by experience and repeatedly adjust, but can adopt a plurality of image compression ratios suitable for the original image to try compression from small to large until a target compressed image is obtained, wherein the target compressed image is closest to and not greater than a compression loss threshold value, so that the original image can be compressed to the greatest extent possible on the basis of meeting the image requirements (not greater than the compression loss threshold value), and the image compression effect is also better improved on the basis of saving the labor cost.
In some embodiments, the apparatus further comprises a category setting module for setting a plurality of image categories in advance based on image content and/or image usage.
In some embodiments, the compression loss threshold is different for different image classes, and/or the compression ratio of the plurality of images is different for different image classes.
In some embodiments, the image compression module 306 is specifically configured to: sequentially taking a plurality of image compression ratios as target ratios from small to large, and performing compression processing on the original image by adopting the target ratios to obtain a compressed image corresponding to the target ratios; acquiring a compression loss value of a compressed image corresponding to the target proportion; and updating the target proportion based on the comparison result of the compression loss value and the compression loss threshold value until a target compressed image is obtained.
In some embodiments, the image compression module 306 is specifically configured to: when the target proportion is not the maximum proportion of the image compression proportions and the compression loss value corresponding to the target proportion is smaller than the compression loss threshold, updating the target proportion until the maximum proportion is adopted as the target proportion or until the compression loss value corresponding to the target proportion is larger than or equal to the compression loss threshold; when the target proportion is the maximum proportion and the compression loss value corresponding to the target proportion is smaller than or equal to the compression loss threshold, adopting the compressed image corresponding to the maximum proportion as a target compressed image; under the condition that the compression loss value corresponding to the target proportion is larger than the compression loss threshold value, taking the compressed image corresponding to the image compression proportion one bit before the target proportion as a target compressed image; and taking the compressed image corresponding to the target proportion as a target compressed image under the condition that the compression loss value corresponding to the target proportion is equal to the compression loss threshold value.
In some embodiments, the image compression module 306 is specifically configured to: determining a pixel loss value of the compressed image corresponding to the target proportion based on the pixel value of the original image and the pixel value of the compressed image corresponding to the target proportion; determining a smooth loss value of the compressed image corresponding to the target proportion according to the line smoothness of the original image and the line smoothness of the compressed image corresponding to the target proportion; and generating a compression loss value of the compressed image corresponding to the target proportion according to the pixel loss value and the smooth loss value.
In some embodiments, the line smoothness is characterized based on a number of jaggies of the line; the image compression module 306 is specifically configured to: determining the line sawtooth increment of the compressed image corresponding to the target proportion according to the number of the line sawtooth in the original image and the number of the line sawtooth in the compressed image corresponding to the target proportion; determining a target increment interval to which a line sawtooth increment of the compressed image belongs according to a plurality of preset sawtooth increment intervals; and acquiring a smooth loss value corresponding to the target increment interval according to a preset corresponding relation between each sawtooth increment interval and the smooth loss value, and taking the acquired smooth loss value as the smooth loss value corresponding to the line sawtooth increment of the compressed image.
In some embodiments, the image compression module 306 is specifically configured to: acquiring a first weight corresponding to the pixel loss value and a second weight corresponding to the smoothing loss value; normalizing the pixel loss value and the smooth loss value; and according to the first weight and the second weight, performing weighted average operation on the normalized pixel loss value and the normalized smoothing loss value, and taking an operation result as a compression loss value of the compressed image corresponding to the target proportion.
In some embodiments, the image compression method is applied to a Unity content development platform.
The image compression device provided by the embodiment of the disclosure can execute the image compression method provided by any embodiment of the disclosure, and has corresponding functional modules and beneficial effects of the execution method.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatus embodiments may refer to corresponding processes in the method embodiments, and are not described herein again.
An exemplary embodiment of the present disclosure also provides an electronic device including: at least one processor; and a memory communicatively coupled to the at least one processor. The memory stores a computer program executable by the at least one processor, the computer program, when executed by the at least one processor, is for causing the electronic device to perform a method according to an embodiment of the disclosure.
The disclosed exemplary embodiments also provide a non-transitory computer readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is adapted to cause the computer to perform a method according to an embodiment of the present disclosure.
The exemplary embodiments of the present disclosure also provide a computer program product comprising a computer program, wherein the computer program, when executed by a processor of a computer, is adapted to cause the computer to perform a method according to an embodiment of the present disclosure.
The computer program product may write program code for carrying out operations for embodiments of the present disclosure in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server.
Furthermore, embodiments of the present disclosure may also be a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, cause the processor to perform the image compression method provided by embodiments of the present disclosure. The computer-readable storage medium may take any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may include, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
Referring to fig. 4, a block diagram of a structure of an electronic device 400, which may be a server or a client of the present disclosure, which is an example of a hardware device that may be applied to aspects of the present disclosure, will now be described. Electronic device is intended to represent various forms of digital electronic computer devices, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 4, the electronic device 400 includes a computing unit 401 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) 402 or a computer program loaded from a storage unit 408 into a Random Access Memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the device 400 can also be stored. The calculation unit 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
A number of components in the electronic device 400 are connected to the I/O interface 405, including: an input unit 406, an output unit 407, a storage unit 408, and a communication unit 409. The input unit 406 may be any type of device capable of inputting information to the electronic device 400, and the input unit 406 may receive input numeric or character information and generate key signal inputs related to user settings and/or function control of the electronic device. Output unit 407 may be any type of device capable of presenting information and may include, but is not limited to, a display, speakers, a video/audio output terminal, a vibrator, and/or a printer. Storage unit 408 may include, but is not limited to, magnetic or optical disks. The communication unit 409 allows the electronic device 400 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers and/or chipsets, such as bluetooth (TM) devices, wiFi devices, wiMax devices, cellular communication devices, and/or the like.
Computing unit 401 may be a variety of general and/or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various dedicated Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The calculation unit 401 executes the respective methods and processes described above. For example, in some embodiments, the image compression method may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 408. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 400 via the ROM 402 and/or the communication unit 409. In some embodiments, the computing unit 401 may be configured to perform the image compression method by any other suitable means (e.g., by means of firmware).
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
As used in this disclosure, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and/or device (e.g., magnetic discs, optical disks, memory, programmable Logic Devices (PLDs)) used to provide machine instructions and/or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal used to provide machine instructions and/or data to a programmable processor.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising one of 8230; \8230;" 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present disclosure, which enable those skilled in the art to understand or practice the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the disclosure. Thus, the present disclosure is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (9)

1. An image compression method comprising:
acquiring an original image to be compressed;
acquiring a target class to which the original image belongs, a compression loss threshold value and a plurality of image compression ratios corresponding to the target class from a plurality of preset image classes; the compression loss thresholds corresponding to different image categories are different, and/or the compression ratios of a plurality of images corresponding to different image categories are different;
sequentially taking a plurality of image compression ratios as target ratios from small to large, and performing compression processing on the original image by adopting the target ratios to obtain a compressed image corresponding to the target ratios;
determining a pixel loss value of the compressed image corresponding to the target proportion based on the pixel value of the original image and the pixel value of the compressed image corresponding to the target proportion;
determining a smooth loss value of the compressed image corresponding to the target proportion according to the line smoothness of the original image and the line smoothness of the compressed image corresponding to the target proportion;
generating a compression loss value of the compressed image corresponding to the target proportion according to the pixel loss value and the smoothing loss value;
updating the target proportion based on the comparison result of the compression loss value and the compression loss threshold value until a target compressed image is obtained; the target compressed image is a compressed image of which the compression loss is closest to the compression loss threshold and is not greater than the compression loss threshold among the compressed images corresponding to the image compression ratios.
2. The image compression method of claim 1, wherein the method further comprises:
a plurality of image categories are set in advance based on image contents and/or image usages.
3. The image compression method according to claim 1, wherein the step of updating the target proportion based on the comparison result of the compression loss value and the compression loss threshold until the target compressed image is acquired comprises:
when the target proportion is not the maximum proportion of the image compression proportions and the compression loss value corresponding to the target proportion is smaller than the compression loss threshold, updating the target proportion until the maximum proportion is adopted as the target proportion or until the compression loss value corresponding to the target proportion is larger than or equal to the compression loss threshold;
when the target proportion is the maximum proportion and the compression loss value corresponding to the target proportion is smaller than or equal to the compression loss threshold, adopting the compressed image corresponding to the maximum proportion as a target compressed image;
under the condition that the compression loss value corresponding to the target proportion is larger than the compression loss threshold value, taking the compressed image corresponding to the image compression proportion one bit before the target proportion as a target compressed image;
and taking the compressed image corresponding to the target proportion as a target compressed image under the condition that the compression loss value corresponding to the target proportion is equal to the compression loss threshold value.
4. A method of image compression as claimed in claim 1 in which the line smoothness is characterised based on the number of jaggies of the line; determining a smoothness loss value of the compressed image corresponding to the target proportion according to the line smoothness of the original image and the line smoothness of the compressed image corresponding to the target proportion, wherein the step comprises the following steps of:
determining the line sawtooth increment of the compressed image corresponding to the target proportion according to the line sawtooth quantity in the original image and the line sawtooth quantity in the compressed image corresponding to the target proportion;
determining a target increment interval to which a line sawtooth increment of the compressed image belongs according to a plurality of preset sawtooth increment intervals;
and acquiring a smooth loss value corresponding to the target increment interval according to a preset corresponding relation between each sawtooth increment interval and the smooth loss value, and taking the acquired smooth loss value as the smooth loss value corresponding to the line sawtooth increment of the compressed image.
5. The image compression method according to claim 1, wherein the step of generating the compression loss value of the compressed image corresponding to the target scale according to the pixel loss value and the smoothing loss value comprises:
acquiring a first weight corresponding to the pixel loss value and a second weight corresponding to the smoothing loss value;
normalizing the pixel loss value and the smoothing loss value;
and according to the first weight and the second weight, carrying out weighted average operation on the normalized pixel loss value and the normalized smooth loss value, and taking an operation result as a compression loss value of the compressed image corresponding to the target proportion.
6. The image compression method of any one of claims 1 to 5, wherein the image compression method is applied to a Unity content development platform.
7. An image compression apparatus comprising:
the original image acquisition module is used for acquiring an original image to be compressed;
the threshold and proportion acquisition module is used for acquiring a target class to which the original image belongs, a compression loss threshold corresponding to the target class and a plurality of image compression proportions from a plurality of preset image classes; wherein, the compression loss threshold values corresponding to different image categories are different, and/or the compression ratios of a plurality of images corresponding to different image categories are different;
the image compression module is used for sequentially taking a plurality of image compression ratios as target ratios from small to large, and performing compression processing on the original image by adopting the target ratios to obtain a compressed image corresponding to the target ratios; determining a pixel loss value of the compressed image corresponding to the target proportion based on the pixel value of the original image and the pixel value of the compressed image corresponding to the target proportion; determining a smooth loss value of the compressed image corresponding to the target proportion according to the line smoothness of the original image and the line smoothness of the compressed image corresponding to the target proportion; generating a compression loss value of the compressed image corresponding to the target proportion according to the pixel loss value and the smoothing loss value; updating the target proportion based on the comparison result of the compression loss value and the compression loss threshold value until a target compressed image is obtained; the target compressed image is a compressed image of which the compression loss is closest to the compression loss threshold and is not greater than the compression loss threshold among the compressed images corresponding to the image compression ratios.
8. An electronic device, comprising:
a processor; and
a memory for storing a program, wherein the program is stored in the memory,
wherein the program comprises instructions which, when executed by the processor, cause the processor to carry out the image compression method according to any one of claims 1-6.
9. A computer-readable storage medium storing a computer program for executing the image compression method of any one of claims 1 to 6.
CN202210626130.0A 2022-06-02 2022-06-02 Image compression method, apparatus, device and medium Active CN115037937B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210626130.0A CN115037937B (en) 2022-06-02 2022-06-02 Image compression method, apparatus, device and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210626130.0A CN115037937B (en) 2022-06-02 2022-06-02 Image compression method, apparatus, device and medium

Publications (2)

Publication Number Publication Date
CN115037937A CN115037937A (en) 2022-09-09
CN115037937B true CN115037937B (en) 2023-04-07

Family

ID=83123184

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210626130.0A Active CN115037937B (en) 2022-06-02 2022-06-02 Image compression method, apparatus, device and medium

Country Status (1)

Country Link
CN (1) CN115037937B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111683254A (en) * 2020-06-24 2020-09-18 湖南国科微电子股份有限公司 Image compression method and device, electronic equipment and storage medium
CN113379858A (en) * 2021-05-31 2021-09-10 超级视线科技有限公司 Image compression method and device based on deep learning

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20010072430A (en) * 1999-06-14 2001-07-31 오노 시게오 Compression encoding method, recorded medium on which compression encoding program is recorded, and imaging device
US7085420B2 (en) * 2002-06-28 2006-08-01 Microsoft Corporation Text detection in continuous tone image segments
CN102957906A (en) * 2011-08-29 2013-03-06 广州九游信息技术有限公司 Method and system for image classifying compression
US9497357B2 (en) * 2013-11-20 2016-11-15 Kyocera Document Solutions Inc. Image compressing/decompressing apparatus and image forming apparatus
EP3185555B1 (en) * 2015-12-23 2023-07-05 Université de Genève Image compression method with negligible and quantifiable information loss and high compression ratio
JP6806264B2 (en) * 2017-09-22 2021-01-06 日本電気株式会社 Information processing equipment, information processing system, information processing method, and program
CN109376762A (en) * 2018-09-13 2019-02-22 西安万像电子科技有限公司 Image processing method and device
CN109672888B (en) * 2018-09-25 2022-04-22 平安科技(深圳)有限公司 Picture compression method, equipment and computer readable storage medium
CN109816739B (en) * 2018-12-14 2024-02-20 上海昇晔网络科技有限公司 Picture compression method, device, computer equipment and computer readable storage medium
CN110830807B (en) * 2019-11-04 2022-08-23 腾讯科技(深圳)有限公司 Image compression method, device and storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111683254A (en) * 2020-06-24 2020-09-18 湖南国科微电子股份有限公司 Image compression method and device, electronic equipment and storage medium
CN113379858A (en) * 2021-05-31 2021-09-10 超级视线科技有限公司 Image compression method and device based on deep learning

Also Published As

Publication number Publication date
CN115037937A (en) 2022-09-09

Similar Documents

Publication Publication Date Title
US11741292B2 (en) Adaptive content delivery
CN113808231B (en) Information processing method and device, image rendering method and device, and electronic device
US11861498B2 (en) Method and apparatus for compressing neural network model
CN110830437A (en) Data compression method, device, equipment and storage medium for high-frequency service data
CN112488060B (en) Target detection method, device, equipment and medium
CN112306793A (en) Method and device for monitoring webpage
CN115037937B (en) Image compression method, apparatus, device and medium
CN114374703B (en) Cloud mobile phone information acquisition method, device, equipment and storage medium
CN115731319A (en) Graph drawing method, device, equipment and storage medium
CN113556575A (en) Method, apparatus, device, medium and product for compressing data
CN106296757A (en) A kind of image processing method and device
CN111447219B (en) Image display method and device, storage medium and computer equipment
CN115205163A (en) Method, device and equipment for processing identification image and storage medium
CN114219731A (en) Picture optimization method, device, equipment and storage medium
CN105469433B (en) Picture compression method and equipment thereof
CN114138358A (en) Application program starting optimization method, device, equipment and storage medium
CN115880416A (en) Three-dimensional model display method and device, server and storage medium
CN115272524B (en) Multi-curve parallel drawing method, device, equipment and storage medium
CN115842892A (en) Picture compression method and device, electronic equipment and storage medium
CN113569092B (en) Video classification method and device, electronic equipment and storage medium
CN113762510B (en) Data processing method and device for target model, electronic equipment and medium
CN113900734B (en) Application program file configuration method, device, equipment and storage medium
CN114222073B (en) Video output method, video output device, electronic equipment and storage medium
CN113721877A (en) Screen pushing method, device, equipment and storage medium
CN115237240A (en) Method and device for managing power of multi-partition platform

Legal Events

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