A grayscale image compression method based on Hilbert scanning

By combining the efficient Hilbert decoding algorithm and the minimum variance partitioning strategy, the problem of low efficiency of the Hilbert encoding and decoding algorithm in the image compression and decompression process is solved, higher cohesion and decoding speed are achieved, and the number of partitions and storage space are reduced. , improving the compression rate of images.

CN114022577BActive Publication Date: 2024-09-27KUNMING UNIV OF SCI & TECH
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202111321469.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-09
Publication Date
2024-09-27
Estimated Expiration
2041-11-09

AI Technical Summary

Technical Problem

The existing Hilbert encoding and decoding algorithm has low efficiency in the image compression and decompression process, especially the decoding time accounts for nearly 50% of the total time, and the space overhead in the partition merging process is large, resulting in low image compression and decompression efficiency.

Method used

A grayscale image compression method based on the efficient Hilbert decoding algorithm is used to create a Hilbert decoding state view through the data mapping stage, scan the image into a one-dimensional array, divide the partitions with similar grayscale values ​​​​according to the minimum variance partitioning strategy, and merge the small partitions to Reduce the number of partitions to compress the image into a two-bit array of length and grayscale, and use the Hilbert curve decoding algorithm to compress and restore the image.

Benefits of technology

It improves the compression and decompression speed of images, reduces the number of partitions and storage space, improves the compression rate of images, and achieves higher cohesion and decoding speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114022577B
    Figure CN114022577B
Patent Text Reader

Abstract

The invention relates to a grayscale image compression method based on Hilbert scanning, and belongs to the technical field of image storage. The invention comprises a data mapping stage, a compression stage and an image restoration stage. In the data mapping stage, a Hilbert decoding state view is created, and an image is scanned based on an efficient Hilbert curve decoding algorithm, and the image is mapped into a one-dimensional array. In the compression stage, one-dimensional data is divided into partitions with similar grayscale values ​​according to a minimum variance partitioning strategy, and smaller partitions that meet specific conditions are merged to reduce the number of partitions, thereby compressing the original image into two bit arrays of length and grayscale. In the restoration stage, the compressed data is restored to a corresponding image based on a Hilbert curve decoding algorithm. The invention combines an efficient Hilbert decoding algorithm with a minimum variance partitioning and a partition merging strategy, has high cohesion, can make more adjacent pixel points be divided into the same partition, thereby reducing the number of partitions; and has a high decoding speed, thereby improving the compression and decompression speed of the image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a grayscale image compression method based on Hilbert scanning, belonging to the technical field of image storage. Background Art

[0002] Image compression is the basis of image storage and efficient transmission. There are many image compression algorithms, such as the JPEG algorithm and the algorithm proposed by Kamata et al. As an important branch of the Peano filling curve, the Hilbert curve has been widely used in image compression. Compared with raster scanning, Hilbert curve scanning has better cohesion, so it can better store pixels with similar grayscale values ​​in adjacent positions.

[0003] Early Hilbert encoding and decoding algorithms were mostly based on recursion, with low coding efficiency. The Hilbert decoding algorithm used by Kamata accounts for nearly 50% of the total compression time. By introducing an efficient Hilbert decoding algorithm and optimizing the image compression process, the efficiency of image compression can be effectively improved. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a grayscale image compression method based on Hilbert scanning, thereby solving the problem of low image compression and decompression efficiency caused by low image scanning efficiency and large space overhead in the partition merging process.

[0005] The technical solution of the present invention is: a grayscale image compression method based on Hilbert scanning, including a data mapping stage, a compression stage and an image restoration stage. In the data mapping stage, a Hilbert decoding state view is created, and the image is scanned based on an efficient Hilbert curve decoding algorithm to map the image into a one-dimensional array. In the compression stage, the one-dimensional data is divided into partitions with similar grayscale values ​​according to the minimum variance partitioning strategy, and smaller partitions that meet specific conditions are merged to reduce the number of partitions, thereby compressing the original image into two bit arrays of length and grayscale. In the restoration stage, the compressed data is restored to the corresponding image based on the Hilbert curve decoding algorithm.

[0006] The specific steps are:

[0007] Step 1. Construct the Hilbert state view, sequentially scan the image along the direction of the Hilbert curve, and obtain the one-dimensional grayscale array G of the image.

[0008] Step 2: Divide the one-dimensional grayscale array G into small partitions with similar grayscale values, and insert the length and grayscale value of each small partition into the length bit array R len and grayscale bit array R grayThus, the original image is compressed and represented as R len and R gray 2 bit arrays.

[0009] Step 3: Compress the bit array R len and R gray Restore to the corresponding image.

[0010] The Step 1 is specifically as follows:

[0011] Step 1.1: Construct a decoding state view based on the first-order Hilbert curve, and then use an efficient Hilbert decoding algorithm based on the state view to scan the image data. The first-order Hilbert curve contains four basic states: opening downward, left, upward and right, corresponding to states 0, 1, 2, and 3 respectively.

[0012] Step 1.2: Given the first-order code values ​​00, 01, 10, 11, the corresponding coordinate values ​​in the four states and the next-order state are as follows:

[0013] State 0: Physical coordinates: (0,0), (0,1), (1,1), (1,0). Next-order states: 1, 0, 0, 3.

[0014] State 1: Physical coordinates: (0,0), (1,0), (1,1), (0,1). Next-order states: 0, 1, 1, 2.

[0015] State 2: Physical coordinates: (1,1), (1,0), (0,0), (0,1). Next state: 3, 2, 2, 1.

[0016] State 3: Physical coordinates: (1,1), (0,1), (0,0), (1,0). Next state: 2, 3, 3, 0.

[0017] Step 1.3: Given an n*n grayscale image, determine the Hilbert order as log2n, where n is the number of pixels in the image height or width.

[0018] Step 1.4: Along the direction of the Hilbert curve, decode each coded value C in the Hilbert space into the corresponding coordinate P(x,y) in the image.

[0019] Step 1.5: Store the grayscale value of the pixel point P(x,y) into the Cth position of the array G. That is to say, the encoding value C is 1, 2, 3...n, and the grayscale value of the pixel point P(x,y) is stored in the Cth position of the array G.

[0020] The Step 1.4 is specifically as follows:

[0021] Step 1.4.1: Set the initial state s=0, that is, the first order of C always starts decoding from the open downward state, x=0, y=0.

[0022] Step1.4.2: Loop variable i from 1 to log2n, and execute Step1.4.3 and Step1.4.4 in a loop.

[0023] Step 1.4.3: Take the 2-bit code value c of the i-th order of C. The leftmost 2 bits of C are the first order, and the next 2 bits are the second order, and so on. According to the current state s, query the state view to obtain the corresponding i-th order coordinate value (x i ,y i ) and the i+1th order state value s'.

[0024] Step 1.4.4: Let x = x < < 1 | x i ,y=y<<1|y i , s=s', where "|" is a logical OR operation.

[0025] The Step 2 is specifically as follows:

[0026] Step 2.1: Divide the array G evenly into q partitions of length m. The length of the last partition may be less than m, where m represents the length of the initial partition, where q = n*n / m.

[0027] Step 2.2: For each partition p, if p.len < t1 and p.var < t2, use the delayed insertion strategy to insert p.len and p.avg into the in-place array R respectively. len and R gray middle.

[0028] If not, p is further divided into two partitions, p1 and p2, so that p1.var+p2.var is minimized, where t1 represents the partition length threshold, t2 represents the partition variance threshold, p.len represents the partition length, p.avg represents the average grayscale value of partition p, and p.var represents the variance of the grayscale value in partition p.

[0029] Step 2.3: Recursively execute Step 2.2 on partitions p1 and p2 to further partition them until the lengths and variances of all partitions meet the thresholds of t1 and t2.

[0030] Step 2.4: Finally, R len and R gray The compressed segment length and segment grayscale information are stored in respectively, and the total number of segments finally obtained is segNum.

[0031] The strategy for delayed insertion in Step 2.2 is specifically as follows:

[0032] For the partition p to be inserted where p.len is less than t1 and p.var is less than t2, determine whether p.len+prevLen is less than t1 and |p.gray-prevGray| is less than t3.

[0033] If so, set prevGray = (p.len*p.gray+prevLen*prevGray) / (p.len+prevLen) and prevLen = prevLen+p.len, so as to merge the current partition with the previous partition that has not been inserted into the bit array, and not insert it into the bit array for the time being.

[0034] If not, insert prevLen (length is log2t1 bit binary) and prevGray (length is 8 bit binary) into the in-place array R respectively. len and R gray , and set prevLen = p.len, prevGray = p.avg.

[0035] Where prevLen and prevGray represent the total length and average gray value of the partition to be merged before inserting p, respectively. The initial values ​​are both 0. t3 represents the gray difference threshold between p and prevGray.

[0036] The Step 3 is specifically as follows:

[0037] Step 3.1: Set totalLen = 0.

[0038] Step 3.2: For each segment p from segment 0 to segment segNum-1, from R len Read the length information p.len of the log2t1 bit segment p from R gray Read the 8-bit grayscale information p.gray of segment p and execute Step 3.3 to Step 3.5 in a loop.

[0039] Step 3.3: For each position k from 0 to p.len-1 in segment p, loop through Step 3.4.

[0040] Step 3.4: Decode totalLen+k into the corresponding coordinate value P(x,y), and set the pixel value at position P(x,y) of the image to p.gray.

[0041] Step 3.5: Set totalLen = totalLen + p.len.

[0042] The beneficial effects of the present invention are as follows: the present invention combines the efficient Hilbert decoding algorithm with the minimum variance partitioning and partition merging strategy, and has the following advantages:

[0043] 1. High cohesion can make more adjacent pixels be divided into the same partition, thereby reducing the number of partitions.

[0044] 2. High decoding speed, thereby improving the compression and decompression speed of images.

[0045] 3. The partition merging strategy can further reduce the storage space of the image and improve the image compression rate. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 It is a Hilbert curve diagram corresponding to different resolutions of the present invention;

[0047] Figure 2 It is a comparison diagram of the original image and the image after compression and decompression of the present invention;

[0048] Figure 3 It is a comparison diagram of Hilbert decoding efficiency of the present invention;

[0049] Figure 4 is a comparison chart of compression efficiency of the present invention;

[0050] Figure 5 It is a comparison chart of decompression efficiency of the present invention. DETAILED DESCRIPTION

[0051] The present invention will be further described below in conjunction with the accompanying drawings and specific implementation methods.

[0052] A grayscale image compression method based on Hilbert scanning, characterized in that:

[0053] Step 1: Construct the Hilbert state view, sequentially scan the image along the direction of the Hilbert curve, and obtain the one-dimensional grayscale array G of the image.

[0054] Step 2: Divide the one-dimensional grayscale array G into small partitions with similar grayscale values, and insert the length and grayscale value of each small partition into the length bit array R len and grayscale bit array R gray Thus, the original image is compressed and represented as R len and R gray 2 bit arrays.

[0055] Step 3: Compress the bit array R len and R gray Restore to the corresponding image.

[0056] The Step 1 is specifically as follows:

[0057] Step 1.1: Construct a decoding state view based on the first-order Hilbert curve, and then use the efficient Hilbert decoding algorithm based on the state view to scan the image data. The first-order Hilbert curve contains four basic states: opening downward, leftward, upward, and rightward, corresponding to states 0, 1, 2, and 3, respectively. The schematic diagram of the Hilbert curve corresponding to different resolutions is shown in the figure below. Figure 1 shown.

[0058] Step 1.2: Given the first-order code values ​​00, 01, 10, 11, the corresponding coordinate values ​​in the four states and the next-order state are as follows:

[0059] State 0: Physical coordinates: (0,0), (0,1), (1,1), (1,0). Next-order states: 1, 0, 0, 3.

[0060] State 1: Physical coordinates: (0,0), (1,0), (1,1), (0,1). Next-order states: 0, 1, 1, 2.

[0061] State 2: Physical coordinates: (1,1), (1,0), (0,0), (0,1). Next state: 3, 2, 2, 1.

[0062] State 3: Physical coordinates: (1,1), (0,1), (0,0), (1,0). Next state: 2, 3, 3, 0.

[0063] Step 1.3: Given an n*n grayscale image, determine the Hilbert order as log2n, where n is the number of pixels in the image height or width.

[0064] In this embodiment, assuming that a grayscale image of n*n=512*512 is given, the corresponding Hilbert order is log2n=9.

[0065] Step 1.4: Along the direction of the Hilbert curve, decode each coded value C in the Hilbert space into the corresponding coordinate P(x,y) in the image.

