Image Compression Device, Method, Electronic Device, and Computer Readable Storage Medium

By dividing the image into macroblocks and partitioning, the first and second components of each partition are determined, and compressed in combination with the color index of the pixels, the problems of high cost of image compression hardware and large compression error in the prior art are solved, and efficient and low-cost image compression effect is achieved.

CN114584773BActive Publication Date: 2025-06-10HAINING ESWIN IC DESIGN CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210119394.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-08
Publication Date
2025-06-10
Estimated Expiration
2042-02-08

AI Technical Summary

Technical Problem

The prior art has high hardware costs for image compression and large compression errors.

Method used

By dividing the target image into several macroblocks and partitioning each macroblock, the first component and the second component of each partition are determined, and the macroblock is compressed according to the color index of these components and pixels to obtain a compressed code stream.

Benefits of technology

The process of image compression is simple and the calculation is small, which effectively reduces compression errors and reduces hardware costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114584773B_ABST
    Figure CN114584773B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide an image compression device, method, electronic device, and computer-readable storage medium, which relate to the technical field of image compression. The device includes: an image partitioning module, configured to partition a target image into a plurality of macroblocks; a macroblock partitioning module, configured to partition each macroblock; a component determination module, configured to, for each partition, determine a first component and a second component of the partition in each color channel; a color index determination module, configured to determine a color index of a pixel in the corresponding partition according to the first component and the second component corresponding to the pixel partition; and a compressed bitstream obtaining module, configured to obtain a preset image compression ratio, and for any one macroblock, compress the macroblock according to the number of partitions of the macroblock, the first component and the second component of each partition in each color channel, and the color indexes of all pixels, to obtain a compressed bitstream of the macroblock. Embodiments of the present application achieve the compression of an image, the implementation manner is simple, and the compression error is small.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of image compression. Specifically, the present application relates to an image compression device, method, electronic device, and computer-readable storage medium. Background Art

[0002] Assume that the size of an original image is 1920*1080, that is, it includes 1920*1080 pixels. If the pixel of each pixel is 30bit, then the content size required to store the image is (1920*1080*30) / 8 = 7776000Byte, approximately 7M. If the memory of a certain chip is 1G, then the chip can only store about 143 images, which seriously wastes memory resources. To reduce the waste of memory resources by images, it is necessary to compress the images.

[0003] Image compression is to reduce the amount of data required to represent a digital image and represent the original image with less information. There are mainly two existing image compression technologies: 1) Compression methods based on transform coding. The common transform coding is Discrete Cosine Transform (DCT). First, the image is divided into blocks, the data of the macroblock is subjected to DCT transformation, and then the coefficients are quantized to retain the low-frequency information of the image as much as possible. This type of compression algorithm is relatively complex, and the hardware implementation is complex and costly; 2) Compression methods based on Block Truncation Coding (BTC). Its essence is a binary compression method. The algorithm is simple and easy to implement, but the compression error is relatively large. Summary of the Invention

[0004] Embodiments of the present application provide an image compression device, method, electronic device, and computer-readable storage medium for solving the technical problem of high hardware cost in the prior art when compressing images.

[0005] According to one aspect of the embodiments of the present application, an image compression device is provided. The device includes:

[0006] An image division module for dividing a target image into a plurality of macroblocks;

[0007] A macroblock partitioning module for partitioning each macroblock, and the pixel distance between any two pixels in different partitions is greater than a preset threshold;

[0008] A component determination module for determining a first component and a second component of each partition in each color channel;

[0009] A color index determination module for determining the color index of each pixel in the corresponding partition according to the first component and the second component of the corresponding partition of the pixel;

[0010] A compressed bitstream obtaining module, configured to obtain a preset image compression ratio. For any macroblock, compress the macroblock according to the number of partitions of the macroblock, the first and second components of each partition in each color channel, and the color indices of all pixels, so as to obtain a compressed bitstream corresponding to the macroblock.

[0011] In a possible implementation, the macroblock partitioning module includes:

[0012] A partition center determining sub-module, configured to determine the partition center of the previous iteration process;

[0013] A pixel partition determining sub-module, configured to, for each pixel, determine the pixel distance between the pixel and the partition center of each previous iteration process, and divide the pixel into the partition where the partition center of the previous iteration process corresponding to the minimum pixel distance is located;

[0014] Wherein, the partition center of the first iteration process is characterized by a combination of the maximum value, the minimum value, and the average value of the components of any one color channel of all pixels.

[0015] In a possible implementation, the pixel partition determining sub-module further includes:

[0016] An average value determining unit, configured to determine the average value of the components of all pixels in the same partition in each color channel;

[0017] A partition center iteration unit, configured to update the partition center of the previous iteration process to obtain the partition center of the current iteration process, and the partition center of the current iteration process is characterized by the average value of all pixels in the corresponding partition in each color channel;

[0018] A first pixel distance determining unit, configured to determine the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process;

[0019] A second pixel distance determining unit, configured to, if the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process is greater than a preset threshold, calculate the pixel distance between each pixel and the partition center of each current iteration process;

[0020] A pixel partition dividing unit, configured to divide each pixel into the partition where the partition center of the current iteration process corresponding to the minimum pixel distance is located, until the pixel distance between the partition centers of two adjacent iteration processes is less than the preset threshold.

[0021] In a possible implementation, the component determining module includes:

[0022] A component determination sub-module, configured to determine the maximum base pixel value and the minimum base pixel value in a partition, input the maximum base pixel value and the minimum base pixel value into the objective functions of the respective color channels of the corresponding partition, and obtain a first component and a second component of the partition in each color channel;

[0023] Wherein, the objective function is obtained by performing linear fitting on the components of the pixels in the partition in the corresponding color channel.

[0024] In a possible implementation manner, the component determination sub-module includes:

[0025] A base pixel value obtaining unit, configured to obtain the base pixel value of a corresponding pixel according to the algebraic sum of the components of all color channels of each pixel in the partition;

[0026] A maximum base pixel value and minimum base pixel value determination unit, configured to determine the maximum base pixel value and the minimum base pixel value from the base pixel values of all pixels in the partition.

[0027] In a possible implementation manner, the color index determination module includes:

[0028] A quantization number determination sub-module, configured to determine the quantization number of a macroblock according to the number of partitions of the macroblock;

[0029] A target color channel determination sub-module, configured to determine the target color channel of a pixel in the corresponding partition;

[0030] A color index determination sub-module, configured to determine the color index of a pixel in the corresponding partition according to the quantization number of the macroblock to which the pixel belongs, the component of the pixel in the target color channel, and the first component and the second component of the target color channel.

[0031] In a possible implementation manner, the target color channel determination sub-module includes:

[0032] A first parameter determination unit, configured to obtain a first parameter for any one color channel according to the difference between the component of the pixel in the corresponding color channel and the second component of the partition in the corresponding color channel;

[0033] A second parameter determination unit, configured to determine the difference between the first component and the second component of the partition in the corresponding color channel to obtain a second parameter;

[0034] A third parameter determination unit, configured to obtain a third parameter according to the ratio of the first parameter to the second difference;

[0035] A target color channel determination unit, configured to determine the color channel corresponding to the maximum third parameter as the target color channel of the pixel.

[0036] In a possible implementation, the color index determination module includes:

[0037] A first target parameter determination sub-module, configured to determine a difference between a component of a pixel in a target color channel and a second component of the target color channel, to obtain a first target parameter;

[0038] A second target parameter determination sub-module, configured to determine a difference between a first component and a second component of the target color channel, to obtain a second target parameter;

[0039] A third target parameter determination sub-module, configured to determine a ratio between the first target parameter and the second target parameter, to obtain a third target parameter;

[0040] A color index determination sub-module, configured to determine a color index of a pixel in a corresponding partition according to the third target parameter and a quantization number.

[0041] According to a second aspect of the embodiments of the present application, an image compression method is provided, the method including: dividing a target image into a plurality of macroblocks;

[0042] Partitioning each macroblock, where a pixel distance between any two pixels in different partitions is greater than a preset threshold;

[0043] For each partition, determining a first component and a second component of the partition in each color channel;

[0044] For each pixel, determining a color index of the pixel in the corresponding partition according to the first component and the second component of the corresponding partition of the pixel;

[0045] Obtaining a preset image compression ratio, and for any one macroblock, compressing the macroblock according to the number of partitions of the macroblock, the first component and the second component of each partition in each color channel, and the color indices of all pixels, to obtain a compressed bitstream corresponding to the macroblock.

[0046] In a possible implementation, partitioning each macroblock includes:

[0047] Determining a partition center of the previous iteration process;

[0048] For each pixel, determining a pixel distance between the pixel and each partition center of the previous iteration process, and dividing the pixel into the partition where the partition center with the minimum pixel distance is located;

[0049] Wherein, the partition center of the first iteration process is represented by a combination of a maximum value of components of any one color channel of all pixels, a minimum value of components of any one color channel, and an average value of components of any one color channel.

[0050] In a possible implementation, pixels are partitioned into the partition where the center of the partition in the previous iteration corresponding to the minimum pixel distance is located. After that, the following steps are further included:

[0051] Determine the average value of the components of all pixels in the same partition in each color channel;

[0052] Update the partition center of the previous iteration process to obtain the partition center of the current iteration process. The partition center of the current iteration process is characterized by the average value of all pixels in the corresponding partition in each color channel;

[0053] Determine the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process;

[0054] If the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process is greater than a preset threshold, calculate the pixel distance between each pixel and the partition center of each current iteration process;

[0055] Partition each pixel into the partition where the partition center of the current iteration process corresponding to the minimum pixel distance is located until the pixel distance between the partition centers of two adjacent iteration processes is less than the preset threshold.

[0056] In a possible implementation, determining the first component and the second component of a partition in each color channel includes:

[0057] Determine the maximum base pixel value and the minimum base pixel value in the partition, and input the maximum base pixel value and the minimum base pixel value into the objective functions of each color channel of the corresponding partition to obtain the first component and the second component of the partition in each color channel;

[0058] Among them, the objective function is obtained by performing linear fitting on the components of the pixels in the partition in the corresponding color channel.

[0059] In a possible implementation, determining the color index of a pixel according to the first component and the second component of the corresponding partition of the pixel includes:

[0060] Determine the quantization number of the macroblock according to the number of partitions of the macroblock; determine the target color channel of the pixel in the corresponding partition;

[0061] Determine the color index of the pixel in the corresponding partition according to the quantization number of the macroblock to which the pixel belongs, the component of the pixel in the target color channel, and the first component and the second component of the target color channel.

[0062] According to another aspect of the embodiments of the present application, an electronic device is provided. The electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the method provided in the second aspect are implemented.

[0063] According to another aspect of the embodiments of the present application, there is provided a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method provided in the second aspect are implemented.

[0064] According to yet another aspect of the embodiments of the present application, there is provided a computer program product, which includes computer instructions stored in a computer-readable storage medium. When a processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, the computer device is caused to execute the steps of the method provided in the second aspect.

[0065] The beneficial effects brought by the technical solution provided by the embodiments of the present application are as follows: In the embodiments of the present application, a target image is divided into a plurality of macroblocks; each macroblock is partitioned, and the pixel distance between any two pixels in different partitions is greater than a preset threshold; for each partition, a first component and a second component of the partition in each color channel are determined; for each pixel, a color index of the pixel in the corresponding partition is determined according to the first component and the second component of the pixel in the corresponding partition; a preset image compression ratio is obtained, and for any one macroblock, the macroblock is compressed according to the number of partitions of the macroblock, the first component and the second component of each partition in each color channel, and the color indexes of all pixels, so as to obtain a compressed bitstream corresponding to the macroblock. In the embodiments of the present application, the first component and the second component of each partition in each color channel and the color index of each pixel are used to represent the components of all pixels in the entire partition in each color channel, the calculation amount is small, and the implementation process is relatively simple. In addition, the color indexes of each pixel are respectively on their corresponding target color channels, and the proportion of the components of each pixel on the target color channel is the largest, which can effectively reduce the compression error. Description of the Drawings

[0066] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description in the embodiments of the present application.

[0067] Figure 1 It is a schematic structural diagram of an image compression device provided by an embodiment of the present application;

[0068] Figure 2 It is a schematic flow chart of partitioning a macroblock provided by an embodiment of the present application;

[0069] Figure 3a It is a schematic diagram of a partition map corresponding to a macroblock including one partition provided by an embodiment of the present application;

[0070] Figure 3bSchematic diagram of a partition map corresponding to a macroblock including two partitions provided by an embodiment of the present application;

[0071] Figure 3c Schematic diagram of a partition map corresponding to a macroblock including three partitions provided by an embodiment of the present application;

[0072] Figure 4 Schematic diagram of the number of partitions corresponding to each macroblock of a target image provided by an embodiment of the present application;

[0073] Figure 5 Schematic flowchart of an image compression method provided by an embodiment of the present application;

[0074] Figure 6 Schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Detailed implementation manners

[0075] The embodiments of the present application will be described below with reference to the accompanying drawings in the present application. It should be understood that the embodiments described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application, and do not constitute limitations on the technical solutions of the embodiments of the present application.

[0076] Those skilled in the art of the present technology can understand that unless specifically stated, the singular forms "a", "an", "the" and "said" used herein may also include the plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application mean that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements, and / or components, but do not exclude the implementation of other features, information, data, steps, operations, elements, components, and / or their combinations supported by the art of the present technology. It should be understood that when we say an element is "connected" or "coupled" to another element, this element can be directly connected or coupled to the other element, or it can mean that this element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used here can include wireless connection or wireless coupling. The term "and / or" used here indicates at least one of the items defined by the term, for example, "A and / or B" can be implemented as "A", or implemented as "B", or implemented as "A and B".

[0077] To make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0078] First, several terms related to the present application will be introduced and explained:

[0079] Image compression refers to the technology of representing the original pixel matrix with fewer bits, either lossy or lossless. It is also known as image coding. Under the condition of meeting a certain quality, it is the technology of representing an image or the information contained in the image with fewer bits.

[0080] Image compression is divided into lossy compression and lossless compression. Lossless compression is the compression of the file itself. Similar to the compression of other data files, it optimizes the data storage method of the file, uses a certain algorithm to represent the repeated data information, and the file can be completely restored without affecting the file content. For digital images, it will not cause any loss of image details.

[0081] Lossy compression is a change to the image itself. When saving the image, more luminance information is retained, while the information of hue and color purity is merged with the surrounding pixels. Different merging ratios result in different compression ratios. Since the amount of information is reduced, the compression ratio can be very high, and the image quality will also decrease accordingly.

[0082] The basic principle of image compression:

[0083] The reason why image data can be compressed is that there is redundancy in the data. The redundancy of image data is mainly manifested as: spatial redundancy caused by the correlation between adjacent pixels in the image; temporal redundancy caused by the correlation between different frames in the image sequence; spectral redundancy caused by the correlation between different color planes or spectral bands. The purpose of data compression is to reduce the number of bits required to represent the data by removing this data redundancy. Due to the huge amount of image data, it is very difficult to store, transmit, and process, so the compression of image data is very important.

[0084] A macro block. An image first needs to be divided into multiple blocks (4*4 pixels) for processing. Obviously, a macro block should be composed of an integer number of blocks. Usually, the macro block size is 16*16 or 4*4 pixels. In this solution, it is preferred to divide the image into 4*4 pixels.

[0085] The image compression device, method, electronic device, and computer-readable storage medium provided by this application aim to solve the above technical problems in the prior art.

[0086] The technical solutions of the embodiments of this application and the technical effects produced by the technical solutions of this application will be described below through the description of several exemplary embodiments.

[0087] An image transmission device is provided in the embodiments of this application, as Figure 1 shown. The device includes:

[0088] An image division module 110, configured to divide a target image into a plurality of macro blocks.

[0089] In the embodiment of the present application, the target image is the original image before compression, which can be any single image or any frame of a video.

[0090] A macroblock is the basic unit for encoding processing. In the embodiment of the present application, the target image is divided into blocks, and the image to be processed is divided into consecutive and non-overlapping macroblocks of the same size. For example, each macroblock is 4*4 pixels.

[0091] It should be noted that each macroblock in the embodiment of the present application is independent, and there is no mutual dependence between macroblocks. That is, when the target image is compressed in the subsequent process, in fact, each macroblock is compressed separately. Such a compression method makes the bitstreams corresponding to each macroblock independent of each other and can avoid error propagation.

[0092] The macroblock partitioning module 120 is used to partition each macroblock, and the pixel distance between any two pixels in different partitions is greater than a preset threshold.

[0093] In the embodiment of the present application, after the target image is divided into several macroblocks, each macroblock is further partitioned to obtain multiple partitions.

[0094] A pixel, also known as a pixel point, an image is composed of several pixels, and the components of a pixel in each color channel can be represented in the form of spatial coordinates.

[0095] In the embodiment of the present application, each pixel includes three color channels. For example, in the RGB model, there are 3 color channels: the R (Red) channel, the G (Green) channel, and the B (Blue) channel. Of course, the three color channels in the embodiment of the present application can also be the three channels corresponding to other color models, such as the three channels corresponding to the three dimensions of the HSV model.

[0096] For example, assuming that a pixel is described by 3 color channels, and a certain pixel is (r1, b1, c1), it can be interpreted that the component of this pixel in the first color channel is r1, the component in the second color channel is b1, and the component in the third color channel is c1.

[0097] The pixel distance between two pixels can be represented by the sum of the absolute values of the differences between the two pixels in each color channel, or in other forms. The embodiment of the present application does not limit this. Specifically, assuming that pixel A is (r1, g1, b1) and B is (r2, g2, b2), then the pixel distance d between the two pixels can be calculated by the formula:

[0098] d = |r1 - r2| + |g1 - g2| + |b1 - b2|.

[0099] Wherein, d is the pixel distance between two pixels, r1 is the component of pixel A in the first color channel, g1 is the component of pixel A in the second color channel, and b1 is the component of pixel A in the third color channel; r2 is the component of pixel B in the first color channel, g2 is the component of pixel B in the second color channel, and b2 is the component of pixel B in the third color channel.

[0100] In the embodiment of the present application, the macroblock is partitioned according to the pixel distances between pixels. The pixel distance between any two pixels in the same partition is less than a preset threshold, that is, the pixel distances between any two pixels in the same partition are relatively close. If the pixel distance between two pixels is greater than the preset threshold, these two pixels will be divided into two partitions.

[0101] In the embodiment of the present application, the macroblock is partitioned to obtain multiple partitions. Each partition contains at least one pixel. It should be noted that when the macroblock is partitioned in the embodiment of the present application, a macroblock has at most 3 partitions, that is, the number of partitions of a macroblock can be 1, 2, or 3. The process of partitioning the macroblock will be described in the following content.

[0102] In the embodiment of the present application, the quantization number of the macroblock is determined according to the number of partitions of the macroblock. The quantization number of the macroblock can be determined according to the number of partitions. The quantization number is the ratio of the number of pixels in the macroblock to the number of partitions of the macroblock. Assume the quantization number is N, the number of pixels in the macroblock is m, and the number of partitions is q (q = 1, 2, 3), then N = m / q. For a macroblock with one partition, the quantization number of this macroblock can be determined to be 16. For a macroblock with two partitions, the quantization number of this macroblock is 8. For a macroblock with three partitions, the quantization number of this macroblock is 4.

[0103] The component determination module 130 is configured to determine, for each partition, the first component and the second component of the partition in each color channel.

[0104] In the embodiment of the present application, the first component and the second component are determined by the base pixel value. For each partition, the maximum base pixel value and the minimum base pixel value in the partition are determined from the base pixel values of all pixels, and the maximum base pixel value and the minimum base pixel value are respectively input into the objective functions of the corresponding color channels of the corresponding partition to obtain the first component and the second component of the partition in each color channel. Among them, the objective function is obtained by performing a linear fit on the components of the pixels in the corresponding color channel of the corresponding partition. The detailed process of determining the objective function will be described in the following content.

[0105] In the embodiment of the present application, the base pixel value refers to the algebraic sum of the components of a pixel in multiple color channels. Specifically, the components of pixel C in each color channel can be expressed as (r, g, b), and the base pixel value x of pixel C can be calculated as x = r + g + b.

[0106] After determining the base pixel values of all pixels in the present application embodiment, the maximum base pixel value x is determined from the base pixel values of all pixels in the partition. max and the minimum base pixel value x min .

[0107] In each partition of the present application embodiment, each color channel has its corresponding objective function. The pixels within the same partition are similar or linearly related. The objective function corresponding to each color channel can be obtained by performing a linear fit on the components of the pixels in each color channel within the same partition. The detailed process is described in the subsequent part.

[0108] After determining the objective functions of each color channel, the maximum base pixel value, and the minimum base pixel value in the partition in the present application embodiment, the maximum base pixel value and the minimum base pixel value are respectively substituted into each objective function to obtain the first component and the second component of the partition in each color channel. The detailed process is described in the subsequent content.

[0109] The color index determination module 140 is configured to determine, for each pixel, the color index of the pixel in the corresponding partition according to the first component and the second component of the corresponding partition of the pixel.

[0110] In the present application embodiment, the color index corresponding to each pixel in the partition is determined by calculating the first component and the second component of each partition in each color channel. The components of the pixel in each color channel can be restored through the first component, the second component, and the color index. When calculating the first component and the second component of each partition in each color channel, the component of each pixel in the corresponding color channel must be between the first component and the second component of the corresponding color channel of the partition to which it belongs. The color displayed by each pixel is affected by multiple color channels. When performing compression, it is necessary to determine the target color channel that has the greatest influence on the pixel.

[0111] For each pixel, the target color channel corresponding to the pixel is determined according to the components of the pixel in each color channel and the first component and the second component of the corresponding partition of the pixel in each color channel.

[0112] Specifically, for any one color channel, the difference between the first component and the second component of the partition in this color channel is calculated to obtain a first parameter. The difference between the component of the pixel in this color channel and the minimum color is calculated to obtain a second parameter. The ratio of the second parameter to the first parameter is determined, and the color channel where the maximum ratio is located is determined. This color channel is the target color channel.

[0113] After determining the target color channel in the present application embodiment, the color index of the pixel is obtained according to the component of the pixel in the target color channel, the quantization number of the macroblock to which the pixel belongs, and the first component and the second component of the corresponding partition of the pixel in the target color channel.

[0114] It can be calculated according to the formula idx = (N - 1) * (v - v 2 ) / (v 1 - v 2 ), where idx is the color index, v is the component of the pixel in the target color channel, v 1 is the first component of the pixel partition in the target color channel, v 2 is the second component of the pixel partition in the target color channel, N is the quantization number of the macroblock, and the value of N can be 4, 8, or 16. That is, for a macroblock with one partition, the quantization number of the macroblock is 16; for a macroblock with two partitions, the quantization number of the macroblock is 8; for a macroblock with three partitions, the quantization number of the macroblock is 4.

[0115] Specifically, assume a pixel (100, 80, 90), that is, the components of the pixel in the three color channels are 100, 80, and 90 respectively. The first component and the second component of the partition to which the pixel belongs in the first color channel are 100 and 30 respectively. It can be calculated that (100 - 30) / (100 - 30) = 1. In the second color channel, the first component and the second component are 100 and 20 respectively. It can be calculated that (80 - 20) / (100 - 20) = 4 / 5. In the third color channel, the first component and the second component are 150 and 60 respectively. It can be calculated that (90 - 60) / (150 - 60) = 1 / 3. Then it is determined that the target color channel is the first color channel.

[0116] The partition of the pixel macroblock is 1. It can be determined that the quantization number corresponding to the pixel macroblock is 16. Then the quantization index idx of the pixel in the corresponding partition can be calculated as idx = (16 - 1) * (100 - 30) / (100 - 30) = 15. Then it can be determined that the quantization index of the pixel is 15.

[0117] The color index of the present application is an index established on the target color channel. The target color channel is the color channel that has the greatest influence on the pixel. Replacing the index on other color channels with the color index on the target color channel can effectively reduce the error caused by scaling, and is simpler than using the interpolation method or calculating the color index by finding the minimum distance.

[0118] If the first component and the second component of a pixel in each color channel in the partition to which the pixel belongs and the color index of the pixel are known, the components of the pixel in each color channel can be restored through the first component and the second component of the corresponding partition of the pixel in each color channel and the color index of the pixel. It can be restored through the formula v = idx * (v 1 - v 2 ) / (N - 1) + v 2 to restore the components of the pixel in each color channel, where idx is the color index of the pixel, v1 and v 2 respectively represent the first component and the second component of the corresponding partition of the pixel in a certain color channel. N is the quantization number of the macroblock, and the value of N is 4, 8 or 16.

[0119] Continuing with the above example, the quantization index of a certain pixel is 15. The first component and the second component of the partition where the pixel is located in the first color channel are 100 and 30, the first component and the second component in the second color channel are 100 and 20 respectively, and the first component and the second component in the third color channel are 150 and 60 respectively. After restoring the components of the pixel in the three color channels, the three component values obtained are 100, 100 and 150 respectively, and there is a certain pixel distance from the components of the pixel in the three color channels which are 100, 80 and 90 respectively as described above. From this, it can be determined that there is a certain loss in compressing the image with the color index of one color channel in this application, which is lossy compression. However, the color index in this application is the index on the target color channel, and the target color channel is the color channel that has the greatest impact on the pixel. Replacing the index on other color channels with the color index on the target color channel can effectively reduce the error caused during scaling.

[0120] The compression bitstream obtaining module 150 is used to obtain a preset image compression ratio. For any macroblock, compress the macroblock according to the number of partitions of the macroblock, the first component and the second component of each partition in each color channel, and the color indexes of all pixels, so as to obtain the compression bitstream corresponding to the macroblock.

[0121] The preset image compression ratio in the embodiments of this application refers to the compression ratio expected by the user. The image compression ratio is the ratio of the compression bitstream of the target image to the original bitstream of the target image. For example, the compression ratio is 1:3, that is, the compression bitstream of the target image is 1 / 3 of the original bitstream of the target image, realizing the compression of the target image. In the embodiments of this application, the target image is divided into several macroblocks, and the image compression ratio is also the macroblock compression ratio, that is, the image compression ratio is also the ratio of the compression bitstream of the macroblock to the original bitstream of the macroblock.

[0122] After determining the preset image compression ratio in the embodiments of this application, determine the bit lengths required for each of the number of partitions in the macroblock, the first component and the second component of each partition in each color channel, and the color indexes of all pixels to be pushed into the bitstream.

[0123] Specifically, a first identifier can be set for the number of partitions of the macroblock. For a macroblock with 1 partition, the first identifier is set to 00, consuming 2 bits. For a macroblock with 2 partitions, the first identifier is set to 01, consuming 2 bits. For a macroblock with 3 partitions, the first identifier is set to 1, consuming 1 bit. It can be understood that when pushing the first identifier into the code stream, the first bit of the code stream can be determined first. If the first bit is 0, it is determined that there are either 1 or 2 partitions, and then the second bit is determined. If the second bit is 0, it is determined that there is 1 partition. If the second bit is 1, it is determined that there are 2 partitions. If the first bit is 1, it is determined that there are 3 partitions.

[0124] Similarly, a partition index can be set for each pixel. The partition index can be the partition number corresponding to the pixel partition. For a macroblock with 1 partition, the partition index can be not set to save the code stream, consuming 0 bits. For a macroblock with 2 partitions, the partition index of each pixel is either 1 or 0, so it is determined that 16 bits are consumed to store the partition indexes of each pixel; for a macroblock with 3 partitions, the partition index of each pixel is any one of 00, 01, or 10, so it is determined that 32 bits are consumed to store the partition indexes of each pixel.

[0125] Pushing the components of each pixel of the target image in each color channel into the code stream requires 10 bits. Each pixel has components in three color channels, so pushing the components of each pixel in each color channel into the code stream requires 30 bits. For a 4*4 macroblock, pushing the components of all pixels in the macroblock in each color channel into the code stream requires 480 bits. The compression ratio of the image in the embodiment of the present application is 4:15, that is, it is necessary to implement the compressed code stream corresponding to the target image to be 128 bits.

[0126] Continuing the above example, the number of bits required to push the flag bits, partition indexes, and color indexes corresponding to the number of partitions into the code stream has been determined. Subtracting the number of bits required to push the number of partitions, partition indexes, and color indexes into the code stream from the total number of bits of the compressed code stream, that is, the number of bits corresponding to the first component and the second component of each partition in each color channel is obtained. For a macroblock with 1 partition, pushing the first component and the second component of each color channel of the sub-region into the code stream both require 10 bits; for a macroblock with 2 partitions, pushing the first component and the second component of each color channel of each sub-region into the code stream both require 5 bits (the 5 high bits. When restoring the components of each color channel of the pixel, first shift this bit 5 bits to the left); for a macroblock with 3 partitions, pushing the first component and the second component of each color channel of each sub-region into the code stream both require 4 bits (the 4 high bits. When restoring the components of each color channel of the pixel, first shift this bit 6 bits to the left).

[0127] After determining the number of bits required to push the flag bits corresponding to the number of partitions, the partition index, the color index, and the first and second components of each partition in each color channel into the bitstream, in a preset order, such as the order of the number of partition flag bits, the partition index, the color index, and the first and second components of each partition in each color channel, push the above-mentioned number of partition flag bits, partition index, color index, and the first and second components of each partition in each color channel into the bitstream respectively.

[0128] In the embodiment of the present application, after determining the first and second components of each partition in each color channel and the color index of all pixels, each partition is compressed to obtain the compressed bitstream of the partition, and then the compressed bitstreams of each partition are combined to obtain the compressed bitstream of the macroblock. When combining the bitstreams of each partition, it is necessary to determine the index corresponding to each pixel and push the index corresponding to each pixel into the bitstream. For the entire macroblock, the bitstream of the macroblock includes the following information: the number of partitions, the partition index of each pixel, the first and second components of each partition in each color channel, and the color index of each pixel.

[0129] The embodiment of the present application can set different coding modes for different numbers of partitions. The coding mode includes a format set for the number of bits occupied by the first identifier corresponding to the number of partitions, the number of bits occupied by the partition index of each pixel, the number of bits occupied by the first and second components of each color channel, and the number of bits occupied by the color index of each pixel.

[0130] In fact, after determining the number of partitions of the macroblock in the embodiment of the present application, the corresponding coding mode of the macroblock can be directly determined. For a macroblock with 1 partition, the corresponding coding mode is mode1; for a macroblock with 2 partitions, the corresponding coding mode is mode2; for a macroblock with 3 partitions, the corresponding coding mode is mode3. By determining the number of partitions of each macroblock, the corresponding coding mode of each macroblock can be determined, without using the recovery error to judge which compression mode to select. The method of using the recovery error to determine the compression mode needs to determine the error corresponding to each pixel respectively. Although this compression method reduces the compression error to a certain extent, the calculation amount is large, there are many coding modes, and the hardware implementation is relatively complex. The embodiment of the present application directly determines the compression mode of the macroblock according to the number of partitions. Each macroblock corresponds to only one compression mode, and the compression method is relatively simple. For a macroblock with complex colors, the corresponding number of partitions is relatively large, and the compression error is relatively small, which can achieve a compression error similar to that of the method of using the recovery error to determine the compression mode.

[0131] In the embodiment of the present application, by determining the first component and the second component of each partition in each color channel and the color index of each pixel to characterize the components of all pixels in the entire partition in each color channel, the amount of calculation is small and the implementation process is relatively simple. In addition, the color indices of each pixel are respectively on their corresponding target color channels, and the proportion of the components of each pixel on the target color channel is the largest, which can effectively reduce the compression error.

[0132] The embodiment of the present application provides a possible implementation manner. The macroblock partitioning module includes:

[0133] The partition center determination sub-module is used to determine the partition center of the previous iteration process;

[0134] The partition determination sub-module for the pixel where the pixel is located is used to, for each pixel, determine the pixel distance between the pixel and the partition center of each previous iteration process, and divide the pixel into the partition where the partition center of the previous iteration process corresponding to the minimum pixel distance is located;

[0135] Wherein, the partition center of the first iteration process is characterized by a combination of the maximum value of the components of any one color channel, the minimum value of the components of any one color channel, and the average value of the components of any one color channel.

[0136] The partitioning of the macroblock in the embodiment of the present application is a continuously iterative process. First, the partition center of the iteration process is characterized by a combination of the maximum value of the components of any one color channel, the minimum value of the components of any one color channel, and the average value of the components of any one color channel.

[0137] Specifically, obtain the components of each pixel in each color channel, and right-shift the components of each pixel in each color channel by the length of the first preset number of bits. Specifically, the initial length of the components of each pixel in the color channel is 10 bit, and the length of the first preset number of bits is 4, that is, 6 bit remains after the right shift.

[0138] In the embodiment of the present application, right-shifting the components of each pixel in each color channel can reduce the bit width in the calculation process, eliminate the influence of the fine pixel distance between each pixel, improve the accuracy of partitioning, thereby reducing the error of over-drive compression, and making the partitioning result more stable and reliable.

[0139] After the components of each pixel in each color channel are shifted in the embodiments of the present application, the maximum value, minimum value, and average value of the components of all pixels in each color channel are determined, namely Rmin, Rmean, Rmax, Gmin, Gmean, Gmax, Bmin, Bmean, Bmax, where R, G, and B represent different color channels. Thus, the partition centers of the first iteration process can be generated, which are (Rmax, Gmean, Bmin), (Rmean, Gmin, Bmax), and (Rmin, Gmax, Bmean). That is, the partition centers of the first iteration process are characterized by the combination of the maximum value of the components of any one color channel of all pixels, the minimum value of the components of any one color channel, and the average value of the components of any one color channel. Thus, three partition centers in the first iteration process can be generated.

[0140] The partition centers of the first iteration process in the embodiments of the present application are characterized by the combination of the maximum value of the components of any one color channel of all pixels, the minimum value of the components of any one color channel, and the average value of the components of any one color channel, so that the three partition centers of the first iteration process are relatively dispersed and can cover all pixels.

[0141] After determining the three partition centers in the previous iteration process in the embodiments of the present application, the pixel distance (the pixel distance is also called the difference) between each pixel and each partition center is determined. Assuming that each pixel in the macroblock is represented by (r i , g i , b i ), and each partition center is represented by (r j , g j , b j ), the formula for calculating the pixel distance between the two is as follows:

[0142] d = |r i - r j | + |g i - g j | + |b i - b j |, (i = 0 to 15, j = 0 to 2)

[0143] where d represents the pixel distance between each pixel i and partition center j, r i represents the component of a certain pixel in the macroblock in the first color channel, g i represents the component of a certain pixel in the macroblock in the second color channel, b i represents the component of a certain pixel in the macroblock in the third color channel; r j represents the component of a certain partition center in the first color channel, g j represents the component of a certain partition center in the second color channel, bj Represents the component of a certain partition center in the third color channel.

[0144] After calculating the pixel distance between each pixel and each partition center in the embodiments of the present application, the pixel distance is shifted to the right by the length of the second bit. Specifically, in the embodiments of the present application, the pixel distance can be shifted to the right by 3 bits, that is, d>>3 (>> represents shifting to the right), and the minimum pixel distance is determined from the pixel distance after shifting to the right. The smaller the pixel distance, the more similar the two are. After determining the minimum pixel distance in the embodiments of the present application, the pixel is divided into the partition where the partition center corresponding to the minimum pixel distance is located.

[0145] The embodiments of the present application provide a possible implementation manner. The pixel location determination sub-module further includes:

[0146] An average value determination unit, configured to determine the average value of all pixels in the same partition in each color channel.

[0147] A partition center iteration unit, configured to update the partition center of the previous iteration process to obtain the partition center of the current iteration process. The partition center of the current iteration process is characterized by the average value of all pixels in the corresponding partition in each color channel.

[0148] A pixel distance first determination unit, configured to determine the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process.

[0149] A pixel distance second determination unit, configured to calculate the pixel distance between each pixel and each partition center of the current iteration process if the pixel distance is greater than a preset threshold.

[0150] A pixel location partition unit, configured to divide each pixel into a new partition where the partition center of the current iteration process corresponding to the minimum pixel distance is located until the pixel distance between the partition centers of two adjacent iteration processes is less than a preset threshold.

[0151] After the embodiments of the present application divide each pixel into the partition where the previous iteration process corresponding to the minimum pixel distance is located, the average value of all pixels in the same partition in each color channel is determined. In practical applications, a partition number can be set for each partition center, and a partition index can be set for each pixel at the same time. The partition index is the partition number corresponding to the partition center, and is used to represent the partition to which the pixel belongs.

[0152] Assume that the partition centers in the previous iteration process are A, B, and C respectively, where the partition number of A is 00, the partition number of B is 01, and the partition number of C is 11. If the partition index of the pixels in a certain macroblock is any one of 00, 01, or 11, it can be determined that the macroblock has only one partition. If the partition index of the pixels in a certain macroblock includes any two of 00, 01, or 11, it is determined that the macroblock has two partitions. If the partition index of the pixels in a certain macroblock includes 00, 01, and 11 at the same time, it is determined that the macroblock has three partitions.

[0153] After determining the partitions to which each pixel belongs in the embodiments of the present application, the average value of all pixels in the same partition in each color channel is determined.

[0154] After determining the average value of all pixels in the same partition in each color channel in the embodiments of the present application, the partition centers in the previous iteration process are updated to obtain the partition centers in the current iteration process. The partition centers in the current iteration process are characterized by the average value of the corresponding partition centers in each color channel.

[0155] After updating the partition centers in the previous iteration process in the embodiments of the present application, the partition centers in the current iteration process are obtained. At this time, the pixel distance between the partition centers in the current iteration process and the partition centers in the previous iteration process needs to be calculated, and whether each partition center tends to be stable is judged through this pixel distance, and then whether the partitioning of the macroblock tends to be stable is judged.

[0156] If the pixel distance between the partition centers in the current iteration process and the partition centers in the previous iteration process is greater than a preset threshold, and the preset threshold can be 16, it can be determined that the partition centers in the current iteration process do not tend to be stable, and it is necessary to calculate the pixel distance between each pixel and the partition centers in the current iteration process again, and divide each pixel into the partition where the partition center corresponding to the minimum pixel distance is located until the pixel distance between the partition centers in two adjacent iteration processes is less than the preset threshold.

[0157] In the embodiments of the present application, when the pixel distance between the partition centers in two adjacent iteration processes is less than the preset threshold, it is determined that each partition center tends to be stable.

[0158] As Figure 2 shown, it exemplarily shows a flowchart of partitioning a macroblock, including:

[0159] Step S201, shifting the components of each pixel in the macroblock in each color channel to the right by the first preset bit length;

[0160] Step S202, calculate the maximum value, minimum value, and average value of the components of all pixels in each color channel within the macroblock, which can be represented by Rmin, Rmean, Rmax, Gmin, Gmean, Gmax, Bmin, Bmean, and Bmax;

[0161] Step 203, generate the partition centers for the first iteration process as c0(Rmax, Gmean, Bmin), c1(Rmean, Gmin, Bmax), and c2(Rmin, Gmax, Bmean);

[0162] Step S204, calculate the pixel distance d1 between each pixel within the macroblock and the partition center of the previous iteration process;

[0163] Step S205, divide the pixels into the partition where the partition center of the previous iteration process corresponding to the minimum pixel distance is located, and establish a partition index for each pixel;

[0164] Step S206, determine the average value of all pixels in the same partition in each color channel;

[0165] Step S207, update the partition centers of the previous iteration to obtain the partition centers of the current iteration process. The partition centers of the current iteration process are characterized by the average values of all pixels in the corresponding partitions in each color channel;

[0166] Step S208, determine the pixel distance d2 between the partition centers of the current iteration process and the previous iteration process;

[0167] Step S209, determine whether the pixel distance d2 is greater than a preset threshold; if so, repeat steps S204 - S209;

[0168] Step S210, if not, output the partition map; the partition map includes the partition indices of each pixel.

[0169] As Figure 3a shown, it exemplarily shows the partition map corresponding to a macroblock containing one partition, and the partition indices of all pixels are the same;

[0170] As Figure 3b shown, it exemplarily shows the partition map corresponding to a macroblock containing two partitions, where the partition indices of some pixels are 1 and those of some pixels are 0;

[0171] As Figure 3c shown, it exemplarily shows the partition map corresponding to a macroblock containing three partitions, where the partition indices of some pixels are 00, those of some pixels are 10, and those of some pixels are 11.

[0172] Obviously, for a macroblock of a partition, there is no need to push the corresponding partition map into the bitstream; for a macroblock of two partitions, the partition index of each pixel needs to be represented by 0 or 1, and it costs 16 bits to push it into the bitstream. For a macroblock of three partitions, the partition index of each pixel needs to be represented by 00, 01, or 11, and it costs 32 bits to push it into the bitstream.

[0173] An embodiment of the present application provides a possible implementation manner. The component determination module includes:

[0174] The component determination sub-module is used to determine the maximum base pixel value and the minimum base pixel value in the partition, input the maximum base pixel value and the minimum base pixel value into the objective functions of the respective color channels of the corresponding partition, and obtain the first component and the second component of the partition in each color channel;

[0175] Among them, the objective function is obtained by performing linear fitting on the components of the pixels in the partition in the corresponding color channel.

[0176] In the embodiment of the present application, the base pixel value refers to the algebraic sum of the components of a pixel in multiple color channels. Specifically, if the components of pixel C in each color channel are represented by (r, g, b), the base pixel value x of pixel C can be calculated as x = r + g + b.

[0177] After determining the base pixel values of all pixels in the embodiment of the present application, the maximum base pixel value x is determined from the base pixel values of all pixels in the partition max and the minimum base pixel value x min .

[0178] The objective function in the embodiment of the present application includes:

[0179] R = a 0 *x m +b 0

[0180] G = a 1 *x m +b 1

[0181] B = a 2 *x m +b 2

[0182] Among them, R, G, and B are respectively the first component or the second component of each color channel, and x m is the maximum base pixel value or the minimum base pixel value. Specifically, input the maximum base pixel value x max into R = a 0 *x m +b 0 , the first component of the partition in the R color channel can be obtained. Input the minimum base pixel value xmin Input to R = a 0 *x m +b 0 , the second component of the partition in the R color channel can be obtained, and thus the first and second components of the partition in each color channel are obtained.

[0183] The a in the above objective function 0 、a 1 、a 2 、b 0 、b 1 and b 2 are determined by the following formulas:

[0184] a 0 = SUM rx *m - SUM x *SUM r ,

[0185] b 0 = SUM xx *SUM r - SUM x *SUM rx ,

[0186] a 1 = SUM gx *m - SUM x *SUM g ,

[0187] b 1 = SUM bx *SUM g - SUM x *SUM gx ,

[0188] a 2 = SUM bx *m - SUM x *SUM b ,

[0189] b 2 = SUM xx *SUM b - SUM x *SUM bx ,

[0190] where x represents the maximum base pixel value or the minimum base pixel value, r, g, and b represent color channels, SUM r 、SUM g 、SUM b respectively represent the algebraic sum of the components of each color channel, SUM xRepresents the algebraic sum of all base pixel values, SUM rx 、SUM gx 、SUM bx respectively represent the algebraic sum of the product of the components of each color channel and the base pixel value, SUM xx represents the algebraic sum of the squares of all base pixels. SUM r 、SUM g 、SUM b 、SUM x 、SUM rx 、SUM gx 、SUM bx and SUM xx The calculation formulas are as follows:

[0191]

[0192]

[0193]

[0194] where m is the number of pixels in the sub-region, i represents the i-th pixel, and r, g, and b represent color channels.

[0195] In the embodiment of the present application, after determining the above SUM r 、SUM g 、SUM b 、SUM x 、SUM rx 、SUM gx 、SUM bx and SUM xx substitute them into the formula:

[0196] a 0 =SUM rx *m - SUM x *SUM r ,

[0197] b 0 =SUM xx *SUM r -SUM x *SUM rx ,

[0198] a 1 =SUM gx *m - SUM x *SUM g ,

[0199] b 1 =SUM bx *SUM g -SUMx *SUM gx ,

[0200] a 2 =SUM bx *m - SUM x *SUM b ,

[0201] b 2 =SUM xx *SUM b -SUM x *SUM bx ,

[0202] to calculate the values of a 0 、b 0 、a 1 、b 1 、a 2 and b 2 and substitute these values into the objective functions of each color channel:

[0203] R = a 0 *x m +b 0

[0204] G = a 1 *x m +b 1

[0205] B = a 2 *x m +b 2

[0206] Then, the objective functions corresponding to each color channel can be obtained. Substitute the maximum base pixel value x max and the minimum base pixel value x min into the above objective functions to obtain the first and second components of each partition in each color channel, and get the first and second components corresponding to each partition in each color channel, which are R 1 and R 2 , G 1 and G 2 , B 1 and B 2 . Combine the first components of each color channel to get the color of the first partition as (R 1 , G 1 , B 1 ), and combine the second components of each color channel to get the color of the second partition as (R 2 , G 2 , B 2 ), R 1 and R 2are the first and second components of the same color channel; G 1 and G 2 are the first and second components of the same color channel; B 1 and B 2 are the first and second components of the same color channel.

[0207] In the embodiment of the present application, the base pixel value is used as the base axis for linear fitting to obtain the objective function, with stable results, resistance to noise, improved accuracy of the fitted line, and a simpler and more efficient implementation process than using the components of one of the color channels as the base axis.

[0208] The embodiment of the present application provides a possible implementation manner. The component determination sub-module includes:

[0209] The base pixel value acquisition unit is configured to obtain the base pixel value of the corresponding pixel according to the algebraic sum of the components of all color channels of each pixel in the partition;

[0210] The maximum base pixel value and minimum base pixel value determination unit is configured to determine the maximum base pixel value and the minimum base pixel value from the base pixel values of all pixels in the partition.

[0211] In the embodiment of the present application, the base pixel value refers to the algebraic sum of the components of a pixel in multiple color channels. Specifically, the components of pixel C in each color channel are (r, g, b), and the base pixel value x of pixel C can be calculated as x = r + g + b.

[0212] After determining the base pixel values of all pixels in the embodiment of the present application, the maximum base pixel value x max and the minimum base pixel value x min are determined, and no further elaboration will be provided here.

[0213] The embodiment of the present application provides a possible implementation manner. The color index determination module includes:

[0214] The quantization number determination sub-module is configured to determine the quantization number of the macroblock according to the number of partitions of the macroblock;

[0215] The target color channel determination sub-module is configured to determine the target color channel of the pixel in the corresponding partition;

[0216] The color index determination sub-module is configured to determine the color index of the pixel in the corresponding partition according to the quantization number of the macroblock to which the pixel belongs, the component of the pixel in the target color channel, and the first and second components of the target color channel.

[0217] In the embodiment of the present application, the quantization number of a macroblock is determined according to the number of partitions of the macroblock. The quantization number of the macroblock can be determined according to the number of partitions. The quantization number is the ratio of the number of pixels in the macroblock to the number of partitions of the macroblock. Assuming the quantization number is N, the number of pixels in the macroblock is m, and the number of partitions is q (q = 1, 2, 3), then N = m / q. For a macroblock with one partition, the quantization number of the macroblock can be determined to be 16. For a macroblock with two partitions, the quantization number of the macroblock is 8. For a macroblock with three partitions, the quantization number of the macroblock is 4.

[0218] The embodiment of the present application includes multiple color channels. For any one color channel, calculate the difference between the first component and the second component of the partition in this color channel to obtain a first parameter. Calculate the difference between the component of the pixel in this color channel and the minimum color to obtain a second parameter. Determine the ratio of the second parameter to the first parameter, and determine the color channel where the maximum ratio is located. This color channel is the target color channel.

[0219] After determining the target color channel in the embodiment of the present application, obtain the color index of the pixel according to the component of the pixel on the target color channel, the quantization number of the macroblock to which the pixel belongs, and the first component and the second component of the corresponding partition of the pixel on the target color channel.

[0220] It can be calculated according to the formula idx = (N - 1) * (v - v 2 ) / (v 1 - v 2 ), where idx is the color index, v is the component of the pixel on the target color channel, v 1 is the first component of the pixel partition on the target color channel, v 2 is the second component of the pixel partition on the target color channel, and N is the quantization number of the macroblock.

[0221] Substitute the components of each pixel on the target color channel, the first component and the second component of the target color channel, and the quantization number of the macroblock into the above formula, and the quantization index of each pixel can be calculated. It can be determined that (v - v 2 ) / (v 1 - v 2) If the value is less than or equal to 1, then idx <= N - 1. For a macroblock with 1 partition, the quantization number N = 16, so the maximum color index of each pixel in this macroblock is 15. Thus, it is determined that 4 bits are required to store the color index of each pixel, and 64 bits are required to store the color indexes of 16 pixels. For a macroblock with 2 partitions, the quantization number N = 18, and the maximum color index of each pixel in this macroblock is 7. Thus, it is determined that 3 bits are required to store the color index of each pixel, and 64 bits are required to store the color indexes of 16 pixels. For a macroblock with 3 partitions, the quantization number N = 4, and the maximum color index of each pixel in this macroblock is 3. Thus, it is determined that 2 bits are required to store the color index of each pixel, and 32 bits are required to store the color indexes of 16 pixels.

[0222] An embodiment of the present application provides a possible implementation manner. The target color channel determination sub-module includes:

[0223] The first parameter determination unit is configured to, for any one color channel, obtain a first parameter according to the difference between the component of the pixel in the corresponding color channel and the second component of the partition in the corresponding color channel;

[0224] The second parameter determination unit is configured to determine the difference between the first component of the partition in the corresponding color channel and the second component of the partition in the corresponding color channel, and obtain a second parameter;

[0225] The third parameter determination unit is configured to obtain a third parameter according to the ratio of the first parameter and the second difference;

[0226] The target color channel determination unit is configured to determine the color channel corresponding to the maximum third parameter as the target color channel.

[0227] In the embodiment of the present application, the first component and the second component of each partition in each color channel are calculated. The component of each pixel in the corresponding color channel must be between the first component and the second component of the partition to which it belongs in the corresponding color channel. The color presented by each pixel is affected by multiple color channels. When performing compression, it is necessary to determine the target color channel that has the greatest impact on the pixel.

[0228] For any one color channel, calculate the difference between the first component and the second component of the partition in this color channel to obtain a first parameter, calculate the difference between the component of the pixel in this color channel and the minimum color to obtain a second parameter, determine the ratio of the second parameter and the first parameter to obtain a third parameter, and determine the color channel where the maximum third parameter is located. This color channel is the target color channel.

[0229] Suppose a pixel (100, 80, 90), that is, the components of this pixel in the three color channels are 100, 80, and 90 respectively. The first component and the second component of the partition to which this pixel belongs in the first color channel are 100 and 30 respectively. It can be calculated that (100 - 30) / (100 - 30) = 1. In the second color channel, the first component and the second component are 100 and 20 respectively. It can be calculated that (80 - 20) / (100 - 20) = 4 / 5. In the third color channel, the first component and the second component are 150 and 60 respectively. It can be calculated that (90 - 60) / (150 - 60) = 1 / 3. Then the target color channel is determined to be the first color channel.

[0230] An embodiment of the present application provides a possible implementation manner. The color index determination module includes:

[0231] The first target parameter determination sub-module is used to determine the difference between the component of the pixel in the target color channel and the second component of the target color channel to obtain the first target parameter;

[0232] The second target parameter determination sub-module is used to determine the difference between the first component and the second component of the target color channel to obtain the second target parameter;

[0233] The third target parameter determination sub-module is used to determine the ratio between the first target parameter and the second target parameter to obtain the third target parameter;

[0234] The color index determination sub-module is used to determine the color index of the pixel in the corresponding partition according to the third target parameter and the quantization number.

[0235] In the embodiment of the present application, the first target parameter is the difference between the component of the pixel in the target color channel and the second component of the target color channel; the second target parameter is the difference between the first component and the second component of the target color channel; the third target parameter is the ratio between the first target parameter and the second target parameter. The color index of the pixel in the corresponding partition can be determined according to the third target parameter and the quantization number.

[0236] Specifically, continuing with the above example, in the above embodiment, the color index idx = (N - 1) * [(v - v 2 ) / (v 1 - v 2 )] has been determined, where v is the component of the pixel in the target color channel, v 1 and v 2 are the first component and the second component of the target color channel of the partition to which this pixel belongs, N is the quantization number, (v - v 2 ) is the first target parameter, (v 1 - v 2 ) is the second target parameter, [(v - v 2 ) / (v1 -v 2 )] is the third target parameter, (N - 1) * [(v - v 2 ) / (v 1 -v 2 )] is the color index of the pixel.

[0237] In the embodiment of the present application, by establishing the color index of each pixel on the corresponding partition, it is no longer necessary to store the components of each pixel in each color channel. Compared with storing the components of each pixel in each color channel, storing the color index only requires a small number of bits.

[0238] As Figure 4 shown, it exemplarily shows a schematic diagram of the number of corresponding partitions of each macroblock of the target image. As shown in the figure, the number of partitions of the blank unfilled macroblock is 1, the number of partitions of the slant-filled macroblock is 3, and the number of partitions of the vertical-line-filled macroblock is 2.

[0239] The embodiment of the present application provides an image compression method. As Figure 5 shown, the method includes:

[0240] Step S501: Divide the target image into several macroblocks;

[0241] Step S502: Partition each macroblock, and the pixel distance between any two pixels in different partitions is greater than a preset threshold;

[0242] Step S503: For each partition, determine the first component and the second component of the partition in each color channel;

[0243] Step S504: For each pixel, determine the color index of the pixel in the corresponding partition according to the first component and the second component of the corresponding partition of the pixel;

[0244] Step S505: Obtain a preset image compression ratio. For any one macroblock, compress the macroblock according to the number of partitions of the macroblock, the first component and the second component of each partition in each color channel, and the color indexes of all pixels to obtain the compressed bitstream corresponding to the macroblock.

[0245] In the embodiment of the present application, the components of all pixels in each color channel of the entire partition are represented by the first component and the second component of each partition in each color channel and the color index of each pixel. The calculation amount is small and the implementation process is relatively simple. In addition, the color indexes of each pixel are respectively on their corresponding target color channels, and the proportion of each pixel on the target color channel is the largest, which can effectively reduce the compression error.

[0246] The embodiment of the present application provides a possible implementation manner. Partitioning each macroblock includes:

[0247] Determine the partition center of the previous iteration process;

[0248] For each pixel, determine the pixel distance between the pixel and the partition center of each previous iteration process, and divide the pixel into the partition where the partition center of the previous iteration process corresponding to the minimum pixel distance is located;

[0249] Among them, the partition center of the first iteration process is characterized by a combination of the maximum value, the minimum value, and the average value of the components of any one color channel of all pixels.

[0250] An embodiment of the present application provides a possible implementation manner. After dividing the pixel into the partition where the partition center of the previous iteration process corresponding to the minimum pixel distance is located, it further includes:

[0251] Determine the average value of the components of all pixels in the same partition in each color channel;

[0252] Update the partition center of the previous iteration process to obtain the partition center of the current iteration process. The partition center of the current iteration process is characterized by the average value of all pixels in the corresponding partition in each color channel;

[0253] Determine the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process;

[0254] If the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process is greater than the preset threshold, calculate the pixel distance between each pixel and the partition center of each current iteration process;

[0255] Divide each pixel into the partition where the partition center of the current iteration process corresponding to the minimum pixel distance is located until the pixel distance between the partition centers of two adjacent iteration processes is less than the preset threshold.

[0256] An embodiment of the present application provides a possible implementation manner. Determining the first component and the second component of the partition in each color channel includes:

[0257] Determine the maximum base pixel value and the minimum base pixel value in the partition, and input the maximum base pixel value and the minimum base pixel value into the objective function of each color channel of the corresponding partition to obtain the first component and the second component of the partition in each color channel;

[0258] Among them, the objective function is obtained by performing linear fitting on the components of the pixels in the partition in the corresponding color channel.

[0259] An embodiment of the present application provides a possible implementation method. Determining the color index of a pixel in a corresponding partition according to the first component and the second component of the corresponding partition of the pixel includes:

[0260] Determining the quantization number of a macroblock according to the number of partitions of the macroblock; determining the target color channel of the pixel in the corresponding partition;

[0261] Determining the color index of the pixel in the corresponding partition according to the quantization number of the macroblock to which the pixel belongs, the component of the pixel in the target color channel, and the first component and the second component of the target color channel.

[0262] The device according to the embodiment of the present application can execute the method provided by the embodiment of the present application, and its implementation principle is similar. The actions performed by each module in the device according to the embodiments of the present application correspond to the steps in the method according to the embodiments of the present application. For the detailed function description of each module of the device, reference can be specifically made to the description in the corresponding method shown above, and details are not described herein again.

[0263] An electronic device is provided in an embodiment of the present application, including a memory, a processor, and a computer program stored on the memory. The processor executes the above computer program to implement the steps of an image compression method. Compared with the related art, it can be realized that: in the embodiment of the present application, the components of all pixels in the entire partition in each color channel are characterized by the first component and the second component of each partition in each color channel and the color index of each pixel, the calculation amount is small, and the implementation process is relatively simple. In addition, the color indexes of each pixel are respectively on their corresponding target color channels, and the proportion of the components of each pixel on the target color channel is the largest, which can effectively reduce the compression error.

[0264] In an optional embodiment, an electronic device is provided, as Figure 6 shown, Figure 6 The electronic device 6000 shown includes: a processor 6001 and a memory 6003. Among them, the processor 6001 and the memory 6003 are connected, such as connected through a bus 6002. Optionally, the electronic device 6000 may further include a transceiver 6004, and the transceiver 6004 may be used for data interaction between the electronic device and other electronic devices, such as data sending and / or data receiving, etc. It should be noted that in practical applications, the transceiver 6004 is not limited to one, and the structure of the electronic device 6000 does not constitute a limitation to the embodiment of the present application.

[0265] The processor 6001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logical blocks, modules, and circuits described in connection with the disclosure of this application. The processor 6001 may also be a combination that implements a determined function, such as a combination including one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0266] The bus 6002 may include a path for transmitting information between the above components. The bus 6002 may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 6002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 only a thick line is used to represent it herein, but it does not mean that there is only one bus or one type of bus.

[0267] The memory 6003 may be a ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, a RAM (Random Access Memory) or other type of dynamic storage device that can store information and instructions, or it may also be an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory), or other optical disc storage, optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store a computer program and can be read by a computer, which is not limited herein.

[0268] The memory 6003 is used to store the computer program for implementing the embodiments of the present application, and is controlled by the processor 6001 to execute. The processor 6001 is used to execute the computer program stored in the memory 6003 to implement the steps shown in the foregoing method embodiments.

[0269] The embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps and corresponding content of the foregoing method embodiments can be implemented. Compared with the prior art, it can be realized that: in the embodiments of the present application, the first component and the second component of each partition in each color channel and the color index of each pixel are used to represent the components of all pixels in the entire partition in each color channel, and the calculation amount is small, and the implementation process is relatively simple. In addition, the color indexes of each pixel are respectively on their corresponding target color channels, and the proportion of the components of each pixel on the target color channel is the largest, which can effectively reduce the compression error.

