A method and apparatus for lossy compression of JPG pictures

By using the target detection model to distinguish different areas of JPG images and combining DCT transformation and weighted quantization, more efficient lossy compression is achieved without losing image quality, solving the file size and computing resource consumption problems of existing JPG compression methods.

CN118612437BActive Publication Date: 2025-10-17XIAMEN UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410685525.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2025-10-17
Estimated Expiration
2044-05-30

AI Technical Summary

Technical Problem

Existing JPG image compression methods are difficult to effectively reduce file size without losing image quality, and machine learning compression methods consume large computing resources, rely on the distribution of training data, and are difficult to deploy.

Method used

The target detection model is used to detect targets in JPG images. Different weights are assigned to pixels based on the detection results. Combined with DCT transformation and weighted quantization, the quantization table is adjusted to distinguish the importance of different areas and lossy compression is performed.

Benefits of technology

While maintaining the clarity of key parts of the image, the image file size is reduced by 50% and can be deployed without changing the JPG format, avoiding the computing resource consumption and data flow changes of machine learning methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118612437B_ABST
    Figure CN118612437B_ABST
Patent Text Reader

Abstract

The application discloses a kind of JPG picture loss compression method and device, comprising: obtaining the JPG picture to be compressed and reading the RGB data of the JPG picture to be compressed;The target detection model is input to the JPG picture to be compressed, and the target detection result is obtained, each pixel in the JPG picture to be compressed is given corresponding weight according to the target detection result, and the weight matrix is obtained;RGB data is processed, and the data after DCT transformation is obtained;Weighted quantization is carried out on the data after DCT transformation using weight matrix, and the quantized data is obtained;The compressed JPG picture is obtained by standard coding to the quantized data.The application can combine the content of the JPG picture to be compressed, without changing JPG picture storage format, on the basis of keeping the clear key target area in JPG picture, compress the size of picture as far as possible.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of image processing, and particularly relates to a JPG picture lossy compression method and device. BACKGROUND

[0002] With the rapid development of network technology, people are increasingly dependent on online storage and transmission of pictures, so picture compression plays a crucial role in modern digital life. It can effectively reduce the size of picture files, thereby speeding up the upload and download speed and improving the fluency of web browsing. In addition, for devices with limited storage capacity, picture compression is particularly necessary, which can save valuable storage space and allow users to save more pictures in limited space. Compression technology can also optimize pictures without losing too much image quality, meeting the user's use requirements in different situations.

[0003] Picture compression has a significant effect on space reduction, which is mainly reflected in the comparison between the size of the picture in the memory and the size of the most commonly used JPG or PNG file. The size of the picture in the memory usually refers to the space occupied by its original data. These original data include every pixel point of the image and its color, brightness and other detailed information, so they often occupy a large space. On the disk, for JPG format, it uses lossy compression method to exchange smaller file size for a certain loss of image quality; while PNG format uses lossless compression method to compress under the premise of maintaining image quality.

[0004] Although PNG and JPG formats use compression methods that greatly reduce the space occupied by image data. But because pictures contain a large amount of information compared to text, lossless compression algorithms like PNG still cannot compress the space occupied by pictures to a satisfactory size. And the lossy compression algorithm used by JPG is difficult to achieve both image quality and space occupation. The larger compression rate of JPG format can greatly reduce the space occupied by pictures, but will cause unacceptable loss of image clarity. Moreover, as a general compression method, JPG format must carefully balance compression speed and space size, so it cannot be responsible for scenarios that focus on space occupation.

[0005] Existing new technologies more use machine learning methods to compress pictures. With the continuous progress of machine learning and deep learning technology, machine learning, especially deep learning, can learn the features and patterns of images and use this knowledge to more efficiently compress images. By training a deep neural network model, images can be converted to smaller sizes while maintaining the quality and details of the images. There are already some machine learning-based image compression methods that have been proposed and have achieved good results. For example, convolutional neural network (CNN) based methods can learn the features of images and use these features for image compression. In addition, there are also some methods based on generative adversarial networks (GAN) that can generate high-quality compressed images.

[0006] However, there are still many difficulties in applying machine learning to compress pictures in practice. On the one hand, using machine learning to compress a picture requires a large amount of computing resources for training and inference, which can result in a large amount of time spent when processing a large number of pictures. On the other hand, the performance of a machine learning model is largely dependent on the training data, and if the training data is inconsistent with the data distribution in the actual application scenario, it can cause the model performance to decline. Most importantly, the machine learning model compresses the picture into a binary file, and the decompression and reading of this file requires the use of the same model. This makes it necessary for enterprises to change the data flow of existing services when applying machine learning to compress pictures, and the large machine learning model also limits the large-scale deployment of picture compression services. Some enterprises try to further compress the size of the picture file without changing the JPG picture storage format and accepting a certain loss of image quality. SUMMARY

[0007] The purpose of the present application is to propose a JPG picture lossy compression method and device to solve the above-mentioned technical problems.

[0008] In a first aspect, the present application provides a JPG picture lossy compression method, comprising the following steps:

[0009] Obtaining a JPG picture to be compressed and reading the RGB data of the JPG picture to be compressed;

[0010] Inputting the JPG picture to be compressed into a target detection model to obtain a target detection result, and assigning a corresponding weight to each pixel in the JPG picture to be compressed according to the target detection result to obtain a weight matrix;

[0011] Processing the RGB data to obtain DCT transformed data;

[0012] Weighted quantization of the DCT transformed data using the weight matrix to obtain quantized data;

[0013] The quantized data is standard encoded to obtain a compressed JPG picture.

[0014] As preferred, a corresponding weight is assigned to each pixel in the JPG picture to be compressed according to the target detection result to obtain a weight matrix, specifically including:

[0015] Each pixel in the JPG picture to be compressed is traversed, the target detection result contains at least one target region, and it is judged according to the target detection result whether one of the pixels in the JPG picture to be compressed is covered by the at least one target region, if yes, the weight corresponding to the one of the pixels is assigned to a first weight value, otherwise the weight corresponding to the one of the pixels is assigned to a second weight value, the value range of the first weight value and the second weight value is an integer from 1 to 64 and the first weight value is greater than the second weight value;

[0016] The weight corresponding to each pixel in the JPG picture to be compressed is taken as each element of the weight matrix to construct the weight matrix.

[0017] As preferred, the target detection model includes a VGG16 model.

[0018] As preferred, the RGB data is processed to obtain the DCT transformed data, specifically including:

[0019] The RGB data is format converted and boundary padded to obtain YCbCr data, and a processing unit is divided;

[0020] The Cb channel and the Cr channel in the YCbCr data are down-sampled to obtain the sampled data;

[0021] The sampled data is DCT transformed to obtain the DCT transformed data.

[0022] As preferred, the DCT transformed data is weighted quantized by using the weight matrix to obtain the quantized data, specifically including:

[0023] The compression parameters are obtained, the quantization table of the Y channel is generated according to the compression parameters, the scores of the frequencies from 0 to m in the quantization table of the Y channel are adjusted to be reduced, and the scores of the remaining frequencies remain unchanged to obtain the adjusted quantization table;

[0024] The integral value of the arithmetic mean of the weights corresponding to all pixels in each processing unit is calculated, and the weights of adjacent processing units are adjusted so that the difference between the weights of adjacent processing units does not exceed 1 to obtain the weight corresponding to each processing unit;

[0025] The DCT transformed data is divided by the corresponding score in the adjusted quantization table to obtain the quantized processing unit;

[0026] The scores of all frequencies in the quantized processing unit are adjusted based on the weight corresponding to each processing unit, to obtain quantized data.

[0027] As a preferred, the scores of all frequencies in the quantized processing unit are adjusted based on the weight corresponding to each processing unit, and specifically includes:

[0028] The weight corresponding to the processing unit is w;

