JPG picture lossy compression method and device

Lossy compression of JPG images is performed through the target detection model, and weighted quantization and adjustment quantization tables are used to solve the compression problem of JPG images on devices with limited storage capacity, achieving higher compression rate and image quality, and is suitable for large-scale deployment .

CN118612437AActive Publication Date: 2024-09-06XIAMEN UNIV +1
View PDF 3 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing JPG image compression methods are difficult to significantly reduce file size while maintaining image quality, and the traditional JPG format is difficult to balance between compression speed and space size, especially on devices with limited storage capacity. Machine learning methods However, large-scale deployment is limited due to computing resource consumption and model dependency.

Method used

The target detection model is used to perform lossy compression on JPG images. The RGB data is obtained for DCT transformation and weighted quantization, and the weight matrix is ​​used to adjust the quantization table to achieve differential compression of different image areas, ensuring the retention of key low-frequency components and reducing file size. .

Benefits of technology

Without changing the JPG image format, a higher compression rate and better image quality are achieved. Compared with the standard JPG compression method, the file size is reduced by an additional 50%, and there is no need to change the data flow and external tools. Easy to deploy on a large scale.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118612437A
    Figure CN118612437A
Patent Text Reader

Abstract

The invention discloses a lossy compression method and device for a JPG picture. The lossy compression method comprises the steps that the JPG picture to be compressed is acquired, and RGB data of the JPG picture to be compressed are read; inputting a to-be-compressed JPG picture into the target detection model to obtain a target detection result, and endowing each pixel in the to-be-compressed JPG picture with a corresponding weight according to the target detection result to obtain a weight matrix; processing the RGB data to obtain data after DCT (Discrete Cosine Transform); carrying out weighted quantization on the data subjected to DCT by adopting a weight matrix to obtain quantized data; and carrying out standard coding on the quantized data to obtain a compressed JPG picture. According to the method, the content of the to-be-compressed JPG picture can be combined, and the size of the picture can be compressed as much as possible on the basis that the storage format of the JPG picture is not changed and the key target area in the JPG picture is kept clear.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing, and in particular to a JPG picture lossy compression method and device. Background Art

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

[0003] Image compression can significantly reduce space, as shown by the size of the image in memory compared to the size of the image stored as the most commonly used JPG or PNG files. The size of an image in memory usually refers to the space occupied by its raw data. This raw data includes every pixel of the image and its color, brightness and other detailed information, so it often takes up a large amount of space. On disk, for the JPG format, it uses lossy compression, sacrificing a certain amount of image quality in exchange for a smaller file size; while the PNG format uses lossless compression, which can be compressed while maintaining image quality.

[0004] Although the compression methods used by PNG and JPG formats greatly reduce the space occupied by image data. However, compared with text, images contain a lot of information, so lossless compression algorithms like PNG still cannot compress the space occupied by images to a satisfactory size. The lossy compression algorithm used by JPG is difficult to achieve both image quality and space occupied. The higher compression rate of JPG format can greatly reduce the space occupied by images, but it 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 is not suitable for scenarios that focus on space occupied.

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

[0006] However, in practice, applying machine learning to compress images still faces many difficulties. On the one hand, using machine learning to compress an image requires a lot of computing resources for training and inference, which may result in a lot of time spent processing a large number of images. On the other hand, the performance of the machine learning model depends largely on the training data. If the training data is inconsistent with the data distribution in the actual application scenario, the model performance may be degraded. Most importantly, the machine learning model compresses the image into a binary file, and the same model is required to decompress and read the file. In this way, for enterprises, when applying machine learning to compress images, they have to change the data flow of existing services. At the same time, the huge machine learning model also limits the large-scale deployment of image compression services. Some companies try to further compress the size of image files without changing the JPG image storage format and accepting a certain loss of image quality. Summary of the invention

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

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

[0009] Get the JPG image to be compressed and read the RGB data of the JPG image to be compressed;

[0010] Input the JPG image to be compressed into the target detection model to obtain the target detection result, and assign corresponding weights to each pixel in the JPG image to be compressed according to the target detection result to obtain a weight matrix;

[0011] Process the RGB data to obtain the data after DCT transformation;

[0012] The weight matrix is ​​used to perform weighted quantization on the data after DCT transformation to obtain quantized data;

[0013] The quantized data is encoded by standard encoding to obtain a compressed JPG image.

[0014] Preferably, a corresponding weight is assigned to each pixel in the JPG image to be compressed according to the target detection result to obtain a weight matrix, which specifically includes:

[0015] Traverse each pixel in the JPG image to be compressed, the target detection result includes at least one target area, and determine 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. If so, assign a first weight value to the weight corresponding to one of the pixels; otherwise, assign a second weight value to the weight corresponding to one of the pixels, and 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 image to be compressed is used as each element of the weight matrix to construct a weight matrix.

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