[0066] In this embodiment, for each coded value C in the range from 0 to 512*512-1 in the Hilbert space, C is decoded into the corresponding coordinates P(x, y) in the image, so that the corresponding coordinates are (0, 0), (0, 1), (1, 1) ... (511, 511) ... (511, 1), (511, 0) in sequence.

[0067] Step 1.5: Store the grayscale value of the pixel P(x,y) into the Cth position of the array G.

[0068] In this embodiment, the grayscale value corresponding to the pixel point P(x, y) is stored in the array G to obtain G={164, 148, 148, 157, 164, 157, 148 ... 151, 143, 151, 143 ... 64, 57, 59, 63, 59, 57, 59, 57, 59}.

[0069] Specifically, Step 1.4 is as follows:

[0070] Step 1.4.1: Set the initial state s=0, that is, the first order of C always starts decoding from the open downward state, x=0, y=0.

[0071] Step1.4.2: Loop variable i from 1 to log2n, and execute Step1.4.3 and Step1.4.4 in a loop.

[0072] In this embodiment, taking the code value 161073 as an example, its binary form is 100111010100110001, and the loop variable i ranges from 1 to 9.

[0073] Step 1.4.3: Take the 2-bit code value c of the i-th order of C, and query the state view to obtain the corresponding i-th order coordinate value (x i ,y i ) and the i+1th order state value s'.

[0074] In this embodiment, the first-order code value of C is c=10, the current state is s=0, and the query state view obtains the first-order coordinate value (x1, y1)=(1, 1) and the second-order state value s′=0.

[0075] The second-order code value c=01, the current state s=s′=0, and the query state view obtains the second-order coordinate value (x2, y2)=(0,1) and the third-order state value s′=0.

[0076] The third-order coding value c=11, the current state s=s′=0, and the query state view obtains the third-order coordinate value (x3, y3)=(1,0) and the fourth-order state value s′=3.

[0077] The loop continues until the 9th stage c=01, and the current state s=s'=0, resulting in (x9, y9)=(0, 1).

[0078] Step 1.4.4: Let x = x < < 1 | x i ,y=y<<1|y i , s=s', where "|" is a logical OR operation.

[0079] In this embodiment, after the final loop executes 143 and 144, x=101001000, y=110111101, (x, y)=(328, 445).

[0080] The Step 2 is specifically as follows:

[0081] Step 2.1: Divide the array G evenly into q partitions of length m, where q = n*n / m.

[0082] In this embodiment, the length m is set to 256, then q=n*n / m=1024, that is, the array G is evenly divided into 1024 partitions with a length of 256.

[0083] Step 2.2: For each partition p, if p.len < t1 and p.var < t2, use the delayed insertion strategy to insert p.len and p.avg into the in-place array R respectively. len and R gray middle.

[0084] If not, p is further divided into two partitions, p1 and p2, so that p1.var+p2.var is minimized, where t1 represents the partition length threshold, t2 represents the partition variance threshold, p.len represents the partition length, p.avg represents the average grayscale value of partition p, and p.var represents the variance of the grayscale value in partition p.

[0085] In this embodiment, taking the first partition as an example, the length threshold of the given partition is t1=64, the partition variance threshold is t2=2000, and p.len=256 in the first partition. By calculation, the variance of the grayscale value in partition p is p.var=62353.000000, p.len>t1, p.var>t2, and the delayed insertion strategy conditions are not met. p needs to be divided into two partitions, p1 and p2, so that p1.var+p2.var is minimized.

[0086] Step 2.3: Recursively execute Step 2.2 on partitions p1 and p2 to further partition them until the lengths and variances of all partitions meet the thresholds of t1 and t2.

[0087] In this embodiment, when p1.len is calculated to be 194 and p2.len=62, p1.var+p2.var is the smallest. At this time, p1.len>t1, p1.var>t2, so p1 needs to be further divided. Until the length and variance of all partitions meet the thresholds of t1 and t2, for a given image, without merging, it is divided into 19268 partitions in total, and the length set of each partition is {32, 24, 8, 56, 27...36, 18, 48,...62, 7}, and the grayscale set of the partition is {149, 159, 160, 174, 167...114, 120, 121...64, 58}.

[0088] After delayed insertion and merging of adjacent small partitions, the number of partitions is compressed to 18771. The final partition length set is {32, 32, 56, 27, 35...26, 11, 36...62, 7}, and the final grayscale set is {149, 160, 174, 167, 176...144, 128, 106...64, 58}.