[0029] For each processing unit, in response to determining that one of the frequencies in the quantized processing unit is greater than or equal to 0 and less than w, the score of the one of the frequencies remains unchanged;

[0030] In response to determining that one of the frequencies in the quantized processing unit is greater than or equal to max(w, 32), the score of the one of the frequencies is set to 0;

[0031] For the processing unit with w less than 32, the scores of the frequencies in the quantized processing unit greater than or equal to w and less than 32 are sorted from small to large and grouped, and the scores in the group are set to the average of the scores in the group.

[0032] In a second aspect, the present application provides a JPG picture lossy compression device, comprising:

[0033] A data reading module configured to obtain a JPG picture to be compressed and read RGB data of the JPG picture to be compressed;

[0034] A target detection module configured to input the JPG picture to be compressed into a target detection model to obtain a target detection result, and assign a corresponding weight to each pixel in the JPG picture to be compressed according to the target detection result to obtain a weight matrix;

[0035] A data processing module configured to process the RGB data to obtain DCT transformed data;

[0036] A weighted quantization module configured to perform weighted quantization on the DCT transformed data using the weight matrix to obtain quantized data;

[0037] An encoding module configured to perform standard encoding on the quantized data to obtain a compressed JPG picture.

[0038] In a third aspect, the present application provides an electronic device, comprising one or more processors; a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the implementations of the first aspect.

[0039] In a fourth aspect, the present application provides a computer readable storage medium, having stored thereon a computer program, which, when executed by a processor, implements the method according to any implementation form of the first aspect.

[0040] In a fifth aspect, the present application provides a computer program product comprising a computer program which, when executed by a processor, implements the method according to any implementation form of the first aspect.

[0041] Compared with the prior art, the present application has the following beneficial effects:

[0042] (1) The JPG picture lossy compression method proposed in the present application adjusts the generated quantization table, reduces the loss of key low-frequency DCT frequency as much as possible, so that the picture has better image quality at a higher compression ratio compared with general JPG pictures, while maintaining similar image size.

[0043] (2) The JPG picture lossy compression method proposed in the present application uses a target detection model to detect the target of the JPG picture to be compressed, so as to distinguish different parts of the JPG picture to be compressed, reduce the occupied space of the picture, and at the same time not lose important information. For common photos of 1MB or more, the JPG picture lossy compression method proposed in the present application reduces the file size by an additional 50% compared with the standard JPG compression method.

[0044] (3) The JPG picture lossy compression method proposed in the present application applies the target detection method to the traditional JPG picture compression process. Unlike the method of completely compressing pictures using machine learning, the present application does not change the format of the file, that is, it does not need to be decompressed, and can be opened and viewed without any external tools. This feature allows enterprises to not need to change the data flow of the service, and can be deployed in large quantities. BRIEF DESCRIPTION OF DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0046] Figure 1 The flowchart of the JPG picture lossy compression method of the embodiments of the present application;

[0047] Figure 2 The flowchart of the JPG picture lossy compression method of the embodiments of the present application;

[0048] Figure 3A schematic diagram of a target detection model used in a JPG picture lossy compression method of an embodiment of the present application;

[0049] Figure 4 A schematic diagram of a Y component quantization bar before and after adjustment in a JPG picture lossy compression method of an embodiment of the present application;

[0050] Figure 5 A schematic diagram of a JPG picture lossy compression device of an embodiment of the present application;

[0051] Figure 6 A hardware structure schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0052] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.

[0053] Figure 1 A JPG picture lossy compression method provided by an embodiment of the present application is shown, which comprises the following steps:

[0054] S1, obtaining a JPG picture to be compressed and reading RGB data of the JPG picture to be compressed.

[0055] Specifically, referring to Figure 2 , the preliminarily read RGB data records the length, width and pixels of the JPG picture. The pixels are stored in the form of a one-dimensional byte array in the memory, and the pixel information of the JPG picture is stored in the form of first row and then column. Each pixel uses 3 bytes to represent the values of R, G and B three channels respectively.

