Image compression method with controllable compression ratio based on JPEG-LS

By setting the target compression ratio and NEAR adjustment parameter table, compressing the image in chunks and adjusting the NEAR value of the JPEG-LS compression module, the problem of uncontrollable compression ratio in the JPEG-LS algorithm is solved, and the controllability of the image compression ratio and resource optimization are achieved.

CN120455683APending Publication Date: 2025-08-08SUZHOU JITIAN XINGZHOU SPACE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510726082.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-03
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

The compression parameters in the existing JPEG-LS algorithm are fixed, resulting in a large gap in image compression ratio, making it difficult to estimate the amount of compressed image data, resulting in wasting resources of back-end storage devices and digital transmission devices.

Method used

By setting the target compression ratio and NEAR adjustment parameter table, the image is compressed in blocks and the NEAR value of the JPEG-LS compression module is adjusted in real time to control the compression ratio of the entire image to converge to the target value.

Benefits of technology

The image compression ratio is controlled, the resource waste of back-end storage devices and digital transmission devices is reduced, and the structure is simple and easy to implement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120455683A_ABST
    Figure CN120455683A_ABST
Patent Text Reader

Abstract

The invention discloses a controllable compression ratio image compression method based on JPEG-LS (Joint Photographic Experts Group-Least Squares), relates to the technical field of image processing, and solves the problems that in an existing image compression method, compression parameters are fixed, so that the difference of image compression ratios is large, the data volume of compressed images is difficult to estimate, and resources of rear-end storage equipment and data transmission equipment are wasted. Setting a target compression ratio, an image depth and parameter values of the NEAR adjustment parameter table of the to-be-compressed image; partitioning the to-be-compressed image according to a target line number, and sending the partitioned images into a JPEG-LS encoder one by one for image compression; according to the method, the NEAR value of the JPEG-LS compression module is adjusted in real time by using the difference value between the compression ratio of the current block image and the target compression ratio, so that the final compression ratio of the whole image is stabilized near the target compression ratio, the controllability of the image compression ratio is effectively improved, and the resource waste of rear-end storage equipment and data transmission equipment is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular to an image compression method with controllable compression ratio based on JPEG-LS. Background Art

[0002] As the resolution of aerospace CMOS cameras continues to increase, the amount of image data is increasing, placing enormous pressure on back-end storage devices. In addition to increasing storage device capacity or improving data transmission systems, image compression algorithms can also be used to significantly reduce the amount of data by compressing images.

[0003] The JPEG-LS algorithm, based on the LOCO-I algorithm developed by HP Labs, offers both lossless and lossy compression capabilities. The algorithm boasts excellent lossless compression performance, preserving image detail. Its structure is suitable for hardware implementation, making it widely used in aerospace, medical imaging, and other fields.

[0004] In traditional JPEG-LS implementations, the compression parameter NEAR is often fixed, resulting in significant differences in compression ratios between "flat" and "non-flat" areas of the image. This makes it difficult to estimate the amount of compressed image data, leading to wasted resources on back-end storage and data transmission devices. Therefore, the algorithm needs to be improved to minimize the overall image compression ratio to the desired value. Summary of the Invention

[0005] The present invention provides an image compression method with controllable compression ratio based on JPEG-LS to solve the problems in existing image compression methods, such as fixed compression parameters, large differences in image compression ratios, difficulty in estimating the amount of compressed image data, and waste of resources of back-end storage devices and data transmission devices.

[0006] An image compression method with controllable compression ratio based on JPEG-LS is implemented by the following steps:

[0007] Step 1: Set the target compression ratio of the image to be compressed, the image depth and the parameter values of the NEAR adjustment parameter table;

[0008] Step 2: Divide the image to be compressed into blocks according to the target number of rows, and send the divided images one by one to the JPEG-LS encoder for image compression;

[0009] Step 3: For each image, perform the following operations:

[0010] Scan the image pixels row by row, construct a causal template for the current pixel to be encoded, calculate the local gradient value, quantize it, and merge it; determine the pixel encoding method based on the merged Q value and the previous encoding state, and then encode it. After encoding is completed, perform statistics on the output encoded bitstream and calculate the compression ratio of the current block image, i.e., the current compression ratio;

[0011] Step 4: Compare the compression ratio of the image block in step 3 with the target compression ratio set in step 1. If the absolute value of the difference is less than 0.6, keep the current near value and continue to compress the next image block;