[0270] It should be understood that although the flowcharts of the embodiments of the present application indicate various operation steps by arrows, the execution order of these steps is not limited to the order indicated by the arrows. Unless there is a clear description in this article, in some implementation scenarios of the embodiments of the present application, the implementation steps in each flowchart can be executed in other orders according to requirements. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage of these sub-steps or stages can also be executed at different times respectively. In the scenario where the execution times are different, the execution order of these sub-steps or stages can be flexibly configured according to requirements, and the embodiments of the present application do not limit this.

[0271] The above are only optional implementation manners of some implementation scenarios of the present application. It should be noted that for those of ordinary skill in the art, without departing from the technical concept of the solution of the present application, other similar implementation means based on the technical idea of the present application also belong to the protection scope of the embodiments of the present application.

Claims

1. An image compression device, characterized in that, comprising: An image division module for dividing a target image into a plurality of macroblocks; A macroblock partitioning module for partitioning each of the macroblocks, and the pixel distance between any two pixels in different partitions is greater than a preset threshold; A component determination module for determining, for each partition, a first component and a second component of the partition in each color channel; A color index determination module for determining, for each pixel, a color index of the pixel in the corresponding partition according to the first component and the second component of the corresponding partition of the pixel; A compressed bitstream obtaining module for obtaining a preset image compression ratio, and for any one macroblock, compressing the macroblock according to the number of partitions of the macroblock, the first component and the second component of each partition in each color channel, and the color indices of all pixels to obtain a compressed bitstream corresponding to the macroblock; The component determination module includes: A component determination sub-module for determining a maximum base pixel value and a minimum base pixel value in the partition, inputting the maximum base pixel value and the minimum base pixel value into objective functions of the corresponding color channels of the partition respectively, and obtaining the first component and the second component of the partition in each color channel; the base pixel value refers to the algebraic sum of the components of a pixel in multiple color channels; wherein, the objective function is obtained by performing linear fitting on the components of the pixels in the corresponding color channel of the partition; The color index determination module includes: A quantization number determination sub-module for determining a quantization number of the macroblock according to the number of partitions of the macroblock; A target color channel determination sub-module for determining a target color channel of the pixel in the corresponding partition; A color index determination sub-module for determining a color index of the pixel in the corresponding partition according to the quantization number of the macroblock corresponding to the pixel, the component of the pixel in the target color channel, and the first component and the second component of the target color channel.

2. The device according to claim 1, characterized in that, The macroblock partitioning module includes: A partition center determination sub-module for determining a partition center of the previous iteration process; A pixel location partition determination sub-module for, for each pixel, determining a pixel distance between the pixel and each partition center of the previous iteration process, and dividing the pixel into the partition where the partition center with the minimum pixel distance is located; wherein, the partition center of the first iteration process is characterized by a combination of the maximum value of the components of any one color channel of all pixels, the minimum value of the components of any one color channel, and the average value of the components of any one color channel.

3. The device according to claim 2, characterized in that, The pixel location partition determination sub-module further includes: An average value determination unit for determining an average value of the components of all pixels in the same partition in each color channel; A partition center iteration unit for updating the partition center of the previous iteration process to obtain a partition center of the current iteration process, and the partition center of the current iteration process is characterized by the average value of all pixels in the corresponding partition in each color channel; A pixel distance first determination unit, configured to determine a pixel distance between a partition center of the current iteration process and a partition center of the previous iteration process; A pixel distance second determination unit, configured to calculate a pixel distance between each pixel and a partition center of each current iteration process if the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process is greater than a preset threshold; A pixel location partition division unit, configured to divide each pixel into a partition where the partition center corresponding to the minimum pixel distance is located, until the pixel distance between partition centers of two adjacent iteration processes is less than the preset threshold.

4. The apparatus according to claim 1, wherein, the component determination sub-module includes: A base pixel value obtaining unit, configured to obtain a base pixel value of a corresponding pixel according to an algebraic sum of components of all color channels of each pixel in the partition; A maximum base pixel value and minimum base pixel value determination unit, configured to determine a maximum base pixel value and a minimum base pixel value from the base pixel values of all pixels in the partition.

5. The apparatus according to claim 1, wherein, the target color channel determination sub-module includes: A first parameter determination unit, configured to obtain a first parameter for any one color channel according to a difference between a component of the pixel in the corresponding color channel and a second component of the partition in the corresponding color channel; A second parameter determination unit, configured to determine a difference between a first component and a second component of the partition in the corresponding color channel, to obtain a second parameter; A third parameter determination unit, configured to obtain a third parameter according to a ratio of the first parameter and the second parameter; A target color channel determination unit, configured to determine a color channel corresponding to the maximum third parameter as the target color channel corresponding to the pixel.

6. The apparatus according to claim 5, wherein, the color index determination sub-module includes: A first target parameter determination sub-module, configured to determine a difference between a component of the pixel in the target color channel and a second component of the target color channel, to obtain a first target parameter; A second target parameter determination sub-module, configured to determine a difference between a first component and a second component of the target color channel, to obtain a second target parameter; A third target parameter determination sub-module, configured to determine a ratio between the first target parameter and the second target parameter, to obtain a third target parameter; A color index determination grandchild module, configured to determine a color index of the pixel in the corresponding partition according to the third target parameter and the quantization number.

7. An image compression method, wherein, comprising: dividing a target image into a plurality of macroblocks; partitioning each of the macroblocks, such that a pixel distance between any two pixels in different partitions is greater than a preset threshold; for each partition, determining a first component and a second component of the partition in each color channel; for each pixel, determining a color index of the pixel in the corresponding partition according to the first component and the second component of the corresponding partition of the pixel; Obtain a preset image compression ratio. For any macroblock, compress the macroblock according to the number of partitions of the macroblock, the first component and the second component of each partition in each color channel, and the color index of all pixels, to obtain a compressed bitstream corresponding to the macroblock; The determining the first component and the second component of the partition in each color channel includes: Determine the maximum base pixel value and the minimum base pixel value in the partition, and input the maximum base pixel value and the minimum base pixel value into the objective function of each color channel corresponding to the partition respectively to obtain the first component and the second component of the partition in each color channel; the base pixel value refers to the algebraic sum of the components of a pixel in multiple color channels; Wherein, the objective function is obtained by performing linear fitting on the components of the pixels in the partition in the corresponding color channel; The determining the color index of the pixel in the corresponding partition according to the first component and the second component of the corresponding partition of the pixel includes: Determine the quantization number of the macroblock according to the number of partitions of the macroblock; determine the target color channel of the pixel in the corresponding partition; Determine the color index of the pixel in the corresponding partition according to the quantization number of the macroblock to which the pixel belongs, the component of the pixel in the target color channel, and the first component and the second component of the target color channel.

8. The method according to claim 7, wherein, The partitioning each of the macroblocks includes: Determine the partition center of the previous iteration process; For each pixel, determine the pixel distance between the pixel and the partition center of each previous iteration process, and divide the pixel into the partition where the partition center of the previous iteration process corresponding to the minimum pixel distance is located; Wherein, the partition center of the first iteration process is characterized by a combination of the maximum value of the components of any one color channel of all pixels, the minimum value of the components of any one color channel, and the average value of the components of any one color channel.

9. The method according to claim 8, wherein, After dividing the pixel into the partition where the partition center of the previous iteration process corresponding to the minimum pixel distance is located, it further includes: Determine the average value of the components of all pixels in the same partition in each color channel; Update the partition center of the previous iteration process to obtain the partition center of the current iteration process, and the partition center of the current iteration process is characterized by the average value of all pixels in the corresponding partition in each color channel; Determine the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process; If the pixel distance between the partition center of the current iteration process and the partition center of the previous iteration process is greater than a preset threshold, then calculate the pixel distance between each pixel and the partition center of each current iteration process; Divide each pixel into the partition where the partition center of the current iteration process corresponding to the minimum pixel distance is located until the pixel distance between the partition centers of two adjacent iteration processes is less than the preset threshold.

10. An electronic device, including a memory, a processor, and a computer program stored on the memory, wherein, The processor executes the computer program to implement the steps of the method according to any one of claims 7-9.

11. A computer-readable storage medium, on which a computer program is stored, wherein, when the computer program is executed by a processor, the steps of the method according to any one of claims 7-9 are implemented.

Citation Information

Patent Citations

  • Compressed data arrangement method and device and electronic equipment

    CN112102144A

  • Reference frame cache data compression method, computer device and computer readable storage medium

    CN112887725A