[0056] Embodiments of the present application apply a target detection method of machine learning to a traditional JPG picture compression process. The JPG picture divides the picture into 8x8 processing units, and each processing unit is represented by a series of scores from 0 to 63 after DCT transformation. The quality loss of the JPG picture occurs in the quantization process of the DCT coefficients. The quality loss of the standard JPG picture processing is entirely derived from the precision error of the integer division of the quantization table. And because the human eye is not sensitive to high-frequency information, discarding high-frequency components can also achieve the effect of sacrificing picture quality for smaller size. Since the quantization table of the JPG picture is unique, the quality compression in the integer division of the quantization table cannot be applied to each processing unit of the picture. But the method of discarding high-frequency components can achieve the effect of lossy compression by discarding any high-frequency components, so it becomes the basis of the embodiments of the present application.

[0057] S2, input the JPG picture to be compressed into a target detection model to obtain a target detection result, and assign a corresponding weight to each pixel in the JPG picture to be compressed according to the target detection result to obtain a weight matrix.

[0058] In specific embodiments, assigning a corresponding weight to each pixel in the JPG picture to be compressed according to the target detection result to obtain a weight matrix specifically includes:

[0059] Traverse each pixel in the JPG picture to be compressed. The target detection result contains at least one target region. Determine whether one of the pixels in the JPG picture to be compressed is covered by the at least one target region according to the target detection result. If yes, assign a first weight value to the weight corresponding to the one of the pixels. If not, assign a second weight value to the weight corresponding to the one of the pixels. The first weight value and the second weight value are integers in the range of 1-64, and the first weight value is greater than the second weight value.

[0060] Assign the weight corresponding to each pixel in the JPG picture to be compressed as each element of the weight matrix to construct the weight matrix.

[0061] In specific embodiments, the target detection model includes a VGG16 model.

[0062] Specifically, the target detection model is used to detect the target in the JPG picture to be compressed, assign a higher weight to the target region, and assign a lower weight to other regions to obtain a weight matrix with the same dimension as the original picture, so that the target region has higher clarity after compression. Each element of the weight matrix is the weight of the pixel at the corresponding position of the JPG picture to be compressed. The weight of each pixel is an integer in the range of [1, 64]. The target detection model used in the embodiments of the present application is a VGG16 model, and other target detection models can also be used. The specific structure of the target detection model in the embodiments of the present application is not limited, as long as it can identify the target region. For reference Figure 3For example, the VGG16 model is used to adjust the size of the JPG picture to be compressed, and then extract features through several convolutional layers and pooling layers. Since the target detection is not the focus of the present application, the present application does not have other requirements for the target detection model, and any target detection method can achieve the purpose. The target detection model finally outputs several groups of information, each group of information contains four parameters to determine a target region, if a pixel of the JPG picture to be compressed is covered by at least one region, the corresponding position in the weight matrix is assigned a higher weight, i.e. the first weight value, otherwise a lower weight, i.e. the second weight value. In one embodiment, the first weight value is set to 56 and the second weight value is set to 4. In other embodiments, the first weight value and the second weight value can also be selected as other values, but need to meet the requirements of being an integer in the range [1, 64] and the first weight value being greater than the second weight value.

[0063] S3, processing the RGB data to obtain DCT transformed data.

[0064] In specific embodiments, step S3 specifically includes:

[0065] Converting the format of the RGB data and performing boundary padding to obtain YCbCr data, and dividing the processing unit;

[0066] Down-sampling the Cb channel and the Cr channel in the YCbCr data to obtain the sampled data;

[0067] Performing DCT transformation on the sampled data to obtain the DCT transformed data.

[0068] Specifically, format conversion and boundary padding are classic steps in the standard compression process of JPG pictures. The format conversion formula from RGB data to YCbCr data used in the embodiments of the present application is:

[0069] Y=(0.299*r)+(0.587*g)+(0.114*b)-128.0;

[0070] Cr=-(0.168736*r)-(0.331264*g)+(0.5*b);

[0071] Cb=(0.5*r)-(0.418688*g)-(0.081312*b);

[0072] Then the length and width of the JPG picture to be compressed are padded to be an integer multiple of 8, and then divided into several processing units with a size of 8x8.

[0073] Because the human eye is not sensitive to the Cb and Cr channels, the general JPG standard down-samples these two channels, that is, one byte is used to represent 2x2 bytes in the original channel. The sampling formula used in the embodiments of the present application is:

[0074]

[0075] where x is the sampled data, a, b, c and d are respectively the data of 2x2 pixels in the Cb / Cr channel, and A, B, C and D are respectively the data of 2x2 pixels in the Y channel.

[0076] The DCT transformation is performed on the sampled data, and 64 frequency coefficients of 64 different frequencies of sine waves in [0, 63] are used to represent 64 values in each processing unit. The 64 frequency coefficients are arranged in order of frequency from low to high, and the coefficient of the sine wave with low frequency is called a low-frequency component, and vice versa. The arrangement uses the "zigzag scanning" as in the standard JPG processing algorithm, and the data after the DCT transformation is represented in the form of a two-dimensional matrix.

[0077] The DCT transformation and processing are the same as in the classic JPG picture processing, and the formula for an 8x8 block is:

[0078]

[0079] S4, the data after the DCT transformation is weighted and quantized using a weight matrix to obtain quantized data.

[0080] In specific embodiments, step S4 specifically includes:

[0081] Obtaining a compression parameter, generating a quantization table for the Y channel according to the compression parameter, adjusting the values of the frequencies 0-m in the quantization table for the Y channel to be lower, and keeping the values of the remaining frequencies unchanged to obtain an adjusted quantization table;

[0082] Calculating the integer value of the arithmetic mean of the weights corresponding to all pixels in each processing unit, and adjusting the weights of adjacent processing units so that the difference between the weights of adjacent processing units does not exceed 1 to obtain the weight corresponding to each processing unit;

[0083] Dividing the data after the DCT transformation by the corresponding values in the adjusted quantization table to obtain quantized processing units;

[0084] Traversing each processing unit, segmenting and adjusting the values of all frequencies in the quantized processing units based on the weight corresponding to each processing unit to obtain quantized data.

[0085] In specific embodiments, each processing unit is traversed, and the scores of all frequencies in the quantized processing unit are adjusted in segments based on the weight corresponding to each processing unit, specifically including:

[0086] Let the weight corresponding to the processing unit be w;

[0087] For each processing unit, in response to determining that one of the frequencies in the quantized processing unit is greater than or equal to 0 and less than w, the score of the one of the frequencies remains unchanged;

[0088] In response to determining that one of the frequencies in the quantized processing unit is greater than or equal to max(w, 32), the score of the one of the frequencies is set to 0;

[0089] For processing units with w less than 32, the scores of the frequencies in the quantized processing unit that are greater than or equal to w and less than 32 are sorted from small to large and grouped, and the scores in the group are set to the average of the scores in the group.

[0090] Specifically, the weight matrix in step S2 is used to weight and quantize the data after DCT transformation, specifically including the following sub-steps:

[0091] S31, generate a quantization table for the Y channel according to the user-specified compression coefficient, and reduce the m+1 scores of the frequencies [0, m] in the quantization table of the Y component to obtain an adjusted quantization table. In the embodiments of the present application, m=5 is taken as an example, that is, the corresponding scores of the first 6 low-frequency components after zigzag run-length coding are reduced. Since the processing algorithm of the embodiments of the present application can only retain a few low-frequency components for the unimportant background part of the picture, the quantization table used by the standard JPG algorithm is not designed for this extreme lossy compression case, and here the scores of the low-frequency components in the quantization table of the Y component are reduced, so that the low-frequency components have smaller loss. The form of the adjustment of the quantization table of the Y component is as shown in Figure 4 .