[0089] Step 2.4: Finally, R len and R gray The compressed segment length and segment grayscale information are stored in respectively, and the total number of segments finally obtained is segNum.

[0090] In this embodiment, finally, the entire grayscale image information is stored in R len and R gray middle,

[0091] Array R len ={100000|100000|111000|……001100|**,……,000111}.

[0092] R gray ={10010101|10100000|10101110|*******,……,00111010},

[0093] The total number of segments finally obtained is segNum = 18771. In this example, assuming R len and R gray Each element in is represented by 32-bit binary. The comma represents the separator of elements in the set. For ease of understanding, a virtual "|" is added here to represent the separator between partitions.

[0094] The strategy for delayed insertion in Step 2.2 is specifically as follows:

[0095] For the partition p to be inserted where p.len is less than t1 and p.var is less than t2, determine whether p.len+prevLen is less than t1 and |p.gray-prevGray| is less than t3.

[0096] If so, set prevGray = (p.len*p.gray+prevLen*prevGray) / (p.len+prevLen) and prevLen = prevLen+p.len, so as to merge the current partition with the previous partition that has not been inserted into the bit array, and not insert it into the bit array for the time being.

[0097] If not, insert prevLen (length is log2t1 bit binary) and prevGray (length is 8 bit binary) into the in-place array R respectively. len and R gray , and set prevLen = p.len, prevGray = p.avg.

[0098] Where prevLen and prevGray represent the total length and average gray value of the partition to be merged before inserting p, respectively. The initial values ​​are both 0. t3 represents the gray difference threshold between p and prevGray.

[0099] In this example, let the grayscale difference threshold t3 between p and prevGray = 10, the partition length set before executing the delayed insertion strategy is {32, 24, 8, 56, 27...36, 18, 48,...62, 7}, and the partition grayscale set is {149, 159, 160, 174, 167...114, 120, 121...64, 58}.

[0100] This example introduces the delayed insertion strategy starting from the second partition p. Because there is only one partition before p, prevLen=32, prevGray=149. At this time, p.len=24, p.gray=159. Because |p.gray-prevGray|>t3=10, p cannot be merged with the first partition. Therefore, the length of the first partition 32 is stored in the bit array R. len The gray value 149 of the first partition is stored in R gray The 0th to 7th bits of . Set prevLen=24, preGray=159, indicating that the current partition p is the partition to be merged.

[0101] For the third partition p, p.len = 8, p.gray = 160. Since p.len + prevLen = 8 + 24 = 32 < t1, and |p.gray - prevGray| = |159 - 160| = 1 < t3, p can be merged with the previous partition to be merged and is not inserted into the in-place array for the time being. Further calculation yields:

[0102] prevGray=(p.len*p.gray+prevLen*prevGray) / (p.len+prevLen)=(8*160+24*159) / (8+24)=159.25, prevLen=8+24=32.

[0103] For the fourth partition p, p.len = 56, p.gray = 174. Since p.len + prevLen = 56 + 32 = 88 > t1, p cannot be merged with the previous partition. At this time, the length 32 corresponding to prevLlen is stored in the bit array R. len The gray value 174 corresponding to prevGray is stored in R gray The 8th to 15th bits of . Set prevLen=56 and preGray=174, indicating that the current partition p is the partition to be merged.

[0104] By analogy, after all partitions are delayed and inserted, the image can be compressed and represented as fewer partitions. It should be noted that the present invention delays the insertion of small partitions while partitioning, and does not need to divide all small partitions in advance before insertion. Compared with the existing segmentation merging strategy, it can avoid moving a large number of elements during the merging process and reduce space overhead. The partition merging strategy can further reduce the storage space of the image and improve the compression rate of the image. Secondly, the introduction of an efficient Hilbert decoding algorithm can improve the compression and decompression speed of the image. Due to the high Hilbert cohesion, more adjacent pixels can be divided into the same partition, thereby reducing the number of partitions, and therefore has higher efficiency.

[0105] The Step 3 is specifically as follows:

[0106] Step 3.1: Set totalLen = 0.

[0107] Step 3.2: For each segment p from segment 0 to segment segNum-1, from R len Read the length information p.len of the log2t1 bit segment p from R gray Read the 8-bit grayscale information p.gray of segment p and execute Step 3.3 to Step 3.5 in a loop.