[0012] If the absolute value of the difference is greater than 0.6 and the current compression ratio is greater than the target compression ratio, the near value is changed to the step value plus 1 in the NEAR adjustment parameter table;

[0013] If the absolute value of the difference is greater than 0.6 and the current compression ratio is less than the target compression ratio, the near value is changed to the step value minus 1 in the NEAR adjustment parameter table;

[0014] If the absolute value of the difference is greater than 0.6 and the current compression ratio is greater than the target compression ratio and the near value is 0, the next image is compressed while keeping the near value at 0.

[0015] Beneficial effects of the present invention:

[0016] First, the present invention finds the relationship between the lossless / lossy compression threshold NEAR in the JPEG-LS algorithm and the image compression ratio. That is, the lossless / lossy compression threshold NEAR is dynamically adjusted to control the output bitstream size of the entire image. This overcomes the problem in the prior art that the JPEG-LS compression ratio is uncontrollable and can only be guessed based on the NEAR value. This allows the image compression ratio to quickly converge to the target compression ratio.

[0017] 2. After experiments, the present invention adopts a method of tabulating NEAR values. It only needs to compare the current compression ratio with the target compression ratio and select the appropriate NEAR value by adjusting the step size of the NEAR table. This method solves the problem that the compression ratio control technology of the existing image compression algorithm is not conducive to hardware implementation due to the complexity of the algorithm, and achieves a better convergence effect with a simple method.

[0018] Third, the present invention uses the difference between the current block image compression ratio and the target compression ratio to adjust the NEAR value of the JPEG-LS compression module in real time, so that the final compression ratio of the entire image is stabilized near the target compression ratio, effectively improving the controllability of the image compression ratio and reducing the waste of resources of back-end storage devices and data transmission equipment; secondly, the above method has a simple structure, is easy to implement in hardware, and can be applied to satellite-borne equipment. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 This is a flow chart of the image compression method with controllable compression ratio based on JPEG-LS according to the present invention;

[0020] Figure 2 This is the schematic diagram of the run-length encoding module in the JPEG-LS encoder;

[0021] Figure 3 Schematic diagram of the context modeling module in the JPEG-LS encoder;

[0022] Figure 4 This is the compression ratio convergence diagram when the target compression ratio is 4;

[0023] Figure 5 is the original image effect diagram of the image to be compressed;

[0024] Figure 6 This is an image effect diagram after compression using the method of the present invention. DETAILED DESCRIPTION

[0025] Combine Figures 1 to 6 This embodiment describes an image compression method with a controllable compression ratio based on JPEG-LS. The method is implemented by the following steps:

[0026] Step 1: Enter the target compression ratio, image depth bpp, where bpp is an integer between 8 and 16, and the parameter values in the NEAR adjustment parameter table;

[0027] Step 2: Divide the image into blocks according to the target number of rows, and send the divided images to the compression module one by one for compression;

[0028] In this embodiment, the image segmentation standard a, the height H and width W of the image to be compressed are determined, and the number of blocks block_num into which the image to be compressed is divided according to the segmentation standard a is calculated using the formula block_num=H÷a. The block_num block images are cyclically sent to the image compression module.

[0029] Set LIMIT = 2 × (bpp + max(8,bpp));

[0030] J[1:32]=[0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,15];

[0031] Assign initial values to the thresholds: T1 = 3 + 3 × near, T2 = 7 + 5 × near, and T3 = 21 + 4 × near; near is the parameter value in the NEAR adjustment parameter table;

[0032] Assign initial values to the context array; A[1:365]=4, B[1:365]=0, C[1:365]=0, N[1:365]=1; where the A array is the accumulator of the absolute value of the quantized residual, used to estimate the Golomb coding parameter k; the B array is the accumulator of the reconstructed residual, used to calculate the prediction deviation value C; the C array is the context average prediction deviation value (residual correction value) to correct the pixel prediction value, and the N array is the counter of the corresponding context, which stores the number of times the corresponding context appears;

[0033] Set Ar[1:2] = [4,4], Br[1:2] = [0,0], Nr[1:2] = [1,1] to be the updated arrays, and the initial index value run_idx = 0;

[0034] Step 3: Scan the image pixels row by row, construct a causal template for the current pixel to be encoded (upper and lower file modeling module), calculate the local gradient value, quantize and merge it; determine the pixel encoding method based on the merged Q value and the previous encoding state and encode it. After encoding, perform statistics on the output bitstream and calculate the compression ratio of the block image. The compression process for each block image is as follows:

[0035] Step 3.1: Set the block image width w and block image height h of the input image compression module and the compression parameter near;

[0036] Step 3.2: For the current pixel value to be encoded I X Construct a causal template and obtain the values of its four neighboring pixels R a 、R b 、R c 、R d . Specially, when the pixel to be encoded is in the first row of the image, R b =R c =R d =0; when the pixel to be encoded is in the last column of the image, R b =R d ; When the current pixel to be encoded is in the first column of the image, R a =R b ; When the pixel to be encoded is in the first column of the image and in the first and second rows of the image, R c =0;

[0037] Step 3.3: For the R obtained in step 3.2 a 、R b 、R c 、R d By the formula D1=R d -R b , D2=R b -R c , D3=Rc -R a ; Obtain local gradient values D1, D2, D3, and quantize D1, D2, D3 using thresholds T1, T2, T3 to obtain quantized values Q1, Q2, Q3;

[0038] The absolute value and sign bit of Q are obtained by combining the formula Q=81*Q1+9*Q2+Q3, where i=1, 2, 3.

[0039]

[0040] Step 3.4: If Figure 2 As shown, if the local gradient values D1, D2, and D3 in step 3.3 satisfy that their absolute values are all less than near and the previous pixel value is in run-length continuous coding, that is, RunMode_con=1, then the current pixel to be coded also enters the run-length coding module, and if the current pixel value to be coded I x With R a If the absolute value of the difference is less than or equal to near, the current pixel to be encoded enters the run-length continuous encoding module and executes step 3.5; otherwise, it enters the run-length interrupt encoding module and executes steps 3.6 to 3.9; if the current pixel to be encoded does not enter the run-length encoding module, it enters the conventional encoding module and executes step 3.10.

[0041] In this embodiment, the run-length encoding module is divided into run-length continuous encoding and run-length interrupt encoding. The run-length continuous encoding encodes a large continuous image area, and the run-length interrupt encoding encodes the last pixel in the continuous area.

[0042] Step 3.5: If the run-length continuous encoding is entered after step 3.4, it is necessary to add 1 to the run counter run_cnt, and then determine if the run counter run_cnt is greater than or equal to 2 J(run_idx+1) , then add a bit 1 to the code stream and reduce run_cnt by 2 J(run_idx+1) ; At this time, if run_idx < 32, then run_idx + 1; and continue to determine whether the current pixel to be encoded is the last column of the image and run_cnt is greater than 0. If so, add another bit 1 to the code stream and execute step 3.13;

[0043] Step 3.6: If run-length interruption coding is entered after step 3.4, first calculate the truncation bit of Golomb limit-length coding as LIMIT-1-J(run_idx+1) using the formula, then add a 0 bit to the code stream, and then write the binary run_cnt into the code stream, occupying J(run_idx) bits. If run_idx is greater than 0 at this time, decrement it by 1 and execute step 3.7.

[0044] Step 3.7: Set run_cnt = 0. If R a 、R b If the absolute value of the difference is less than or equal to near, then let the predicted pixel value p x =R a And the variable Ritype=1, otherwise, p x =R b And the variable Ritype=0. If R a 、R b The absolute value of the difference is greater than near and R a >R b , then the sign bit sign = -1, otherwise sign = 1;

[0045] Step 3.8: Set the prediction error errval = sign × (I x -p x ); If near is not equal to 0, it is necessary to quantize the prediction error errval and calculate the reconstructed value R of the pixel value x ; Reconstruction value R x The calculation method is:

[0046] If p x +sign*(2*near+1)*errval belongs to [0,2^bpp], then R x =p x +sign*(2*near+1)*errval;

[0047] If p x +sign*(2*near+1)*errval is less than 0, then R x Equal to 0; if p x +sign*(2*near+1)*errval is greater than 0, then Rx is equal to 2^bpp.

[0048] Step 3.9: Perform modular subtraction on the prediction error errval and map it to obtain the mapping error merrval. Calculate the Golomb coding parameter k using the context arrays Ar[Ritype+1] and Nr[Ritype+1]. Then perform Golomb limited-length coding on merrval to obtain the bitstream; proceed to step 3.13.

[0049] In this embodiment, after the Golomb length-limited coding is completed, the context array needs to be updated; specifically: if errval<0, Br[Ritype+1]+1;

[0050] Calculate Ar[Ritype+1] = Ar[Ritype+1] + (merrval+1 - Ritype) ÷ 2. If Nr[Ritype+1] is equal to the reset value RESET_VAL, then divide Ar[Ritype+1], Br[Ritype+1], and Nr[Ritype+1] by 2, and finally calculate Nr[Ritype+1] = Nr[Ritype+1]+1.

[0051] Step 3.10: If the conventional encoding is entered after step 3.4, the pixels to be encoded enter the non-flat image area;

[0052] Step 3.11: Set run_cnt = 0. If R c Greater than R a And R c Greater than R b , p x =min(R a ,R b ); if R c Less than R a And R c Less than R b , p x =max(R a ,R b ); If none of the above holds true, then p x =R a +R b -R c Then let p x =p x +sign×C[Q+1], get the predicted value p x ;

[0053] Set the prediction error errval = sign × (I x -p x ), if near is not equal to 0, it is necessary to quantize the prediction error errval and calculate the reconstructed value R of the pixel value x ;

[0054] Step 3.12: Perform modular subtraction on the prediction error errval and map it to obtain merrval. Calculate the Golomb coding parameter k using the context arrays Ar[Q+1] and Nr[Q+1]. Then perform Golomb limited-length coding on merrval to obtain the bitstream; proceed to step 3.13.

[0055] In this embodiment, after the Golomb length-limited coding is completed, the context array needs to be updated. Specifically, B[Q+1]=B[Q+1]+errval×2*near+1 and A[Q+1]=A[Q+1]+abs(errval) are first calculated.

[0056] If N[Q+1]>=RESET_VAL, divide A[Q+1] by 2. If B[Q+1] is greater than 0, divide B[Q+1] by 2. Otherwise, B[Q1]=-(1-B[Q+1])÷2. Then divide N[Q+1] by 2 again.

[0057] Then, calculate N[Q+1]=N[Q+1]+1. If B[Q+1]<-N[Q+1], then B[Q+1]=B[Q+1]+N[Q+1]. Continue to judge if B[Q+1]<=-N[Q+1]. If so, set B[Q+1]=1-N[Q+1]. If C[Q+1]>-128, set C[Q+1]=C[Q+1]-1.

[0058] If B[Q+1]<-N[Q+1] does not hold, if B[Q+1]>0, then B[Q+1]=B[Q+1]-N[Q+1]; if B[Q+1]>0 still holds, then let B[Q+1]=0; if C[Q+1]<127, then let C[Q+1]=C[Q+1]-1.

[0059] Step 3.13: After encoding, add a header and trailer to the bitstream. The header includes the width, height, and image depth (bpp) of the compressed image. The bitstream is scanned. If "FF" appears in the bitstream, a 0 bit is added after the "FF" to prevent data from overlapping with the header and trailer. jls_all is the compressed bitstream. The compression ratio is calculated using the formula yasuobi = (h*w*bpp) ÷ length(jls_all), where length() is the truncation length function.

[0060] Step 4: Set the NEAR adjustment table to [0, 1, 2, 3, 4, 5, 6, 8, 12, 18, 24]. Compare the current compression ratio with the target compression ratio through the compression ratio comparison module. If the absolute value of the difference is less than 0.6, keep the current near value and continue to compress the next image.

[0061] If the absolute value of the difference is greater than 0.6 and the current compression ratio is greater than the target compression ratio, the near value is changed to the value in the NEAR adjustment parameter table plus 1 step size;

[0062] If the absolute value of the difference is greater than 0.6 and the current compression ratio is smaller than the target compression ratio, the near value is changed to the value in the NEAR adjustment parameter table minus 1 step size;

[0063] If the absolute value of the difference is greater than 0.6 and the current compression ratio is greater than the target compression ratio and the near value is 0, the next image block is compressed while keeping the near value at 0.

[0064] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0065] The above-described embodiments merely illustrate several implementations of the present invention, and while their descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the patent for this invention shall be determined by the appended claims.

Claims

1. An image compression method with controllable compression ratio based on JPEG-LS, characterized by: The method is implemented by the following steps: Step 1: Set the target compression ratio of the image to be compressed, the image depth and the parameter values of the NEAR adjustment parameter table; Step 2: Divide the image to be compressed into blocks according to the target number of rows, and send the divided images one by one to the JPEG-LS encoder for image compression; Step 3: For each image, perform the following operations: Scan the image pixels row by row, construct a causal template for the current pixel to be encoded, calculate the local gradient value, quantize it, and merge it; determine the pixel encoding method based on the merged Q value and the previous encoding state, and then encode it. After encoding is completed, perform statistics on the output encoded bitstream and calculate the compression ratio of the current block image, i.e., the current compression ratio; Step 4: Compare the compression ratio of the image block in step 3 with the target compression ratio set in step 1. If the absolute value of the difference is less than 0.6, keep the current near value and continue to compress the next image block; If the absolute value of the difference is greater than 0.6 and the current compression ratio is greater than the target compression ratio, the near value is changed to the step value plus 1 in the NEAR adjustment parameter table; If the absolute value of the difference is greater than 0.6 and the current compression ratio is less than the target compression ratio, the near value is changed to the step value minus 1 in the NEAR adjustment parameter table; If the absolute value of the difference is greater than 0.6 and the current compression ratio is greater than the target compression ratio and the near value is 0, the next image block is compressed while keeping the near value at 0.

2. The image compression method with controllable compression ratio based on JPEG-LS according to claim 1, characterized in that: In step 2, the block division standard of the image to be compressed, the height and width of the image to be compressed are determined, and the number of blocks of the image to be compressed is calculated.

3. The image compression method with controllable compression ratio based on JPEG-LS according to claim 2, characterized in that: Determine the image segmentation standard a, the height H and width W of the image to be compressed, calculate the number of image blocks to be compressed, block_num, and cyclically send the block_num block images to the image compression module; Set the variable value LIMIT = 2×(bpp+max(8,bpp)); set the array: J[1:32]=[0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,15]; Assign initial values to the thresholds: T1 = 3 + 3 × near, T2 = 7 + 5 × near, T3 = 21 + 4 × near; Assign initial values to the context array; A[1:365]=4, B[1:365]=0, C[1:365]=0, N[1:365]=1; Ar[1:2]=[4,4], Br[1:2]=[0,0], Nr[1:2]=[1,1], initial index value run_idx=0.

4. The image compression method with controllable compression ratio based on JPEG-LS according to claim 1, characterized in that: The specific process of step three is: Step 3.1: Input the width, height and compression parameter of the block image; Step 32: the current pixel to be encoded I X Construct a causal template and obtain the current pixel to be encoded I through the context modeling module X The four neighboring pixel values R a 、R b 、R c 、R d ; By calculating D1=R d -R b , D2=R b -R c , D3=R c -R a Obtain local gradient values D1, D2, and D3, quantize D1, D2, and D3 using thresholds T1, T2, and T3 to obtain quantized values Q1, Q2, and Q3, and merge them using the formula Q = 81*Q1+9*Q2+Q3 to obtain the absolute value and sign bit of Q; Step 33: Determine whether the absolute values of the local gradient values D1, D2, and D3 are all less than near and the previous pixel value is in run-length continuous coding. If so, the current pixel to be coded enters the run-length coding module and executes steps 34; Otherwise, execute steps 3 and 5; Step 34: Determine the current pixel to be encoded I x With R a The absolute value of the difference is less than or equal to near. If so, the current pixel to be encoded enters the run-length continuous encoding module and executes step 36; otherwise, it enters the run-length interrupt encoding module and executes step 37; Step 35: The current pixel to be encoded enters the conventional encoding module to obtain a code stream; then execute step 38; Step 36: Add 1 to the run counter run_cnt, and then determine if the run counter run_cnt is greater than or equal to 2 J(run _idx+1) , a bit 1 is added to the code stream, and run_cnt is subtracted by 2 J(run_idx+1) If run_idx<32, then run_idx+1; continue to determine whether the current pixel to be encoded is the last column of the image and run_cnt is greater than 0. If so, add another bit 1 to the bitstream; execute step 38; Step 37. First, calculate the truncation bit of the Golomb limit length code as: LIMIT-1-J(run_idx+1), then add a bit 0 to the code stream, and then write the binary RUNcnt into the code stream, occupying J(run_idx) bits; if run_idx is greater than 0 at this time, decrement it by 1; Then, let run_cnt = 0 and judge R a With R b Is the absolute value of the difference less than or equal to near? If so, let the predicted pixel value p x =R a And the variable Ritype=1; otherwise, p x =R b And the variable Ritype=0; if R a With R b The absolute value of the difference is greater than near and R a >R b , then the sign bit sign = -1, otherwise sign = 1; Finally, if near is not equal to 0, the prediction error errval is quantized and the reconstructed value R of the pixel value is calculated. x ; Perform modular subtraction on the prediction error errval, and obtain the mapping error merrval after mapping; calculate the Golomb coding parameter k through the context arrays Ar[Ritype+1] and Nr[Ritype+1], and then perform Golomb limited length coding on merrval to obtain the encoded bit stream; execute step 38; Step 38: Add a file header and a file trailer to the encoded code stream through the compression ratio control module to calculate the compression ratio of the image block.

