Picture compression and decompression method and system suitable for MCU
By identifying and encoding new color points and the same color points in the picture in the MCU, and using RGB565 encoding for compression and decompression, the problem of data parsing time for low-performance MCUs in traditional methods is solved, and the image storage space and parsing time are realized optimization.
Patent Information
- Application Number
- CN202410974982.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-11-22
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In traditional image decompression methods, low-performance MCUs have long data parsing time and poor practicality, resulting in large image storage space and affecting display efficiency.
By determining the new color points and the same color points in the picture, use RGB565 encoding for compression and decompression, reduce storage space and number of parsing times, and shorten the data parsing time.
This reduces image storage space and shortens MCU data parsing time, and improves the efficiency of image display.
Smart Images

Figure CN119011857A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of picture processing, and in particular relates to a picture compression and decompression method and system suitable for MCU. Background Art
[0002] TFT screen is Thin Film Transistor Liquid Crystal Display. TFT screen has become one of the mainstream technologies of liquid crystal display due to its advantages such as high resolution, fast response and bright colors.
[0003] TFT screens generally use progressive scanning for display. There are m×n dots in the TFT screen, and each dot has three colors. The number of dots and the color depth determine the data size of each picture displayed. The color value of each pixel in the picture needs to be stored after RGB565 encoding in sequence. When displaying, you only need to read the color value in sequence and pass it to the TFT screen to complete the display of the picture. Generally, the resolution of a commonly used small-size TFT screen is 320*240, and the color value of each pixel occupies 2 bytes. The storage space required for a picture is 320*240*2=153600 bytes, that is, 153600 / 1024=150kb, and the storage space of the picture is relatively large.
[0004] In order to solve the problem of large image storage space, some current methods require compressing images before storing them. When displaying, the MCU decompresses the compressed images and transmits them to the TFT screen for display. However, for low-performance MCUs, the traditional decompression method still needs to read the codes of each pixel in the image one by one and then write them into the TFT screen for display. The data parsing time is long and the practicality is poor. Summary of the invention
[0005] In view of the defects in the prior art, the present invention provides a method and system for compressing and decompressing pictures suitable for MCU, which occupies little storage space for pictures and shortens the data parsing time of MCU decompressing pictures.
[0006] In a first aspect, a method for compressing and decompressing an image applicable to an MCU includes:
[0007] Get the original image;
[0008] According to the colors of all the pixels in the original image, determine the new color point in the original image and N consecutive same color points after the new color point; the new color point includes the first pixel point and the pixel point with a different color from the previous pixel point; the same color point has the same color as the corresponding new color point;
[0009] Encoding is performed according to the color of the new color point or the number N of the same color points to obtain the encoding of the new color point and some of the same color points;
[0010] Generate a compressed image based on all the codes in the original image;
[0011] When a compressed image is received, the color values of the new color point and the same color point are restored according to each code in the compressed image to obtain a decompressed image.
[0012] Furthermore, the encoding method of the new color point includes:
[0013] Define one bit in RGB565 encoding as a flag bit;
[0014] Set the flag bit to 0;
[0015] Generate a color value according to the color of the new color point;
[0016] Fill the color value into the bits of the RGB565 code except the identification bit to obtain the code of the new color point.
[0017] Furthermore, the identification bit is the lowest bit of the green component in the RGB565 encoding.
[0018] Furthermore, the encoding method of the same color point includes:
[0019] When N≤2^L, encode according to the number of identical color points N to obtain the code of the first identical color point after the new color point, where L is the number of bits used to record the number of identical color points in the RGB565 code;
[0020] When N>2^L, encode according to 2^L to obtain the code of the first same color point after the new color point; encode according to the color of the corresponding new color point to obtain the codes of the 2^L+1th to Nth same color points.
[0021] Furthermore, the encoding method of the first same color point after the new color point includes:
[0022] Set the flag bit to 1;
[0023] Convert the number of points of the same color N or 2^L into a binary number;
[0024] Fill the binary number into the L bit of the RGB565 code except the identification bit to obtain the code of the first identical color point after the new color point.
[0025] Furthermore, the encoding method of the 2^L+1th to Nth same color points is the same as the encoding method of the new color point.
[0026] Furthermore, the method for restoring the codes in the new color point and the 2^L+1th to Nth identical color points includes:
[0027] The value of the second lowest bit of the green component in the code is filled into the identification bit to obtain the new color point and the color value of the 2^L+1th to Nth identical color points after restoration.
[0028] Furthermore, the method for restoring the code in the first same color point after the new color point includes:
[0029] Get the color value of the new color point after encoding and restoration;
[0030] Get a binary number consisting of L bits of the code of the first identical color point excluding the identification bit;
[0031] Convert the binary number to decimal to get the number of replications J;
[0032] The color value is copied J times to obtain the restored color values of the first to J-th identical color points after the new color point.
[0033] In a second aspect, a picture compression and decompression system suitable for MCU includes:
[0034] Acquisition unit: used to obtain original images;
[0035] Analysis unit: used to determine the new color point in the original picture and N consecutive same color points after the new color point according to the colors of all the pixels in the original picture; the new color point includes the first pixel point and the pixel point with a different color from the previous pixel point; the same color point has the same color as the corresponding new color point;
[0036] Coding unit: used for encoding according to the color of the new color point or the number N of the same color points to obtain the encoding of the new color point and some of the same color points;
[0037] Compression unit: used to generate a compressed image based on all the codes in the original image;
[0038] Decompression unit: when receiving a compressed image, restore the color value of a new color point and the same color point according to each code in the compressed image to obtain a decompressed image.
[0039] Furthermore, the encoding unit is specifically used for:
[0040] When N≤2^L, encode according to the number of identical color points N to obtain the code of the first identical color point after the new color point, where L is the number of bits used to record the number of identical color points in the RGB565 code;
[0041] When N>2^L, encode according to 2^L to obtain the code of the first same color point after the new color point; encode according to the color of the corresponding new color point to obtain the codes of the 2^L+1th to Nth same color points.
[0042] It can be seen from the above technical solutions that the image compression and decompression method and system suitable for MCU provided by the present invention uses a small number of pixel codes to represent the colors of all pixel points of the image, thereby reducing the storage space occupied by the compressed image. When restoring the image, the number of times the MCU reads and parses the code is reduced, shortening the data parsing time. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following is a brief introduction to the drawings required for the specific embodiments or the description of the prior art. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn according to the actual scale.
[0044] Figure 1 A flowchart of a method for compressing and decompressing an image provided in an embodiment.
[0045] Figure 2 A flowchart of a new color point encoding method provided in an embodiment.
[0046] Figure 3 A flowchart of a first same-color point encoding method provided in an embodiment.
[0047] Figure 4 The flowchart of the first same color point encoding restoration method provided in the embodiment.
[0048] Figure 5 A schematic diagram of the comparison between the first original image and the decompressed image provided in the embodiment.
[0049] Figure 6 A schematic diagram of the comparison between the second original image and the decompressed image provided in the embodiment.
[0050] Figure 7 A schematic diagram of the comparison between the third original image and the decompressed image provided in the embodiment.
[0051] Figure 8 A module block diagram of the image compression and decompression system provided in the embodiment. DETAILED DESCRIPTION
[0052] The embodiments of the technical solution of the present invention will be described in detail below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and are therefore only used as examples, and the protection scope of the present invention cannot be limited thereto. It should be noted that, unless otherwise specified, the technical terms or scientific terms used in this application should be the common meanings understood by those skilled in the art to which the present invention belongs.
[0053] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0054] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0055] As used in this specification and the appended claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrases "if it is determined" or "if [described condition or event] is detected" may be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0056] Example:
[0057] A method for image compression and decompression suitable for MCU, see Figure 1 ,include:
[0058] Get the original image;
[0059] According to the colors of all the pixels in the original image, determine the new color point in the original image and N consecutive same color points after the new color point; the new color point includes the first pixel point and the pixel point with a different color from the previous pixel point; the same color point has the same color as the corresponding new color point;
[0060] Encoding is performed according to the color of the new color point or the number N of the same color points to obtain the encoding of the new color point and some of the same color points;
[0061] Generate a compressed image based on all the codes in the original image;
[0062] When a compressed image is received, the color values of the new color point and the same color point are restored according to each code in the compressed image to obtain a decompressed image.
[0063] In this embodiment, the method obtains the original image, and then determines the new color point in the original image and the N consecutive same color points after the new color point according to the colors of all the pixels in the original image; the new color point includes the first pixel point and the pixel point with a different color from the previous pixel point; the same color point has the same color as the corresponding new color point. For example, the pixel points of the image include the new color point A, 10 consecutive same color points A after the new color point A, the new color point B, and 100 consecutive same color points B after the new color point B, wherein the color of the new color point A is different from the color of the new color point B, the color of the same color point A is the same as the color of the new color point A, and the color of the same color point B is the same as the color of the new color point B.
[0064] In this embodiment, after the new color point and the same color point in the original image are confirmed, the new color point is encoded according to the color or the number N of the same color points to obtain the encoding of the new color point and some of the same color points, and the compressed image is generated according to all the encodings in the original image. In this way, the compressed image only contains the encoding of the new color point and some of the same color points, and does not contain the encoding of all pixel points, thereby reducing the storage space occupied by the compressed image.
[0065] In this embodiment, when the MCU controlling the TFT screen receives a compressed image, it obtains all the codes in the compressed image, restores each code separately, and obtains the color values of all the pixels in the image. In this way, the MCU only needs to read the codes of new color points and some of the same color points to restore the colors of all the pixels, without having to read the codes of all the pixels to restore the colors of all the pixels, thereby reducing the number of times the MCU reads and parses the codes and shortening the data parsing time.
[0066] This image compression and decompression method suitable for MCU uses a small number of pixel codes to represent the colors of all pixels in the image, reducing the storage space occupied by the compressed image. When restoring the image, it reduces the number of times the MCU reads and parses the code, shortening the data parsing time.
[0067] Further, in some embodiments, see Figure 2 , the encoding methods of the new color points include:
[0068] Define one bit in RGB565 encoding as a flag bit;
[0069] Set the flag bit to 0;
[0070] Generate a color value according to the color of the new color point;
[0071] Fill the color value into the bits of the RGB565 code except the identification bit to obtain the code of the new color point.
[0072] In this embodiment, the RGB565 code has 16 bits, occupying 2 bytes, of which the red component occupies 5 bits (R5-R1), the green component occupies 6 bits (G6-G1, where the upper three bits are in the first byte and the lower three bits are in the second byte), and the blue component occupies 5 bits (B5-B1). The format is as follows:
[0073] R5 R4 R3 R2 R1 G6 G5 G4 G3 G2 G1 B5 B4 B3 B2 B1
[0074] In this embodiment, the flag bit can be represented by the lowest bit G1 of the green component in the RGB565 code, which is used to identify whether the color of the current pixel is the same as the color of the previous pixel. When the color of a pixel in the image is different from the color of the previous pixel, the flag bit G1 is set to 0. At this time, a color value is generated according to the color of the new color point, and the color value is filled into the bits of the RGB565 code except the flag bit, that is, the color value of the red component is filled into R5~R1, the color value of the green component is filled into G5~G1, and the color value of the blue component is filled into B5~B1 to obtain the code of the new color point.
[0075] In this embodiment, most of the pictures are toned. Such as warm tones (red, orange, yellow, brown), cold tones (green, cyan, blue, purple) and neutral tones (black, gray, white). Different pictures often lack different colors. For example, for a picture of a blue sky, the picture lacks red. At this time, the method can also set the lowest bit R1 of the red component as the identification bit, so that the decompressed picture has a better effect. The method can also determine the compressed base color according to the difference between the decompressed picture and the original picture and the storage space, that is, determine the color component occupied by the identification bit.
[0076] Furthermore, in some embodiments, the encoding method of the same color point includes:
[0077] When N≤2^L, encode according to the number of identical color points N to obtain the code of the first identical color point after the new color point, where L is the number of bits used to record the number of identical color points in the RGB565 code;
[0078] When N>2^L, encode according to 2^L to obtain the code of the first same color point after the new color point; encode according to the color of the corresponding new color point to obtain the codes of the 2^L+1th to Nth same color points.
[0079] In this embodiment, the method can use only 10 bits G2 to R5 to record the number of identical color points, then L = 10, and one code can record the color values of 1024 identical color points at most. Therefore, the method divides the encoding of identical color points into two cases:
[0080] 1) N ≤ 2^L. This method only needs to encode according to the number of identical color points N to obtain the code of the first identical color point after the new color point, so that the color values of N pixels can be recorded with the code of only one pixel. For example, the color values of 10 identical color points A are recorded with the code of the first identical color point A, indicating that the colors of the 10 consecutive pixels after the new color point A are the same as the color of the new color point A. This method can represent the color values of up to 1025 identical color points with 2 codes, that is, compress 1025*2=2050 bytes into 4 bytes.
[0081] 2) N>2^L. The color values of 1 to 2^L points are recorded with the code of the first same color point, which is converted according to 2^L. For the 2^L+1th to Nth same color points, they are respectively treated as new color points for encoding. At this time, the color values of N pixels are represented by 2+(N-2^L) codes, that is, 2^L*2 bytes are compressed into 4+2(N-2^L) bytes. For example, assuming N=2000, the color values of the 1st to 1024th same color points are recorded with the code of the first same color point, and the color values of the 1025th to 2000th same color points are recorded with separate codes, that is, the color values of the 1025th to 2000th same color points are recorded with the codes of 975 new color points, and these 2001 same color points require 2+975 codes to represent.
[0082] Further, in some embodiments, see Figure 3 , the encoding methods of the first same color point after the new color point include:
[0083] Set the flag bit to 1;
[0084] Convert the number of points of the same color N or 2^L into a binary number;
[0085] Fill the binary number into the L bit of the RGB565 code except the identification bit to obtain the code of the first identical color point after the new color point.
[0086] In this embodiment, when obtaining the code of the first same color point, the method first sets the flag bit to 1, indicating that the color of the current pixel is the same as that of the previous pixel. When N≤2^L, the number of same color points N is converted into a binary number, and the binary number is filled into the RGB565 code. For example, after converting the number of same color points A 10 into a binary number, it is filled into G2~R5 of the RGB565 code to obtain the code of the first same color point A. When N>2^L, 2^L is converted into a binary number, and the binary number is filled into the RGB565 code to obtain the code of the first same color point.
[0087] Further, in some embodiments, the encoding method of the 2^L+1th to Nth same color points is the same as the encoding method of the new color point.
[0088] In this embodiment, when N>2^L, the 2^L+1th to Nth identical color points are encoded according to the encoding method of the new color point. That is, a color value is generated according to the color of the new color point, and the color value is filled into the bit of the RGB565 code except the identification bit to obtain the encoding of the 2^L+1th to Nth identical color points.
[0089] Further, in some embodiments, the method for restoring the codes in the new color point and the 2^L+1th to Nth identical color points includes:
[0090] The value of the second lowest bit of the green component in the code is filled into the identification bit to obtain the new color point and the color value of the 2^L+1th to Nth identical color points after restoration.
[0091] In this embodiment, when encoding a new color point or the 2^L+1th to Nth identical color points, since one bit in the RGB565 code is used as an identification bit, for the TFT screen, the code is missing one bit of data, so when restoring the pixel, the method also needs to fill in the corresponding value in the identification bit. Since the identification bit occupies the lowest bit of the green component, in order to better restore the green component of the pixel, the method fills the second lowest bit of the green component into the identification bit, fills the missing identification bit, and restores the original color value of the pixel. The restored encoding value is as follows:
[0092] R5 R4 R3 R2 R1 G6 G5 G4 G3 G2 G2 B5 B4 B3 B2 B1
[0093] Further, in some embodiments, see Figure 4 , the restoration method encoded in the first same color point after the new color point includes:
[0094] Get the color value of the new color point after encoding and restoration;
[0095] Get a binary number consisting of L bits of the code of the first identical color point excluding the identification bit;
[0096] Convert the binary number to decimal to get the number of replications J;
[0097] The color value is copied J times to obtain the restored color values of the first to J-th identical color points after the new color point.
[0098] In this embodiment, when restoring the code in the first same color point, the method first obtains the color value of the new color point of the same color after restoration, obtains the binary number consisting of L bits of the code of the first same color point excluding the identification bit, converts the binary number into a decimal number to obtain the number of copies J, and copies the color value of the new color point of the same color J times to obtain the color values of the first to Jth same color points after restoration after the new color point. For example, after converting the binary numbers of G2 to R5 in the code of the same color point A into decimal, the number of copies is 10, and at this time, the color value of the new color point A after restoration is copied 10 times as the color values of the first to 10th same color points after restoration after the new color point A.
[0099] To further illustrate that the difference between the decompressed image and the original image is small, this method is practical. Figure 5-7 , Figure 5 The number 100 in the middle left picture represents the original image, and the number 92 in the upper right corner of the right picture represents the compression ratio. Figure 6 The number 100 in the middle left image represents the original image, and the number 76 in the upper right corner of the right image represents the compression ratio. Figure 7 The number 100 in the middle left picture represents the original image, and the number 52 in the upper right corner of the right picture represents the compression ratio. Figure 5-7 The difference between the compressed images is not big. For some images with rich colors and few repeated codes, you can set a smaller compression ratio, and for images with more repeated colors, you can set a larger compression ratio.
[0100] An image compression and decompression system suitable for MCU, see Figure 8 ,include:
[0101] Acquisition unit: used to obtain original images;
[0102] Analysis unit: used to determine the new color point in the original picture and N consecutive same color points after the new color point according to the colors of all the pixels in the original picture; the new color point includes the first pixel point and the pixel point with a different color from the previous pixel point; the same color point has the same color as the corresponding new color point;
[0103] Coding unit: used for encoding according to the color of the new color point or the number N of the same color points to obtain the encoding of the new color point and some of the same color points;
[0104] Compression unit: used to generate a compressed image based on all the codes in the original image;
[0105] Decompression unit: when receiving a compressed image, restore the color value of a new color point and the same color point according to each code in the compressed image to obtain a decompressed image.
[0106] Furthermore, in some embodiments, the encoding unit is specifically used to:
[0107] When N≤2^L, encode according to the number of identical color points N to obtain the code of the first identical color point after the new color point, where L is the number of bits used to record the number of identical color points in the RGB565 code;
[0108] When N>2^L, encode according to 2^L to obtain the code of the first same color point after the new color point; encode according to the color of the corresponding new color point to obtain the codes of the 2^L+1th to Nth same color points.
[0109] The system provided in the embodiment of the present invention is briefly described. For matters not mentioned in the embodiment part, reference may be made to the corresponding contents in the aforementioned embodiment.
[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.
Claims
1. A picture compression and decompression method suitable for MCU, It is characterized in that include: Get the original image; Determine, according to the colors of all pixels in the original image, a new color point in the original image and N consecutive same color points after the new color point; wherein the new color point includes a first pixel point and a pixel point with a different color from a previous pixel point; and the same color point has the same color as the corresponding new color point; Encoding is performed according to the color of the new color point or the number N of the same color points to obtain the encoding of the new color point and some of the same color points; Generate a compressed image based on all the codes in the original image; When the compressed picture is received, the color values of the new color point and the same color point are restored according to each code in the compressed picture to obtain the decompressed picture.
2. According to the image compression and decompression method suitable for MCU according to claim 1, It is characterized in that The encoding method of the new color point comprises: Define one bit in RGB565 encoding as a flag bit; Set the flag bit to 0; generating a color value according to the color of the new color point; The color value is filled into the bits of the RGB565 code except the identification bit to obtain the code of the new color point.
3. According to the image compression and decompression method suitable for MCU according to claim 2, It is characterized in that The identification bit is the lowest bit of the green component in the RGB565 encoding.
4. According to the image compression and decompression method suitable for MCU according to claim 2, It is characterized in that The encoding method of the same color point comprises: When N≤2^L, encode according to the number of identical color points N to obtain the code of the first identical color point after the new color point, where L is the number of bits used to record the number of identical color points in the RGB565 code; When N>2^L, encode according to 2^L to obtain the code of the first same color point after the new color point; encode according to the color of the corresponding new color point to obtain the codes of the 2^L+1th to Nth same color points.
5. According to the image compression and decompression method suitable for MCU according to claim 4, It is characterized in that The encoding method of the first same color point after the new color point includes: Set the flag bit to 1; Convert the number N or 2^L of the same color points into a binary number; The binary number is filled into the L bits of the RGB565 code except the identification bit to obtain the code of the first same color point after the new color point.
6. According to the image compression and decompression method suitable for MCU according to claim 4, It is characterized in that The encoding method of the 2^L+1th to Nth same color points is the same as the encoding method of the new color point.
7. According to the image compression and decompression method suitable for MCU according to claim 4, It is characterized in that The method for restoring the codes in the new color point and the 2^L+1th to Nth identical color points includes: The value of the second lowest bit of the green component in the code is filled into the identification bit to obtain the restored color values of the new color point and the 2^L+1th to Nth identical color points.
8. According to the image compression and decompression method suitable for MCU according to claim 7, It is characterized in that The method for restoring the code in the first same color point after the new color point includes: Obtaining the color value of the new color point after encoding and restoration; Obtain a binary number consisting of L bits of the encoding of the first same color point excluding the identification bit; Convert the binary number into a decimal number to obtain the number of replications J; The color value is copied J times to obtain the restored color values of the first to J-th identical color points after the new color point.
9. An image compression and decompression system suitable for MCU, It is characterized in that include: Acquisition unit: used to obtain original images; An analysis unit: used to determine a new color point in the original image and N consecutive same color points after the new color point according to the colors of all the pixels in the original image; wherein the new color point includes the first pixel point and a pixel point with a different color from the previous pixel point; and the same color point has the same color as the corresponding new color point; Coding unit: used for encoding according to the color of the new color point or the number N of the same color points to obtain the encoding of the new color point and some of the same color points; Compression unit: used to generate a compressed image based on all the codes in the original image; Decompression unit: used for restoring the color value of the new color point and the same color point according to each code in the compressed picture when the compressed picture is received, so as to obtain the decompressed picture.
10. The image compression and decompression system suitable for MCU according to claim 9, It is characterized in that The encoding unit is specifically used for: When N≤2^L, encode according to the number of identical color points N to obtain the code of the first identical color point after the new color point, where L is the number of bits used to record the number of identical color points in the RGB565 code; When N>2^L, encode according to 2^L to obtain the code of the first same color point after the new color point; encode according to the color of the corresponding new color point to obtain the codes of the 2^L+1th to Nth same color points.
Citation Information
Patent Citations
Digital image nondestructive compression method and device, resolution method and image encoder
CN101272442A
Image coding method, image decoding method and device for embedded system
CN102075752A
Pixel frame buffer processing system of liquid crystal display controller (LCDC) and method thereof
CN102522069A
Screen superposition display system and method and picture compression method
CN112165588A
Image compression coding method and device for entropy-free coding, equipment and storage medium
CN116684646A