[0018] Preferably, the RGB data is processed to obtain data after DCT transformation, specifically including:

[0019] Perform format conversion and border filling on RGB data to obtain YCbCr data, and divide the processing units;

[0020] Downsample the Cb channel and Cr channel in the YCbCr data to obtain sampled data;

[0021] Perform DCT transformation on the sampled data to obtain DCT transformed data.

[0022] Preferably, a weight matrix is ​​used to perform weighted quantization on the DCT transformed data to obtain quantized data, which specifically includes:

[0023] Obtain compression parameters, generate a quantization table of the Y channel according to the compression parameters, adjust and reduce the scores of frequencies 0 to m in the quantization table of the Y channel, and keep the scores of other frequencies unchanged, thereby obtaining an adjusted quantization table;

[0024] 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, thereby obtaining the weight corresponding to each processing unit;

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

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

[0027] Preferably, 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, specifically includes:

[0028] Let the weight corresponding to the processing unit be 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 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), setting the score of one of the frequencies to 0;

[0031] For processing units with w less than 32, the scores in the quantized processing units with frequencies 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 all set to the average of the scores in the group.

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

[0033] 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;

[0034] The target detection module is configured to input the JPG image to be compressed into the target detection model to obtain the 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;

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

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

[0037] The encoding module is configured to perform standard encoding on the quantized data to obtain a compressed JPG image.

[0038] In a third aspect, the present invention provides an electronic device comprising one or more processors; a storage device for storing one or more programs, wherein 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 implementation manner in the first aspect.

[0039] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.

[0040] In a fifth aspect, the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.

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

[0042] (1) The JPG image lossy compression method proposed in the present invention adjusts the generated quantization table to minimize the loss of key low-frequency DCT frequencies, so that the image has better image quality than the general JPG image at a higher compression rate while keeping the image size similar.

[0043] (2) The JPG image lossy compression method proposed in the present invention uses the target detection model to perform target detection on the JPG image to be compressed, so as to distinguish different parts of the JPG image to be compressed, reduce the space occupied by the image, and do not lose important information. For commonly taken photos of more than 1MB, the JPG image lossy compression method proposed in the present invention reduces the file size by an additional 50% compared with the standard JPG compression method.

[0044] (3) The JPG image lossy compression method proposed in the present invention applies the target detection method to the traditional JPG image compression process. Unlike the method of compressing images completely using machine learning, the present invention does not change the file format, that is, no decompression operation is required, and it can be opened and viewed without any external tools. This feature allows enterprises to deploy in large quantities without changing the data flow of the service. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0046] Figure 1 A schematic diagram of the process of a JPG image lossy compression method according to an embodiment of the present application;

[0047] Figure 2 This is a flowchart of a JPG image lossy compression method according to an embodiment of the present application;

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

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

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

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

[0052] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

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

[0054] S1, obtain a JPG image to be compressed and read RGB data of the JPG image to be compressed.

[0055] Specifically, refer to Figure 2 The RGB data initially read records the length, width and pixels of the JPG image. The pixels are stored in the memory in the form of a one-dimensional byte array, first in rows and then in columns. Each pixel uses 3 bytes to represent the values ​​of the three channels of R, G, and B respectively.

[0056] The embodiments of the present application apply the machine learning target detection method to the traditional JPG image compression process. The JPG image divides the image into 8×8 processing units, and each processing unit is represented by a series of scores from 0 to 63 after the DCT transform. The quality loss of the JPG image occurs in the quantization process of the DCT coefficients. The quality loss of the standard JPG image processing all comes 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 image quality in exchange for a smaller volume. Since the quantization table of the JPG image is unique, the quality compression in the integer division of the quantization table cannot be applied to each processing unit of the image in a differentiated manner. However, the method of discarding high-frequency components can achieve the effect of lossy compression by discarding any high-frequency components, and therefore becomes the basis of the embodiments of the present application.

[0057] S2, input the JPG image to be compressed into the target detection model to obtain the 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.

[0058] In a specific embodiment, a corresponding weight is assigned to each pixel in the JPG image to be compressed according to the target detection result to obtain a weight matrix, which specifically includes:

[0059] Traverse each pixel in the JPG image to be compressed, the target detection result includes at least one target area, and determine 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. If so, assign a first weight value to the weight corresponding to one of the pixels; otherwise, assign a second weight value to the weight corresponding to one of the pixels, and 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;

[0060] The weight corresponding to each pixel in the JPG image to be compressed is used as each element of the weight matrix to construct a weight matrix.

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

[0062] Specifically, target detection is performed on the JPG image to be compressed, and a higher weight is assigned to the target area, and a lower weight is assigned to other areas to obtain a weight matrix with the same dimension as the original image, so that the target area has higher clarity after compression. Each element of the weight matrix is ​​the weight of the pixel at the corresponding position of the JPG image to be compressed, and the value range of the weight of each pixel is an integer of [1,64]. The target detection model used in the embodiment of the present application is the VGG16 model. Of course, other target detection models can also be used. The specific structure of the target detection model in the embodiment of the present application is not limited, and it is sufficient to be able to identify the target area. Reference Figure 3, taking the VGG16 model as an example, the JPG image to be compressed will be adjusted to a specified size, and then features will be extracted through several convolutional layers and pooling layers. Since target detection is not the focus of the present invention, the present invention has no other requirements for the target detection model, and any target detection method can achieve the purpose here. The target detection model finally outputs several groups of information, each group of information contains four parameters to determine a target area. If a pixel of the JPG image to be compressed is covered by at least one area, a higher weight is assigned to the pixel at the corresponding position in the weight matrix, that is, the first weight value, otherwise a lower weight is assigned to it, that is, 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 may also select other values, but they need to meet the requirements that the value range is an integer of [1,64] and the first weight value is greater than the second weight value.

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

[0064] In a specific embodiment, step S3 specifically includes:

[0065] Perform format conversion and border filling on RGB data to obtain YCbCr data, and divide the processing units;

[0066] Downsample the Cb channel and Cr channel in the YCbCr data to obtain sampled data;

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

[0068] Specifically, format conversion and border filling are both classic steps in the JPG image standard compression process. The format conversion formula from RGB data to YCbCr data used in the embodiment 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 image to be compressed are padded to an integer multiple of 8, and then divided into several processing units of size 8×8.

[0073] Since the human eye is not sensitive to the Cb and Cr channels, the general JPG standard downsamples these two channels, that is, one byte is used to represent 2×2 bytes on the original channel. The sampling formula used in the embodiment of the present application is:

[0074]

[0075] Among them, x is the sampled data, a, b, c and d are the 2×2 pixel data of the Cb / Cr channel respectively, and A, B, C and D are the 2×2 pixel data of the Y channel respectively.

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

[0077] The DCT transformation and processing are the same as the DCT transformation in classic JPG image processing. For an 8×8 block, the formula is:

[0078]

[0079] S4, using a weight matrix to perform weighted quantization on the data after DCT transformation to obtain quantized data.

[0080] In a specific embodiment, step S4 specifically includes:

[0081] Obtain compression parameters, generate a quantization table of the Y channel according to the compression parameters, adjust and reduce the scores of frequencies 0 to m in the quantization table of the Y channel, and keep the scores of other frequencies unchanged, thereby obtaining an adjusted quantization table;

[0082] 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, thereby obtaining the weight corresponding to each processing unit;

[0083] Dividing the DCT transformed data by the corresponding score in the adjusted quantization table to obtain a quantized processing unit;

[0084] Each processing unit is traversed, and the scores of all frequencies in the quantized processing unit are adjusted in sections based on the weight corresponding to each processing unit to obtain quantized data.

[0085] In a specific embodiment, each processing unit is traversed, and the scores of all frequencies in the quantized processing unit are adjusted in sections 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 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), setting the score of one of the frequencies to 0;

[0089] For processing units with w less than 32, the scores in the quantized processing units with frequencies 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 all set to the average of the scores in the group.

[0090] Specifically, the weight matrix in step S2 is used to perform weighted quantization on the DCT transformed data, which specifically includes the following sub-steps:

[0091] S31, generate a quantization table for the Y channel according to the compression coefficient specified by the user, and reduce the m+1 scores with a frequency of [0, m] in the quantization table of the Y component to obtain an adjusted quantization table. In the embodiment 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 encoding are reduced. Since the processing algorithm of the embodiment of the present application may 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 such extreme lossy compression. 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 a smaller loss. The form of adjustment of the quantization table for the Y component is as follows: Figure 4 shown.

[0092] S32, calculate the weights 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 weights of all pixels in the processing unit and is rounded to an integer. If the weights of adjacent processing units change too quickly, the compressed JPG picture will have certain jagged edges. Therefore, in a further preferred solution, the weights of adjacent processing units can be adjusted to slowly decay. Specifically, the following processing is performed in sequence starting from the processing unit with the largest weight, and the difference between its four adjacent processing units and the processing unit is checked. If it is 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 out a processing unit from the modification queue and repeat the above process, and finally achieve the effect that the difference between any two adjacent processing units does not exceed 1, and obtain the weight corresponding to each processing unit.