5. The image compression method with controllable compression ratio based on JPEG-LS according to claim 4, characterized in that: In step 32, when the pixel to be encoded is in the first row of the image, R b =R c =R d =0; when the pixel to be encoded is in the last column of the image, R b =R d ; When the pixel to be encoded is in the first column of the image, R a =R b ; When the pixel to be encoded is in the first column of the image and in the first and second rows of the image, R c =0.

6. The image compression method with controllable compression ratio based on JPEG-LS according to claim 4, characterized in that: In steps 3 and 5, the working process of the conventional encoding module is as follows: First, let run_cnt=0, if R c Greater than R a And R c Greater than R b , then p x =min(R a ,R b ); if R c Less than R a And R c Less than R b , then p x =max(R a ,R b ); If the above formulas are not true, then p x =R a +R b -R c , and then let,p x =p x +sign×C[Q+1], get the predicted value p x ; Finally, if near is not equal to 0, the prediction error errval is quantized and the reconstructed value R of the pixel value is calculated. x ; Perform modular subtraction on the prediction error errval, and obtain the mapping error merrval after mapping. By calculating the context arrays Ar[Q+1] and Nr[Q+1], the Golomb coding parameter k is obtained, and then the mapping error merrval is subjected to Golomb limited length coding to obtain the encoded bit stream.

7. The image compression method with controllable compression ratio based on JPEG-LS according to claim 6, characterized in that: In steps 3 and 5, after obtaining the encoded code stream, the context array is updated. The specific process is as follows: First calculate B[Q+1]=B[Q+1]+errval×2*near+1,A[Q+1]=A[Q+1]+ abs(errval); If N[Q+1]>=RESET_VAL, divide A[Q+1] by 2. If B[Q+1] is greater than 0, divide B[Q+1] by 2. Otherwise, B[Q1]=-(1-B[Q+1])÷2. Then divide N[Q+1] by 2 again. Then, calculate N[Q+1]=N[Q+1]+1. If B[Q+1]<-N[Q+1], then B[Q+1]=B[Q+1]+N[Q+1]. At this time, continue to judge. If B[Q+1]<=-N[Q+1], then set B[Q+1]=1-N[Q+1]. If C[Q+1]>-128, then set C[Q+1]=C[Q+1]-1. Finally, if B[Q+1]<-N[Q+1] does not hold, if B[Q+1]>0, B[Q+1]=B[Q+1]-N[Q+1], if B[Q+1]>0 still holds, then let B[Q+1]=0; if C[Q+1]<127, then let C[Q+1]=C[Q+1]-1.

8. The image compression method with controllable compression ratio based on JPEG-LS according to claim 4, characterized in that: In step 37, Golomb limited length coding is performed, and after obtaining the coded bit stream, the context array is updated; specifically: If errval<0, Br[Ritype+1]+1; Calculate Ar[Ritype+1]=Ar[Ritype+1]+(merrval+1-Ritype)÷2; If Nr[Ritype+1] is equal to the reset value RESET_VAL, then the values of Ar[Ritype+1], Br[Ritype+1], and Nr[Ritype+1] are all divided by 2, and Nr[Ritype+1]=Nr[Ritype+1]+1 is calculated.

9. The image compression method with controllable compression ratio based on JPEG-LS according to claim 4, characterized in that: The prediction error errval=sign×(I x -p x ), I x is the current pixel to be encoded, p x is the predicted pixel value.

10. The image compression method with controllable compression ratio based on JPEG-LS according to claim 4, characterized in that: In step 38, the file header includes the width w, height h, image depth bpp and near of the block image to be compressed; at the same time, the encoded bitstream is scanned, and if FF appears in the encoded bitstream, a bit 0 is added after FF; The compression ratio of the image block is calculated using the compression ratio formula: yasuobi = (h*w*bpp) ÷ length(jls_all), where jls_all is the compressed code stream and length() is the truncation length function.