[0108] In this embodiment, taking the first segment p as an example, log2t1=6, each segment is represented by 6 bits of binary. len Read the first 6 binary digits of segment p as 100000, and get p.len = 32. gray Read R gray The 8-bit binary grayscale value is 10010101, so p.gray=149.

[0109] Step 3.3: For each position k from 0 to p.len-1 in segment p, loop through Step 3.4.

[0110] Step 3.4: Decode totalLen+k into the corresponding coordinate value P(x,y), and set the pixel value at the P(x,y) position of the image to p.gray. The decoding method is the same as that in Step 1.4.

[0111] When k = 0, totalLen + k = 0, and Hilbert decoding is performed to obtain P(x, y) = (0, 0). When k = 1, totalLen + k = 1, and Hilbert decoding is performed to obtain P(x, y) = (0, 1). Until k = 31, P(x, y) = (3, 4) is obtained. Since the pixel value corresponding to this segment is 149, the pixel values ​​of the above 32 coordinate points corresponding to this segment are all set to 149.

[0112] Step 3.5: Set totalLen = totalLen + p.len. Update totalLen = totalLen + p.len = 32, traverse all segments in turn, obtain the pixels corresponding to all coordinate points, and complete the restoration process.

[0113] The present invention can be further illustrated by the following experimental results.

[0114] Experimental environment: CPU is Intel(R)Core(TM)i7-7500U CPU@2.7GHz, memory is 8GB, operating system is Windows 10, and compilation environment is Microsoft Visual Studio 2015.

[0115] Experimental data: The image size given by the present invention is 512*512, that is, the corresponding Hilbert order is 9. There are 49 grayscale images in total, and the images are compressed and decompressed.

[0116] Analysis of experimental results: The experiment is a comparison of the compression and decompression time of the compression algorithm and the decompression algorithm of the present invention with the Kamata compression algorithm and the Kamata decompression algorithm as the number of pictures changes. Figure 4 Figure 5As shown in Figure 2, the time comparison of Hilbert decoding efficiency with the order is shown in Figure 2. The experimental results show that while ensuring the image compression quality (such as Figure 2 As shown in FIG. 1 ), the decoding time of the Hilbert decoding algorithm of the present invention, the Moore-Hilbert decoding algorithm and the like is compared with the change of the order. The comparison results are shown in FIG. Figure 3 As shown in the figure, the efficiency of this algorithm is better than other methods, and the advantage becomes more and more obvious as the order increases. For example, when decoding a complete 16-order window, the decoding time of the Hilbert decoding algorithm of the present invention is only 432.194439s, which is nearly 2.6 times more efficient than the Moore decoding algorithm. The compression and decompression efficiency of grayscale images is much higher than that of traditional compression algorithms. The image compression efficiency is improved by 37.8% based on the Kamata compression algorithm.

[0117] The specific implementation modes of the present invention are described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above implementation modes, and various changes can be made within the knowledge scope of ordinary technicians in this field without departing from the purpose of the present invention.

Claims

1. A grayscale image compression method based on Hilbert scanning, characterized in that: Step 1: Construct the Hilbert state view, sequentially scan the image along the direction of the Hilbert curve, and obtain the one-dimensional grayscale array G of the image; Step 2: Divide the one-dimensional grayscale array G into small partitions with similar grayscale values, and insert the length and grayscale value of each small partition into the length bit array R len and grayscale bit array R gray Thus, the original image is compressed and represented as R len and R gray 2 bit arrays; Step 3: Compress the bit array R len and R gray Restore to the corresponding image; The Step 2 is specifically as follows: Step 2.1: Divide the array G evenly into q partitions of length m, where q = n*n / m; Step 2.2: For each partition p, if p.len < t1 and p.var < t2, use the delayed insertion strategy to insert p.len and p.avg into the in-place array R respectively. len and R gray middle; If not, p is further divided into two partitions, p1 and p2, so that p1.var+p2.var is minimized, where t1 represents the partition length threshold, t2 represents the partition variance threshold, p.len represents the partition length, p.avg represents the average grayscale value of partition p, and p.var represents the variance of the grayscale value in partition p; Step 2.3: Recursively execute Step 2.2 on partitions p1 and p2 to further partition them until the lengths and variances of all partitions meet the thresholds of t1 and t2; Step 2.4: Finally, R len and R gray The compressed segment length and segment grayscale information are stored in respectively, and the total number of segments finally obtained is recorded as segNum; The strategy for delayed insertion in Step 2.2 is specifically as follows: For the partition p to be inserted where p.len<t1 and p.var<t2, determine whether p.len+prevLen<t1 and |p.gray-prevGray|<t3; If yes, set prevGray = (p.len*p.gray+prevLen*prevGray) / (p.len+prevLen) and prevLen = prevLen+p.len, so as to merge the current partition with the previous partition that has not been inserted into the bit array, and do not insert it into the bit array for the time being; If not, insert prevLen and prevGray into the in-place array R respectively. len and R gray The tail of , concatenate prevLen = p.len, prevGray = p.avg; Where prevLen and prevGray represent the total length and average gray value of the partition to be merged before inserting p, respectively. The initial values ​​are both 0. t3 represents the gray difference threshold between p and prevGray.

