CN116828171A - Lossless compression method of RGB/RGBA image - Google Patents

Lossless compression method of RGB/RGBA image Download PDF

Info

Publication number
CN116828171A
CN116828171A CN202310830672.4A CN202310830672A CN116828171A CN 116828171 A CN116828171 A CN 116828171A CN 202310830672 A CN202310830672 A CN 202310830672A CN 116828171 A CN116828171 A CN 116828171A
Authority
CN
China
Prior art keywords
bits
block
data
difference
index
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310830672.4A
Other languages
Chinese (zh)
Inventor
陈一宁
曾立超
蔡宇
陈海栋
高大为
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CN202310830672.4A priority Critical patent/CN116828171A/en
Publication of CN116828171A publication Critical patent/CN116828171A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/102Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • H04N19/103Selection of coding mode or of prediction mode
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/17Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object
    • H04N19/176Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object the region being a block, e.g. a macroblock
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/182Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being a pixel
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/90Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using coding techniques not provided for in groups H04N19/10-H04N19/85, e.g. fractals
    • H04N19/93Run-length coding

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

The invention relates to a method for lossless compression of RGB/RGBA images, which comprises the following steps: loading image data; constructing a hash array, and calculating a difference value and an index value; sequentially judging whether the pixel value to be encoded meets the conditions of a run block, an index block, a small difference block, a medium difference block, a large difference block, an oversized difference block, a transparency block and a rewriting block or not so as to determine an optimal encoding mode and encode; and traversing the pixels of the image in sequence from left to right and from top to bottom until the encoding is completed. The unique coding mode combines the advantages of various codes such as run length coding, index coding, differential coding and the like, can effectively reduce redundant information of data and improves the compression rate.

Description

