Image compression encoding method and device, computer device and storage medium
By dividing the image into multiple blocks and making conditional judgments based on pixel type, the encoding method solves the problem of large storage space in existing lossless image compression technologies, and achieves efficient image data compression and storage.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN AIXIESHENG TECH CO LTD
- Filing Date
- 2022-01-27
- Publication Date
- 2026-07-10
AI Technical Summary
Existing lossless image compression technologies require a large amount of storage space in high-resolution image processing, which cannot effectively reduce the storage requirements of image data. In particular, it is difficult to achieve lossless reading, writing and storage of image data in chip and hardware development with DDR bandwidth limitations.
The image to be compressed is divided into multiple image blocks. The pixel type is determined and corresponding preset conditions are used for encoding, including pixel grouping conditions, equal pixel component conditions, and the relationship between pixel component difference and corresponding threshold conditions. The encoding result with the smallest compression error is selected as the final encoding result.
Block coding reduces the storage space of compressed image data while maintaining high-quality decompressed data, thus improving image transmission efficiency and storage capacity utilization.
Smart Images

Figure CN114222129B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to an image compression coding method, apparatus, computer device, and storage medium. Background Technology
[0002] Digital representation, transmission, and storage are crucial for image processing. Images contain the most information, but the sheer volume of information in digital images also hinders the digitization process, necessitating effective compression. For the storage and transmission of image data such as remote sensing photographs, reconnaissance photographs, fingerprint images, medical images, and weather cloud maps, lossless compression is often employed to preserve critical information and facilitate subsequent processing and applications. Especially during chip and hardware development, limitations such as DDR bandwidth hinder the smooth reading, writing, storage, and caching of high-resolution video images (e.g., 1080P, 4k*2k), making lossless or near-lossless compression even more essential.
[0003] In lossless encoding, there is no data loss, meaning that images can be decoded and restored without distortion after lossless encoding. Classic lossless compression techniques include Huffman coding, arithmetic coding, and dictionary compression, but image data compressed using traditional lossless image compression methods requires a large storage space. Summary of the Invention
[0004] Therefore, it is necessary to provide an image compression coding method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can reduce the data storage space of image compression data in order to address the above-mentioned technical problems.
[0005] Firstly, an image compression coding method is provided. The method includes:
[0006] Obtain the image to be compressed, and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels;
[0007] For each image block, the type of the image block is determined based on the pixels in the image block;
[0008] If the image block is a color image block, then determine whether the pixels in the image block meet the preset conditions; wherein, the preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions;
[0009] If the pixels in the image block satisfy one of the preset conditions, then the image block is encoded using the encoding rule corresponding to the preset condition.
[0010] In one embodiment, the method further includes:
[0011] If the pixels in the image block satisfy at least two of the preset conditions, then the encoding result corresponding to each condition of the image block is decoded to obtain the corresponding first decoded data;
[0012] Based on the first decoded data and the data of the image block, the corresponding first compression error is obtained;
[0013] The encoding result corresponding to the smallest compression error among the first compression errors is selected as the final encoding result corresponding to the image block.
[0014] In one embodiment, determining whether the pixels in the image block satisfy the pixel grouping condition includes:
[0015] The pixels in the image block are divided into multiple groups;
[0016] For each group, calculate the difference between the maximum and minimum values of the pixel components in that group;
[0017] If the maximum value of the difference in each of the multiple groups is less than a preset grouping threshold, it means that the pixels in the image block meet the pixel grouping condition.
[0018] In one embodiment, the method further includes:
[0019] When the pixels in the image block satisfy at least two pixel grouping conditions, the encoding result obtained by encoding according to the encoding rule corresponding to each pixel grouping condition is obtained, and the encoding result is decoded to obtain the corresponding second decoded data;
[0020] Based on the second decoded data and the data of the image block, the corresponding second compression error is obtained;
[0021] The encoding result corresponding to the smallest second compression error among the second compression errors is selected as the encoding result of the image block satisfying the pixel grouping condition.
[0022] In one embodiment, determining whether the pixels in the image block satisfy the condition of equal pixel components includes:
[0023] Determine whether the difference between the maximum and minimum values of the same component of each pixel in the image block is less than a first threshold. If so, it is determined that the condition of equal pixel components is met, and the same component of each pixel can be represented by the same data.
[0024] Determine whether the difference between two different components of the same pixel in the image block is less than a second threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to the same pixel can be represented by the same data.
[0025] Determine whether the difference between the maximum and minimum values of the two components of each pixel in the image block is less than a third threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to each pixel can be represented by the same data.
[0026] In one embodiment, the pixel components include a first component, a second component, and a third component; determining whether the pixels in the image block satisfy the relationship condition between the pixel component difference and the corresponding threshold includes:
[0027] Obtain the first difference between the maximum and minimum values of the first component of the pixels in the image block, the second difference between the maximum and minimum values of the second component, and the third difference between the maximum and minimum values of the third component;
[0028] Determine whether the first difference, the second difference, and the third difference satisfy the set of relationships between pixel component differences and corresponding thresholds. Each set of relationships in the set of relationships between pixel component differences and corresponding thresholds includes the relationship between the first difference and the first difference threshold, the relationship between the second difference and the second difference threshold, and the relationship between the third difference and the third difference threshold. If any set of relationships is satisfied, it is determined that the pixels of the image block satisfy the condition of the relationship between pixel component differences and corresponding thresholds.
[0029] Secondly, this application also provides an image compression encoding apparatus. The apparatus includes:
[0030] The image segmentation module is used to acquire the image to be compressed and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels;
[0031] An image type module is used to determine the type of an image block based on the pixels in the image block for each image block;
[0032] A color image module is used to determine whether the pixels in the image block meet preset conditions if the image block is a color image block; wherein the preset conditions include at least one of pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions.
[0033] An image encoding module is used to encode the image block using an encoding rule corresponding to one of the preset conditions if the pixels in the image block satisfy one of the preset conditions.
[0034] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0035] Obtain the image to be compressed, and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels;
[0036] For each image block, the type of the image block is determined based on the pixels in the image block;
[0037] If the image block is a color image block, then determine whether the pixels in the image block meet the preset conditions; wherein, the preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions;
[0038] If the pixels in the image block satisfy one of the preset conditions, then the image block is encoded using the encoding rule corresponding to the preset condition.
[0039] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0040] Obtain the image to be compressed, and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels;
[0041] For each image block, the type of the image block is determined based on the pixels in the image block;
[0042] If the image block is a color image block, then determine whether the pixels in the image block meet the preset conditions; wherein, the preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions;
[0043] If the pixels in the image block satisfy one of the preset conditions, then the image block is encoded using the encoding rule corresponding to the preset condition.
[0044] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0045] Obtain the image to be compressed, and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels;
[0046] For each image block, the type of the image block is determined based on the pixels in the image block;
[0047] If the image block is a color image block, then determine whether the pixels in the image block meet the preset conditions; wherein, the preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions;
[0048] If the pixels in the image block satisfy one of the preset conditions, then the image block is encoded using the encoding rule corresponding to the preset condition.
[0049] The aforementioned image compression encoding method, apparatus, computer equipment, storage medium, and computer program product acquire an image to be compressed, divide the image into multiple image blocks, each image block containing several pixels; for each image block, determine the type of the image block based on the pixels in the image block; if the image block is a color image block, determine whether the pixels in the image block meet preset conditions; wherein, the preset conditions include at least one of pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions; if the pixels in the image block meet one of the preset conditions, then the image block is encoded using the encoding rule corresponding to the preset condition. This application divides the image to be compressed into multiple image blocks, performs corresponding type determination on each image block, and if it is a color image block, determines whether the pixels in the color image block meet the corresponding preset conditions. If they do, the image block is encoded using the encoding rule corresponding to the preset conditions, resulting in a small amount of encoded data, less storage space occupied, and high-quality decompressed data. Attached Figure Description
[0050] Figure 1 This is a diagram illustrating the application environment of an image compression coding method in one embodiment;
[0051] Figure 2 This is a flowchart illustrating an image compression coding method in one embodiment;
[0052] Figure 3 This is a flowchart illustrating an image compression coding method in another embodiment;
[0053] Figure 4 This is a flowchart illustrating step 206 in one embodiment;
[0054] Figure 5 This is a flowchart illustrating step 206 in another embodiment;
[0055] Figure 6This is a flowchart illustrating step 206 in another embodiment;
[0056] Figure 7 This is a flowchart illustrating step 206 in another embodiment;
[0057] Figure 8 This is a structural block diagram of an image compression coding device in one embodiment;
[0058] Figure 9 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0059] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0060] The image compression coding method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104 or placed on a cloud or other network server. Server 104 receives the image to be compressed sent by terminal 102. Server 104 divides the image to be compressed into multiple image blocks, each containing several pixels. For each image block, the type of the image block is determined based on the pixels in the image block. If the image block is a color image block, it is determined whether the pixels in the image block meet preset conditions. The preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions. If the pixels in the image block meet one of the preset conditions, the image block is encoded using the encoding rule corresponding to the preset condition. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart vehicle devices, etc. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0061] In one embodiment, such as Figure 2 As shown, an image compression coding method is provided, which can be applied to... Figure 1 The server in the middle can also be used on the terminal, including the following steps:
[0062] Step 202: Obtain the image to be compressed and divide it into multiple image blocks, each containing several pixels.
[0063] The purpose of image compression coding is to eliminate a large amount of redundant information in an image, representing the original data with as few bytes as possible, thereby improving image transmission efficiency and reducing image storage capacity. In this embodiment, encoding is performed according to representative block units. Block unit encoding involves dividing an image display into multiple image blocks and encoding each block. First, the server or terminal obtains the image to be compressed and divides it into a preset number of image blocks according to a preset block division rule. Each image block contains several pixels. The image to be compressed can be divided into multiple image blocks of equal or unequal size. For example, a frame of the image to be compressed can be divided into multiple image blocks of equal size, each containing 6 pixels, distributed in a 2x3 or 3x2 grid.
[0064] In one possible implementation, the image is compressed and encoded in blocks. One image block is compressed and encoded before the next image is compressed and encoded, and there is no connection between the image blocks. For example, if an image is divided into multiple blocks of the same size, each block containing 2 rows and 3 columns (6 pixels), and each block of 6 pixels is encoded, the input data size is 144 bits (bits) because each pixel includes three components: R, G, and B, and each component occupies 8 bits. The preset output data size after compression and encoding is 56 bits (bits). In specific processing, the first image block can be composed of 6 pixels, consisting of columns 1 to 3 of the first row and columns 1 to 3 of the second row; the second image block can be composed of 6 pixels, consisting of columns 4 to 6 of the first row and columns 4 to 6 of the second row. After compressing and encoding the first image block, outputting compressed and encoded data of a preset size, then compressing and encoding the second image block, and so on, processing the data of the last two rows after processing the data of the first two rows, until all image blocks in the image are compressed and encoded. In this embodiment, if the number of columns in the image is not an integer multiple of 3, the total number of columns in the image can be expanded by copying the last column of image data to meet the calculation requirements.
[0065] Step 204: For each image block, determine the type of the image block based on the pixels in the image block.
[0066] Each image block contains several pixels. The data type of each pixel in the image block is determined sequentially, and the image block type is determined based on the data type of all pixels within the block. If all pixel components of the same pixel data are identical, it is determined to be grayscale pixel data; if all pixel data in an image block belongs to grayscale pixel data, then the image block is a grayscale image block; otherwise, the image block is a color image block. For example, suppose the 6 pixels in each image block are P1 = (R1, G1, B1), P2 = (R2, G2, B2), P3 = (R3, G3, B3), P4 = (R4, G4, B4), P5 = (R5, G5, B5), and P6 = (R6, G6, B6). If R1 = G1 = B1, then P1 is grayscale pixel data. If all 6 pixels in an image block belong to grayscale pixel data, then the image block is a grayscale image block; otherwise, it is a color image block.
[0067] Step 206: If the image block is a color image block, determine whether the pixels in the image block meet the preset conditions; wherein, the preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions.
[0068] If the image patch is determined to be a color image patch, then it is further determined whether the pixels in the image patch meet the preset conditions corresponding to the color image patch. These preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions. Pixel grouping conditions are used to determine whether the pixels in the image patch meet the corresponding grouping conditions. There can be multiple grouping conditions, and the same image patch can simultaneously meet multiple grouping conditions. Different grouping conditions correspond to different encoding rules. For example, pixels in the same image patch can simultaneously meet the grouping conditions corresponding to being divided into two, three, or four groups. Pixel component equality conditions are used to determine whether the pixel components in the image patch meet the corresponding component equality conditions. Pixel component equality conditions include equality relationships between different components of the same pixel within an image patch, and between the same component of different pixels. The pixel component difference and corresponding threshold relationship condition refers to the relationship between the pixel component difference and the corresponding threshold. Multiple thresholds can be set, and different pixel component differences are compared with different thresholds to obtain the relationship between the pixel component difference and the corresponding threshold.
[0069] Step 208: If the pixels in the image block meet one of the preset conditions, then the image block is encoded using the encoding rule corresponding to the preset condition.
[0070] If a pixel in an image block meets one of the preset conditions, the image block is encoded using the encoding rule corresponding to that preset condition. If a pixel in an image block meets multiple preset conditions, the image block is encoded using multiple encoding rules corresponding to those multiple preset conditions, resulting in multiple encoding results. Correspondingly, if an image block meets the condition of being a grayscale image block, it is encoded according to the encoding method corresponding to grayscale image blocks. After compression encoding, the image block includes mode marker bits, type marker bits, and the data retained by each pixel in the image block. Understandably, mode marker bits are used to distinguish whether pixels in an image block meet different preset conditions, and type marker bits are used to distinguish whether pixels in an image block meet different types under the same preset condition; different preset conditions result in different mode marker bits; under the same preset condition, different types result in different type marker bits.
[0071] In the aforementioned image compression coding method, the image to be compressed is acquired and divided into multiple image blocks, each containing several pixels. For each image block, the type of the image block is determined based on the pixels within it. If the image block is a color image block, it is determined whether the pixels in the image block meet preset conditions. These preset conditions include at least one of the following: pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions. If the pixels in the image block meet one of the preset conditions, the image block is encoded using the coding rule corresponding to that preset condition. This embodiment divides the image to be compressed into multiple image blocks, performs a corresponding type determination on each image block, and if it is a color image block, further determines whether the pixels in the color image block meet the corresponding preset conditions. If they do, the image block is encoded using the coding rule corresponding to the satisfied preset conditions, resulting in a smaller encoded data size, less storage space occupied, and higher quality decompressed data.
[0072] In one embodiment, such as Figure 3 As shown, the above image compression coding method also includes:
[0073] Step 302: If the pixels in the image block satisfy at least two of the preset conditions, then the encoding result corresponding to each condition of the image block is decoded to obtain the corresponding first decoded data.
[0074] If the image block is a color image block, and the pixels in the image block satisfy at least two of the preset conditions, then the image block is encoded using the encoding rules corresponding to the preset conditions to obtain at least two encoding results corresponding to the at least two conditions; the at least two encoding results corresponding to the at least two conditions are then decoded to obtain the corresponding first decoded data. The first decoded data includes at least two types. The decoding method in this embodiment can be the decoding method corresponding to image encoding, or other decoding methods, which are not specifically limited here. For example, if the pixels in an image block satisfy the pixel grouping condition, then the image block is encoded using the encoding rules corresponding to the pixel grouping condition to obtain the encoding result satisfying the pixel grouping condition; simultaneously, the image block also satisfies the pixel component equality condition, then the image block is encoded using the encoding rules corresponding to the pixel component equality condition to obtain the encoding result satisfying the pixel component equality condition; then, the encoding results satisfying the pixel grouping condition and the encoding results satisfying the pixel component equality condition are decoded respectively to obtain the first decoded data of the encoding result satisfying the pixel grouping condition and the first decoded data of the encoding result satisfying the pixel component equality condition.
[0075] Step 304: Based on the first decoded data and the data of the image block, obtain the corresponding first compression error.
[0076] The first compression error is obtained based on the first decoded data and the corresponding image block data before encoding. The first compression error has at least two components. Optionally, the first compression error can be obtained based on the absolute value of the difference between the first decoded data and the corresponding image block data before encoding.
[0077] In one optional implementation, the differences between corresponding pixels and pixel components in the first decoded data and the data of the image block are calculated, and the absolute values of the differences between the pixel components are obtained. The absolute values are then summed to obtain the corresponding first compression error. For example, if the image block contains 6 pixels, the differences between the first decoded data and the data of the image block are calculated to obtain 18 differences corresponding to the 18 pixel components of the 6 pixels. The absolute values of these differences are then summed to obtain the corresponding first compression error.
[0078] Step 306: Select the encoding result corresponding to the smallest first compression error among the first compression errors as the final encoding result corresponding to the image block.
[0079] Among the multiple first compression errors obtained, the encoding result corresponding to the smallest first compression error is selected as the final encoding result for the image block and output. In this embodiment, by selecting the encoding result corresponding to the smallest first compression error, the image occupies less space after compression, and at the same time, it still has high quality after decoding the encoded data.
[0080] In one embodiment, such as Figure 4 As shown, step 206, determining whether the pixels in the image block satisfy the pixel grouping condition, includes:
[0081] Step 402: Divide the pixels in the image block into multiple groups.
[0082] Depending on the compression coding requirements, the pixels in an image block can be pre-grouped randomly, for example, into two, three, or four groups. In any grouping method, the number of pixels in each group can be the same or different. For example, assuming an image block contains 6 pixels, dividing these 6 pixels into two groups could involve groups of 3 pixels each, or groups of 2 pixels each with the remaining 4 pixels in the other group. It is understood that grouping the pixels in an image block can follow mathematical permutations and combinations, and no restrictions are imposed here.
[0083] Step 404: For each group, calculate the difference between the maximum and minimum values of the pixel components in the group.
[0084] For each group, calculate the difference between the maximum and minimum values of each pixel component within that group. For example, for a group with three pixels, calculate the difference between the maximum and minimum values of the R component, G component, and B component of each pixel. The differences between the maximum and minimum values of pixel components in other groups are calculated using the same method.
[0085] Step 406: If the maximum value of the difference between each group in the multiple groups is less than the preset grouping threshold, it means that the pixels in the image block meet the pixel grouping condition.
[0086] In this embodiment, different preset grouping thresholds correspond to different grouping methods. For example, the preset grouping thresholds for dividing the pixels in an image block into two, three, and four groups are all different. Generally, the more groups there are, the larger the corresponding preset grouping threshold. For the same grouping method, if the maximum difference between each group is less than the corresponding preset grouping threshold, it means that the pixels in the image block meet the pixel grouping conditions.
[0087] In an optional implementation, after determining that the pixels in an image block satisfy the pixel grouping conditions, the pixels within each group can be re-represented using the approximate mean of the pixel components within each group. Here, the approximate mean of the pixel components refers to the arithmetic mean of the maximum and minimum values of the pixel components within the group. For example, if one group includes three pixels P1(R1, G1, B1), P2(R2, G2, B2), and P3(R3, G3, B3), then Rmean = (Rmax + Rmin) / 2, Gmean = (Gmax + Gmin) / 2, and Bmean = (Bmax + Bmin) / 2. Where Rmax equals the maximum value of R1, R2, and R3, Rmin equals the minimum value of R1, R2, and R3, Gmax equals the maximum value of G1, G2, and G3, Gmin equals the minimum value of G1, G2, and G3, and Bmax equals the maximum value of B1, B2, and B3, Bmin equals the minimum value of B1, B2, and B3. Therefore, (Rmean, Gmean, Bmean) can be used to represent the three pixels within this group. Following the same logic, for other grouping methods, the approximate mean of the pixel components within the corresponding group can also be used to represent the pixels within that group.
[0088] In one embodiment, such as Figure 5 As shown, the above image compression coding method also includes:
[0089] Step 502: When the pixels in the image block satisfy at least two pixel grouping conditions, obtain the encoding result obtained by encoding according to the encoding rule corresponding to each pixel grouping condition, decode the encoding result, and obtain the corresponding second decoded data.
[0090] For several pixels in an image patch, at least two pixel grouping conditions may be satisfied simultaneously. At least two encoding results are obtained by encoding according to the encoding rules corresponding to each pixel grouping condition. These encoding results are then decoded to obtain corresponding second decoded data. The second decoded data has at least two types. For example, if the pixels in the image patch can be divided into two groups, thus satisfying the pixel grouping conditions corresponding to two groups, then the encoding rules corresponding to these conditions are used to encode the pixels, resulting in the encoding result corresponding to the pixel grouping conditions. Simultaneously, the pixels in the image patch can also be divided into three groups, satisfying the pixel grouping conditions corresponding to three groups. In this case, the encoding rules corresponding to these conditions are used to encode the pixels, resulting in the encoding result corresponding to the pixel grouping conditions. The encoding results satisfying both the two and three groups are then decoded to obtain second decoded data for the two-group-corresponding pixel grouping conditions and the second decoded data for the three-group-corresponding pixel grouping conditions.
[0091] Step 504: Based on the second decoded data and the data of the image block, obtain the corresponding second compression error.
[0092] The second compression error is obtained based on the second decoded data and the corresponding image block data before encoding. Since the pixels in the image block satisfy at least two pixel grouping conditions, each satisfying one pixel grouping condition corresponds to one type of second decoded data, which in turn corresponds to one second compression error. Therefore, the number of second compression errors is at least two, that is, the number of second compression errors is the same as the number of pixels in the corresponding image block that satisfy the pixel grouping conditions. Specifically, the absolute value of the difference between the second decoded data and the corresponding image block data before encoding can be used as the corresponding second compression error.
[0093] Step 506: Select the encoding result corresponding to the smallest second compression error among the second compression errors as the encoding result of the image block satisfying the pixel grouping condition.
[0094] Among the multiple second compression errors obtained, the smallest second compression error is selected as the encoding result for the image block to satisfy the pixel grouping condition.
[0095] In this embodiment, for an image block that satisfies multiple pixel grouping conditions, the encoding results corresponding to these conditions are decoded to obtain corresponding second decoded data. The second decoded data is then compared with the image block data before encoding to obtain the corresponding second compression error. The encoding result with the smallest second compression error is selected as the encoding result for the image block that satisfies the pixel grouping conditions. The image compression encoding method in this embodiment can reduce the computational complexity of image compression encoding, allowing the final encoding result to occupy less storage space while maintaining high quality of the original image after decoding.
[0096] In one embodiment, such as Figure 6 As shown, step 206, determining whether the pixels in the image block satisfy the condition of equal pixel components, includes:
[0097] Step 602: Determine whether the difference between the maximum and minimum values of the same component of each pixel in the image block is less than the first threshold. If so, it is determined that the condition of equal pixel components is met, and the same component of each pixel can be represented by the same data.
[0098] An image block contains several pixels, each of which contains three pixel components. The difference between the maximum and minimum values of the same component in each pixel of the image block is evaluated sequentially. If the difference between the maximum and minimum values of any one pixel component is less than a first threshold, then the pixel component is considered to meet the condition of equal pixel components, and these pixel components can be represented using the same data. It can be understood that if two or three pixel components in the image block have differences between their maximum and minimum values that are all less than the first threshold, the pixel component equality condition is also considered met. For example, if the difference between the maximum and minimum values of pixel component G in a pixel is less than the first threshold, then the pixel component equality condition is met, and pixel component G can be represented using the same data. If the difference between the maximum and minimum values of pixel components R and B in a pixel is less than the first threshold, then the pixels in this image block meet the condition of equal pixel components, and pixel components R and B can both be represented using the same data.
[0099] Optionally, when the pixel components in a pixel satisfy the condition of equal pixel components, the approximate mean of the corresponding pixel components can be used to represent all the corresponding pixel components in the pixel. For example, continuing with the above example, when the difference between the maximum and minimum values of the R pixel components in a pixel is less than a first threshold, then the approximate mean of the R pixel components can be used to replace all the R pixel components in the pixel.
[0100] Step 604: Determine whether the difference between two different components of the same pixel in the image block is less than the second threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to the same pixel can be represented by the same data.
[0101] For any pixel in an image block, if the difference between two different components of the same pixel is less than a second threshold, then the condition of equal pixel components is met, and the two components corresponding to the same pixel can be represented using the same data. For example, for pixel P1(R1, G1, B1) in an image block, if R1 = G1, R1 = B1, or G1 = B1, then R1 and G1, R1 and B1, or G1 and B1 can be represented using the same data respectively.
[0102] Step 606: Determine whether the difference between the maximum and minimum values of the two components of each pixel in the image block is less than the third threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to each pixel can be represented by the same data.
[0103] For any two components in each pixel of an image block, calculate the difference between the maximum and minimum values of the two components. If the difference between the maximum and minimum values of the two components is less than the third threshold, then the condition that the pixel components are equal is satisfied, and the corresponding two components in the image block can be represented by the same data.
[0104] In this embodiment, the first threshold, the second threshold, and the third threshold are all different. For pixels in the same image block, the pixel components corresponding to the first threshold, the second threshold, and the third threshold can all be equal, or any two of the pixel component equality conditions can be satisfied.
[0105] In one embodiment, such as Figure 7 As shown, the pixel components include a first component, a second component, and a third component. Step 206, determining whether the pixels in the image block satisfy the relationship between the pixel component difference and the corresponding threshold, includes:
[0106] Step 702: Obtain the first difference between the maximum and minimum values of the first component of the pixels in the image block, the second difference between the maximum and minimum values of the second component, and the third difference between the maximum and minimum values of the third component.
[0107] In an image patch, each pixel comprises three pixel components: a first component, a second component, and a third component. For example, the first component can be an R component, the second component can be a G component, and the third component can be a B component. The algorithm retrieves the first difference between the maximum and minimum values of the first component, the second difference between the maximum and minimum values of the second component, and the third difference between the maximum and minimum values of the third component for each pixel in the image patch.
[0108] Step 704: Determine whether the first difference, the second difference, and the third difference satisfy the set of relationships between pixel component differences and corresponding thresholds. Each set of relationships in the set of relationships between pixel component differences and corresponding thresholds includes the relationship between the first difference and the first difference threshold, the relationship between the second difference and the second difference threshold, and the relationship between the third difference and the third difference threshold. If any set of relationships is satisfied, it is determined that the pixels of the image block satisfy the condition of the relationship between pixel component differences and corresponding thresholds.
[0109] In this embodiment, multiple sets of thresholds are set, each set of thresholds including a first difference threshold, a second difference threshold, and a third difference threshold. The relationship between the first difference and the first difference threshold in each set of thresholds, the second difference and the second difference threshold, and the third difference and the third difference threshold are determined in turn. If there exists a set of thresholds such that the first difference is less than the first difference threshold, the second difference is less than the second difference threshold, and the third difference is less than the third difference threshold, then it is determined that the pixels of the image block satisfy the relationship condition between the pixel component difference and the corresponding threshold.
[0110] In an optional embodiment, multiple sets of thresholds are set and sorted in ascending order. The first difference, second difference, and third difference are compared sequentially with the multiple sets of thresholds in ascending order. An encoding rule corresponding to the relationship between pixel component differences and the corresponding threshold is used to encode the image block, resulting in an encoding result for the image block encoded according to the encoding rules corresponding to the multiple sets of thresholds. After decoding the encoding result, a third compression error is calculated between the decoded image block data and the image block data before encoding. The encoding result corresponding to the smallest third compression error is selected as the encoding result for the image block where the pixels satisfy the relationship between pixel component differences and the corresponding threshold.
[0111] In one embodiment, the image compression coding method of this application is described in detail with a more specific example. Assume that the image is divided into multiple image blocks of equal size, each image block comprising 2 rows and 3 columns, totaling 6 pixels. Each pixel contains three components, and the 6 pixels total 144 bits. The final output is pre-set to be 56 bits. The 6 pixels can be represented as P1(R1, G1, B1), P2(R2, G2, B2), P3(R3, G3, B3), P4(R4, G4, B4), P5(R5, G5, B5), and P6(R6, G6, B6).
[0112] (1) If the three pixel components of each pixel in an image block are equal, then the image block belongs to a grayscale image block. Set the storage mode flag bit to 1110, then use 48 bits to store 6 pixel data, and pad the remaining 4 bits with 4 zeros each, for a total of 56 bits, i.e. 4+6*8+4=56, to achieve lossless compression.
[0113] (2) If the image block does not belong to the grayscale image block, it belongs to the color image block. Determine whether the pixels in the image block meet the preset conditions.
[0114] ① First, determine whether the pixels in the image block meet the pixel grouping conditions. If they do, divide the 6 pixels in the image block into two groups. Use the approximate mean of the pixel components of each pixel in the group to represent each pixel in the group. That is, there are 2 groups of approximate means, including a new pixel composed of 6 approximate means. These 6 approximate means need to be encoded. Specifically: set the storage mode flag bit to 0, use 6 bits for type marking. 6 bits can represent 64 types. Dividing 6 pixels into two groups results in 13 types. Use 13 data from 0 to 12 to mark the type of each group. Then use 48 bits to store the 6 data, and pad the remaining 1 bit with 1 0, for a total of 56 bits, i.e., 1+6+48+1=56, to achieve data compression encoding.
[0115] If the pixel grouping condition of dividing 6 pixels in an image block into three groups is met, the approximate mean of the pixel components of each pixel in the group is used to represent each pixel in the group. That is, there are 3 groups of approximate means, including a new pixel composed of 9 approximate means. These 9 approximate means need to be encoded. Specifically: save the mode flag bit 0, use 6 bits for type marking. 6 bits can represent 64 types. Dividing 6 pixels into three groups results in 13 types. 13 data points from 13 to 25 can be used to mark the type of each group. Then, use 48 bits to save the 9 approximate means. Specifically, 3 G approximate means can be saved using 6 bits each, saving their high 6 bits, for a total of 18 bits; the remaining 6 approximate means can be saved using 5 bits each, saving their high 5 bits, for a total of 30 bits; the remaining 1 bit is padded with 1 0, for a total of 56 bits, i.e., 6 + 3*6 + 5*6 + 1 = 56, to achieve data compression encoding.
[0116] If the pixel grouping condition of dividing 6 pixels in an image block into four groups is met, each pixel in the group is represented by the approximate mean of the pixel components. There are a total of 4 groups of approximate means, resulting in a new pixel composed of 12 approximate means. These 12 approximate means need to be encoded. Specifically: The mode flag bit 0 is saved, and 6 bits are used for type marking. 6 bits can represent 64 types. Dividing the 6 pixels into four groups results in 20 types, which can be marked using 20 data points from 26 to 45. Then, 49 bits are used to save the 12 approximate means. Specifically, the last group's G approximate mean is saved using 5 bits, and the other approximate means are saved using 4 bits, for a total of 56 bits, i.e., 1 + 6 + 11 * 4 + 5 = 56, thus achieving image block data compression encoding.
[0117] In determining whether pixels in an image block meet the pixel grouping conditions, the grouping method is not limited to the specific example mentioned above. Six pixels can even be divided into five groups, with a similar calculation process, which will not be elaborated here. Furthermore, even when the number of groups is determined, there are multiple pixel combination types. Therefore, when pixels in an image block meet at least two pixel grouping conditions, the encoding result obtained by encoding according to the encoding rule corresponding to each pixel grouping condition is acquired. The encoding result is then decoded to obtain the corresponding second decoded data. Based on the second decoded data and the data of the image block, the corresponding second compression error is obtained. The encoding result corresponding to the smallest second compression error is selected as the encoding result for the image block to meet the pixel grouping conditions.
[0118] ② Determine whether the pixels in the image block satisfy the condition that the pixel components are equal.
[0119] a. When the difference between the maximum and minimum values of the same pixel component among the 6 pixels in an image block is less than the first threshold, it is determined that the condition of equal pixel components is met, and the same pixel component among the 6 pixels can be represented by the same data, specifically by the approximate mean of the same component.
[0120] b. When the difference between two different pixel components of the same pixel in an image block is less than the second threshold, the corresponding two pixel components can be represented by the same data.
[0121] c. When the difference between two pixel components of 6 pixels in an image patch is less than the third threshold, the corresponding two pixel components can be represented by the same data.
[0122] The conditions for equality of the three pixel components a, b, and c mentioned above can be satisfied simultaneously, or only one or two of them can be satisfied. If the R pixel component of 6 pixels satisfies condition a, and the G and B pixel components of 6 pixels satisfy condition b, then a total of 7 data points need to be saved. Similarly, the conditions that need to be satisfied when only 7 data points need to be saved include: the G pixel component of 6 pixels satisfies condition a, and the R and B pixel components of 6 pixels satisfy condition b; the B pixel component of 6 pixels satisfies condition a, and the R and G pixel components of 6 pixels satisfy condition b; the R and G pixel components of 6 pixels satisfy condition c, but the B pixel component of 6 pixels does not satisfy any condition; the R and B pixel components of 6 pixels satisfy condition c, but the C pixel component of 6 pixels does not satisfy any condition; the G and B pixel components of 6 pixels satisfy condition c, but the R pixel component of 6 pixels does not satisfy any condition, and so on.
[0123] For the specific encoding method corresponding to the need to save 7 data, the mode flag bit is 0, 6 bits are used for type marking, 6 bits can represent 64 types, and there are 6 cases mentioned above when saving 7 data. 6 data bits from 46 to 51 can be used for type marking, 49 bits are used to save 7 data, and each data is saved using 7 bits, for a total of 56 bits, that is, 1+6+7*7=56, to realize the image block data compression encoding.
[0124] ③ Determine whether the pixels in the image block satisfy the condition of the relationship between pixel component difference and corresponding threshold.
[0125] Calculate the maximum and minimum values of the R component (Rmax) and G component (Gmax) and B component (Bmin) for each of the six pixels. Compare Rmax-Rmin, Gmax-Gmin, and Bmax-Bmin with different thresholds. Assume the first difference threshold is 8, the second is 16, and the third is 8. If Rmax-Rmin < 8, Gmax-Gmin < 8, and Bmax-Bmin < 8, the specific encoding process is as follows: Set the storage mode flag bit to 110; use 5 bits for type marking (5 bits can represent 32 types; for types that meet the above difference threshold conditions, data 0 can be used for type marking); use 24 bits to store Rmin, Gmin, and Bmin respectively, with each data point using 8 bits; then use 24 bits to store the difference between each pixel component and its corresponding minimum pixel component, i.e., 1*6 + 2*6 + 1*6 = 24. The process is as follows: 1 bit is used to store the most significant bits of R1-Rmin, and the calculation process for R2, R3, R4, R5, and R6 is similar. Therefore, the R component requires a total of 6 bits to store the corresponding data. 2 bits are used to store the most significant bits of G1-Gmin, and the calculation process for G2, G3, G4, G5, and G6 is similar. Therefore, the G component requires a total of 12 bits to store the corresponding data. 1 bit is used to store the most significant bits of B1-Bmin, and the calculation process for B2, B3, B4, B5, and B6 is similar. Therefore, the B component requires a total of 6 bits to store the corresponding data. In summary, a total of 56 bits are needed, i.e., 3+5+24+24=56, thus achieving image block data compression encoding.
[0126] For color image blocks, if the pixels in the image block do not meet the preset conditions, namely, they do not meet any of the following conditions: pixel grouping conditions, equal pixel components conditions, or the relationship between pixel component differences and corresponding threshold conditions, the specific encoding method is as follows: save the mode flag bit 10, and then use 54 bits to save the 18 pixel components corresponding to the 6 pixels. Each pixel component retains its high 3 bits, for a total of 56 bits, i.e., 2 + 18 * 3 = 56, thereby realizing image block data compression.
[0127] The image block compression encoding method described above encodes images according to the corresponding encoding rules as long as the preset conditions are met. The decoded data is then compared with the original image block data to determine the error, and the encoding result with the smallest error is selected as the final encoding result for that image block. The final encoded result only accounts for 38.9% of the original image block data, resulting in a small space footprint and low computational cost.
[0128] The following is the corresponding decoding process for the image block compression encoding process described above: The corresponding decoding method is selected based on the mode marker bits used during image block encoding. If the first four bits of the data to be decoded are 1110, then the data to be decoded is determined to be grayscale image data. The first grayscale value is obtained from bits 5-12 of the data to be decoded; the second grayscale value is obtained from bits 13-20; the third grayscale value is obtained from bits 21-28; the fourth grayscale value is obtained from bits 29-36; the fifth grayscale value is obtained from bits 37-44; and the sixth grayscale value is obtained from bits 45-52. These six grayscale values correspond to six pixels, thus obtaining the decoded data.
[0129] If the first bit of the data to be decoded is 0, then bits 2-7 of the data to be decoded are the type marker. The value of the type marker is converted to decimal, and the corresponding decoding method is selected according to the magnitude of the value, as follows:
[0130] If the value is between 0 and 12, it means that the pixels in the original image block are divided into two groups. The approximate mean of the R pixel components in the first group (RAmean) is obtained from bits 8-15 of the data to be decoded; the approximate mean of the G pixel components in the first group (GAmean) is obtained from bits 16-23; the approximate mean of the B pixel components in the first group (BAmean) is obtained from bits 24-31; the approximate mean of the R pixel components in the second group (RBmean) is obtained from bits 32-39; the approximate mean of the G pixel components in the second group (GBmean) is obtained from bits 40-47; and the approximate mean of the B pixel components in the second group (BBmean) is obtained from bits 48-55. Then, (RAmean, GAmean, BAmean) are assigned to the pixels in the first group, and (RBmean, GBmean, BBmean) are assigned to the pixels in the second group, thus obtaining the decoded data.
[0131] If the value is between 13 and 25, it means that the pixels in the original image block are divided into three groups. The approximate mean of the first group of R components is obtained from the 8th to 12th bits of the data to be decoded: RAmean = bin2dec(str(8:12))*8+4, where str represents the compressed data stream, which is 56 bits in total. bin2dec can convert the corresponding binary data to decimal data, and subsequent related operations are similar. The approximate mean of the first group of G components, GAmean, is obtained from bits 13-18 of the data to be decoded; the approximate mean of the first group of B components, BAmean, is obtained from bits 19-23 of the data to be decoded; the approximate mean of the second group of R components, RBmean, is obtained from bits 24-28 of the data to be decoded; the approximate mean of the second group of G components, GBmean, is obtained from bits 29-34 of the data to be decoded; the approximate mean of the second group of B components, BBmean, is obtained from bits 35-39 of the data to be decoded; the approximate mean of the third group of R components, RCmean, is obtained from bits 40-44 of the data to be decoded; the approximate mean of the third group of G components, GCmean, is obtained from bits 45-50 of the data to be decoded; and the approximate mean of the third group of B components, BCmean, is obtained from bits 51-55 of the data to be decoded. Then, (RAmean, GAmean, BAmean) are assigned to the pixels in the first group, (RBmean, GBmean, BBmean) are assigned to the pixels in the second group, and (RCmean, GCmean, BCmean) are assigned to the pixels in the third group, thus obtaining the decoded data.
[0132] If the value is between 26 and 45, it means that the pixels in the original image block are divided into four groups. The approximate mean of the first group's R component, RAmean, is obtained from bits 8-11 of the data to be decoded: RAmean = bin2dec(str(8:11))*16+8, where str represents the compressed data stream, totaling 56 bits. bin2dec converts the corresponding binary data to decimal, and subsequent related operations are similar. The approximate mean of the first group's G component, GAmean, is obtained from bits 12-15 of the data to be decoded; the approximate mean of the first group's B component, BAmean, is obtained from bits 16-19 of the data to be decoded; the approximate mean of the second group's R component, RBmean, is obtained from bits 20-23 of the data to be decoded; the approximate mean of the second group's G component, GBmean, is obtained from bits 24-27 of the data to be decoded; the approximate mean of the second group's B component, BBmean, is obtained from bits 28-31 of the data to be decoded; and the approximate mean of the second group's B component, BBmean, is obtained from bits 32-35 of the data to be decoded. The approximate mean of the third group of R components, RCmean, is obtained from bits 36-39 of the data to be decoded. The approximate mean of the third group of G components, GCmean, is obtained from bits 40-43 of the data to be decoded. The approximate mean of the third group of B components, BCmean, is obtained from bits 44-47 of the data to be decoded. The approximate mean of the fourth group of R components, RDmean, is obtained from bits 44-47 of the data to be decoded. The approximate mean of the fourth group of G components, GDmean, is obtained from bits 48-52 of the data to be decoded. The approximate mean of the fourth group of B components, BDmean, is obtained from bits 53-56 of the data to be decoded. Then, (RAmean, GAmean, BAmean) are assigned to the pixels of the first group, (RBmean, GBmean, BBmean) are assigned to the pixels of the second group, (RCmean, GCmean, BCmean) are assigned to the pixels of the third group, and (RDmean, GDmean, BDmean) are assigned to the pixels of the fourth group, thus obtaining the decoded data.
[0133] If the value is between 46 and 51, it means that the pixels of the original image block satisfy the condition of equal pixel components. The first data (data1) is obtained from bits 8-14 of the data to be decoded; the second data (data2) is obtained from bits 15-21; the third data (data3) is obtained from bits 22-28; the fourth data (data4) is obtained from bits 29-35; the fifth data (data5) is obtained from bits 36-42; the sixth data (data6) is obtained from bits 43-49; and the seventh data (data7) is obtained from bits 50-56. Then, according to the specific value and the content described in step ②, the seven data values are assigned to the corresponding pixel components to obtain the decoded data.
[0134] If the first two bits of the data to be decoded are 10, it means that the pixel combination does not meet the preset conditions. Decoding is performed using the following method: Based on bits 3-5 of the data to be decoded, obtain R1 = bin2dec(str(3:5))*32+16, where str represents the compressed data stream, totaling 56 bits. bin2dec can convert the corresponding binary data to decimal, and subsequent related operations are similar. Obtain R2 based on bits 6-8 of the data to be decoded; obtain R3 based on bits 9-11; obtain R4 based on bits 12-14; obtain R5 based on bits 15-17; obtain R6 based on bits 18-20; obtain G1 based on bits 21-23; obtain G2 based on bits 24-26; obtain G3 based on bits 27-29; obtain G3 based on bits 30-25; obtain G2 based on bits 21-23; obtain G2 based on bits 24-26; obtain G3 based on bits 27-29; obtain G3 based on bits 30-25; obtain G2 based on bits 21-23; obtain G2 based on bits 24-26; obtain G3 based on bits 27-29; obtain G3 based on bits 20-25; obtain G2 based on bits 21-25; obtain G2 based on bits 24-26; obtain G2 based on bits 27-29; obtain G3 based on bits 20-25; obtain G2 based on bits 21 ... G4 is obtained from -32 bits; G5 is obtained from bits 33-35 of the data to be decoded; G6 is obtained from bits 36-38 of the data to be decoded; B1 is obtained from bits 39-41 of the data to be decoded; B2 is obtained from bits 42-44 of the data to be decoded; B3 is obtained from bits 45-47 of the data to be decoded; B4 is obtained from bits 48-50 of the data to be decoded; B5 is obtained from bits 51-53 of the data to be decoded; and B6 is obtained from bits 54-56 of the data to be decoded.
[0135] If the first 3 bits of the data to be decoded are 110, it means that the original pixel satisfies the relationship between the pixel component difference and the corresponding threshold. First, calculate the corresponding type based on the 4th to 8th bits of the data to be decoded, and then obtain the decoded data based on the subsequent data bits. Taking the example in step ③ of the compression encoding process as an example, the decoding process is explained as follows: obtain the mode flag bit 0 based on the 4th to 8th bits of the data to be decoded, then obtain Rmin based on the 9th to 16th bits of the data to be decoded, obtain Gmin based on the 17th to 24th bits of the data to be decoded, obtain Bmin based on the 25th to 32nd bits of the data to be decoded, and obtain DiffR1 = bin2dec(str(31))*4+2 based on the 33rd bit of the data to be decoded, then R1 = Rmin + DiffR1. Based on the 34th bit of the data to be decoded, we obtain DiffR2, then R2 = Rmin + DiffR2. Based on the 35th bit of the data to be decoded, we obtain DiffR3, then R3 = Rmin + DiffR3. Based on the 36th bit of the data to be decoded, we obtain DiffR4, then R4 = Rmin + DiffR4. Based on the 37th bit of the data to be decoded, we obtain DiffR5, then R5 = Rmin + DiffR5. Based on the 38th bit of the data to be decoded, we obtain DiffR6, then R6 = Rmin + DiffR6. Based on bits 39-40 of the data to be decoded, we obtain DiffG1, then G1 = Gmin + DiffG1. Based on bits 41-42 of the data to be decoded, we obtain DiffG2, then G2 = Gmin + DiffG2. Based on bits 43-44 of the data to be decoded, we obtain DiffG3, then G3 = Gmin + DiffG3. Based on bits 45-46 of the data to be decoded, we obtain DiffG2. If we obtain DiffG4 from bits 47-48 of the data to be decoded, then G4 = Gmin + DiffG4. Similarly, if we obtain DiffG5 from bits 49-50, then G5 = Gmin + DiffG5. If we obtain DiffG6 from bits 49-50, then G6 = Gmin + DiffG6. If we obtain DiffB1 from bit 51, then B1 = Bmin + DiffB1. If we obtain DiffB2 from bit 52, then B2 = Bmin + DiffB2. If we obtain DiffB3 from bit 53, then B3 = Bmin + DiffB3. If we obtain DiffB4 from bit 54, then B4 = Bmin + DiffB4. If we obtain DiffB5 from bit 55, then B5 = Bmin + DiffB5. If we obtain DiffB6 from bit 56, then B6 = Bmin + DiffB6. Thus, we obtain the corresponding decoded data.
[0136] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0137] Based on the same inventive concept, this application also provides an image compression coding apparatus for implementing the image compression coding method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more image compression coding apparatus embodiments provided below can be found in the limitations of the image compression coding method described above, and will not be repeated here.
[0138] In one embodiment, such as Figure 8 As shown, an image compression encoding device is provided, including: an image segmentation module 802, an image type module 804, a color image module 806, and an image encoding module 808, wherein:
[0139] The image segmentation module 802 is used to acquire the image to be compressed and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels;
[0140] Image type module 804 is used to determine the type of an image block based on the pixels in the image block for each image block;
[0141] The color image module 806 is used to determine whether the pixels in the image block meet preset conditions if the image block is a color image block; wherein the preset conditions include at least one of pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions.
[0142] The image encoding module 808 is used to encode the image block using the encoding rule corresponding to the preset condition if the pixels in the image block satisfy one of the preset conditions.
[0143] In one embodiment, the image compression encoding apparatus further includes:
[0144] The decoding module is used to decode the encoding result corresponding to each of the preset conditions if the pixels in the image block satisfy at least two of the preset conditions, so as to obtain the corresponding first decoded data.
[0145] The compression error module is used to obtain the corresponding first compression error based on the first decoded data and the data of the image block;
[0146] The comparison module is used to select the encoding result corresponding to the smallest first compression error among the first compression errors as the final encoding result corresponding to the image block.
[0147] In one embodiment, when determining whether pixels in an image block satisfy pixel grouping conditions, the color image module 806 is used to:
[0148] The pixels in the image block are divided into multiple groups;
[0149] For each group, calculate the difference between the maximum and minimum values of the pixel components in that group;
[0150] If the maximum value of the difference in each of the multiple groups is less than a preset grouping threshold, it means that the pixels in the image block meet the pixel grouping condition.
[0151] In one embodiment, when determining whether pixels in an image block satisfy pixel grouping conditions, the color image module 806 is further configured to:
[0152] When the pixels in the image block satisfy at least two pixel grouping conditions, the encoding result obtained by encoding according to the encoding rule corresponding to each pixel grouping condition is obtained, and the encoding result is decoded to obtain the corresponding second decoded data;
[0153] Based on the second decoded data and the data of the image block, the corresponding second compression error is obtained;
[0154] The encoding result corresponding to the smallest second compression error among the second compression errors is selected as the encoding result of the image block satisfying the pixel grouping condition.
[0155] In one embodiment, when determining whether pixels in an image block satisfy the condition of equal pixel components, the color image module 806 is used to:
[0156] Determine whether the difference between the maximum and minimum values of the same component of each pixel in the image block is less than a first threshold. If so, it is determined that the condition of equal pixel components is met, and the same component of each pixel can be represented by the same data.
[0157] Determine whether the difference between two different components of the same pixel in the image block is less than a second threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to the same pixel can be represented by the same data.
[0158] Determine whether the difference between the maximum and minimum values of the two components of each pixel in the image block is less than a third threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to each pixel can be represented by the same data.
[0159] In one embodiment, the color image module 806, in determining whether pixels in an image block satisfy the relationship between pixel component differences and corresponding thresholds, is used to:
[0160] Obtain the first difference between the maximum and minimum values of the first component of the pixels in the image block, the second difference between the maximum and minimum values of the second component, and the third difference between the maximum and minimum values of the third component;
[0161] Determine whether the first difference, the second difference, and the third difference satisfy the set of relationships between pixel component differences and corresponding thresholds. Each set of relationships in the set of relationships between pixel component differences and corresponding thresholds includes the relationship between the first difference and the first difference threshold, the relationship between the second difference and the second difference threshold, and the relationship between the third difference and the third difference threshold. If any set of relationships is satisfied, it is determined that the pixels of the image block satisfy the condition of the relationship between pixel component differences and corresponding thresholds.
[0162] Each module in the aforementioned image compression encoding device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0163] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 9 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database stores image compression data. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements an image compression encoding method.
[0164] Those skilled in the art will understand that Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0165] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described image compression coding method embodiments.
[0166] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps in the above-described image compression coding method embodiments.
[0167] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above-described image compression coding method embodiments.
[0168] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0169] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0170] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. An image compression coding method, characterized in that, The method includes: Obtain the image to be compressed, and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels; For each image block, the type of the image block is determined based on the pixels in the image block; the image block type includes grayscale image blocks and color image blocks. If the image block is a color image block, then determine whether the pixels in the image block meet the preset conditions; wherein, the preset conditions include pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions; If the pixels in the image block satisfy one of the preset conditions, then the image block is encoded using the encoding rule corresponding to the preset condition. The determination of whether the pixels in the image block satisfy the pixel grouping condition includes: The pixels in the image block are divided into multiple groups; For each group, calculate the difference between the maximum and minimum values of each pixel component in that group; If the maximum value of the difference in each of the multiple groups is less than a preset grouping threshold, it indicates that the pixels in the image block meet the pixel grouping condition; the more groups there are, the larger the preset grouping threshold is. After determining that the pixels in the image block meet the pixel grouping conditions, the pixel components in the corresponding group are represented by the approximate mean of the pixel components in the group; the approximate mean of the pixel components refers to the arithmetic mean of the maximum and minimum values of the pixel components in the group. The determination of whether the pixels in the image block satisfy the condition of equal pixel components includes: Determine whether the difference between the maximum and minimum values of the two components of each pixel in the image block is less than a third threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to each pixel can be represented by the same data. The pixel components include a first component, a second component, and a third component; determining whether the pixels in the image block satisfy the relationship between the pixel component difference and the corresponding threshold includes: Obtain the first difference between the maximum and minimum values of the first component of the pixels in the image block, the second difference between the maximum and minimum values of the second component, and the third difference between the maximum and minimum values of the third component; Determine whether the first difference, the second difference, and the third difference satisfy the set of relationships between pixel component differences and corresponding thresholds. Each set of relationships in the set of relationships between pixel component differences and corresponding thresholds includes the relationship between the first difference and the first difference threshold, the relationship between the second difference and the second difference threshold, and the relationship between the third difference and the third difference threshold. If any set of relationships is satisfied, it is determined that the pixels of the image block satisfy the condition of the relationship between pixel component differences and corresponding thresholds. After determining that the pixels in the image block satisfy the relationship between the pixel component difference and the corresponding threshold, the minimum value of each pixel component is saved, and the difference between each pixel component and the corresponding minimum value of the pixel component is saved, so as to encode the image block.
2. The method according to claim 1, characterized in that, The method further includes: If the pixels in the image block satisfy at least two of the preset conditions, then the encoding result corresponding to each condition of the image block is decoded to obtain the corresponding first decoded data; Based on the first decoded data and the data of the image block, the corresponding first compression error is obtained; The encoding result corresponding to the smallest compression error among the first compression errors is selected as the final encoding result corresponding to the image block.
3. The method according to claim 1, characterized in that, The method further includes: When the pixels in the image block satisfy at least two pixel grouping conditions, the encoding result obtained by encoding according to the encoding rule corresponding to each pixel grouping condition is obtained, and the encoding result is decoded to obtain the corresponding second decoded data; Based on the second decoded data and the data of the image block, the corresponding second compression error is obtained; The encoding result corresponding to the smallest second compression error among the second compression errors is selected as the encoding result of the image block satisfying the pixel grouping condition.
4. The method according to claim 1, characterized in that, The step of determining whether the pixels in the image block satisfy the condition of equal pixel components further includes: Determine whether the difference between the maximum and minimum values of the same component of each pixel in the image block is less than a first threshold. If so, it is determined that the condition of equal pixel components is met, and the same component of each pixel can be represented by the same data. Determine whether the difference between two different components of the same pixel in the image block is less than a second threshold. If so, it is determined that the condition of equal pixel components is met, and the two components corresponding to the same pixel can be represented by the same data.
5. An image compression encoding device, characterized in that, The device includes: The image segmentation module is used to acquire the image to be compressed and divide the image to be compressed into multiple image blocks, each of which contains a number of pixels; An image type module is used to determine the type of each image block based on the pixels in the image block; the image block type includes grayscale image blocks and color image blocks. A color image module is used to determine whether the pixels in the image block meet preset conditions if the image block is a color image block; wherein, the preset conditions include pixel grouping conditions, pixel component equality conditions, and pixel component difference and corresponding threshold relationship conditions. An image encoding module is used to encode the image block using an encoding rule corresponding to satisfying one of the preset conditions if the pixels in the image block satisfy one of the preset conditions. This includes: after determining that the pixels in the image block satisfy a pixel grouping condition, representing the pixel components in the corresponding group by the approximate mean of the pixel components in the group; the approximate mean of the pixel components refers to the arithmetic mean of the maximum and minimum values of the pixel components in the group; after determining that the pixels in the image block satisfy the relationship between the pixel component difference and a corresponding threshold, saving the minimum value of each pixel component and the difference between each pixel component and the corresponding minimum value of the pixel component to encode the image block. The color image module, when determining whether pixels in the image block meet the pixel grouping conditions, divides the pixels in the image block into multiple groups; for each group, it calculates the difference between the maximum and minimum values of each pixel component in the group; if the maximum value of the difference in each group in multiple groups is less than a preset grouping threshold, it indicates that the pixels in the image block meet the pixel grouping conditions; the more groups there are, the larger the preset grouping threshold is; when determining whether pixels in the image block meet the pixel component equality conditions, it determines whether the difference between the maximum and minimum values of the two components of each pixel in the image block is less than a third threshold; if so, it determines that the pixel component equality conditions are met, and the two components corresponding to each pixel can be represented by the same data; the pixel component includes a first component, a second component, and a third component. Two components and a third component; when determining whether the pixels in the image block satisfy the relationship condition between pixel component difference and corresponding threshold, the first difference between the maximum and minimum values of the first component of the pixels in the image block, the second difference between the maximum and minimum values of the second component, and the third difference between the maximum and minimum values of the third component are obtained; it is determined whether the first difference, the second difference, and the third difference satisfy the set of relationships between pixel component difference and corresponding threshold, wherein each set of relationships in the set of relationships between pixel component difference and corresponding threshold includes the relationship between the first difference and the first difference threshold, the relationship between the second difference and the second difference threshold, and the relationship between the third difference and the third difference threshold. If any set of relationships is satisfied, it is determined that the pixels in the image block satisfy the relationship condition between pixel component difference and corresponding threshold.
6. The apparatus according to claim 5, characterized in that, The device further includes: The decoding module is used to decode the encoding result corresponding to each of the preset conditions if the pixels in the image block satisfy at least two of the preset conditions, so as to obtain the corresponding first decoded data. The compression error module is used to obtain the corresponding first compression error based on the first decoded data and the data of the image block; The comparison module is used to select the encoding result corresponding to the smallest first compression error among the first compression errors as the final encoding result corresponding to the image block.
7. The apparatus according to claim 5, characterized in that, When determining whether pixels in an image block meet pixel grouping conditions, the color image module is also used to: When the pixels in the image block satisfy at least two pixel grouping conditions, the encoding result obtained by encoding according to the encoding rule corresponding to each pixel grouping condition is obtained, and the encoding result is decoded to obtain the corresponding second decoded data; Based on the second decoded data and the data of the image block, the corresponding second compression error is obtained; The encoding result corresponding to the smallest second compression error among the second compression errors is selected as the encoding result of the image block satisfying the pixel grouping condition.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 4.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4.