Pulse video data lossless coding and decoding method based on prediction model
Through the coding method and secondary compression technology based on the prediction model, the problem of low compression efficiency of pulsed video data is solved, and high-efficiency lossless compression and pixel-level recovery are achieved.
Patent Information
- Application Number
- CN202510720438.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2025-08-29
AI Technical Summary
Existing lossless compression tools still have room for improvement in the compression efficiency of pulsed video data. Traditional high-speed photography technology is costly and has strict data processing requirements.
The coding method based on the prediction model is adopted to generate prediction error values using the historical time data of each pixel, and secondary compression is performed through run coding and exponential Columbus coding, and the compression rate is improved in combination with cascade coding.
Effectively reduce the number of ‘1’ in each frame of data, achieve efficient compression, and achieve pixel-level lossless recovery through reverse multiplexing prediction model and cyclic queue update logic.
Smart Images

Figure CN120568058A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of high-speed photography, and in particular relates to a lossless encoding and decoding method for pulse video data. Background Art
[0002] With the continuous development of video technology, people's demand for capturing high-speed moving objects is becoming more and more urgent. However, although traditional high-speed photography can reach thousands or even tens of thousands of frames per second, it is too expensive and can only be used in special fields such as scientific research, and has been slow to be widely adopted.
[0003] Recently, a new high-speed photography technique known as "pulse video" has emerged. This technique differs from traditional methods in its filming principle. It employs an integration and comparison mechanism: an integrator accumulates the charge output by a photoelectric converter. A comparator compares the charge on the integrator with a preset threshold at regular intervals. If the accumulated charge reaches the threshold, a 1 is output and the charge on the integrator is cleared. If the charge on the integrator does not reach the threshold, a 0 is output and the charge on the integrator is maintained. This method is significantly different from traditional filming methods, which extract the charge on the integrator at regular intervals and clear it regardless of the charge level.
[0004] Traditional imaging methods use the extracted charge as the brightness of the corresponding pixel in the integrator. In the digital photography era, this brightness is quantized into an integer, represented by 8 or more bits. This presents two challenges: First, it requires a very high processor sensitivity. This is because in high-speed photography, the signal is spread over all time intervals, making the signal collected at each interval very weak. Second, it requires a very high data processing speed. In high-speed photography, the amount of data is proportional to the frame rate.
[0005] Pulse video effectively overcomes two issues with traditional high-speed photography. First, pulse video doesn't require extracting the specific signal strength at each time interval; instead, it simply compares the signal strength (charge count) with a preset threshold. Second, each pixel generates only one bit of data per time interval, reducing the amount of data required.
[0006] Because pulse video is sampled at a high frequency, even though each pixel outputs only one bit at a time, the data rate is still very high, necessitating compression encoding of the pulse video data. However, conventional lossless file compression tools, such as WinZip and WinRAR, still have significant room for improvement in their efficiency in compressing pulse video data. Summary of the Invention
[0007] Each pixel maintains a historical queue of L moments to establish a prediction model
[0008] In response to the shortcomings of the existing technology, the present invention provides a lossless compression encoding and decoding method for pulse video data based on a prediction model. The encoding method introduces a prediction model established based on a data queue of L historical moments for each pixel to process the pulse video data, effectively reducing the number of "1"s in each frame of data. At the same time, run-length encoding and exponential Golomb coding are used to perform secondary compression on the processed data, greatly reducing data redundancy and improving compression efficiency. The decoding method reversely multiplexes the prediction model and queue update logic to accurately restore the original pulse video data, ensuring pixel-level lossless recovery.
[0009] To achieve the above object, the present invention provides the following technical solutions:
[0010] In a first aspect, the present invention provides a method for lossless encoding of impulse video data based on a prediction model, characterized by comprising:
[0011] Step 1: Acquire a segment of original pulse video data having N frames, wherein each frame of the original pulse video data includes H rows of pixels, and the number of pixels in each row is W;
[0012] Step 2, open up storage space, including: open up W*H circular queues Q[i] with a capacity of L, i∈[0,W*H), each circular queue corresponds to a pixel position; open up a first buffer area Buf[K][i] with a capacity of W*H*N, used to cache the original pulse data of the previous L frames and the prediction error data of the pulse data from L+1 to N frames, K∈[1,N], i∈[0,W*H); open up a second buffer area Pre_Buf with a capacity of W*H, used to cache the prediction bits of each pixel position generated by the prediction model in the next frame;
[0013] Step 3: Process the original pulse video data frame by frame starting from K=1 to K=N, including:
[0014] Step 3.1. Initialize the circular queue Q[i], the first buffer Buf[K][i], and the second buffer Pre_Buf: When K <= L, scan each frame of pulse data according to the preset scanning method and cache them in Buf[K][i] in sequence according to time sorting; sort the data of each pixel position at each moment according to time and store them in the circular queue Q[i] corresponding to each pixel position; when K = L, call the prediction model based on the L frame data in the current circular queue Q[i], obtain the predicted bits of the K+1 frame for each pixel position, and store them in Pre_Buf according to the preset scanning method;
[0015] Step 3.2, Obtain the current frame prediction error and store it in Buf[K][i]: When L < K <= N, obtain and compare the actual bits of each pixel position i in the current frame and the predicted bits of the current frame stored in Pre_Buf, obtain the prediction error, and store it in Buf[K][i] according to the preset scanning method: If the current actual bit is equal to the predicted bit, the prediction error is 0; otherwise, the prediction error is 1.
[0016] Step 3.3, Update the circular queue Q[i] and the second buffer Pre_Buf: Dequeue the oldest data in the circular queue, and add the actual bits of the current frame to the circular queue Q[i]; For each pixel position, call the prediction model based on the L-frame data in the current circular queue Q[i], obtain the predicted bits of the next frame for each pixel position, and update them to Pre_Buf.
[0017] Step 3.4, Incrementally update K, and loop through steps 3.2 and 3.3 until K = N, then jump out of the loop.
[0018] Step 4, Traverse the first buffer Buf[K][i] frame by frame, generate a bit string for each frame of data, define the micro string and the length of the micro string, encode the length of the micro string of each bit string according to the preset encoding method, and sort them by time to generate a bitstream.
[0019] Preferably, the preset scanning method is raster scanning.
[0020] Preferably, the preset encoding method is unsigned 0th-order exponential Golomb coding.
[0021] Preferably, the method for generating the predicted bits in the prediction model includes:
[0022] Step 1, Construct a data stream: Randomly obtain a segment of original pulse video data, sort the values of the same pixel position at different times along the time axis and expand them into a time series, and then splice the time series of all pixels into a continuous one-dimensional bitstream according to the preset scanning method based on the spatial position of each pixel.
[0023] Step 2, Construct a state-predicted bit table:
[0024] Step 2.1, Based on the data stream constructed in Step 1, perform statistical modeling using the sliding window mechanism: Take the first L bits starting from the initial position as the first state with a fixed window length of L bits, and record the occurrence frequency of 0 / 1 of the next bit (the (L + 1)th bit) at the end of the window in this state.
[0025] Step 2.2: Shift the window forward bit by bit, dynamically updating the current L-bit state. If the new state already exists in the statistics table, simply add the frequency count of the 0 / 1 bit in that state. Otherwise, create a new state entry and initialize the 0 / 1 bit frequency in that state. Continue iterating until the window covers bits K to K+L-1 from the end of the data stream.
[0026] Step 2.3: Record each state entry and its predicted bit to obtain a state-prediction bit table; the predicted bit is the bit with the highest frequency in the state.
[0027] Further preferably, the storage method of the prediction bit includes: opening 2 L memory space, corresponding to 2 in the prediction model L different states; cache the corresponding prediction bits in each memory space.
[0028] Still further preferably, the method for storing the predicted bits further comprises: setting a decimal index for each of the memory spaces, the decimal index being the same as the decimal representation of the corresponding state of the memory space.
[0029] In a second aspect, the present invention provides a method for lossless decoding of impulse video data based on a prediction model, characterized in that it comprises the following steps:
[0030] Step 1: Obtain pulse video coded data, and the number of frames N, the number of pixel rows per frame H, and the number of pixels per row W of the pulse video coded data;
[0031] Step 2: Decode the pulse video coded data according to a preset coding method to obtain micro-string length data of each frame of data;
[0032] Step 3, open up storage space, including: open up W*H circular queues D_Q[i] with a capacity of L, each circular queue corresponds to a pixel position; open up a fourth buffer area D_Buf[K][i] with a capacity of W*H*N, used to cache the original pulse data of the previous L frames and the prediction error data of the pulse data of frames L+1 to N, K∈[1,N], i∈[0,W*H); open up a fifth buffer area D_Pre_Buf with a capacity of W*H, used to cache the prediction bits of each pixel position in the next frame; open up a third buffer area Vidar_Buf[K][i] with a capacity of W*H*N, K∈[1,N], i∈[0,W*H), used to cache the decoded pulse video data;
[0033] Step 4: Decode the micro-string length data in sequence to obtain the original pulse data of the first L frames and the prediction error data of the pulse data of frames L+1 to N, and cache these data into D_Buf[K][i];
[0034] Step 5: Process the data in D_Buf[K][i] frame by frame from K = 1 to K = N, including:
[0035] Step 5.1: Load the prediction model and read the generated state - prediction bit table.
[0036] Step 5.2: Initialize the circular queue D_Q[i], the third buffer Vidar_Buf[K][i], and the fifth buffer D_Pre_Buf: When K <= L, directly cache the data into Vidar_Buf[K][i] and D_Q[i] frame by frame according to the preset scanning method; when K = L, call the prediction model for each pixel based on the L - frame data in D_Q[i], obtain the prediction bit of the next frame, and cache it into D_Pre_Buf.
[0037] Step 5.3: When L < K <= N, obtain the prediction bit and the prediction error value of each pixel position in the current frame; if the prediction error value is 0, then the actual bit = the prediction bit; if the prediction error value = 1, then the actual bit = 1 - the prediction bit; store the actual bit in Vidar_Buf[K][i].
[0038] Step 5.4: Update the circular queue D_Q[i] and D_Pre_Buf:
[0039] Dequeue the oldest data in D_Q[i] and add the current actual bit to D_Q[i].
[0040] Call the prediction model for each pixel position based on the L - frame data in the current circular queue D_Q[i], obtain the prediction bit of the next frame and cache it into D_Pre_Buf.
[0041] Loop steps 5.3 and 5.4 until K = N, then jump out of the loop.
[0042] Compared with the prior art, the beneficial effects of the present invention are:
[0043] 1. Since the encoding method of the present invention introduces a prediction model, uses the data of several historical moments of pixels to generate the prediction data of the next moment, encodes based on the difference (prediction error) between the actual data and the prediction data, replaces the direct encoding of actual data in the prior art, eliminates redundancy through spatio - temporal context modeling, effectively reduces the number of "1"s in each frame of data, and achieves high - efficiency compression.
[0044] 2. Since the encoding method of the present invention also performs run - length encoding and exponential Golomb encoding on the prediction error sequence for secondary compression, and further improves the compression ratio by combining cascade encoding.
[0045] 3. Because the decoding method of the present invention reversely multiplexes the prediction model and the circular queue update logic during decoding, the original data is accurately restored from the prediction error and prediction value data, ensuring pixel-level lossless recovery. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 Flowchart of a method for lossless encoding of pulse video data based on a prediction model according to an embodiment of the present invention;
[0047] Figure 2 The present invention is a flowchart of a method for lossless decoding of impulse video data based on a prediction model. DETAILED DESCRIPTION
[0048] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the present invention is specifically described in the following examples in conjunction with the accompanying drawings. It should be noted that the description of these implementation methods is used to help understand the present invention, but does not constitute a limitation of the present invention.
[0049] Based on the definition and characteristics of pulse video data, the present invention provides a method for lossless compression encoding of pulse video data. Since each frame of pulse data consists of "0s" and "1s," statistical data shows that "0s" predominate in each frame. By minimizing the number of "1s" in each frame when encoding pulse video data and then applying run-length encoding to each frame, highly efficient compression can be achieved. To reduce the number of "1s" in each frame, the present invention employs a lossless encoding method based on a prediction model. This method uses the prediction model to predict the data for the next moment using historical pixel data at several moments and outputs a "prediction error value." (The prediction model uses the pixel's historical data to predict the next moment's data. If the predicted data matches the actual data, a "0" is output; otherwise, a "1" is output. The "0" or "1" output here is referred to as the "prediction error value.") Using a prediction model combined with run-length encoding significantly reduces data redundancy and improves compression efficiency.
[0050] (1) Encoding method
[0051] The preset prediction model generates prediction bits based on L frames of historical data of pixels.
[0052] like Figure 1 As shown, the lossless encoding method of the present invention specifically includes the following steps:
[0053] Step 1: Acquire a segment of original pulse video data with N frames, wherein each frame of the original pulse video data includes H rows of pixels, and the number of pixels in each row is W.
[0054] Step 2: Create storage space, including:
[0055] Create W*H circular queues Q[i], i∈[0,W*H), each corresponding to a pixel position. The capacity of each circular queue is L (i.e., each circular queue can hold L consecutive frames of time series data for a pixel). When the queue is full, the oldest data in the queue is removed first.
[0056] A first buffer area Buf[K][i] with a capacity of W*H*N is opened to cache the original pulse data of the previous L frames and the prediction error data of the pulse data of frames L+1 to N, where K represents a specific frame (time number), K∈[1,N]; i represents the index of a pixel under K in the current frame (current time), i∈[0,W*H).
[0057] A second buffer area Pre_Buf with a capacity of W*H is opened to cache the prediction bits of each pixel position in the next frame generated by the prediction model.
[0058] Step 3: Starting from K=1 and ending at K=N, the original pulse video data is processed frame by frame; the pixel data of each frame is processed according to a preset scanning method (raster scanning is used in this embodiment, i.e., scanning from left to right and from top to bottom).
[0059] The processing steps are as follows:
[0060] Step 3.1, initialize the circular queue Q[i], the first buffer Buf[K][i], and the second buffer Pre_Buf:
[0061] When K <= L, scan each frame of pulse data according to the preset scanning mode (raster scanning is used in this embodiment, that is, scanning from left to right and from top to bottom), and cache them in Buf[K][i] in sequence according to time order (frame number); sort the data of each pixel position at each moment according to time and store them in the circular queue Q[i] corresponding to each pixel position;
[0062] When K=L, the prediction model is called based on the L frame data in the current circular queue to obtain the prediction data (prediction bits) of the K+1 frame at each pixel position and store them in Pre_Buf according to the preset scanning method.
[0063] Step 3.2, obtain the current frame prediction error and store it in Buf[K][i];
[0064] When L < K <= N, obtain and compare the actual bits of each pixel position i in the current frame with the predicted bits of the current frame stored in Pre_Buf, obtain the prediction error, and store it in Buf[K][i] according to the preset scanning method: if the current actual bit is equal to the predicted bit, the prediction error is 0, and 0 (prediction correct) is stored in Buf[K][i]; otherwise, the prediction error is 1, and 1 (prediction incorrect) is stored.
[0065] Step 3.3, update the circular queue Q[i] and the second buffer Pre_Buf:
[0066] Dequeue the oldest data in the circular queue, and add the actual bits of the current frame to the circular queue Q[i];
[0067] For each pixel position, call the prediction model based on the L-frame data in the current circular queue Q[i], obtain the predicted bits of the next frame (next moment) for each pixel position, and update them to Pre_Buf (overwriting the predicted bits of the previous frame).
[0068] Step 3.4, incrementally update K, and loop through steps 3.2 and 3.3 until K = N, then jump out of the loop to obtain the complete original pulse data of the first L frames and the prediction error data of the pulse data from frames L + 1 to N.
[0069] Step 4, run-length encoding: Traverse the first buffer Buf[K][i] frame by frame, generate a bit string for each frame of data, define a micro-string and its length, encode the length of each micro-string in the bit string according to the preset encoding method, and generate a code stream sorted by time (frame number). Figure 1 The run value data in the middle is the micro-string length data.
[0070] For a certain frame of data, during the traversal process, a structure of n (n >= 0) consecutive 0s plus a 1 can be called a "micro-string". For example, in 0100011, there are 3 micro-strings, namely 01, 0001, and 1. And the number n of "0"s in a micro-string is called the "micro-string length". For example, the micro-string length of 01 is 1, the micro-string length of 0001 is 3, and the micro-string length of 1 is 0. If the last bit of a certain frame is not 1, then a 1 is added at the end.
[0071] The main reason for choosing frame-by-frame encoding rather than continuous encoding in this embodiment is to ensure the real-time nature of data transmission.
[0072] Step 4.1, traverse the data in Buf[K][i] frame by frame in the order from left to right and from top to bottom, and count the micro-string lengths of each micro-string in each frame of data.
[0073] Step 4.2, encode each micro-string length using unsigned 0th-order exponential Golomb coding, and finally generate a code stream.
[0074] To further illustrate the solution in the above embodiment, an actual case is given below to illustrate the technical solution of the present invention:
[0075] Assume that the prediction model generates prediction bits based on L=2 frames of historical data of pixels.
[0076] Step 1: Obtain raw pulse video data with N=4 frames, W=2, H=2.
[0077] Original pulse data: 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0
[0078] For ease of understanding and viewing, the raw pulse data above is represented by the first to fourth data points belonging to the first frame, the fifth to eighth data points belonging to the second frame, the ninth to twelfth data points belonging to the third frame, and the remaining data belonging to the fourth frame. The data in each frame are referred to as pixel 0, pixel 1, pixel 2, and pixel 3, respectively, from left to right and from top to bottom.
[0079]
[0080] For example, in the first frame of data, pixel 0 = 0, pixel 1 = 0, pixel 2 = 0, pixel 3 = 1;
[0081] Step 2: Create storage space, including:
[0082] Create W*H=4 circular queues Q[i], each with a capacity of L=2.
[0083] Queue Q[0]: __
[0084] Queue Q[1]: __
[0085] Queue Q[2]: __
[0086] Queue Q[3]: __
[0087] Queue Q[0] corresponds to pixel 0, queue Q[1] corresponds to pixel 1, queue Q[2] corresponds to pixel 2, and queue Q[3] corresponds to pixel 3.
[0088] Create a buffer area Buf[K][i] with a capacity of W*H*N=16, K=4, i=4.
[0089] Create a prediction bit buffer Pre_Buf[i] with a capacity of W*H=4, where i=4.
[0090] Buf:________________
[0091] Pre_Buf:____
[0092] Step 3: Process the pulse video data frame by frame starting from K=1 to K=4. The processing steps are as follows:
[0093] Step 3.1, when K <= 2 (L = 2), directly cache each frame of pulse data in the order from left to right and from top to bottom into Buf[K][i] and circular queue Q[i]:
[0094] Buf: 0 0 0 1 0 1 0 0 _ _ _ _ _ _ _ _
[0095] Queue Q[0]: 0 0 (first 2 frames of data for pixel 0)
[0096] Queue Q[1]: 0 1 (First 2 frames of pixel 1 data)
[0097] Queue Q[2]: 0 0 (First 2 frames of pixel 2 data)
[0098] Queue Q[3]: 1 0 (First 2 frames of pixel 3 data)
[0099] Starting from K=2, (at this time, the data in the circular queue is full of 2 frames, and the prediction model can be called to obtain the prediction data of the next frame.) Based on the 2 frames of historical data in each circular queue, the prediction model is called to obtain the prediction data of the K+1 frame for each pixel position and store it in Pre_Buf[i].
[0100] Pre_Buf: 0 1 1 0 (the prediction bits here are hypothetical and are only used to explain the current case)
[0101] Step 3.2: When K > 2, obtain and compare the actual bit of each pixel position i in the current frame (current time) with the predicted bit at the current time. If the current actual bit is equal to the predicted bit, store 0 in Buf[K][i] (correct prediction); otherwise, store 1 (incorrect prediction).
[0102] Compare the 3rd frame data of the original pulse data with the 3rd frame prediction data stored in Pre_Buf,
[0103] The third frame of original data: 0 0 1 0
[0104] Pre_Buf:0 1 1 0
[0105] The prediction error data is: 0 1 0 0 (pixel 1 is predicted incorrectly, the rest are predicted correctly)
[0106] Cache the prediction error data into Buf:
[0107] Buf: 0 0 0 1 0 1 0 0 0 1 0 0 _ _ _ _
[0108] Step 3.3: Update the circular queue Q[i] and the second buffer Pre_Buf. Remove the oldest data from the circular queue and add the current actual bits to the circular queue. For each pixel, call the prediction model based on the two frames of data, obtain the predicted bits, and cache them in Pre_Buf (overwriting the predicted bits from the previous frame).
[0109] Queue Q[0]: 0 0
[0110] Queue Q[1]: 1 0
[0111] Queue Q[2]: 0 1
[0112] Queue Q[3]: 0 0
[0113] Pre_Buf: 1 0 0 0 (the prediction bits here are hypothetical and are only used to explain the current case)
[0114] Step 3.4: Execute k+1, where K=4, and repeat step 3.2 to obtain the actual bit of each pixel i in the current frame (the fourth frame) and the predicted bit at the current moment.
[0115] By comparing the 4th frame data of the original pulse data with the data in Pre_Buf,
[0116] The 4th frame of original data: 1 0 0 0
[0117] Pre_Buf:1 0 0 0
[0118] The prediction error data is: 0 0 0 0 (all predictions are correct)
[0119] Cache the prediction error data into Buf:
[0120] Buf: 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0
[0121] Because k=N at this time, the process ends and the loop of steps 3.2 and 3.3 is exited.
[0122] Step 4: Convert the data in the Buf into micro-string length frame by frame: 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0
[0124] Micro string length: 3 , 1,2 , 1,2 , 4
[0125] Step 5: Use unsigned 0-order exponential Golomb coding for each micro-string length, and finally generate a code stream.
[0126] (2) Prediction model construction and prediction bit generation method
[0127] Assuming that the prediction model generates prediction bits based on L frames of historical data of pixels, the prediction model corresponds to 2 L Different states, namely 2 L Circular queue type;
[0128] The construction of the above prediction model and the method for generating prediction bits in the prediction model include the following steps:
[0129] Step 1: Build the data flow:
[0130] A segment of raw pulse video data (not limited to the pulse video data to be encoded) is randomly obtained, and the values of the same pixel position at different times are sorted according to the time axis to form a time sequence. Then, according to the spatial position of each pixel, the time sequence of all pixels is spliced into a continuous one-dimensional bit stream according to a preset scanning method (the same as the encoding scanning method, such as from left to right, from top to bottom).
[0131] Step 2: Build a state transition frequency table:
[0132] Based on the data stream constructed in step 1, a sliding window mechanism is used for statistical modeling: Starting from the initial position, a fixed window length of L bits is used as the unit. The first L bits are intercepted as the first state, and the frequency of 0 / 1 occurrences of the next bit at the end of the window (the L+1th bit) in this state is recorded. The window is then shifted forward bit by bit, dynamically updating the current L-bit state. If the new state already exists in the statistical table, the frequency counts of the subsequent bits are simply accumulated. Otherwise, a new state entry is created and the frequency statistics are initialized. This process is iterated until the window covers bits K to K+L-1 from the end of the data stream (K is the total sequence length minus L-1). Each state and its most frequent bit are then retained. Finally, a complete state transition frequency table is constructed, namely the state-predicted data (predicted bit) table.
[0133] Step 3: Create memory space to store prediction data (prediction bits):
[0134] Development 2 L memory space, corresponding to the 2 L Different states. The corresponding prediction data can be cached in the corresponding space. During the decoding or encoding process, when the model is called, the memory space corresponding to a state stored in the circular queue is found, and the corresponding prediction bit can be directly found in this memory space.
[0135] Regarding the method of building a prediction model and generating prediction data, the following is an example:
[0136] Take the following data stream as an example (assuming the sliding window length L = 2): 0 0 0 1 0 0 1 0
[0138] ① First, intercept the first two bits as the first state, that is, state "00", create a new state entry, and initialize the number of times the next bit is 0, C0, and the number of times the next bit is 1, C1, in this state; at this time, because the next bit is 0, C0 is accumulated by 1, that is, C0 = 1; 0 0 0 1 0 0 1 0
[0140] ② Slide the window one bit to the right to obtain the current state "00". Since this state is included in the state table, since the next bit is 1, C1 is accumulated by 1, that is, C1 = 1. 0 0 0 1 0 0 1 0
[0142] ③ Shift the window right one bit to obtain the current state "01". If this state does not exist in the state table, a new state entry is created and the number of times the next bit is 0 (C0) and the number of times the next bit is 1 (C1) are initialized. At this time, because the next bit is 0, C0 is accumulated by 1, that is, C0 = 1. 0 0 0 1 0 0 1 0
[0144] ④ Shift the window right one bit to obtain the current state "10". If this state does not exist in the state table, a new state entry is created and the number of times the next bit is 0 (C0) and the number of times the next bit is 1 (C1) are initialized. At this time, because the next bit is 0, C0 is accumulated by 1, that is, C0 = 1. 0 0 0 1 0 0 1 0
[0146] ⑤ Shift the window right one bit to obtain the current state "00". Since the state table contains this state, the number of times the state is 0 or 1 in the next bit is directly updated; because the next bit is 1, C1 is accumulated by 1, that is, C1 = 2; (In step (2), C1 in state "00" has already accumulated to 1) 0 0 0 1 0 0 1 0
[0148] ⑥ Shift the window right one bit to obtain the current state "01". Since the state table contains this state, the number of times the next bit of this state is 0 or 1 is directly updated. Since the next bit is 0, C0 is accumulated by 1, that is, C0 = 2. (In step (3), C0 in state "01" has already accumulated to 1) 0 0 0 1 0 0 1 0
[0150] ⑦ The window moves right one position. The end of the data stream has been reached, and the statistics are ended. 0 0 0 1 0 0 1 0
[0152] ⑧According to statistics, there are 3 states in total: "00", "01" and "10".
[0153] In the "00" state, C0=1, C1=2. Therefore, bit 1 is used as the prediction bit for the state "00".
[0154] In the "01" state, C0=2, C1=0. Therefore, bit 0 is used as the predicted bit for the state "01".
[0155] In the "10" state, C0=1, C1=0. Therefore, bit 0 is used as the predicted bit for the state "10".
[0156] ⑨Open up memory space to store prediction data:
[0157] For example, L = 2. Then there are 2 L = 4 states. So when loading the model, a cache area Model with a space size of 4 is opened. Each space in the cache area caches the prediction data corresponding to each state.
[0158] The prediction data corresponding to each state is as follows:
[0159] Status, forecast data
[0160] 00,0
[0161] 01,0
[0162] 10,0
[0163] 11,1
[0164] Then, Model: 0 0 0 1
[0165] The loaded model only contains prediction data, but no state data. How can I find the corresponding state accurately?
[0166] Since states are composed of 0s and 1s, each state can be thought of as a binary number. Each binary number corresponds to a decimal integer. Therefore, simply find the corresponding decimal index in the Model cache in order. For example, "00" corresponds to 0 in decimal, so the first predicted data in the Model is the state "00." "01" corresponds to 1 in decimal, so the second data in the Model is the predicted data for state "01." Similarly, the decimal value of state "11" is 3, so the fourth data in the Model is the predicted data for state "11."
[0167] (3) Decoding method
[0168] The present invention provides a decoding method for losslessly compressing pulse video data, comprising the following steps:
[0169] Step 1: Obtain pulse video coding data (code stream), the number of pulse video coding data frames N, the number of pixel rows per frame H, and the number of pixels per row W.
[0170] Step 2: Decode the pulse video coded data using a preset coding method to obtain microstring length data (run length data) of each frame of data. In this embodiment, the preset coding method is an unsigned 0th order exponential Golomb code.
[0171] How to know how many micro-string length data are there in a frame?
[0172] The 0 / 1 data mentioned below refers to the original pulse data of the first L frames and the subsequent prediction error data.
[0173] During encoding, a microstring of a frame is composed of several "0s" plus one "1." However, when calculating the length of a microstring, only the "0s" are counted, while the "1" is ignored. Therefore, when restoring the length of a microstring, a "1" must be added. For example, the length of several microstrings is as follows:
[0174] 3, 4, 3, 2, 1, 0, 1
[0175] Restoring them to 0 / 1 data is 0001, 00001, 0001, 001, 01, 0, 01.
[0176] Since the total number of 0 / 1 data in each frame is constant and equal to w*h, during decoding, in order to accurately find all the micro-string length data of a frame, for each micro-string length data, just accumulate "micro-string length data + 1". Until the accumulated value is equal to w*h or w*h+1, it means that these micro-string length data can just constitute a frame of 0 / 1 data. So why does w*h+1 exist? Because during encoding, if the end data of a frame data is not 1, this will result in the micro-string not having this additional 1 structure. At this time, a "1" is artificially added at the end. During decoding, when accumulating the length of each micro-string, an extra +1 is added, which will cause the final accumulated value to be equal to w*h+1. This means that when restoring the last micro-string length data, there is no need to restore the "1".
[0177] Assume that the length data of several micro strings are as follows (each frame of data is 2*2):
[0178] Micro string length: 3, 1, 2, 1, 2, 4
[0179] For the first micro string length is 3, then the actual length of the micro string is 3+1=4. This is exactly equal to w*h of a frame of data. Then the 0 / 1 data after the frame is restored is: 0 0 0 1
[0180] The length of the second microstring is 1, so the actual length of the microstring is 1+1=2. At this point, w*h has not yet been reached. Continuing to look at the length of the next microstring, the data is 2, and the actual length is 3.
[0181] At this time, 2+3=5=w*h+1. (This means that the last data is 0, and there is no need to restore the "1").
[0182] The 0 / 1 data recovered from this frame is: 0 1 0 0
[0183] The length of the fourth microstring is 1, so the actual length of the microstring is 1 + 1 = 2. At this point, w*h has not yet been reached. Continuing to look at the length of the next microstring, the data is 2, and the actual length is 3. At this time, 2 + 3 = 5 = w*h + 1.
[0184] The 0 / 1 data recovered from this frame is: 0 1 0 0
[0185] The length of the sixth microstring is 4, so the actual length of the microstring is 4+1=5. At this point, w*h+1 is reached. This means that the last data is 0, and there is no need to restore the "1".
[0186] The 0 / 1 data recovered from this frame is: 0 0 0 0
[0187] Step 3: Create storage space, including:
[0188] Create W*H circular queues D_Q[i], one for each pixel position. The capacity of each circular queue is L (i.e., each circular queue can hold L consecutive frames of time series data for a pixel). When the queue is full, the oldest data in the circular queue is removed first.
[0189] A fourth buffer area D_Buf[K][i] with a capacity of W*H*N is opened to cache the original pulse data of the previous L frames and the prediction error data of the pulse data of frames L+1 to N, where K represents a specific frame, K∈[1,N]; i represents the index of a pixel under the current frame K, i∈[0,W*H).
[0190] A fifth buffer D_Pre_Buf with a capacity of W*H is opened to cache the prediction bits of each pixel position in the next frame generated by the prediction model.
[0191] A third buffer area Vidar_Buf[K][i] of size W*H*N is opened to cache the decoded pulse video data, K∈[1,N]; i represents the index of a pixel in the current frame K, i∈[0,W*H).
[0192] Step 4: Decode the microstring length data sequentially to obtain the original pulse data for the first L frames and the prediction error data for the pulse data from frames L + 1 to N, and cache these data in D_Buf[K][i].
[0193] (By accumulating "microstring length data + 1", when the accumulated value is exactly equal to w*h, the last microstring will normally recover n "0"s plus one "1". If the accumulated value is equal to w*h + 1, then the last microstring will only recover n "0"s, because the last "1" is artificially added and does not actually exist in practice.)
[0194] Step 5: Starting from K = 1 until K = N, process the data in D_Buf[K][i] frame by frame, and cache the processed data in Vidar_Buf[K][i]. The pixel data of each frame is processed in sequence from left to right and from top to bottom. The specific processing steps are as follows:
[0195] Step 5.1: Load the prediction model: Read the already generated prediction data (state - predicted bit data) file. The same prediction model data file is used during both the encoding and decoding processes.
[0196] Step 5.2: When K <= L, directly cache the data frame by frame in the order from left to right and from top to bottom into Vidar_Buf[K][i] and the circular queue D_Q[i] (because the data for the first L frames is original pulse data and does not require additional processing. However, it needs to be sent into the circular queue as context data); when K = L, call the prediction model for each pixel based on the L-frame data in the queue to obtain the predicted bit for the next frame and cache it in D_Pre_Buf.
[0197] Step 5.3: When L < K <= N, obtain the predicted bit and the prediction error value for each pixel i in the current frame. If the prediction error value is = 0, it means the actual bit = the predicted bit; if the prediction error value = 1, it means the actual bit = 1 - the predicted bit. Finally, store the actual bit in Vidar_Buf[K][i].
[0198] Step 5.4: Update the circular queue D_Q[i] and D_Pre_Buf. Dequeue the oldest data in the circular queue and add the current actual bit to the circular queue. Call the prediction model for each pixel position based on the L-frame data in the circular queue D_Q[i] to obtain the predicted bit and cache it in D_Pre_Buf (overwriting the predicted bit of the previous frame).
[0199] Step 5.5: Loop through steps 5.3 and 5.4 until K = N, at which point the loop is exited. The data in Vidar_Buf is the original pulse data.
[0200] The basic idea of this invention is to establish a prediction model by maintaining a historical queue of L moments for each pixel. The pixel values of subsequent frames are compared with the predicted values to generate a sparse 0 / 1 prediction error sequence (0 indicates a correct prediction, 1 indicates an error). The prediction error sequence is then compressed using run-length encoding and exponential Golomb coding. During decoding, the prediction model and queue update logic are inversely multiplexed to accurately restore the original data from the prediction error values and predicted values. The core of this method is to eliminate redundancy through spatiotemporal context modeling, combined with cascade coding to achieve high compression rates while ensuring pixel-level lossless recovery.
[0201] Although various embodiments of the present invention have been described above, it should be understood that they are presented by way of example only and not limitation. It will be apparent to those skilled in the relevant art that various combinations, modifications, and variations may be made thereto without departing from the spirit and scope of the present invention. Therefore, the breadth and scope of the present invention disclosed herein should not be limited by the exemplary embodiments disclosed above, but should be defined solely in accordance with the appended claims and their equivalents.
Claims
1. A method for lossless encoding of impulse video data based on a prediction model, characterized in that: including: Step 1: Obtain a segment of original pulse video data with N frames. Each frame of the original pulse video data includes H rows of pixels, and the number of pixels in each row is W; Step 2: Allocate storage space, including: Allocate W*H circular queues Q[i] with a capacity of L, where i ∈ [0, W*H). Each circular queue corresponds to a pixel position; allocate a first buffer Buf[K][i] with a capacity of W*H*N for caching the first L frames of original pulse data and the prediction error data of the pulse data from frames L+1 to N, where K ∈ [1, N] and i ∈ [0, W*H); allocate a second buffer Pre_Buf with a capacity of W*H for caching the predicted bits of each pixel position in the next frame generated by the prediction model; Step 3: Process the original pulse video data frame by frame from K = 1 until K = N, including: Step 3.1: Initialize the circular queue Q[i], the first buffer Buf[K][i], and the second buffer Pre_Buf: When K <= L, scan each frame of pulse data according to a preset scanning method and cache it into Buf[K][i] in chronological order; sort the data of each pixel position at each moment in chronological order and store it into the corresponding circular queue Q[i] of each pixel position; when K = L, call the prediction model based on the L frames of data in the current circular queue Q[i] to obtain the predicted bits of the (K+1)th frame of each pixel position and store them into Pre_Buf according to the preset scanning method; Step 3.2: Obtain the prediction error of the current frame and store it into Buf[K][i]: When L < K <= N, obtain and compare the actual bit of each pixel position i in the current frame and the predicted bit of the current frame stored in Pre_Buf, obtain the prediction error and store it into Buf[K][i] according to the preset scanning method: if the current actual bit is equal to the predicted bit, the prediction error is 0, otherwise the prediction error is 1; Step 3.3: Update the circular queue Q[i] and the second buffer Pre_Buf: Dequeue the oldest data in the circular queue and add the actual bit of the current frame to the circular queue Q[i]; Call the prediction model for each pixel position based on the L frames of data in the current circular queue Q[i] to obtain the predicted bits of the next frame of each pixel position and update them to Pre_Buf; Step 3.4: Incrementally update K, loop through steps 3.2 and 3.3 until K = N, then jump out of the loop; Step 4: Traverse the first buffer Buf[K][i] frame by frame, generate a bit string for each frame, define a micro string and the length of the micro string, encode the length of each bit string's micro string according to a preset encoding method, and sort them in chronological order to generate a bit stream.
2. The method for lossless encoding of impulse video data based on a prediction model according to claim 1, wherein: The preset scanning method is raster scanning.
3. The method for lossless encoding of impulse video data based on a prediction model according to claim 1, wherein: The preset encoding method is unsigned 0th-order exponential Golomb coding.
4. A method for lossless encoding of impulse video data based on a prediction model according to claim 1 or 2, characterized in that: The method for generating the predicted bits in the prediction model includes: Step 1: Construct a data stream: Randomly obtain a segment of raw pulse video data, sort the values of the same pixel position at different times according to the time axis to expand them into a time sequence, and then splice all the time sequence of pixels into a continuous one-dimensional bit stream according to the preset scanning method based on the spatial position of each pixel; Step 2: Construct the state-prediction bit table: Step 2.1: Based on the data stream constructed in Step 1, a sliding window mechanism is used for statistical modeling: using a fixed window length of L bits as the unit, the first L bits from the initial position are intercepted as the first state, and the frequency of 0 / 1 occurrence of the next bit at the end of the window (the L+1th bit) in this state is recorded; Step 2.2: Shift the window forward bit by bit, dynamically updating the current L-bit state. If the new state already exists in the statistics table, simply add the frequency count of the 0 / 1 bit in that state. Otherwise, create a new state entry and initialize the 0 / 1 bit frequency in that state. Continue iterating until the window covers bits K to K+L-1 from the end of the data stream. Step 2.3: Record each state entry and its predicted bit to obtain a state-prediction bit table; the predicted bit is the bit with the highest frequency in the state.
5. The method for lossless encoding of impulse video data based on a prediction model according to claim 4, wherein: The storage method of the prediction bits includes: Development 2 L memory space, corresponding to 2 in the prediction model L different states; cache the corresponding prediction bits in each memory space.
6. The method for lossless encoding of impulse video data based on a prediction model according to claim 5, wherein: The storage method of the prediction bits further includes: setting a decimal index for each of the memory spaces, wherein the decimal index is the same as the decimal representation of the corresponding state of the memory space.
7. A method for lossless decoding of pulse video data based on a prediction model, characterized in that: The following steps are involved: Step 1: Obtain pulse video coded data, and the number of frames N, the number of pixel rows per frame H, and the number of pixels per row W of the pulse video coded data; Step 2: Decode the pulse video coded data according to a preset coding method to obtain micro-string length data of each frame of data; Step 3, open up storage space, including: open up W*H circular queues D_Q[i] with a capacity of L, each circular queue corresponds to a pixel position; open up a fourth buffer area D_Buf[K][i] with a capacity of W*H*N, used to cache the original pulse data of the previous L frames and the prediction error data of the pulse data of frames L+1 to N, K∈[1,N], i∈[0,W*H); open up a fifth buffer area D_Pre_Buf with a capacity of W*H, used to cache the prediction bits of each pixel position in the next frame; open up a third buffer area Vidar_Buf[K][i] with a capacity of W*H*N, K∈[1,N], i∈[0,W*H), used to cache the decoded pulse video data; Step 4: Decode the micro-string length data in sequence to obtain the original pulse data of the first L frames and the prediction error data of the pulse data of frames L+1 to N, and cache these data into D_Buf[K][i]; Step 5: Process the data in D_Buf[K][i] frame by frame starting from K=1 to K=N, including: Step 5.1: Load the prediction model and read the generated state-prediction bit table; Step 5.2, Initialize the circular queue D_Q[i], the third buffer Vidar_Buf[K][i], and the fifth buffer D_Pre_Buf: When K <= L, directly buffer the data frame by frame into Vidar_Buf[K][i] and D_Q[i] according to the preset scanning method; when K = L, call the prediction model for each pixel based on the L-frame data in D_Q[i], obtain the predicted bits of the next frame, and buffer them into D_Pre_Buf; Step 5.3, When L < K <= N, obtain the predicted bits and the predicted error values at each pixel position in the current frame; if the predicted error value is 0, then the actual bit = the predicted bit; if the predicted error value = 1, then the actual bit = 1 - the predicted bit; store the actual bit in Vidar_Buf[K][i]; Step 5.4, Update the circular queue D_Q[i] and D_Pre_Buf: Dequeue the oldest data in D_Q[i], and add the current actual bit to D_Q[i]; Call the prediction model for each pixel position based on the L-frame data in the current circular queue D_Q[i], obtain the predicted bits of the next frame and buffer them into D_Pre_Buf; Loop through steps 5.3 and 5.4 until K = N, then jump out of the loop.
Citation Information
Cited By
Lossless compression coding and decoding method of pulse video data and readable storage medium
CN121442094A
Lossless compression coding method of pulse video data and readable storage medium
CN121442094B