2. The grayscale image compression method based on Hilbert scanning according to claim 1 is characterized in that The Step 1 is specifically as follows: Step 1.1: Construct a decoding state view based on the first-order Hilbert curve, and then use an efficient Hilbert decoding algorithm based on the state view to scan the image data. The first-order Hilbert curve contains four basic states: opening downward, leftward, upward, and rightward, corresponding to states 0, 1, 2, and 3, respectively; Step 1.2: Given the first-order code values ​​00, 01, 10, 11, the corresponding coordinate values ​​in the four states and the next-order state are as follows: State 0: physical coordinates: (0,0), (0,1), (1,1), (1,0); next-order states: 1, 0, 0, 3; State 1: physical coordinates: (0,0), (1,0), (1,1), (0,1); next-order state: 0, 1, 1, 2; State 2: physical coordinates: (1,1), (1,0), (0,0), (0,1); next-order state: 3, 2, 2, 1; State 3: physical coordinates: (1,1), (0,1), (0,0), (1,0); next-order state: 2, 3, 3, 0; Step 1.3: Given an n*n grayscale image, determine the Hilbert order as log2n, where n is the number of pixels in the image height or width; Step 1.4: Along the direction of the Hilbert curve, decode each coded value C in the Hilbert space into the corresponding coordinate P(x,y) in the image; Step 1.5: Store the grayscale value of the pixel P(x,y) into the Cth position of the array G.

3. The grayscale image compression method based on Hilbert scanning according to claim 2 is characterized in that The Step 1.4 is specifically as follows: Step 1.4.1: Set the initial state s = 0, that is, the first order of C always starts decoding from the state of opening downward, x = 0, y = 0; Step1.4.2: The loop variable i increases from 1 to log2n, and the loop executes Step1.4.3 and Step1.4.4; Step 1.4.3: Take the 2-bit code value c of the i-th order of C, and query the state view to obtain the corresponding i-th order coordinate value (x i ,y i ) and the i+1th order state value s'; Step 1.4.4: Let x = x < < 1 | x i ,y=y<<1|y i , s=s', where "|" is a logical OR operation.

4. The grayscale image compression method based on Hilbert scanning according to claim 1, characterized in that The Step 3 is specifically as follows: Step 3.1: Set totalLen = 0; Step 3.2: For each segment p from segment 0 to segment segNum-1, from R len Read the length information p.len of the log2t1 bit segment p from R gray Read the 8-bit grayscale information p.gray of segment p, and execute Step 3.3 to Step 3.5 in a loop; Step 3.3: For each position k from 0 to p.len-1 in segment p, loop through Step 3.4; Step 3.4: Decode totalLen+k into the corresponding coordinate value P(x,y), and set the pixel value at the P(x,y) position of the image to p.gray; Step 3.5: Set totalLen = totalLen + p.len.

Citation Information

Patent Citations

  • Method and device for storing a compression ratio indication in a pixel value buffer in tile encoding

    CN103262531A

  • Structured image compressive sensing restoration method based on double-density dual-tree complex wavelet

    CN104881846A

  • Image encryption algorithm based on smallest granularity full scrambling

    CN108133449A

  • Chaos key-based encryption method for still images

    CN108205793A

  • Hilbert curve encoding and decoding method based on state view

    CN110457317A