[0093] S33, the frequency positions of the DCT transformed data and the quantization table correspond one to one, so first, as in the standard JPG algorithm, the adjusted quantization table in step S31 is applied to each processing unit in the DCT transformed data, that is, the DCT transformed data is divided by the corresponding score in the adjusted quantization table to obtain the quantized processing unit, and then additional compression is performed according to the weight corresponding to each processing unit in step S32, the quantized processing unit is slightly adjusted to suit Huffman coding, and high-frequency components with less impact are directly discarded. Specifically, the weight of the processing unit is set to w, and within a single processing unit, the frequency components with a frequency less than w are not changed, that is, the corresponding scores remain unchanged, and the frequency components with a frequency greater than or equal to max(w,32) are discarded, that is, their corresponding scores are set to 0, so as to achieve the effect of lossy compression. For processing units with w less than 32, the scores of all frequency components between [w, 32) are arranged from small to large, and the arrangement results are grouped into groups of 8. The 8 scores in the group are set to the average of all scores in the group, so as to reduce the number of numerical types, which is beneficial to Huffman coding.

[0094] S5, performing standard encoding on the quantized data to obtain a compressed JPG image.

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

[0096] The present invention can combine the content of the JPG picture to be compressed, without changing the storage format of the JPG picture, and keep the key parts of the image clear, and compress the size of the picture as much as possible. The method detects and determines the key target area in the JPG picture to be compressed and assigns a higher weight, and compresses different areas according to the weight, so as to achieve the effect of keeping the JPG format unchanged while greatly reducing the space occupied by the picture.

[0097] The above steps S1 to S5 do not necessarily represent the order of the steps, but are represented by step symbols, and the order of the steps can be adjusted.

[0098] Further references Figure 5 As an implementation of the methods shown in the above figures, the present application provides an embodiment of a JPG image lossy compression device. Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0099] The embodiment of the present application provides a JPG image lossy compression device, including:

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

[0101] The target detection module 2 is configured to input the JPG image to be compressed into the target detection model to obtain the 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;

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

[0103] The weighted quantization module 4 is configured to perform weighted quantization on the DCT transformed data using a 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 image.

[0105] Figure 6 Schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present invention. Figure 6 As shown, the electronic device of this embodiment includes: a processor 601 and a memory 602; wherein the memory 602 is used to store computer-executable instructions; the processor 601 is used to execute the computer-executable instructions stored in the memory to implement the various steps performed by the electronic device in the above embodiment. For details, please refer to the relevant description in the above method embodiment.

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

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

[0108] An embodiment of the present invention further provides a computer storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the above method is implemented.

[0109] An embodiment of the present invention further provides a computer program product, including a computer program. When the computer program is executed by a processor, the above method is implemented.

[0110] In the embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0111] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.

[0112] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, or each module may exist physically separately, or two or more modules may be integrated into one unit. The above-mentioned module-composed unit may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0113] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.

[0114] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.

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

[0116] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0117] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, 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 memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.

[0118] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component 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 main control device.

[0119] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

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

Claims

1. A JPG picture lossy compression method, characterized in that: The following steps are involved: Obtain a JPG image to be compressed and read 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; Using the weight matrix to perform weighted quantization on the DCT transformed data to obtain quantized data; The quantized data is subjected to standard encoding to obtain a compressed JPG image.

2. The JPG picture lossy compression method according to claim 1, characterized in that: 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 includes at least one target area, judging whether one of the pixels in the JPG image to be compressed is covered by 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, wherein 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 picture lossy compression method according to claim 1, characterized in that: The target detection model includes a VGG16 model.

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

5. The JPG picture lossy compression method according to claim 1, characterized in that: The step of using the weight matrix to weight quantize the DCT transformed data to obtain quantized data specifically includes: Obtain compression parameters, generate a quantization table of the Y channel according to the compression parameters, adjust and reduce the scores of frequencies 0 to m in the quantization table of the Y channel, and keep the scores of other frequencies unchanged, to obtain an adjusted quantization table; 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, thereby obtaining 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; Each processing unit is traversed, and the scores of all frequencies in the quantized processing unit are adjusted in sections based on the weight corresponding to each processing unit to obtain quantized data.

6. The JPG picture lossy compression method according to claim 5, characterized in that: The 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 specifically includes: 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, the scores in the quantized processing units with frequencies 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 all set to the average of the scores in the group.

7. A JPG picture 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; The target detection module is configured to input the JPG image 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 image to be compressed according to the target detection result to obtain a weight matrix; A data processing module is configured to process the RGB data to obtain data after DCT transformation; A weighted quantization module, configured to perform weighted quantization on the DCT transformed data using the weight matrix to obtain quantized data; The encoding module is configured to perform standard encoding on the quantized data to obtain a compressed JPG image.

8. 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 6.

9. 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 6 is implemented.

10. 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 6 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

  • Lossy compression encoding method and apparatus and system-on-chip

    WO2019223428A1