Image compression method, device, electronic device and computer-readable storage medium
By performing DCT transformation on the image and using different quantization parameters for ROI and non-ROI areas, the problem of being unable to specifically encode the ROI area in the existing technology is solved, and a balance between image compression efficiency and quality is achieved.
Patent Information
- Application Number
- CN202111118136.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-23
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2041-09-23
AI Technical Summary
Existing compression coding methods can only provide global quantization parameters for the entire frame image and cannot specifically encode the region of interest (ROI), making it difficult to achieve a balance between image quality and compression efficiency.
The image to be compressed is subjected to discrete cosine transform (DCT) and quantized using different quantization parameters for the ROI and non-ROI regions. Specifically, the method includes using a first quantization parameter for the ROI region and a second quantization parameter for the non-ROI region, where the second quantization parameter is related to the data characteristics after DCT, and generating compressed image data through entropy coding.
It realizes the special encoding of ROI area without increasing the computational complexity, thus improving the efficiency and quality of image compression, and can be decoded by a general decoder without the need for a special decoder.
Smart Images

Figure CN115086683B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of image processing technology, and specifically relates to an image compression method, device, electronic device and computer-readable storage medium. Background Art
[0002] The goal of image compression is to reduce redundant information in image data, enabling more efficient storage and transmission. The JPEG (Joint Photographic Experts Group) compression coding standard offers high compression rates, but the JPEG specification only provides global quantization parameters for the entire image frame, limiting its application scenarios. Furthermore, the JPEG standard lacks a standardized process for encoding ROIs (Regions of Interest). Summary of the Invention
[0003] In view of this, the purpose of this application is to provide an image compression method, device, electronic device and computer-readable storage medium to improve the problem that the existing compression coding method can only provide global quantization parameters for the entire frame image and cannot encode the region of interest (ROI).
[0004] The embodiment of the present application is implemented as follows:
[0005] In a first aspect, an embodiment of the present application provides an image compression method, comprising: obtaining an image to be compressed, the image to be compressed being an image after discrete cosine transformation; determining the ROI region and the non-ROI region in the image to be compressed; quantizing the data in the ROI region based on a preset first quantization parameter, and quantizing the data in the non-ROI region based on a preset second quantization parameter, wherein the first quantization parameter and the second quantization parameter are different, and the second quantization parameter is related to the characteristics of the data after discrete cosine transformation; performing entropy coding on the quantized data to obtain compressed image data. In an embodiment of the present application, a discrete cosine transform is performed on the original image to reduce redundant data and improve processing efficiency. At the same time, when quantizing the ROI region and the non-ROI region, different quantization coefficients are used for quantization to achieve the effect of encoding the region of interest without increasing the computational complexity, and the second quantization parameter is related to the characteristics of the data after discrete cosine transformation to achieve a balance between compression efficiency and image quality.
[0006] In conjunction with a possible implementation of the embodiment of the first aspect, determining the ROI region and non-ROI region in the image to be compressed includes: for each image block in the image to be compressed, determining the region type of the image block according to a preset configuration file, wherein the region type is an ROI region or a non-ROI region; wherein the configuration file includes the region type of each image block in the image to be compressed. In the embodiment of the present application, the ROI region and non-ROI region in the image are quickly identified by using a preset configuration file. By setting the region type of each image block in the image to be compressed in advance, not only can the ROI region in the image be accurately identified, but also processing efficiency can be improved.
[0007] In combination with a possible implementation of the embodiment of the first aspect, the process of determining the second quantization parameter includes: determining the second quantization parameter according to a preset filter coefficient table, a preset first quantization parameter table, and a preset calculation formula, wherein the elements in the first quantization parameter table correspond one-to-one to the elements in the filter coefficient table, and each element in the first quantization parameter table is used to determine a second quantization parameter, and the filter coefficients in the filter coefficient table are related to the characteristics of the data after the discrete cosine transform. In the embodiment of the present application, by filtering the coefficients after the discrete cosine transform, unimportant coefficients are lost to achieve a larger compression ratio, and the filter coefficients and quantization parameters are merged to reduce the algorithm complexity and generate a new quantization parameter (for quantizing the non-ROI area), thereby realizing quantization of the entire image using different quantization parameters according to the ROI area encoding requirements, and achieving the effect of encoding the region of interest without increasing the computational complexity.
[0008] In combination with a possible implementation method of the first aspect, the second quantization parameter is determined according to a preset filter coefficient table, a preset first quantization parameter table and a preset calculation formula, including: i is numbered from 1 to N in sequence, the value of the element numbered i in the first quantization parameter table is amplified M times, and the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table is determined; the quotient is compared with a preset threshold to obtain the minimum value between the quotient and the preset threshold, and the minimum value is the second quantization parameter corresponding to the element numbered i, M is a non-zero integer, and N is the maximum number of the elements in the first quantization parameter table.
[0009] In combination with a possible implementation of the embodiment of the first aspect, before determining the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table, the method further includes: determining that the value of the element numbered i in the filter coefficient table is not 0; if the value of the element numbered i in the filter coefficient table is 0, then the second quantization parameter corresponding to the element numbered i is the preset threshold. In the embodiment of the present application, before determining the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table, it is first determined that the value of the element numbered i in the filter coefficient table is not 0. If the value of the element numbered i in the filter coefficient table is 0, then the second quantization parameter corresponding to the element numbered i is directly determined to be the preset threshold, which can further improve efficiency.
[0010] In combination with a possible implementation method of the embodiment of the first aspect, the filter coefficient table includes two 8*8 matrices, each element in each matrix has a value of [0, 255], and the value of the element located in the upper left corner of the matrix is the largest, and the value of the element located in the lower right corner of the matrix is the smallest. In the embodiment of the present application, when setting the filter coefficient, the following principles are followed: since the DCT transform is a transform from the data space domain to the frequency domain, most of the information in the image after the DCT transform is concentrated in the low-frequency coefficients in the upper left corner, and most images contain more low-frequency components, while the human eye is relatively insensitive to the high-frequency details of the image. Therefore, when designing the filter coefficient, more coefficients are retained in the upper left corner of the filter coefficient matrix (larger values), and fewer coefficients are retained in the lower right corner (smaller values), thereby reducing the size of the image, thereby achieving a larger compression ratio by losing unimportant coefficients, and achieving a balance between compression efficiency and image quality.
[0011] In conjunction with a possible implementation of the embodiment of the first aspect, the method further includes: obtaining a target filter coefficient selected by a user from a plurality of preset filter coefficient groups, wherein different filter coefficients correspond to different second quantization parameters; and accordingly, quantizing the data in the non-ROI region based on the preset second quantization parameter, including: quantizing the data in the non-ROI region based on the preset second quantization parameter corresponding to the target filter coefficient. In this embodiment of the present application, by presetting multiple sets of filter coefficients for user selection, different compression efficiencies are presented.
[0012] In the second aspect, an embodiment of the present application also provides an image compression device, including: an acquisition module and a processing module; the acquisition module is used to acquire the image to be compressed, and the image to be compressed is an image after discrete cosine transformation; the processing module is used to determine the ROI area and the non-ROI area in the image to be compressed, and quantize the data in the ROI area based on a preset first quantization parameter, and quantize the data in the non-ROI area based on a preset second quantization parameter, wherein the first quantization parameter and the second quantization parameter are different, and the second quantization parameter is related to the characteristics of the data after discrete cosine transformation; and is also used to perform entropy encoding on the quantized data to obtain compressed image data.
[0013] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a memory and a processor, the processor being connected to the memory; the memory being used to store programs; and the processor being used to call the programs stored in the memory to execute the method provided in the above-mentioned first aspect embodiment and / or any possible implementation method in combination with the first aspect embodiment.
[0014] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it executes the method provided in the above-mentioned first aspect embodiment and / or any possible implementation method in combination with the first aspect embodiment.
[0015] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or understood by practicing the embodiments of the present application. The objectives and other advantages of the present application can be achieved and obtained through the structures particularly pointed out in the written description and the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. The above and other purposes, features and advantages of the present application will be more clearly shown in the accompanying drawings. The same reference numerals indicate the same parts throughout the drawings. The drawings are not intentionally scaled to actual size, and the focus is on illustrating the main purpose of the present application.
[0017] Figure 1 A flow chart of an image compression method provided in an embodiment of the present application is shown.
[0018] Figure 2A flow chart of another image compression method provided in an embodiment of the present application is shown.
[0019] Figure 3 The figure shows an image effect of an image to be compressed before compression.
[0020] Figure 4 The image compression method shown in the embodiment of the present application is used to Figure 3 The image shown is the image effect after compression.
[0021] Figure 5 A module schematic diagram of an image compression device provided in an embodiment of the present application is shown.
[0022] Figure 6 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0023] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0024] It should be noted that similar numbers and letters represent similar items in the following figures, so once an item is defined in one figure, it does not need to be further defined and explained in the subsequent figures. At the same time, in the description of this application, relational terms such as "first", "second", etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also includes other elements that are not clearly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the sentence "comprise a..." do not exclude the presence of other identical elements in the process, method, article or equipment including the elements.
[0025] Furthermore, the term "and / or" in this application is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0026] In view of the problem that the current compression coding method can only provide global quantization parameters for the entire frame image, and cannot implement coding for the region of interest (ROI), that is, it cannot sacrifice the image quality of the non-ROI area, but only retains the image quality of the ROI area, thereby reducing the image size after coding, the embodiment of the present application provides an image compression method, which achieves the effect of coding the region of interest without increasing the computational complexity by encoding the ROI area and the non-ROI area (i.e., the background area) in the same image with different qualities, so that a universal decoder can be used to decode the code stream generated by the coding of the present application without the need for a special decoder. The following will be combined with Figure 1 , the image compression method provided in the embodiment of the present application is described.
[0027] S1: Acquire an image to be compressed, where the image to be compressed is an image after discrete cosine transformation.
[0028] When an image to be compressed needs to be compressed, the image to be compressed is obtained. In one embodiment, the image to be compressed can be obtained from a database. In one embodiment, the obtained image to be compressed is an image that has undergone a discrete cosine transform (DCT), that is, an image that has been previously subjected to a discrete cosine transform, which can improve image processing efficiency. Of course, the DCT transform can also be performed in real time. In this case, a discrete cosine transform can be performed on the original image to be compressed to obtain transformed image data.
[0029] Among them, DCT-based coding is lossy coding, so it can achieve substantial compression while generating a reconstructed image with high visual fidelity for the source image of the encoder, thereby improving processing efficiency by reducing redundant data.
[0030] S2: Determine the ROI area and the non-ROI area in the image to be compressed.
[0031] After obtaining the image to be compressed after DCT transformation, it is necessary to determine the ROI area and the non-ROI area in the image to be compressed so as to perform differentiated compression coding during compression coding.
[0032] In one embodiment, the process of determining the ROI region and non-ROI region in the image to be compressed can be to determine the region type of each image block (i.e., macroblock) in the image to be compressed, according to a preset configuration file, where the region type is either an ROI region or a non-ROI region. The configuration file includes the region type of each image block in the image to be compressed. In this embodiment, the user can pre-define the ROI and non-ROI regions in the image to be compressed. For example, the image to be compressed can be divided into multiple image blocks, such as 8*8 image blocks. Each image block can be represented by at least one bit to represent the region type of the image block. If a bit is used to represent the region type of the image block, a bit of 1 indicates that the region type of the image block is an ROI region, and a bit of 0 indicates that the region type of the image block is a non-ROI region. Of course, the reverse can also be used, that is, a bit of 0 indicates that the region type of the image block is an ROI region, and a bit of 1 indicates that the region type of the image block is a non-ROI region.
[0033] During the macroblock mapping process, the ROI region is determined for each macroblock through a row-by-row scan. The bit corresponding to the macroblock in the ROI region can be set to 1, and the bit corresponding to the macroblock in the non-ROI region can be set to 0. Whenever eight macroblocks are counted, the 8-bit data is composed into a byte and written sequentially into pre-allocated memory for subsequent determination of the ROI and non-ROI regions in the image to be compressed. In addition, the configuration file also contains the frame number of the image to be compressed to facilitate differentiation, as well as the starting coordinates, width, and height of the rectangular area of each image block area in the image to be compressed to facilitate demarcation of the ROI and non-ROI regions. It should be noted that the starting coordinates, width, and height of only the ROI or non-ROI region in the image to be compressed can be configured, rather than configuring the starting coordinates, width, and height of the rectangular area of each image block area. This can save time and improve efficiency. For example, if the configuration file only configures the ROI region in the image to be compressed, the format of the configuration file can be as follows:
[0034] #pic=X;
[0035] ROI=(left,top,width,height);
[0036] …
[0037] Where X is a non-negative integer representing the frame number of the image to be compressed, left and top are the starting coordinates of the ROI rectangular area, corresponding to the width and height of the area respectively. They jointly determine the size of the rectangular area and cannot exceed the image coding area. Left and top need to be non-negative integer multiples of the macroblock size corresponding to the current coding mode. The macroblock sizes of the coding modes supported by this application can be: 420 coding mode, macroblock size is 16x16; 422 coding mode, macroblock size is 16x8; 400 coding mode, macroblock size is 8x8, etc.
[0038] When determining the ROI and non-ROI regions in a to-be-compressed image, a mapping value P for each image block (i.e., macroblock) in the to-be-compressed image is obtained based on a pre-configured configuration file. If P is 1, indicating that the current macroblock is an ROI region, quantization is performed based on a preset first quantization parameter. If P is 0, indicating that the current macroblock is a non-ROI region, quantization is performed based on a preset second quantization parameter. This achieves separate quantization of the ROI and non-ROI regions. Furthermore, multiple bits can be used to represent the region type of the image block. This not only indicates the region type of the image block, but also distinguishes the weight of the region of interest (ROI) from the non-ROI region. Assuming that the ROI has two weights and the non-ROI has two weights, two bits can be used per image block to represent the region type and the weight of the ROI or non-ROI region. For example, bit values of 0 or 1 can be used to represent the non-ROI region, while bit values of 2 or 3 can be used to represent the ROI region. The reverse can also be used. The bit values corresponding to image blocks of regions of interest or non-regions of interest with different weights are different, while the bit values corresponding to image blocks of regions of interest or non-regions of interest with the same weights are the same. For example, although bit values 0 and 1 both represent non-ROI regions, the difference in their values indicates that the weights of the non-ROI regions are different.
[0039] For another example, assuming that the ROI has 3 weights and the ROI has 1 weight, then each image block can still be represented by 2 bits to represent the region type of the image block and the weight of the ROI or ROI. For example, the ROI region is represented by a bit value of 0, 1, or 2, and the non-ROI region is represented by a bit value of 3. Of course, the reverse can also be used. Among them, the image blocks with different weights for the ROI or ROI have different bit values, and the image blocks with the same weights for the ROI or ROI have the same bit value.
[0040] Specifically, when quantizing regions of interest with different weights, different quantization parameters can be used to distinguish them. Similarly, when quantizing regions of no interest with different weights, different quantization parameters can also be used. When quantizing regions of interest with the same weight, the same quantization parameters are used, and when quantizing regions of no interest with the same weight, the same quantization parameters are used.
[0041] In one optional embodiment, the ROI and non-ROI regions in the image to be compressed can be determined based on a pre-trained neural network model. For example, for an image containing an animal, such as a cat or dog, the ROI region can be the area where the animal is located, and the non-ROI region can be the area where the animal is not located. In this embodiment, the neural network model must be pre-trained to identify the ROI and non-ROI regions in the image.
[0042] It should be noted that, in an optional implementation, discrete cosine transform may not be performed on the image to be compressed. In this case, after obtaining the image to be compressed (equivalent to the original image), the ROI area and non-ROI area in the image to be compressed are directly determined.
[0043] S3: quantizing the data in the ROI region based on a preset first quantization parameter, and quantizing the data in the non-ROI region based on a preset second quantization parameter.
[0044] After determining the ROI area and the non-ROI area, the data in the ROI area can be quantized based on a preset first quantization parameter, and the data in the non-ROI area can be quantized based on a preset second quantization parameter, wherein the first quantization parameter and the second quantization parameter are different, and the second quantization parameter is related to the characteristics of the data after discrete cosine transform, so as to achieve differentiated compression of the ROI area and the non-ROI area, and achieve a balance between compression efficiency and image quality.
[0045] Among them, the principle of quantizing the data in the ROI area based on the preset first quantization parameter is consistent with the principle of quantizing the data in the non-ROI area based on the second quantization parameter, and is consistent with the principle used in the quantization of the ROI area by JPEG compression encoding in the prior art. It is already well known to those skilled in the art and will not be introduced here.
[0046] The preset first quantization parameter can be obtained from a preset first quantization parameter table. The preset first quantization parameter can be consistent with the quantization parameter used when quantizing the ROI area in JPEG compression encoding in the prior art. For example, the first quantization parameter table includes two 8*8 matrices, one matrix is a luminance matrix, and the other matrix is a chrominance matrix, each matrix containing 64 first quantization parameters. Of course, these two matrices can be combined into a matrix containing 128 elements, wherein the first 64 elements are elements in the luminance matrix and the last 64 elements are elements in the chrominance matrix.
[0047] The preset second quantization parameter can be obtained from a preset second quantization parameter table. The preset second quantization parameter can be different from the quantization parameter used when quantizing the non-ROI area in JPEG compression encoding in the prior art.
[0048] In addition, different quantization parameters can be used to quantize regions of interest or non-interest with different weights to reflect the difference. Under this embodiment, each image block needs to use multiple bits to represent the weight of the region of interest or non-interest of the image block. For example, assuming that there are two first quantization parameters (first quantization parameter 1 and first quantization parameter 2) in the ROI area and a second quantization parameter in the non-ROI area, each image block can use 2 bits to represent the weight of the region of interest or non-interest of the image block. For example, if the value of the bit corresponding to the image block is 0, the first quantization parameter 1 is used for quantization. If the value of the bit corresponding to the image block is 1, the first quantization parameter 2 is used for quantization. If the value of the bit corresponding to the image block is 2, the second quantization parameter is used for quantization. In this way, regions of interest or non-interest with different weights can be quantized using different quantization parameters.
[0049] In the embodiment of the present application, when compressing and encoding non-ROI areas, the coefficients after DCT are filtered, and unimportant coefficients are lost to achieve a high compression ratio. At the same time, the filtering and quantization processes are effectively combined to reduce the complexity of the algorithm, so that the algorithm can achieve the effect of encoding the region of interest without increasing the computational complexity. The merging principle is as follows:
[0050] DCT(u,v)*filter(u,v) / QTb(u,v)=DCT(u,v) / QTbNonRoi(u,v);
[0051] DCT(u,v) is the DCT coefficient, filter(u,v) is the filter coefficient, QTb(u,v) is the first quantization parameter, QTbNonRoi(u,v) is the second quantization parameter used in the non-ROI area, and QTbNonRoi(u,v)=QTb(u,v) / filter(u,v).
[0052] After introducing the filter coefficient, under normal circumstances, when compressing and encoding the non-ROI area, the processing logic on the left side of the above formula should be used, that is, the coefficient after DCT transformation needs to be multiplied by the filter coefficient first, and then divided by the first quantization parameter. In order to simplify the complexity of the algorithm, by combining filtering and quantization, a new quantization parameter (second quantization parameter) is generated, and then the processing logic on the right side of the above formula can be used for processing, that is, the coefficient after DCT transformation is divided by the processing logic of the second quantization parameter generated by combining filtering and quantization. In this way, the effect of encoding the region of interest can be achieved without increasing the computational complexity. At the same time, since the processing logic on the right side of the above formula is consistent with the processing logic used in the existing image compression method, a universal decoder can be used to decode the code stream generated by the encoding of this application, without the need for a special decoder.
[0053] Therefore, when determining the second quantization parameter, the process may be to determine the second quantization parameter based on a preset filter coefficient table, a preset first quantization parameter table, and a preset calculation formula, wherein the elements in the first quantization parameter table correspond one-to-one to the elements in the filter coefficient table, and each element in the first quantization parameter table is used to determine a second quantization parameter.
[0054] For example, the filter coefficient table also contains two 8*8 matrices, one matrix for brightness and one matrix for color. Each matrix contains 64 filter coefficients. The value of each element (filter coefficient) in each matrix is [0, 255]. The element in the upper left corner of the matrix has the largest value, such as 255, and the element in the lower right corner has the smallest value, such as 0. Of course, these two matrices can also be merged together.
[0055] In the embodiment of the present application, the filter coefficients in the filter coefficient table are related to the characteristics of the data after discrete cosine transformation. The design principle of the filter coefficients is as follows: based on the distribution relationship of high and low frequency information of the image data after DCT transformation, and the characteristic that the human eye is insensitive to high frequency information, the low frequency information is retained as much as possible and the high frequency information is reduced. Since the DCT transformation is a transformation from the spatial domain of data to the frequency domain, most of the information in the image after DCT transformation is concentrated in the low frequency coefficients in the upper left corner, and most images contain more low frequency components, while the human eye is relatively insensitive to the high frequency details of the image. Taking advantage of this characteristic, when designing the filter coefficients, the present application retains more coefficients in the upper left corner of the filter coefficient matrix (larger values) and fewer coefficients in the lower right corner (smaller values), thereby reducing the size of the image.
[0056] The specific process of determining the second quantization parameter based on the preset filter coefficient table, the preset first quantization parameter table, and the preset calculation formula may be as follows: i is sequentially numbered from 1 to N, the value of the element numbered i in the first quantization parameter table is amplified by M times, and the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table is determined; the quotient is compared with a preset threshold value to obtain the minimum value between the quotient and the preset threshold value, where the minimum value is the second quantization parameter corresponding to the element numbered i, M is a non-zero integer, and N is the maximum number of elements in the first quantization parameter table, which may be 64, for example. For example, i is sequentially numbered from 1 to 64, the value of the element numbered i in the first quantization parameter table is amplified by 255 times, and the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table is determined; the quotient is compared with 255 to obtain the minimum value between the quotient and 255, where the minimum value is the second quantization parameter corresponding to the element numbered i, and M is a non-zero integer.
[0057] Among them, since the filter coefficient in the filter coefficient table may be 0, before determining the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table, it is also necessary to determine that the value of the element numbered i in the filter coefficient table is not 0; if the value of the element numbered i in the filter coefficient table is 0, the second quantization parameter corresponding to the element numbered i is a preset threshold, for example, 255.
[0058] The above preset calculation formula is as follows:
[0059] qTableLumaNonRoi[i]=(filter[i]==0)? (255):(Min(255,qTable.pQlumi[i]*255 / filter[i]));
[0060] qTableChromaNonRoi[i]=(filter[i+64]==0)? (255):(Min(255,qTable.pQchro mi[i]*255 / filter[i+64]));
[0061] Where qTableLumaNonRoi[i] and qTableChromaNonRoi[i] are the luminance matrix and chrominance matrix used for quantization of non-ROI regions, respectively; filter[i] is the luminance coefficient matrix in the filter coefficients, and filter[i+64] is the chrominance coefficient matrix in the filter coefficients; qTable.pQlumi[i] and qTable.pQchromi[i] are the luminance matrix and chrominance matrix in the first quantization parameter table, respectively; the value of i ranges from 1 to 64. The entire operation ensures that the result value remains in the integer range of 0 to 255.
[0062] The above formula is explained as follows: if the value of the filter coefficient is 0, then 255 is taken as the current second quantization parameter. If the value of the filter coefficient is not 0, each coefficient of the brightness matrix and the chrominance matrix in the first quantization parameter table is expanded by 255 times, and then divided by the corresponding filter coefficient, and then compared with 255, and the smaller value of the two is taken as the corresponding second quantization parameter.
[0063] After obtaining each second quantization parameter, it can be saved in a second quantization parameter table in a certain order (e.g., in a numerical order) for subsequent use. The second quantization parameter table can also include two 8*8 matrices, one matrix for luma and one matrix for chroma, each matrix including 64 second quantization parameters.
[0064] It should be noted that, in one embodiment, multiple sets of filter coefficients can be set in advance based on the results of multiple experiments. For example, 10 sets (10 levels) of filter coefficients for brightness and chrominance are set, and the image compression rate difference of each level is about 5%. The second quantization parameters corresponding to the filter parameters of different levels are different. When in use, the user can select the desired target filter coefficient from the preset multiple sets of filter coefficients. At this time, the data in the non-ROI area should be quantized based on the preset second quantization parameter corresponding to the target filter coefficient. By setting multiple sets of filter coefficients in advance, it is convenient for the user to select. For example, the desired target coefficient can be set through the parameter selection item in the software. The value range of the parameter selection item is an integer from 0 to 9, where the smaller the value, the higher the compression rate.
[0065] In addition, in addition to selecting the required filter coefficients through the parameter selection items in the software, you can also configure the filter coefficients independently, and configure the filter coefficients for brightness and chrominance separately. It is no longer the fixed image compression rate mentioned above, thereby improving its flexibility and autonomy.
[0066] S4: Perform entropy coding on the quantized data to obtain compressed image data.
[0067] After quantizing the data in the ROI region based on a preset first quantization parameter, entropy encoding is performed on the quantized data to obtain compressed image data. Alternatively, after quantizing the data in the non-ROI region based on a preset second quantization parameter, entropy encoding is performed on the quantized data to obtain compressed image data. The specific process of entropy encoding data is well known to those skilled in the art and will not be described here.
[0068] It should be noted that, during the image compression process, the above-mentioned processes S2, S3, and S4 may be executed multiple times, not just once. When determining the ROI area and non-ROI area in the image to be compressed, it is not necessary to determine all the ROI areas and non-ROI areas in the image to be compressed at once, but there may be a sequence. Similarly, when quantizing the data in the ROI area based on the preset first quantization parameter, and quantizing the data in the non-ROI area based on the preset second quantization parameter, it is not necessary to quantize all the ROI areas and non-ROI areas at once, but there may be a sequence. Similarly, when entropy encoding is performed on the quantized data, it is not necessary to perform entropy encoding on the quantized data at once, but there may be a sequence. For example, each image block in the image to be compressed can be obtained in sequence from left to right and from top to bottom, and then the region type of the image block can be determined. If the region type is an ROI region, the data in the ROI region is quantized based on a preset first quantization parameter, and then the quantized data is entropy encoded. If the region type is a non-ROI region, the data in the non-ROI region is quantized based on a preset second quantization parameter, and then the quantized data is entropy encoded. Then, similar compression encoding is performed on the next image block (that is, the region type of the image block is determined. If the region type is an ROI region, the data in the ROI region is quantized based on a preset first quantization parameter, and then the quantized data is entropy encoded. If the region type is a non-ROI region, the data in the non-ROI region is quantized based on a preset second quantization parameter, and then the quantized data is entropy encoded). This process is deduced by analogy until the compression encoding of all image blocks is completed, and thus the compressed image data can be obtained. The schematic diagram is shown as follows. Figure 2 shown.
[0069] The image compression method provided in the embodiment of the present application achieves a higher compression ratio by performing DCT transformation on the compressed image, filtering the coefficients after the DCT transformation, and losing unimportant coefficients. It also effectively combines the filtering and quantization processes to reduce the complexity of the algorithm, generates a new quantization parameter table (for quantizing non-ROI areas), and quantizes the entire image using different quantization parameters according to the coding requirements of the ROI area. The effect is as follows: Figure 3 、 Figure 4 As shown, Figure 3 This is the image effect before compression. Figure 4 This is the image compression result after using the image compression method described in this application. This method can accurately locate the ROI region and significantly improve the compression rate. For a 640x480 image size, the image compression method described in this application can reduce the image size from the original 144,521 bytes to 85,161 bytes, ultimately achieving a balance between compression efficiency and image quality.
[0070] Based on the same inventive concept, the embodiment of the present application further provides an image compression device 100, such as Figure 5 The image compression device 100 includes: an acquisition module 110 and a processing module 120 .
[0071] The acquisition module 110 is used to acquire the image to be compressed, where the image to be compressed is an image after discrete cosine transformation.
[0072] The processing module 120 is configured to determine the ROI region and the non-ROI region in the image to be compressed, and to quantize the data in the ROI region based on a preset first quantization parameter, and to quantize the data in the non-ROI region based on a preset second quantization parameter, wherein the first quantization parameter and the second quantization parameter are different and the second quantization parameter is related to characteristics of the data after discrete cosine transformation; and further configured to perform entropy encoding on the quantized data to obtain compressed image data.
[0073] Among them, the processing module 120 is used to determine the region type of each image block in the image to be compressed according to a preset configuration file, where the region type is an ROI region or a non-ROI region; wherein the configuration file includes the region type of each image block in the image to be compressed.
[0074] In which, the acquisition module 110 is also used to obtain the target filter coefficient selected by the user from multiple preset groups of filter coefficients, wherein different filter parameters correspond to different second quantization parameters. Accordingly, the processing module 120 is used to quantize the data in the non-ROI area based on the preset second quantization parameter corresponding to the target filter coefficient.
[0075] The image compression device 100 provided in the embodiment of the present application has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding content in the aforementioned method embodiment.
[0076] like Figure 6 As shown, Figure 6 FIG2 shows a block diagram of an electronic device 200 according to an embodiment of the present application. The electronic device 200 includes a transceiver 210 , a memory 220 , a communication bus 230 , and a processor 240 .
[0077] The transceiver 210, the memory 220, and the processor 240 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses 230 or signal lines. The transceiver 210 is used to send and receive data. The memory 220 is used to store computer programs, such as Figure 5 The software functional module shown in is the image compression device 100. The image compression device 100 includes at least one software functional module that can be stored in the memory 220 in the form of software or firmware or fixed in the operating system (OS) of the electronic device 200. The processor 240 is used to execute the executable module stored in the memory 220, such as the software functional module or computer program included in the image compression device 100. For example, the processor 240 is used to obtain the image to be compressed, which is an image after discrete cosine transformation; determine the ROI area and the non-ROI area in the image to be compressed; quantize the data in the ROI area based on a preset first quantization parameter, and quantize the data in the non-ROI area based on a preset second quantization parameter, wherein the first quantization parameter and the second quantization parameter are different, and the second quantization parameter is related to the characteristics of the data after discrete cosine transformation; perform entropy coding on the quantized data to obtain compressed image data.
[0078] Among them, the memory 220 can be, but is not limited to, random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0079] The processor 240 may be an integrated circuit chip with signal processing capabilities. The above-mentioned processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The various methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor may be a microprocessor or the processor 240 may also be any conventional processor, etc.
[0080] The electronic device 200 mentioned above includes but is not limited to computers, smart phones, tablets, etc.
[0081] An embodiment of the present application further provides a non-volatile computer-readable storage medium (hereinafter referred to as storage medium), on which a computer program is stored. When the computer program is run by a computer such as the above-mentioned electronic device 200, the image compression method shown above is executed.
[0082] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referenced to each other.
[0083] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or can be implemented using a combination of dedicated hardware and computer instructions.
[0084] In addition, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0085] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a computer-readable storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a laptop, a server, or an electronic device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned computer-readable storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0086] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. An image compression method, characterized in that: include: Acquire an image to be compressed, wherein the image to be compressed is an image after discrete cosine transformation; Determine the ROI area and the non-ROI area in the image to be compressed; quantizing the data in the ROI region based on a preset first quantization parameter, and quantizing the data in the non-ROI region based on a preset second quantization parameter, wherein the first quantization parameter and the second quantization parameter are different, and the second quantization parameter is related to a feature of the discrete cosine transformed data; Perform entropy coding on the quantized data to obtain compressed image data; The process of determining the second quantization parameter includes: Determining the second quantization parameter according to a preset filter coefficient table, a preset first quantization parameter table, and a preset calculation formula, wherein elements in the first quantization parameter table correspond one-to-one to elements in the filter coefficient table, and each element in the first quantization parameter table is used to determine one second quantization parameter, and the filter coefficients in the filter coefficient table are related to characteristics of the discrete cosine transformed data; each element in the filter coefficient table has a value in the range [0, 255], with the element located in the upper left corner having the largest value and the element located in the lower right corner having the smallest value; Determining the second quantization parameter according to a preset filter coefficient table, a preset first quantization parameter table, and a preset calculation formula includes: The number i is 1 to N in sequence, the value of the element numbered i in the first quantization parameter table is amplified M times, and the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table is determined; the quotient is compared with a preset threshold to obtain the minimum value of the quotient and the preset threshold, and the minimum value is the second quantization parameter corresponding to the element numbered i, M is a non-zero integer, and N is the maximum number of the elements in the first quantization parameter table.
2. The method according to claim 1, characterized in that Determining the ROI region and the non-ROI region in the image to be compressed includes: For each image block in the image to be compressed, determining a region type of the image block according to a preset configuration file, wherein the region type is a ROI region or a non-ROI region; The configuration file includes the region type of each image block in the image to be compressed.
3. The method according to claim 1, characterized in that Before determining the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table, the method further includes: Determining that the value of the element numbered i in the filter coefficient table is not 0; If the value of the element numbered i in the filter coefficient table is 0, the second quantization parameter corresponding to the element numbered i is the preset threshold.
4. The method according to claim 1, wherein The filter coefficient table includes two 8*8 matrices, each element in each matrix has a value of [0, 255], and the element located in the upper left corner of the matrix has the largest value, and the element located in the lower right corner of the matrix has the smallest value.
5. The method according to claim 1, wherein The method further comprises: Obtaining a target filter coefficient selected by a user from a plurality of preset filter coefficients, wherein different filter parameters correspond to different second quantization parameters; accordingly Quantizing the data in the non-ROI area based on a preset second quantization parameter includes: The data in the non-ROI area is quantized based on a preset second quantization parameter corresponding to the target filter coefficient.
6. An image compression device, characterized in that: include: An acquisition module, configured to acquire an image to be compressed, wherein the image to be compressed is an image after discrete cosine transformation; a processing module, configured to determine an ROI region and a non-ROI region in the image to be compressed, and quantize data in the ROI region based on a preset first quantization parameter, and quantize data in the non-ROI region based on a preset second quantization parameter, wherein the first quantization parameter and the second quantization parameter are different and the second quantization parameter is related to a feature of the discrete cosine transformed data; and further configured to perform entropy coding on the quantized data to obtain compressed image data; The processing module is further configured to determine the second quantization parameter based on a preset filter coefficient table, a preset first quantization parameter table, and a preset calculation formula, wherein elements in the first quantization parameter table correspond one-to-one to elements in the filter coefficient table, and each element in the first quantization parameter table is used to determine one second quantization parameter, and the filter coefficients in the filter coefficient table are related to characteristics of the discrete cosine transformed data; each element in the filter coefficient table has a value in the range [0, 255], with the element located in the upper left corner having the largest value and the element located in the lower right corner having the smallest value; The step of determining the second quantization parameter according to a preset filter coefficient table, a preset first quantization parameter table, and a preset calculation formula includes: The number i is 1 to N in sequence, the value of the element numbered i in the first quantization parameter table is amplified M times, and the quotient of the amplified value of the element numbered i and the element numbered i in the filter coefficient table is determined; the quotient is compared with a preset threshold to obtain the minimum value of the quotient and the preset threshold, and the minimum value is the second quantization parameter corresponding to the element numbered i, M is a non-zero integer, and N is the maximum number of the elements in the first quantization parameter table.
7. An electronic device, characterized in that: include: a memory and a processor, wherein the processor is connected to the memory; The memory is used to store programs; The processor is configured to call a program stored in the memory to execute the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that A computer program is stored thereon, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is executed.
Citation Information
Patent Citations
Image compression method and apparatus
US20170150148A1