[0092] S32, calculate the weight of all pixels in each processing unit, so that each processing unit obtains a weight. Here the weight of each processing unit is the arithmetic mean of the weight of all pixels in the processing unit and is rounded to the nearest integer. If the weight of adjacent processing units changes too quickly, the compressed JPG picture will have some jaggedness, so in a further preferred solution, the weight of adjacent processing units can be adjusted to decay slowly. Specifically, starting from the processing unit with the largest weight, the following processing is performed in turn, checking the difference between the four adjacent processing units and the processing unit, if greater than 1, the adjacent processing unit is modified to the weight of the processing unit minus 1, and a modification queue is added. Take a processing unit from the modification queue and repeat the above process, eventually achieving the effect that the difference between any two adjacent processing units does not exceed 1, and obtaining the weight corresponding to each processing unit.

[0093] S33, the DCT transformed data and the frequency position of the quantization table correspond one by one, so first apply the adjusted quantization table in step S31 to each processing unit in the DCT transformed data as the standard JPG algorithm, that is, divide the DCT transformed data by the corresponding value in the adjusted quantization table to obtain the quantized processing unit, then according to the weight corresponding to each processing unit in step S32, additional compression is performed, the quantized processing unit is slightly adjusted to adapt to Huffman coding, and the high frequency components with less influence are directly discarded. Specifically, let the weight of the processing unit be w, within a single processing unit, for frequency components with a frequency less than w, no change is made, that is, the corresponding value remains unchanged, for frequency components with a frequency greater than or equal to max(w, 32), they are discarded, that is, their corresponding values are set to 0, achieving the effect of lossy compression. For processing units with w less than 32, arrange all frequency components with a frequency between [w, 32) in ascending order of value, and group the arrangement results in groups of 8 each, and set the 8 values in each group to the average of all values in the group, achieving the effect of reducing the number of value types, thereby facilitating Huffman coding.

[0094] S5, standard encoding is performed on the quantized data to obtain the compressed JPG picture.

[0095] Specifically, the quantized data is encoded into a compressed JPG picture according to the standard. This step is consistent with the standard JPG processing procedure, first using the standard Huffman coding to quantize the data, then adding a file header and metadata to generate the compressed JPG picture.

[0096] The application can combine the content of the JPG picture to be compressed, compress the size of the picture as much as possible on the basis of keeping the key part of the image clear without changing the storage format of the JPG picture. The method detects and judges the key target area in the JPG picture to be compressed and gives a higher weight, and compresses different areas according to the weight, so as to realize the effect of greatly reducing the space occupied by the picture while keeping the format of the JPG unchanged.

[0097] The above steps S1-S5 do not necessarily represent the order between the steps, but the step symbols, and the order between the steps can be adjusted.

[0098] Further reference Figure 5 , as the implementation of the method shown in the above figures, the application provides an embodiment of a JPG picture lossy compression device, which corresponds to the method embodiment shown in Figure 1 , and the device can be applied to various electronic devices.

[0099] The application embodiment provides a JPG picture lossy compression device, which comprises:

[0100] The data reading module 1 is configured to obtain the JPG picture to be compressed and read the RGB data of the JPG picture to be compressed;

[0101] The target detection module 2 is configured to input the JPG picture to be compressed into a target detection model to obtain a target detection result, and give a corresponding weight to each pixel in the JPG picture to be compressed according to the target detection result to obtain a weight matrix;

[0102] The data processing module 3 is configured to process the RGB data to obtain DCT transformed data;

[0103] The weighted quantization module 4 is configured to perform weighted quantization on the DCT transformed data by using the weight matrix to obtain quantized data;

[0104] The encoding module 5 is configured to perform standard encoding on the quantized data to obtain a compressed JPG picture.

[0105] Figure 6 The hardware structure diagram of the electronic device provided by the application embodiment is shown in the figure. Figure 6 As shown in the figure, the electronic device of the embodiment comprises a processor 601 and a memory 602; the memory 602 is used to store computer execution instructions; the processor 601 is used to execute the computer execution instructions stored in the memory to realize each step executed by the electronic device in the above embodiment. For details, please refer to the related description in the foregoing method embodiment.

[0106] Optionally, the memory 602 can be independent or integrated with the processor 601.

[0107] When the memory 602 is independently arranged, the electronic device further includes a bus 603 for connecting the memory 602 and the processor 601.

[0108] The embodiment of the present application further provides a computer storage medium, and the computer storage medium stores computer execution instructions, and when a processor executes the computer execution instructions, the method described above is realized.

[0109] The embodiment of the present application further provides a computer program product, and the computer program product includes a computer program, and when the computer program is executed by a processor, the method described above is realized.

[0110] In the embodiments of the present application, it should be understood that the disclosed devices and methods can be implemented in other manners. For example, the above-described device embodiments are merely illustrative, and the division of modules can be different, for example, some features can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the modules shown or discussed can be indirect coupling or communication connection through some interfaces, devices or modules, and can be electrical, mechanical or other forms.

[0111] The modules illustrated as separate components can or can not be physically separate, and the components illustrated as modules can or can not be physical units, i.e., can be located in one place, or can be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to implement the embodiments of the present application.

[0112] In addition, the functional modules in each embodiment of the present application can be integrated in one processing unit, or each module can be physically present alone, or two or more modules can be integrated in one unit. The unit formed by the above modules can be realized in the form of hardware, or in the form of hardware plus software function unit.

[0113] The integrated modules realized in the form of software function modules can be stored in a computer readable storage medium. The software function modules stored in the storage medium include a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute part of the steps of the method of each embodiment of the present application.

[0114] It should be appreciated that the above-mentioned processor can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the application can be directly embodied as hardware processor execution, or executed by a combination of hardware and software modules in the processor.

[0115] The memory can include a high-speed RAM memory, and can also include a non-volatile storage NVM, such as at least one disk memory, and can also be a U disk, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.

[0116] The bus can be an industry standard architecture (ISA) bus, a peripheral component interconnect (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, the bus in the drawings of the present application does not limit to only one bus or one type of bus.

[0117] The above-mentioned storage medium can be realized by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.

[0118] An exemplary storage medium is coupled to the processor, so that the processor can read information from the storage medium and can write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic device or a host device.

[0119] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware. The foregoing program can be stored in a computer readable storage medium. The program executes to perform the steps of the above-mentioned method embodiments; and the foregoing storage medium includes various storage media that can store program codes, such as ROM, RAM, magnetic disk or optical disk.

[0120] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A JPG image lossy compression method, characterized in that: The following steps are involved: Obtain a JPG image to be compressed and read the RGB data of the JPG image to be compressed; Input the JPG image to be compressed into the target detection model to obtain a target detection result, and assign a corresponding weight to each pixel in the JPG image to be compressed according to the target detection result to obtain a weight matrix; Processing the RGB data to obtain DCT transformed data; The weight matrix is ​​used to perform weighted quantization on the DCT transformed data to obtain quantized data, specifically including: Obtaining compression parameters, generating a quantization table for the Y channel according to the compression parameters, adjusting and reducing the scores of frequencies 0 to m in the quantization table of the Y channel, and keeping the scores of other frequencies unchanged, to obtain an adjusted quantization table; Calculate the integer value of the arithmetic mean of the weights corresponding to all pixels in each processing unit, and adjust the weights of adjacent processing units so that the difference between the weights of adjacent processing units does not exceed 1, to obtain the weight corresponding to each processing unit; Dividing the DCT transformed data by the corresponding score in the adjusted quantization table to obtain a quantized processing unit; Traversing each processing unit, and adjusting the scores of all frequencies in the quantized processing unit in sections based on the weight corresponding to each processing unit to obtain quantized data, specifically including: Let the weight corresponding to the processing unit be w; For each processing unit, in response to determining that one of the frequencies in the quantized processing unit is greater than or equal to 0 and less than w, the score of the one of the frequencies remains unchanged; In response to determining that one of the frequencies in the quantized processing unit is greater than or equal to max(w, 32), setting the score of the one of the frequencies to 0; For the processing units with w less than 32, sort the scores in the quantized processing units with frequencies greater than or equal to w and less than 32 from small to large and group them, and set the scores in the group to the average of the scores in the group; The quantized data is subjected to standard encoding to obtain a compressed JPG image.

2. The JPG image lossy compression method according to claim 1, wherein: The step of assigning a corresponding weight to each pixel in the JPG image to be compressed according to the target detection result to obtain a weight matrix specifically includes: Traversing each pixel in the JPG image to be compressed, the target detection result including at least one target area, determining whether one of the pixels in the JPG image to be compressed is covered by the at least one target area according to the target detection result, and if so, assigning a first weight value to the weight corresponding to the one of the pixels; otherwise, assigning a second weight value to the weight corresponding to the one of the pixels, where the first weight value and the second weight value are integers ranging from 1 to 64, and the first weight value is greater than the second weight value; The weight matrix is ​​constructed by taking the weight corresponding to each pixel in the JPG image to be compressed as each element of the weight matrix.

3. The JPG image lossy compression method according to claim 1, wherein: The target detection model includes a VGG16 model.

4. The JPG image lossy compression method according to claim 1, wherein: The processing of the RGB data to obtain DCT transformed data specifically includes: Performing format conversion and boundary filling on the RGB data to obtain YCbCr data, and dividing the data into processing units; Downsampling the Cb channel and the Cr channel in the YCbCr data to obtain sampled data; Performing DCT transformation on the sampled data to obtain DCT transformed data.

5. A JPG image lossy compression device, characterized in that: include: A data reading module is configured to obtain a JPG image to be compressed and read RGB data of the JPG image to be compressed; an object detection module configured to input the JPG image to be compressed into an object detection model to obtain an object detection result, and assign a corresponding weight to each pixel in the JPG image to be compressed according to the object detection result to obtain a weight matrix; A data processing module is configured to process the RGB data to obtain DCT transformed data; The weighted quantization module is configured to perform weighted quantization on the DCT transformed data using the weight matrix to obtain quantized data, specifically including: Obtaining compression parameters, generating a quantization table for the Y channel according to the compression parameters, adjusting and reducing the scores of frequencies 0 to m in the quantization table of the Y channel, and keeping the scores of other frequencies unchanged, to obtain an adjusted quantization table; Calculate the integer value of the arithmetic mean of the weights corresponding to all pixels in each processing unit, and adjust the weights of adjacent processing units so that the difference between the weights of adjacent processing units does not exceed 1, to obtain the weight corresponding to each processing unit; Dividing the DCT transformed data by the corresponding score in the adjusted quantization table to obtain a quantized processing unit; Traversing each processing unit, and adjusting the scores of all frequencies in the quantized processing unit in sections based on the weight corresponding to each processing unit to obtain quantized data, specifically including: Let the weight corresponding to the processing unit be w; For each processing unit, in response to determining that one of the frequencies in the quantized processing unit is greater than or equal to 0 and less than w, the score of the one of the frequencies remains unchanged; In response to determining that one of the frequencies in the quantized processing unit is greater than or equal to max(w, 32), setting the score of the one of the frequencies to 0; For the processing units with w less than 32, sort the scores in the quantized processing units with frequencies greater than or equal to w and less than 32 from small to large and group them, and set the scores in the group to the average of the scores in the group; The encoding module is configured to perform standard encoding on the quantized data to obtain a compressed JPG image.

6. An electronic device comprising: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.

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

8. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Data processing method and device, computer equipment and readable storage medium

    CN115103189A

  • Method for selecting JPEG quantization tables for low bandwidth applications

    US5883979A