Lossless compression method of RGB/RGBA image
Technical Field
The invention relates to the technical field of information, in particular to a RGB/RGBA image lossless compression method.
Background
In the 21 st century, the human society has been continuously developing, so that people have an increasing demand for images and videos, and with the development of science and technology, the storage space occupied by the images and videos has also been increasing. The massive storage demands require that we increase the storage capacity as much as possible and reduce the space occupied by image and video storage as much as possible, the latter relying more on image and video compression techniques, which are often implemented by codec. By encoding and decoding images and video, we can greatly reduce the volume of raw data that is huge and redundant. For example, the original data size of a 4K film may be 10TB, and after encoding, the actual space occupied by the film may reach the order of 10GB, thereby achieving 1000 times of compression. Therefore, the image and video coding and decoding technology is significant.
The most commonly used color image representation method at present is an RGB image, which is a color image represented by three color channels of red, green, and blue. RGBA images have been augmented with a transparency channel on an RGB basis to represent transparency information for the image.
Image compression techniques are divided into two types, lossy compression and lossless compression. Lossy compression brings about a greater space saving in order to achieve a higher compression rate, which can lead to defects and loss of the original information of the image portion. Compared with the lossy compression method, the lossless compression method can reduce the volume of data under the condition of keeping the image quality unchanged, and can completely restore the original image after decompression. Lossless compression is applicable to fields with high requirements on image details, such as medical images, satellite images and the like. The existing lossless image compression method is low in compression rate or can only compress specific image data, such as Huffman coding and run-length coding; or the encoding process is complex and computationally intensive, such as jpeg l s algorithm and png algorithm. On the premise of ensuring high compression ratio, a simple coding process is adopted as much as possible to realize lossless compression of the image, and the lossless compression is still an urgent problem for scientific researchers to solve.
Disclosure of Invention
First, the technical problem to be solved
Aiming at the defects in the prior art, the invention provides a lossless compression method for RGB/RGBA images, which has the advantages of simple coding rule, high coding speed and high compression ratio.
(II) technical scheme
In order to achieve the technical purpose, the main technical scheme adopted by the invention comprises the following steps:
in a first aspect, the present invention provides a method for lossless compression of RGB/RGBA images, comprising:
s1, updating the previous pixel point data and loading the pixel point data to be coded; if the image data is read completely, executing S13, otherwise, executing S2;
s2, constructing a hash array, and calculating the dot data difference value and the index position of the pixel to be coded and the previous pixel;
s3, comparing the pixel point data to be encoded with the previous pixel point data: if the run lengths are the same, adding 1, executing S4, and if the run lengths are not the same, executing S5;
s4, judging whether the run length reaches 32 or whether the pixel value to be encoded is the last pixel point; if yes, adopting a run block to output, setting the run length to 0, and returning to S1; otherwise, directly returning to S1;
s5, judging whether the run length is greater than 0; if yes, adopting run block coding output, setting the run length to 0, and executing S6; otherwise, executing S6;
s6, comparing the data to be coded with the pixel value data stored in the hash array according to the index position calculated in the S2: if the two codes are the same, adopting an index block to encode and output, and returning to S1; if not, updating the hash data according to the current data to be coded, and executing S7;
s7, comparing the difference value calculated in the S2 with the coding range of the small difference block: if the code range of the small difference block is met, adopting the code output of the small difference block, returning to the step S1, otherwise, executing the step S8;
s8, comparing the difference value calculated in the S2 with the coding range of the middle difference block: if the code range of the middle differential block is met, adopting the middle differential block to code and output, returning to S1, otherwise, executing S9;
s9, comparing the difference value calculated in the S2 with the coding range of the large difference block: if the code range of the large difference block is met, adopting the large difference block to code and output, returning to the step S1, otherwise, executing the step S10;
s10, comparing the difference value calculated in the S2 with the coding range of the large difference block: if the code range of the ultra-large differential block is met, adopting the ultra-large differential block to code and output, returning to the step S1, otherwise, executing the step S11;
s11, comparing the transparency value of the pixel point to be encoded with the transparency value of the last pixel point according to the difference value calculated in the S2: if equal, adopting transparent block coding output, returning to S1, otherwise, executing S12;
s12, adopting a rewriting block to encode and output, and returning to S1;
s13, outputting data, and naming the data as co i data format.
According to the lossless compression method of the RGB/RGBA image, according to the data characteristics of the pixel points to be encoded, RGBA values of the pixel points to be encoded are used as integral data, and whether the pixel values to be encoded meet the conditions of a run block, an index block, a small difference block, a medium difference block, a large difference block, an ultra-large difference block, a transparency block and a rewriting block or not is judged in sequence, so that the optimal encoding mode is determined, encoding is performed, redundant information is effectively removed while high compression ratio is guaranteed, and lossless compression of the image is realized.
Further, in the step S2, the difference values include a red difference value, a green difference value, a blue difference value, a transparency difference value, a red-green difference value, and a blue-green difference value, wherein
The red difference is expressed as dr = px. R-px_pre. R;
the green color difference value is expressed as dg=px.g-px_pre.g;
the blue color difference value is expressed as db=px.b-px_pre.b;
the transparency difference is expressed as dr = px.a-px_pre.a;
the red-green difference is expressed as dr-dg;
the blue-green difference is expressed as db-dg.
Further, the run block includes 8 bits, wherein the first 3 bits are 000, which are flag bits of the run block, indicating that the pixels to be encoded adopt the coding mode of the run block; the last 5 bits are run-length data bits, and one run block can represent at most 32 repeated pixels.
Further, the index block includes 8 bits, wherein the first 3 bits are 001, which is a flag bit of the index block, indicating that the pixel to be encoded adopts the encoding mode of the index block; the last 5 bits are index position data bits, and an index block represents pixel point information stored in a hash array at the index.
Wherein the index block uses the idea of dictionary coding, and stores the values which appear before in the dictionary, and each value is associated with a unique index. Each value in the data set is replaced with a corresponding index, thereby enabling compression of the data.
Further, the small differential block comprises 11 bits, wherein the first 3 bits are 010, are marker bits of the index block, and indicate that the pixels to be encoded adopt the encoding mode of the small differential block; the last 8 bits are differential data bits, including dr, dg, db, da each 2 bits.
Further, the middle differential block comprises 16 bits, wherein the first 3 bits are 011, which is a flag bit of the index block, and the coding mode of the middle differential block is adopted by the pixels to be coded; the last 13 bits are differential data bits, including 3 bits each of dr and dg, db, da of 4 bits.
Further, the large differential block comprises 21 bits, wherein the first 3 bits are 100, are flag bits of an index block, and indicate that the pixels to be encoded adopt a coding mode of the large differential block; the last 18 bits are differential data bits, including 6 bits of dr and 4 bits each of dr-dg, db-db, da.
Further, the oversized differential block comprises 25 bits, wherein the first 3 bits are 101, are marker bits of the index block, and indicate that the pixels to be encoded adopt an encoding mode of the oversized differential block; the latter 22 bits are differential data bits, including 7 bits of dr and dr-dg, db-db, da each 5 bits.
Specifically, if the pixel point to be encoded and the index position corresponding array information are different and the condition of the run block is not satisfied, the judgment of the difference block is entered. The idea of residual coding employed by the differential block. The data is encoded as a sequence of residuals by calculating the difference between each data point and the previous data point. This has the advantage that it can more efficiently represent trends and patterns in the data. Since residual coding only focuses on differences between data points, not absolute values themselves, it can reduce redundancy of data to some extent. And layering the differential blocks, and representing smaller residual errors by using shorter code lengths, so that rules among pixel points are fully developed, and the compression rate is improved.
Further, the transparency block includes 27 bits, wherein the first 3 bits are 110 and the last 24 bits are pixel data bits, including 8 bits each of px.r, px.g, px.b.
Further, the rewrite block includes 35 bits, wherein the first 3 bits are 111 and the last 32 bits are pixel data bits including 8 bits each of px.r, px.g, px.b, px.a.
In this case, most pixels can be coded by the condition judgment of four residual blocks, however, pixels at partial edges may not be represented by a given residual block due to excessive residual values, so that the pixels are stored by using the re-writing coding block.
(III) beneficial effects
The beneficial effects of the invention are as follows: according to the data characteristics of different pixel points, the invention adopts various coding modes such as run length coding, index coding, differential coding and the like to carry out only once traversal coding operation on single pixel points, and can effectively eliminate redundant information in images through a simple coding process while ensuring high compression ratio, thereby realizing lossless compression of the images. Compared with the traditional PNG lossless compression algorithm, the method has the advantages of better compression rate, simple coding rule, high compression speed and easy realization.
Drawings
FIG. 1 schematically shows a flow chart of a lossless compression method of an RGB/RGBA image according to the present invention;
FIG. 2 is a diagram of eight coding blocks;
fig. 3 is a schematic diagram of an RGBA compression process of 4*4.
Detailed Description
The invention will be better explained by the following detailed description of the embodiments with reference to the drawings.
In order that the above-described aspects may be better understood, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
Example 1
Referring to fig. 1, the present invention provides a lossless compression method of RGB/RGBA images, comprising:
s1, loading pixel points according to the sequence from left to right and from top to bottom of a source image. According to the difference of the source image channel number, corresponding bytes are read from the image data each time, and the color information of the single pixel point is stored in the pixel point structure px. The previous pixel structure px_prev (initialized to {0, 255 }) is updated before each acquisition of the data to be encoded. If the image data is read, S13 is executed, otherwise S2 is executed.
S2, constructing a hash array, wherein the size of the array can store data of 32 pixel point structures px. And calculating the difference value (including red difference value, green difference value, blue difference value, transparency difference value, red-green difference value and blue-green difference value) of each channel of the pixel to be coded and the previous pixel point data. The pixel point structure is mapped to an unsigned index position of less than 32 using the hash function pos= (3 x px. R+5 x px. G+7 x px. B+11 x px. A)% 32.
S3, judging whether the pixel point data to be encoded is the same as the previous pixel point data, if so, adding 1 to the run length, and executing S4; otherwise, S5 is performed.
S4, judging whether the run length reaches 32 or the pixel value to be coded is the last pixel point, if so, outputting by using a run block, wherein the format of the run block is 3bit flag bit 000+5 bit (run length-1) 11111, setting the run length to 0, and returning to S1; otherwise, directly returning to S1.
S5, judging whether the run length is greater than 0, if so, outputting by adopting run block coding, setting the run length to 0, and executing S6; otherwise, S6 is executed.
S6, comparing whether the data to be encoded is consistent with the pixel value data stored in the hash array or not according to the index position calculated in the S2. If yes, adopting an index block to encode and output, wherein the format of the index block is 3bit flag bit 001+5 bit index position pos, and returning to S1; otherwise, the hash data is updated according to the data to be encoded currently, and S7 is executed.
S7, comparing whether the difference value to be coded accords with the coding range of the small difference block or not according to the difference value calculated in the S2. The coding range of the small differential blocks is dr, dg, db, da: [ -2,1]. If so, dr, dg, db, da are mapped to the unsigned number range [0,3]. The output is encoded by a small differential block, and the format of the small differential block is 3 bits 010+2bit (dr+2) +2bit (dg+2) +2bit (db+2) +2bit (da+2). Returning to S1; otherwise, S8 is performed.
S8, comparing whether the difference value to be coded accords with the coding range of the middle difference block or not according to the difference value calculated in the S2. The coding range of the middle differential block is dg [ (8, 7], dr-dg, db-dg, da= [ -4,3]. If so, dg is mapped to [0,15], dr-dg, db-dg, da is mapped to [0,7]. And (3) outputting by adopting a medium differential block code, wherein the format of the medium differential block is 3 bits 011+4bit (dg+8) +3bit (dr-dg+4) +3bit (db-dg+4) +3bit (da+4), and returning to S1. Otherwise, S9 is performed.
S9, comparing whether the difference value to be encoded accords with the encoding range of the large difference block or not according to the difference value calculated in the S2. The large differential block is encoded in the range dg [ -32,31], dr-dg, db-dg, da= [ -8,7]. If so, dg is mapped to [0,63], dr-dg, db-dg, da is mapped to [0,15]. And (3) adopting a large differential block to encode and output, wherein the format of the medium differential block is 3 bits 100+6bit (dg+32) +4bit (dr-dg+8) +4bit (db-dg+8) +4bit (da+8), and returning to S1. Otherwise, S10 is performed.
S10, comparing whether the difference value to be coded accords with the coding range of the oversized difference block or not according to the difference value calculated in the S2. The coding range of the oversized differential block is dg [ (64, 63], dr-dg, db-dg, da= [ -16,15]. If so, dg is mapped [0,127], dr-dg, db-dg, da to [0,31]. And (3) outputting by adopting an oversized differential block code, wherein the format of the oversized differential block is 3bit101+7bit (dg+64) +5bit (dr-dg+16) +5bit (db-dg+16) +5bit (da+8), and returning to S1. Otherwise, S11 is performed.
S11, comparing whether the transparency values of the pixel point to be encoded and the last pixel point are equal or not according to the difference value calculated in the S2, if so, outputting by using transparency block encoding, and returning to the S1. Otherwise, S12 is performed.
S12, adopting the rewriting block to encode and output, and returning to S1.
S13, the original RGB/RGBA image is compressed into a combination of 8 encoded blocks, named the new format as coi data format.
Referring to fig. 2, the first diagram in fig. 2 represents a run block. Specifically, 8-bit bits are used to represent one run block. The first 3 bits 000 are flag bits of the run block, which indicates that the pixels to be encoded adopt the coding mode of the run block. The last 5 bits are run-length data bits, and one run block can represent at most 32 repeated pixels. Since 5 bits can only represent an unsigned range of 0,31, and a range of run lengths is 1,32, the run length is reduced by one for a specific encoding.
For example, suppose there are 40 consecutive pixel points RGBA {0,0,0,255}, the 41 st pixel point is {0, 254}, and the initial value of Run is 0. Step one: compare whether the first RGBA is equal to the previous pixel RGBA (initialize px_prev to {0, 255 }). The result is equal, and runlength is equal to runlength+1. At this time, run is 1 and less than 32, and then the next pixel is loaded. Repeating the first step, when loading to the 32 th pixel, wherein the runlength is equal to 32, and the maximum coding range of the run block is reached; so 000 (run block flag) +11111 (runlength-1) are output. Then Run is set to 0. And continuing to repeat the step one. When loaded into the 41 st pixel, the pixel value of the RGBA and the pixel value of the previous RGBA are not equal. At this time, run length Run is 8 greater than 0, indicating that the previous Run-length code was applied. It is necessary to output 000 (flag bit) 00111 (Run length Run-1), and then set Run to 0. So far, the first 40 identical pixel value values have been encoded, using only two run blocks. The 41 st pixel is not coded yet, and the index condition judgment is entered.
Referring to fig. 2, the second diagram in fig. 2 represents an index block. In operation, if the RGBA value of a pixel matches exactly the RGBA value of a certain index position in the index array, then the index position will be used for encoding. If the RGBA value of the current pixel cannot be found in the dictionary, updating the RGBA value corresponding to the index position. It is ensured that the array always contains the 32 pixel information which has recently appeared. Specifically, 8 bits are used to represent one index block. Wherein the first 3 bits 001 are flag bits of the index block, which indicates that the pixel to be encoded adopts the coding mode of the index block. The last 5 bits are index position data bits, and one index block can represent pixel point information stored in the hash array at the index.
For example, if there are three pixels rgba= {0,0,1,254}, {5,5,5,254}, {0,0,1,254}, which are different from each other, to be encoded, the run-length encoding block cannot be used, and a judgment of entering the condition of the index encoding block is required.
Step one, initializing a hash index array, wherein the pixel point information stored in 32 positions is {0,0,0,255}. Step two, loading the first pixel, calculating pos= (0×3+0×5+1×7+254×11)% 32=17, index [17] {0,0,0,255} is not equal to the pixel value {0,0,1,254} of the first pixel, indicating that the same pixel has not occurred before, and updating the pixel information corresponding to index [17] to {0,0,1,254}. Step three, loading the second pixel point, calculating pos= (5×3+5×5+5×7+254×11)% 32=21, and similarly, not equalizing index [21], and updating index [21] to {5,5,5,254}. Loading the third pixel, pos= (0×3+0×5+1×7+254×11)% 32=17. This data is found to already exist in the index array index [17] (the RGBA data is identical to the first RGBA data). The best coding mode is index block index. The code stream output is 001 010001, where 001 is the flag bit of the index block, followed by 010001 is an unsigned number representation of index position 17.
Referring to fig. 2, the third diagram in fig. 2 represents a small differential block, the fourth diagram represents a medium differential block, the fifth diagram represents a large differential block, and the sixth diagram represents an oversized differential block. In the present invention, the residual error is calculated by taking the RGBA value of the pixel to be encoded as one whole data, and calculating the difference value with the RGBA of the previous pixel. The types of the differences are divided into 6 types, red difference dr=px.r-px_pre.r, green difference dg=px.g-px_pre.g, blue difference db=px.b-px_pre.b, transparency difference dr=px.a-px_pre.a, red-green difference dr-dg, and blue-green difference db-dg. According to the six kinds of residual errors, the differential blocks are divided into small differential blocks, medium differential blocks, large differential blocks and oversized differential blocks, the code lengths of the differential blocks are sequentially increased, and the range of the residual errors which can be represented is also sequentially increased. Since the principles of these four differential blocks are substantially similar, except for the code length and the range that can be included, only a small differential block will be described herein.
Specifically, 11 bits are used to represent a small differential block. Wherein the first 3 bits 010 are the flag bits of the index block, which indicates that the pixel to be encoded adopts the encoding mode of the small difference block. The last 8 bits are differential data bits, representing 2 bits of dr, dg, db, da, respectively.
For example, if the pixel to be encoded rgba= {0,0,1,254}, the previous pixel is {0,0,0,255}, and the index array index [17] = {0,0,0,255}. First, {0,0,1,254} is different from the previous pixel and index [17] is not equal to {0,0,1,254}, so a small residual block condition judgment is entered. The difference is calculated to find dr=0, dg=0, db=1, da= -1, and the encoding range of the small residual block is dr, dg, db, da= { -2,..1}. The best coding mode is a small residual block diff0. Mapping the residual into an unsigned number which can be represented by 2 bits, namely {0,., 3}, and adding 2 to all dr, dg, db and da. The code stream output is 01010 1011 01. Wherein 010 is the flag bit of the small differential block, 1010 1101 is the binary representation of dr+2, dg+2, db+2, da+2, respectively.
Referring to fig. 2, a seventh drawing in fig. 2 is a transparency block, and an eighth drawing is a rewrite block. The overwrite encoded block uses 35 bits to represent one overwrite block. Wherein the first 3 bits 111 are flag bits of the index block, which indicates that the pixels to be encoded adopt the encoding mode of the rewriting block. The last 32 bits are pixel data bits, 8 bits of px.r, px.g, px.b, px.a, respectively. It is considered that in a real image, a substantial portion of the pixels and the transparency channels of the previous pixels are identical. By storing the transparency information, only rewriting the values of the rgb three channels can improve the compression rate. The transparency compression block uses 27 bits to represent one transparency block. The first 3 bits 110 are flag bits of the index block, which indicates that the pixels to be encoded adopt the encoding mode of the transparency block. The last 24 bits are pixel data bits, 8 bits of px.r, px.g, px.b, respectively.
For example, if two pixels to be encoded rgba= {32,64,128,128}, {0,196,0,128} the previous pixel is {94,94,95,254}, and index [ pos ] is not equal to px. First, a given first pixel point, {32,64,128,128} is encoded differently from the previous pixel and index [ pos ] is not equal to px, so that the residual block condition judgment is entered. By calculating the difference, da= -126, even if the encoding range of the extra large residual block is da= { -16,..15} this pixel cannot be represented. The transparency channel difference is not equal to 0 so that only the pixel can be recorded using the overwrite block. The code stream output is 111 0010000 0100000 1000000010000000. Where 111 is the flag bit of the overwrite block, and each byte later represents a px four-way pixel value 32,64,128,128, respectively. Next, the previous pixel is updated to {32,64,128,128}, and then the second pixel is loaded {0,196,0,128}. According to the previous rule, the second pixel obviously does not meet the conditions of the run block and the index block, and by calculating dg=132, even if the coding range of the oversized residual block is d= { -64,..63} this pixel cannot be represented. Since the transparency channel difference is equal to 0, the pixel can be recorded for the transparency block. The code stream output is 1100000000 1100000 00000000. Where 110 is the flag bit of the transparency block, and each byte later represents a px three channel pixel value 0,196,0, respectively.
Example two
Referring to fig. 3, the encoding method of the present invention is illustrated with an RGBA block example of 4*4. First, the previous pixel structure px_prev (initialized to {0, 255 }). The pixels are loaded in the order of the source image from left to right and top to bottom. The first pixel is different from the previous pixel, and the hash array does not store the data. By calculating dr=0, dg=0, db=1, da= -1, the optimal coding scheme is the small difference block diff0. The difference is mapped to the range of 0,3, i.e. the difference for each channel is added to 2. The code stream output is 01010 1011 01.
The previous pixel is updated, px_prev= {0,0,1,254}. At this time, a second pixel is loaded, and the run length is found to be the same as the previous pixel, plus one. Loading the third pixel, finding the same as the previous pixel, and adding one to the run length.
And the fourth pixel point is the same as the previous pixel point, and the run length is increased by one. At this time, a fifth pixel is loaded, and a run block run is found as the optimal coding mode, which is different from the previous pixel and has a run length greater than 0. The code stream output is 000 00010. Wherein 00010 is the run length minus one because the range of run lengths is [1,32], and the range represented by the 5bit unsigned number is [0,31]. It is calculated that dr=5, dg=5, db=5, da=0, dr-dg=0, db-dg=0, the best coding mode is the medium difference block diff1. Dg is mapped to the range of [0,15], i.e. the difference is added to 8 to get 13. Dr-dg, db-dg and da are mapped to the range of [0,7], i.e. the difference is added by 4 to give 4, respectively. The code stream output is 011 1101 100 100100.
Loading the 6 th pixel, calculating pos= (0×3+0×5+1×7+254×11)% 32=17. This data is found to already exist in the index array index [17] (the RGBA data is identical to the first RGBA data). The best coding mode is index block index. The code stream output is 001 010001.
Loading the 7 th pixel point, and obtaining dr=31, dg=31, db=31, da=0, dr-dg=0 and db-dg=0 through calculation, wherein the optimal coding mode is a large differential block luma0. Dg is mapped to the range of [0,64], i.e., the difference plus 32 results in 63. Dr-dg, db-dg and da are mapped to the range of [0,15], i.e. the difference is added to 8 to give 8, respectively. The code stream output is 100 1111111000 1000 1000.
Loading the 8 th pixel point, and obtaining dr=63, dg=63, db=63, da=0, dr-dg=0 and db-dg=0 through calculation, wherein the optimal coding mode is an oversized differential block luma1. Dg is mapped to the range of [0,128], i.e., the difference plus 64 yields 127. Dr-dg, db-dg and da are mapped to the range of [0,32], i.e. the difference is added by 16 to give 16, respectively. The code stream output is 1011111111 10000 10000 10000.
The 9 th pixel point is loaded, and the da= -126 is calculated, the number of a channels is different, and the same data does not exist in the index array. This does not meet the encoding conditions of the first 7 encoding blocks, and only the information of the pixel point can be recorded by using the rewriting block RGBA. The code stream output is 1011111111 10000 10000 10000.
Loading the 10 th pixel, where dg=196 and the index array does not have the pixel. The transparency of the pixel point is the same as that of the previous pixel point, and the optimal coding mode is a transparency block RGB. The code stream output is 11000000000 1100000000000000.
And loading 11 th to 16 th pixel points, wherein the pixel point data are the same. The run length is 6 but the end of the image has been reached at this point, a run block run needs to be used. The code stream output is 000 00101. Up to this point, the RGBA image block of 4*4 is compressed. Outputting the code stream according to the mode of the compressed block to calculate the size of the compressed file:
diff0 (11) +run (8) +diff1 (16) +index (8) +luma0 (21) +luma1 (25) +rgb a (35) +rgb (27) +run (8) =159 bits.
In actual compression, 0 will be appended to the end of less than one byte. In the above embodiment, it is sufficient to fill one zero, i.e., 160 bits or 20 bytes. The size of the original image is (number of channels) 4 (number of pixels) 16=64 bytes, and the compression ratio is 31.25%.
The invention provides a lossless compression method of RGB/RGBA images, which carries out corresponding coding according to the data characteristics of different pixel points by a unique coding mode, thereby improving the compression efficiency, improving the compression ratio and greatly reducing the redundancy of data.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present invention without departing from the spirit or scope of the invention. Thus, the present invention should also include such modifications and variations provided that they come within the scope of the following claims and their equivalents.
In the description of the present invention, it should be understood that the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature. In the description of the present invention, the meaning of "a plurality" is two or more, unless explicitly defined otherwise.
In the present invention, unless explicitly specified and limited otherwise, the terms "mounted," "connected," "secured," and the like are to be construed broadly, and may be, for example, fixedly connected, detachably connected, or integrally formed; can be mechanically or electrically connected; can be directly connected or indirectly connected through an intermediate medium; may be a communication between two elements or an interaction between two elements. The specific meaning of the above terms in the present invention can be understood by those of ordinary skill in the art according to the specific circumstances.
In the present invention, unless expressly stated or limited otherwise, a first feature is "on" or "under" a second feature, which may be in direct contact with the first and second features, or in indirect contact with the first and second features via an intervening medium. Moreover, a first feature "above," "over" and "on" a second feature may be a first feature directly above or obliquely above the second feature, or simply indicate that the first feature is higher in level than the second feature. The first feature being "under", "below" and "beneath" the second feature may be the first feature being directly under or obliquely below the second feature, or simply indicating that the first feature is level lower than the second feature.
In the description of the present specification, the terms "one embodiment," "some embodiments," "examples," "particular examples," or "some examples," etc., refer to particular features, structures, materials, or characteristics described in connection with the embodiment or example as being included in at least one embodiment or example of the present invention. In this specification, schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, the different embodiments or examples described in this specification and the features of the different embodiments or examples may be combined and combined by those skilled in the art without contradiction.
While embodiments of the present invention have been shown and described above, it will be understood that the above embodiments are illustrative and not to be construed as limiting the invention, and that alterations, modifications, substitutions and variations may be made in the above embodiments by those skilled in the art within the scope of the invention.

Claims (10)

1. A lossless compression method for RGB/RGBA images, characterized by: comprising
S1, updating the previous pixel point data and loading the pixel point data to be coded; if the image data is read completely, executing S13, otherwise, executing S2;
s2, constructing a hash array, and calculating the dot data difference value and the index position of the pixel to be coded and the previous pixel;
s3, comparing the pixel point data to be encoded with the previous pixel point data: if the run lengths are the same, adding 1, executing S4, and if the run lengths are not the same, executing S5;
s4, judging whether the run length reaches 32 or whether the pixel value to be encoded is the last pixel point; if yes, adopting a run block to output, setting the run length to 0, and returning to S1; otherwise, directly returning to S1;
s5, judging whether the run length is greater than 0; if yes, adopting run block coding output, setting the run length to 0, and executing S6; otherwise, executing S6;
s6, comparing the data to be coded with the pixel value data stored in the hash array according to the index position calculated in the S2: if the two codes are the same, adopting an index block to encode and output, and returning to S1; if not, updating the hash data according to the current data to be coded, and executing S7;
s7, comparing the difference value calculated in the S2 with the coding range of the small difference block: if the code range of the small difference block is met, adopting the code output of the small difference block, returning to the step S1, otherwise, executing the step S8;
s8, comparing the difference value calculated in the S2 with the coding range of the middle difference block: if the code range of the middle differential block is met, adopting the middle differential block to code and output, returning to S1, otherwise, executing S9;
s9, comparing the difference value calculated in the S2 with the coding range of the large difference block: if the code range of the large difference block is met, adopting the large difference block to code and output, returning to the step S1, otherwise, executing the step S10;
s10, comparing the calculated difference value in the S2 with the coding range of the oversized difference block: if the code range of the ultra-large differential block is met, adopting the ultra-large differential block to code and output, returning to the step S1, otherwise, executing the step S11;
s11, comparing the transparency value of the pixel point to be encoded with the transparency value of the last pixel point according to the difference value calculated in the S2: if equal, adopting transparent block coding output, returning to S1, otherwise, executing S12;
s12, adopting a rewriting block to encode and output, and returning to S1;
s13, outputting data and naming coi data format.
2. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: in the S2, the difference value comprises a red difference value, a green difference value, a blue difference value, a transparency difference value, a red-green difference value and a blue-green difference value, wherein
The red difference is expressed as dr = px. R-px_pre. R;
the green color difference value is expressed as dg=px.g-px_pre.g;
the blue color difference value is expressed as db=px.b-px_pre.b;
the transparency difference is expressed as dr = px.a-px_pre.a;
the red-green difference is expressed as dr-dg;
the blue-green difference is expressed as db-dg.
3. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the run block comprises 8 bits, wherein the first 3 bits are 000, which are the flag bits of the run block, and indicate that the pixels to be encoded adopt the coding mode of the run block; the last 5 bits are run-length data bits, and one run block can represent at most 32 repeated pixels.
4. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the index block comprises 8 bits, wherein the first 3 bits are 001, are marker bits of the index block, and indicate that the pixel to be encoded adopts the coding mode of the index block; the last 5 bits are index position data bits, and an index block represents pixel point information stored in a hash array at the index.
5. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the small difference block comprises 11 bits, wherein the first 3 bits are 010, are marker bits of the index block, and indicate that the pixels to be encoded adopt the encoding mode of the small difference block; the last 8 bits are differential data bits, including dr, dg, db, da each 2 bits.
6. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the middle differential block comprises 16 bits, wherein the first 3 bits are 011, are the flag bits of the index block, and indicate that the pixels to be coded adopt the coding mode of the middle differential block; the last 13 bits are differential data bits, including 3 bits each of dr and dg, db, da of 4 bits.
7. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the large differential block comprises 21 bits, wherein the first 3 bits are 100, are marker bits of an index block, and indicate that the pixels to be encoded adopt the encoding mode of the large differential block; the last 18 bits are differential data bits, including 6 bits of dr and 4 bits each of dr-dg, db-db, da.
8. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the super-large differential block comprises 25 bits, wherein the first 3 bits are 101, are marker bits of an index block, and indicate that the pixels to be encoded adopt the encoding mode of the super-large differential block; the latter 22 bits are differential data bits, including 7 bits of dr and dr-dg, db-db, da each 5 bits.
9. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the transparency block comprises 27 bits, wherein the first 3 bits are 110, are flag bits of an index block, and indicate that the pixels to be encoded adopt the encoding mode of the transparency block; the last 24 bits are pixel data bits, including 8 bits each of px.r, px.g, px.b.
10. A method of lossless compression of RGB/RGBA images as claimed in claim 1, wherein: the rewriting block comprises 35 bits, wherein the first 3 bits are 111, are flag bits of an index block, and indicate that pixels to be encoded adopt a coding mode of the rewriting block; the last 32 bits are pixel data bits, including 8 bits each of px.r, px.g, px.b, px.a.
CN202310830672.4A 2023-07-06 2023-07-06 Lossless compression method of RGB/RGBA image Pending CN116828171A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310830672.4A CN116828171A (en) 2023-07-06 2023-07-06 Lossless compression method of RGB/RGBA image

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310830672.4A CN116828171A (en) 2023-07-06 2023-07-06 Lossless compression method of RGB/RGBA image

Publications (1)

Publication Number Publication Date
CN116828171A true CN116828171A (en) 2023-09-29

Family

ID=88118369

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310830672.4A Pending CN116828171A (en) 2023-07-06 2023-07-06 Lossless compression method of RGB/RGBA image

Country Status (1)

Country Link
CN (1) CN116828171A (en)

Similar Documents

Publication Publication Date Title
US6639945B2 (en) Method and apparatus for implementing motion detection in video compression
US8379044B2 (en) Method, system and software product for color image encoding
KR100868716B1 (en) Method, system and software product for color image encoding
US5300949A (en) Scalable digital video decompressor
CN116723337B (en) HDMI high definition data optimized transmission method and system
TW201306495A (en) Method for adaptive entropy coding of tree structures
RU2009110512A (en) METHOD FOR COMPRESSING IMAGES AND VIDEO SEQUENCES
KR20190137684A (en) Lossless compression of sparse activation maps of neural networks
CN107105208A (en) A kind of lossless coding and coding/decoding method of Bayer images
CN114286102A (en) Binary image compression coding and decoding method based on Base62 coding
US6584226B1 (en) Method and apparatus for implementing motion estimation in video compression
CN110933438A (en) JPEG image reversible information hiding method
CN116016606A (en) Sewage treatment operation and maintenance data efficient management system based on intelligent cloud
US20220005229A1 (en) Point cloud attribute encoding method and device, and point cloud attribute decoding method and devcie
CN114726926A (en) Self-adaptive variable length coding method for Laplace information source
CN107343203B (en) JPEG lossless compression method based on OPEN-EXR image
CN116828171A (en) Lossless compression method of RGB/RGBA image
US8311090B2 (en) Method for encoding a first and a second data word
CN115474044B (en) Bayer domain image lossy compression method
CN112887722B (en) Lossless image compression method
CN112532990A (en) String length parameter coding and decoding methods and devices
US6433707B1 (en) Universal lossless compressor for digitized analog data
CN112055223A (en) Image coding and decoding method and coder-decoder
CN117651150A (en) Improved QOI image coding strategy
CN113256747B (en) Bitmap index compression method, bitmap index decompression equipment and bitmap index medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination