CN117793361A - Method, device and equipment for data coding and data decoding - Google Patents

Method, device and equipment for data coding and data decoding Download PDF

Info

Publication number
CN117793361A
CN117793361A CN202211148922.8A CN202211148922A CN117793361A CN 117793361 A CN117793361 A CN 117793361A CN 202211148922 A CN202211148922 A CN 202211148922A CN 117793361 A CN117793361 A CN 117793361A
Authority
CN
China
Prior art keywords
sequence
character
binary value
coding
bits
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211148922.8A
Other languages
Chinese (zh)
Inventor
黄羽亮
林宪正
韩永祥
张弓
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202211148922.8A priority Critical patent/CN117793361A/en
Priority to PCT/CN2023/119240 priority patent/WO2024061138A1/en
Publication of CN117793361A publication Critical patent/CN117793361A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/184Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being bits, e.g. of the compressed video stream
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/70Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by syntax aspects related to video coding, e.g. related to compression standards

Landscapes

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

Abstract

The embodiment of the application discloses a method, a device and equipment for data encoding and data decoding, and belongs to the technical field of encoding. The method comprises the following steps: acquiring an initial sequence and a parameter sequence to be coded; sequentially acquiring characters from one end of an initial sequence, each character being acquired, if the currently acquired character is determined to be a high-frequency character, determining first N bits in the code sequence based on a first coding parameter corresponding to the currently acquired character in the parameter sequence, updating the first N bits into a first binary value, wherein a second binary value formed by the first N bits is not smaller than the first coding parameter, the binary value formed by the first N-1 bits is smaller than the first coding parameter, and the first binary value is equal to the sum of the second binary value and a first preset value; if it is determined that the currently acquired character is not a high frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value.

Description

Method, device and equipment for data coding and data decoding
Technical Field
The present disclosure relates to the field of coding technologies, and in particular, to a method, an apparatus, and a device for data encoding and data decoding.
Background
In the big data age, the data volume of various data is greatly increased, which puts great stress on data storage. In order to reduce the pressure of data storage, the data is usually subjected to coding compression by adopting a coding technology before being stored.
In some special scenarios, such as image compression scenarios based on artificial intelligence (Artificial Intelligence, AI) prediction, the current coding scheme is no longer applicable, and thus a data coding scheme is needed that is equally applicable in AI-based image compression scenarios.
Disclosure of Invention
The embodiment of the application provides a method, a device and equipment for data encoding and data decoding, which can be applied to various scenes including an AI-based image compression scene. The technical scheme is as follows:
in a first aspect, there is provided a method of data encoding, the method comprising:
and acquiring an initial sequence to be coded and a parameter sequence, wherein the parameter sequence comprises coding parameters corresponding to each character in the initial sequence. And sequentially acquiring characters in the initial sequence from one end of the initial sequence, if one character is acquired, determining the first N bits in the code sequence based on the first coding parameters corresponding to the currently acquired character in the parameter sequence if the currently acquired character is determined to be a high-frequency character in the initial sequence, and updating the first N bits into a first binary value. Wherein the second binary value of the first N bits is not less than the first encoding parameter, and the third binary value of the first N-1 bits is less than the first encoding parameter, and the first binary value is equal to the sum of the second binary value and the first preset value. If it is determined that the currently acquired character is not a high frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value. Wherein the fourth binary value is positively correlated with the first encoding parameter.
According to the scheme, each character in the initial sequence to be coded is coded respectively, and when each character is coded, coding is performed according to coding parameters corresponding to the character. While the conventional Golomb (Golomb) coding scheme is performed, it is required to convert an initial sequence to be coded into an integer sequence (a plurality of consecutive and identical characters are converted into an integer during conversion) according to a run-length coding, and then, further, a fixed coding parameter is used to code each integer in the integer sequence. In the image compression scene based on AI prediction, coding is required to be performed for each character in the initial sequence, and obviously, the existing Golomb coding cannot meet the requirement, but the scheme provided by the embodiment of the application can better meet the requirement, and the coding parameters of each character in the scheme provided by the embodiment of the application are not limited, and can be the same or different, so that the coding scheme has stronger adaptability. In addition, in the scheme provided by the embodiment of the application, other parameters are not introduced only according to the coding parameters corresponding to the characters during coding, so that the coding scheme has higher certainty.
In one possible implementation, the encoding parameters are used to describe the prediction probability at the time of character generation at the corresponding position in the initial sequence.
For example, in an AI prediction-based image compression scenario, the initial sequence is the feature vector output by the AI prediction module, and the prediction probabilities are generated by the AI prediction module together when generating the feature vector.
In one possible implementation, the coding parameters are used to describe the probability distribution of the high frequency characters in the initial sequence.
In this case, the encoding parameters corresponding to each character are the same.
In one possible implementation, determining the first N bits in the coding sequence based on the first coding parameter corresponding to the currently acquired character in the parameter sequence includes:
if the front in the coding sequenceThe binary value of the individual bit components is not less than M, the front +.>And a number of bits. Wherein M is the first encoding parameter. If the front in the coding sequenceThe binary value of the individual bit components is smaller than M, the front +.>And a number of bits.
In one possible implementation, the initial sequence is a binary character sequence.
For example, the initial sequence is composed of two characters of 0, 1.
In one possible implementation, in the case where the initial sequence is a binary character sequence, the first preset value may be 1. When the first preset value is 1, the compression effect on the initial sequence is good.
In one possible implementation, in the case where the initial sequence is a binary character, the fourth binary value may be a binary value corresponding to 2m+1, where M is the first encoding parameter.
In one possible implementation, the initial sequence is a ternary character sequence.
For example, the initial sequence consists of three characters 0, 1, -1.
In one possible implementation, in the case where the initial sequence is a ternary character sequence, the first preset value may be 2. When the first preset value is 2, the compression effect on the initial sequence is good.
In one possible implementation manner, in the case that the initial sequence is a ternary character, it is determined that the currently acquired character is an intermediate frequency character in the initial sequence, and accordingly, the fourth binary value may be a fourth binary value corresponding to 2m+2, where M is the first coding parameter.
In one possible implementation manner, in the case that the initial sequence is a ternary character, it is determined that the currently acquired character is a low-frequency character in the initial sequence, and accordingly, the fourth binary value is a fourth binary value corresponding to 2m+3, where M is the first coding parameter.
In a second aspect, there is provided a method of data decoding, the method comprising:
and obtaining a coding sequence and a parameter sequence, wherein the coding sequence is obtained by coding an initial sequence, and the parameter sequence comprises coding parameters corresponding to each character in the initial sequence. And sequentially acquiring coding parameters from one end of the parameter sequence, determining the first X bits in the coding sequence based on the currently acquired coding parameters every time one coding parameter is acquired, determining that the character corresponding to the currently acquired coding parameter in the initial sequence is the first character if the binary value formed by the first X bits is the fourth binary value, and updating the first X bits to be 1. The fourth binary value is positively correlated with the currently acquired coding parameter, the first character is not a high-frequency character in the initial sequence, the binary value formed by the first X bits is not smaller than the target value, and the binary value formed by the first X-1 bits is smaller than the target value. Wherein the target value is determined based on the currently acquired encoding parameters and the type of the initial sequence. If the binary value formed by the first X bits is smaller than the fourth binary value, determining that the character corresponding to the coding parameter in the initial sequence is a second character, and updating the first X bits to the second binary value, wherein the binary value formed by the first X bits is the sum of the second binary value and the first preset value, and the second character is a high-frequency character in the initial sequence.
In one possible implementation, the coding parameters are used to describe a prediction probability at the time of character generation at a corresponding position in the initial sequence.
In one possible implementation, the coding parameters are used to describe a probability distribution of high frequency characters in the initial sequence.
In one possible implementation, the initial sequence is a binary character sequence.
In one possible implementation manner, the target value is m+1, and the determining the first X bits in the coding sequence based on the currently acquired coding parameter includes:
if the preceding in the coding sequenceThe binary value of the individual bit components is not less than M+1, the former ++is determined in the coding sequence>A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequenceThe binary value of the individual bit components is smaller than M+1, the former +.>And a number of bits.
In one possible implementation, the first preset value is 1.
In one possible implementation, the fourth binary value is a binary value corresponding to 2m+1.
In one possible implementation, the initial sequence is a ternary character sequence.
In one possible implementation manner, the target value is m+2, and the determining the first X bits in the coding sequence based on the currently acquired coding parameter includes:
if the preceding in the coding sequenceThe binary value of the individual bit components is not less than M+2, the former ++is determined in the coding sequence>A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequenceBinary values of the individual bit components are smaller than M+2, the former +.>And a number of bits.
In one possible implementation, the first preset value is 2.
In one possible implementation, the first character is a medium frequency character in the initial sequence;
the fourth binary value is a binary value corresponding to 2m+2, where M is the currently acquired encoding parameter.
In one possible implementation, the method further includes:
and if the binary value formed by the first N bits is larger than the fourth binary value, determining that the pre-coding character corresponding to the coding parameter is a third character, and updating the first N bits to 1, wherein the third character is a low-frequency character in the pre-coding character sequence.
In one possible implementation manner, the character corresponding to the first acquired coding parameter in the initial sequence is the character that is encoded last in the initial sequence, and the first N bits determined in the coding sequence for the first time are the bits obtained by last encoding in the coding sequence.
In a third aspect, there is provided an apparatus for data encoding, the apparatus comprising:
the acquisition module is used for acquiring an initial sequence to be coded and a parameter sequence, wherein the parameter sequence comprises coding parameters corresponding to each character in the initial sequence;
the coding module is used for sequentially acquiring characters in the initial sequence from one end of the initial sequence, and if one character is acquired, determining that the currently acquired character is a high-frequency character in the initial sequence, based on a first coding parameter corresponding to the currently acquired character in the parameter sequence, determining first N bits in the coding sequence, and updating the first N bits into a first binary value, wherein a second binary value formed by the first N bits is not smaller than the first coding parameter, a third binary value formed by the first N-1 bits is smaller than the first coding parameter, and the first binary value is equal to the sum of the second binary value and a first preset value; if it is determined that the currently acquired character is not a high frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value, wherein the fourth binary value is positively correlated with the first encoding parameter.
In one possible implementation, the coding parameters are used to describe a prediction probability at the time of character generation at a corresponding position in the initial sequence.
In one possible implementation, the coding parameters are used to describe a probability distribution of high frequency characters in the initial sequence.
In one possible implementation, the encoding module is configured to:
if the preceding in the coding sequenceThe binary value of the individual bit components is not less than M, the former ++is determined in the coding sequence>A number of bits, wherein M is the first encoding parameter;
if the preceding in the coding sequenceThe binary value of the individual bit components is smaller than M, the front ++is determined in the coding sequence>And a number of bits.
In one possible implementation, the initial sequence is a binary character sequence.
In one possible implementation, the first preset value is 1.
In one possible implementation, the encoding module is configured to:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+1, wherein M is the first coding parameter.
In one possible implementation, the initial sequence is a ternary character sequence.
In one possible implementation, the first preset value is 2.
In one possible implementation, the encoding module is configured to:
determining that the currently acquired character is an intermediate frequency character in the initial sequence;
the coding module is used for:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+2, wherein M is the first coding parameter.
In one possible implementation, the encoding module is configured to:
determining that the currently acquired character is a low frequency character in the initial sequence;
the updating the first bit in the code sequence to a fourth binary value includes:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+3, wherein M is the first coding parameter.
In a fourth aspect, there is provided an apparatus for decoding data, the apparatus comprising:
the acquisition module is used for acquiring a coding sequence and a parameter sequence, wherein the coding sequence is obtained by coding an initial sequence, and the parameter sequence comprises coding parameters corresponding to each character in the initial sequence;
the decoding module is used for sequentially acquiring coding parameters from one end of the parameter sequence, determining the first X bits in the coding sequence based on the currently acquired coding parameters, determining that a character corresponding to the currently acquired coding parameters in the initial sequence is a first character if the binary value formed by the first X bits is a fourth binary value, and updating the first X bits to 1, wherein the fourth binary value is positively correlated with the currently acquired coding parameters, the first character is not a high-frequency character in the initial sequence, the binary value formed by the first X bits is not less than a target value, and the binary value formed by the first X-1 bits is less than the target value, and the target value is determined according to the currently acquired coding parameters and the type of the initial sequence; and if the binary value formed by the first X bits is smaller than the fourth binary value, determining that the character corresponding to the coding parameter in the initial sequence is a second character, and updating the first X bits to a second binary value, wherein the binary value formed by the first X bits is the sum of the second binary value and a first preset value, and the second character is a high-frequency character in the initial sequence.
In one possible implementation, the coding parameters are used to describe a prediction probability at the time of character generation at a corresponding position in the initial sequence.
In one possible implementation, the coding parameters are used to describe a probability distribution of high frequency characters in the initial sequence.
In one possible implementation, the initial sequence is a binary character sequence.
In one possible implementation manner, the target value is m+1, and the decoding module is configured to:
if the preceding in the coding sequenceBinary values of individual bits are not less than M+1, then in said codingDetermination of the Pre->A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequenceThe binary value of the individual bit components is smaller than M+1, the former +.>And a number of bits.
In one possible implementation, the first preset value is 1.
In one possible implementation, the fourth binary value is a binary value corresponding to 2m+1.
In one possible implementation, the initial sequence is a ternary character sequence.
In one possible implementation manner, the target value is m+2, and the decoding module is configured to:
If the preceding in the coding sequenceThe binary value of the individual bit components is not less than M+2, the former ++is determined in the coding sequence>A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequenceBinary values of the individual bit components are smaller than M+2, the former +.>And a number of bits.
In one possible implementation, the first preset value is 2.
In one possible implementation manner, the first character is an intermediate frequency character in the initial sequence, and the fourth binary value is a binary value corresponding to 2m+2, where M is the currently acquired coding parameter.
In one possible implementation, the decoding module is further configured to:
and if the binary value formed by the first N bits is larger than the fourth binary value, determining that the pre-coding character corresponding to the coding parameter is a third character, and updating the first N bits to 1, wherein the third character is a low-frequency character in the pre-coding character sequence.
In one possible implementation manner, the decoding direction is opposite to the encoding direction, the character corresponding to the encoding parameter obtained for the first time in the initial sequence is the character encoded last in the initial sequence, and the first N bits determined in the encoding sequence for the first time are the bits obtained by encoding last in the encoding sequence.
In a fifth aspect, an electronic device is provided, the electronic device comprising a processor and a memory for storing at least one piece of program code, the at least one piece of program code being loaded by the processor and performing the method of data encoding as described in the first aspect above.
In a sixth aspect, an electronic device is provided, the electronic device comprising a processor and a memory for storing at least one piece of program code, the at least one piece of program code being loaded by the processor and performing the method of data decoding as described in the second aspect above.
In a seventh aspect, a computer readable storage medium is provided, the computer readable storage medium storing at least one piece of program code for performing the method of data encoding according to the first aspect described above.
In an eighth aspect, a computer readable storage medium is provided, the computer readable storage medium storing at least one piece of program code for performing the method of data decoding according to the second aspect.
In a ninth aspect, a computer program product is provided, the computer program product comprising at least one piece of program code for performing the method of data encoding as described in the first aspect above.
In a tenth aspect, a computer program product is provided, the computer program product comprising at least one piece of program code for performing the method of data decoding according to the second aspect described above.
Drawings
Fig. 1 is a schematic diagram of an application scenario provided in an embodiment of the present application;
fig. 2 is a schematic diagram of an application scenario provided in an embodiment of the present application;
fig. 3 is a schematic diagram of an application scenario provided in an embodiment of the present application;
FIG. 4 is a flow chart of a method for encoding data according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a stack provided by an embodiment of the present application;
FIG. 6 is a flow chart of a method for decoding data according to an embodiment of the present application;
FIG. 7 is a schematic diagram of a data encoding provided in an embodiment of the present application;
FIG. 8 is a schematic diagram of data decoding according to an embodiment of the present application;
FIG. 9 is a schematic diagram of a data encoding provided in an embodiment of the present application;
FIG. 10 is a schematic diagram of data decoding according to an embodiment of the present application;
FIG. 11 is a schematic structural diagram of an apparatus for encoding data according to an embodiment of the present application;
fig. 12 is a schematic structural diagram of an apparatus for decoding data according to an embodiment of the present application;
FIG. 13 is a schematic structural diagram of a computer device according to an embodiment of the present application;
fig. 14 is a schematic structural diagram of a terminal according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a data coding method, which can be realized by electronic equipment, wherein the electronic equipment can be a terminal or a server. When the electronic device is a terminal, the electronic device may be a mobile phone, a tablet computer, a desktop computer, a notebook computer, and the like. When the electronic device is a server, the electronic device may be a single server or a server cluster.
The data coding method provided by the embodiment of the application can be suitable for coding compression scenes of various data, such as traditional image coding compression, image coding compression based on AI prediction, hybrid video coding compression and other scenes.
As shown in fig. 1, in a conventional image coding compression scenario, a feature extraction module performs feature extraction on an original image to obtain a feature vector, and then, the data coding method provided by the application encodes the feature vector as an initial sequence to be coded, and outputs a coding sequence.
As shown in fig. 2, for a pre-encoded compression scene based on AI prediction, the AI prediction module performs feature extraction and probability prediction on an original image, and then, the method of data encoding provided by the present application uses a feature vector as an initial sequence to be encoded, uses a prediction probability as an encoding parameter, encodes the encoded sequence.
As shown in fig. 3, a hybrid video coding compression scene is provided, which includes a video frame input coding module, a motion estimation prediction module, and an inter prediction module. After the video frames pass through the three modules, each module inputs the feature vector to the module executing the scheme, and further, the method for encoding data provided by the embodiment of the application carries out encoding compression on the feature vector input in each path and outputs corresponding encoding sequences respectively.
The method for encoding data provided in the embodiments of the present application is described below with reference to the accompanying drawings. Referring to fig. 4, the process flow of the method may include the steps of:
step 401, an initial sequence and a parameter sequence to be encoded are obtained.
The parameter sequence comprises coding parameters corresponding to each character in the initial sequence.
In practice, the meaning and source represented by the initial sequence to be encoded and the encoding parameters may be different in different application scenarios. The following describes the parameter sequences in different application scenarios:
1. AI-based image video coding
As shown in fig. 2, in this application scenario, the AI prediction model outputs a prediction probability value while outputting a feature vector. The feature vector is an initial sequence to be coded in the application, and the predicted probability value sequence is a parameter sequence. Each element in the feature vector corresponds to a predicted probability value in a sequence of predicted probability values, the predicted probability value being an integer deformed by a decimal. Each prediction probability value is used to describe a prediction probability at which an element of a corresponding position in the feature vector is generated.
For example, the initial sequence is 10010, the initial sequence has only 0 and 1, taking the coding parameter corresponding to 1 of the fourth bit as an example, when the AI prediction model generates the fourth bit in the initial sequence, the AI prediction model predicts that the fourth bit is 1 prediction probability and the prediction probability of 0, and the corresponding character with large prediction probability is compared with the two prediction probabilities, so that the prediction probability of the fourth bit is determined to be greater than the prediction probability of the fourth bit being 0, and the AI prediction model further determines the fourth bit to be 1 and outputs the prediction probability of the fourth bit being 1. Therefore, the prediction probability of the fourth bit being 1 is the coding parameter corresponding to the fourth bit. The prediction probabilities are all integer values after being deformed, and the deformation mode can be to refer to decimal numbers as preset integer values and rounding.
2. Conventional image coding compression
As shown in fig. 1, in this application scenario, the feature vector is the initial sequence to be encoded. The system does not automatically generate the prediction probability as the encoding parameter, in which case, in the embodiment of the present application, the encoding parameter may be calculated according to the number of occurrences of the character having the largest number of occurrences in the initial sequence (i.e., the feature vector in the figure), and the length of the initial sequence (the total number of characters). And taking the calculated coding parameter as the coding parameter corresponding to each character in the initial sequence, namely in the case, the coding parameters of each character in the initial sequence are the same.
For example, the initial sequence is composed of 0 and 1, wherein the number of occurrences of 0 is greater than the number of occurrences of 1, and the ratio of the number of occurrences of 0 to the total number of characters in the initial sequence is denoted by p, and the coding parameter M is an integer satisfying the following relation:
p M +p M+1 ≤1<p M +p M-1
step 402, sequentially acquiring characters in the initial sequence from one end of the initial sequence, if each character is acquired, determining the first N bits in the code sequence based on the first coding parameters corresponding to the currently acquired character in the parameter sequence if the currently acquired character is determined to be a high-frequency character in the initial sequence, and updating the first N bits into a first binary value.
Wherein the second binary value of the first N bits is not less than the first encoding parameter, and the third binary value of the first N-1 bits is less than the first encoding parameter, and the first binary value is equal to the sum of the second binary value and the first preset value.
Step 402 is described in the following:
step 4021, starting from one end of the initial sequence, sequentially acquiring the characters in the initial sequence.
When encoding an initial sequence, it is necessary to sequentially acquire characters from either end of the initial sequence to encode. For example, the characters may be sequentially acquired from the end of the initial sequence, or the characters may be sequentially acquired from the beginning of the initial sequence.
In step 4022, after each character is obtained, it is determined whether the currently obtained character is a high frequency character in the initial sequence.
The initial sequence may be a binary character sequence, e.g., the initial sequence is composed of two characters, 0 and 1.
The initial sequence may also be a ternary character sequence, e.g., the initial sequence is composed of three characters, 0, 1, and-1.
When the initial sequence is a binary character sequence, after the initial sequence is acquired, the high-frequency character and the low-frequency character in the initial sequence can be determined according to the occurrence times of each character in the initial sequence. For example, the initial sequence is composed of two kinds of characters of 0 and 1, and in the initial sequence, 0 occurs 20 times and 1 occurs 2 times, and then 0 is a high frequency character of the initial sequence and 1 is a low frequency character of the initial sequence. In the case where the number of occurrences of both characters is the same, either character may be regarded as a high-frequency character, and the other character may be regarded as a low-frequency character, accordingly.
In the case where the initial sequence is a ternary character, in the initial sequence obtained, the high-frequency character, the medium-frequency character, and the low-frequency character in the initial sequence may be determined according to the number of occurrences of each character in the initial sequence. For example, the initial sequence is composed of three characters of 0, 1 and-1, in which 0 appears 20 times, 1 appears 5 times, -1 appears 2 times, then 0 is the high frequency character of the initial sequence, +1 is the medium frequency character of the initial sequence, -1 is the low frequency character of the initial sequence. In the case where the number of occurrences of the three characters is the same, any one character may be used as a high-frequency character, and correspondingly, any one character of the other two characters may be used as a medium-frequency character, and the remaining one character may be used as a low-frequency character. And when the occurrence times of the two characters are the same and smaller than the occurrence times of the third character, taking the third character as a high-frequency character, taking any one of the two characters with the same occurrence times as a medium-frequency character, and taking the rest character as a low-frequency character. And when the occurrence times of the two characters are the same and are larger than the occurrence times of the third character, the third character is used as a low-frequency character, any character of the two characters with the same occurrence times is used as a high-frequency character, and the rest character is used as an intermediate-frequency character.
Step 4023, if it is determined that the currently acquired character is a high frequency character, determining the first N bits in the coding sequence based on the first coding parameter corresponding to the currently acquired character in the parameter sequence, and updating the first N bits to the first binary value.
The code sequence is updated in each encoding, and before the first encoding, the initial state of the code sequence is a preset bit sequence with the first bit being 1 (may be called an initial code sequence), for example: 1000. furthermore, the coding sequence may be stored in the stack with the first 1 at the top of the stack when the coding sequence is in the initial state.
After determining that the currently acquired character is a high frequency character, if the previous character in the code sequence is determinedThe binary value of the individual bit components is not less than M, the front +.>And a number of bits. If the first>Binary values of individual bit components being less than M, the preceding determination in the code sequenceAnd a number of bits. M is a first coding parameter corresponding to the currently acquired character.
Thus, the value of N can meet that the second binary value formed by the first N bits in the coding sequence is not smaller than the first coding parameter, and the third binary value formed by the first N-1 bits in the coding sequence is smaller than the first coding parameter.
The first N bits in the encoded sequence are then updated to the first binary value. Wherein the first binary value is equal to the sum of the second binary value and the first predetermined value.
In the case that the initial sequence is a binary character sequence, the value of the first preset value may be 1. In the case where the initial sequence is a ternary character sequence, the value of the first preset value may be 2. It should be noted that, the value of the first preset value is only one possible example, and in other examples, in the case that the initial sequence is a binary character sequence, the value of the first preset value may be 2. In the case where the initial sequence is a ternary character sequence, the value of the first preset value may be 3. The embodiment of the present application is not limited thereto, as long as the purpose of encoding compression can be achieved.
There are several ways to update the first N bits in the code sequence to the first binary value, several of which are described below.
The method comprises the following steps:
the first binary value is determined first, then the first N bits of the coding sequence are popped out of the stack, and the first binary value is pushed into the stack, so that the first N bits in the coding sequence are updated to the first binary value. For example, as described in fig. 5, assuming n=3 and a first binary value of 101, the first 3 bits (100) of the top of the stack are popped and 101 is pushed onto the stack. There are a number of ways to determine the first binary value, several of which are described below:
(1) The first binary value is determined by a look-up table method.
Specifically, after the first coding parameter is obtained, a codeword table corresponding to the first coding parameter is obtained according to the first coding parameter. Alternatively, a codeword table corresponding to each different coding parameter in the coding sequence may be pre-established and stored, so that when the first binary value is determined, the codeword table corresponding to the first coding parameter is directly acquired. Or after the first coding parameter is obtained, if the code word table corresponding to the first coding parameter is determined to be stored, the code word table is directly obtained, and if the code word table corresponding to the first coding parameter is not stored, the code word table corresponding to the first coding parameter is established and stored.
In the case that the initial sequence is a binary character sequence, assuming that 0 is a high frequency character, 1 is a low frequency character, the first preset value is 1, and the first coding parameter is M, the codeword table corresponding to the first coding parameter may be as shown in table 1 below. Wherein ( 2 The binary value is expressed as decimal values.
TABLE 1
Character(s) Read (Read) Write (Write)
0 (M) 2 (M-1) 2
0 (M+1) 2 (M+2) 2
0 (2M-1) 2 (2M) 2
1 1 (2M+1) 2
In the codeword table, the second binary value formed by the first N bits corresponds to the second column, and the first binary value to be queried corresponds to the third column. Based on the determined second binary number value composed of the first N bits and the currently acquired character, the corresponding first binary number can be queried Values. For example, the currently acquired character is 0, and the second binary value of the first N bits is (M+1) 2 Then by looking up the code word table it can be determined that the first binary value is (m+2) 2
In the case that the initial sequence is a ternary character sequence, assuming that 0 is a high frequency character, 1 is an intermediate frequency character, -1 is a low frequency character, the first preset value is 2 (2 is a decimal value, and the corresponding binary value is 10), and the first coding parameter is M, the first coding parameter corresponding codeword table may be as shown in table 2 below.
TABLE 2
The method for determining the first binary value by looking up the codeword table shown in table 2 is the same as the method for determining the first binary value by looking up the codeword table of table 1, and will not be described here again.
(2) And adding the first preset value to the second binary value formed by the first N bits of the coding sequence to obtain a first binary value.
The second method is as follows:
in the stack, the first binary value is updated by adding the first preset value to the second binary value formed by the first N bits of the code sequence.
For example, in the case where the initial sequence is a binary sequence, assuming that the first preset value is 1, after the first N bits in the encoded sequence are determined, a second binary value consisting of the first N bits of the encoded sequence is added by 1 in the stack.
For another example, in the case that the initial sequence is a ternary sequence, assuming that the first preset value is 2, after the first N bits in the coding sequence are determined, the first N bits in the coding sequence are updated to the first binary value by adding the binary value 10 to the second binary value formed by the first N bits in the coding sequence in the stack.
Compared with the method one, the method only needs simple addition and shift operation, and has simple calculation and higher coding efficiency.
Step 403, if it is determined that the currently acquired character is not a high frequency character in the initial sequence, updating the first bit in the encoded sequence to a fourth binary value.
Wherein the fourth binary value is positively correlated with the first encoding parameter.
In an implementation, in the case where the initial sequence is a binary character sequence, if it is determined that the currently acquired character is a low frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value. Wherein, in the case that the first preset value is 1, the fourth binary value may be (2M+1) 2
In the case where the initial sequence is a ternary character sequence, if it is determined that the currently acquired character is an intermediate frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value. In this case, assuming that the first preset value is 2, the fourth binary value may be (2M+2) 2
If it is determined that the currently acquired character is a low frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value. In this case, assuming that the first preset value is 2, the fourth binary value may be (2M+3) 2
It should be noted that, the value of the fourth binary value is only one possible example, and in other examples, in the case that the initial sequence is a binary character sequence, the value of the fourth binary value may be 2m+2. In the case where the initial sequence is a ternary character sequence and the currently acquired character is an intermediate frequency character, the value of the fourth binary value may be 2m+3. In the case where the initial sequence is a ternary character sequence and the currently acquired character is an intermediate frequency character, the value of the fourth binary value may be 2m+4. The embodiment of the application does not limit specific values, as long as coding compression can be achieved, and the coding sequence can be decoded and restored to the initial sequence.
The method of updating the first bit in the code sequence to the fourth binary value may be as follows.
The method comprises the following steps:
the first bit in the code sequence is updated to the fourth binary value by determining the fourth binary value and then ejecting the first bit of the code sequence from the stack and pushing the fourth binary value into the stack.
There are a number of ways to determine the fourth binary value, several of which are described below:
(1) The fourth binary value is determined by a look-up table method.
Specifically, a codeword table corresponding to the first coding parameter may be obtained, and the fourth binary value may be determined by querying the codeword table.
The codeword table obtaining method is the same as that provided by the method one in step 4023, and will not be described herein.
In the case where the initial sequence is a binary character sequence, taking the above table 1 as an example of a codeword table corresponding to the first coding parameter, the first bit in the coding sequence corresponds to the second column in the above table 1, and the fourth binary value corresponds to the third column in the above table 1. Assuming that the currently acquired character is 1, a fourth binary value is determined to be (2M+1) by looking up Table 1 2
In the case where the initial sequence is a ternary character sequence, taking the above table 2 as an example of a codeword table corresponding to the first coding parameter, the first bit in the coding sequence corresponds to the second column in the above table 2, and the fourth binary value corresponds to the third column in the above table 2. Assuming that the currently acquired character is 1 and is an intermediate frequency character, a fourth binary value is determined to be (2M+2) by looking up table 2 2 . Assuming that the currently acquired character is-1 and is a low frequency character, a fourth binary value of (2M+3) is determined by looking up Table 2 2
(2) Composing the first bit of the code sequence into a binary systemNumerical value adding (2M) 2 A fourth binary value is obtained.
The second method is as follows:
in the case of binary sequences as the initial sequence, assuming that the currently acquired character is 1, which is a low frequency character, the first bit of the encoded sequence is formed into a binary value plus (2M) in the stack 2 Updating the first bit in the encoded sequence to the fourth binary value is achieved.
In the case of ternary sequence as initial sequence, assuming that the currently acquired character is 1 and is an intermediate frequency character, the first bit in the coded sequence is formed into binary value plus (2M+1) in the stack 2 I.e. an update of the first bit in the code sequence to the fourth binary value is achieved. Assuming that the currently acquired character is-1, which is a low frequency character, the first bit in the code sequence is formed into a binary value plus (2M+2) in the stack 2 Updating the first bit in the encoded sequence to the fourth binary value is achieved.
And (3) until the last character in the initial sequence is coded, finishing coding, wherein the coding sequence in the stack is the coding sequence corresponding to the initial sequence.
According to the scheme, each character in the initial sequence to be coded is coded respectively, and when each character is coded, coding is performed according to coding parameters corresponding to the character. While the conventional Golomb (Golomb) coding scheme is performed, it is required to convert an initial sequence to be coded into an integer sequence (a plurality of consecutive and identical characters are converted into an integer during conversion) according to a run-length coding, and then, further, a fixed coding parameter is used to code each integer in the integer sequence. In the image compression scene based on AI prediction, coding is required to be performed for each character in the initial sequence, and obviously, the existing Golomb coding cannot meet the requirement, but the scheme provided by the embodiment of the application can better meet the requirement, and the coding parameters of each character in the scheme provided by the embodiment of the application are not limited, and can be the same or different, so that the coding scheme has stronger adaptability. In addition, in the scheme provided by the embodiment of the application, other parameters are not introduced only according to the coding parameters corresponding to the characters during coding, so that the coding scheme has higher certainty.
For the method of data encoding shown in fig. 4, the embodiment of the present application further provides a method of data decoding, referring to fig. 6, a process flow of the method may include the following steps:
step 601, acquiring a coding sequence and a parameter sequence.
The coding sequence is obtained by coding the initial sequence based on the parameter sequence by adopting the coding method shown in the figure 4.
In implementations, when the encoded sequence needs to be decrypted, the encoded sequence, the parameter sequence used in encoding, and the high frequency character, the low frequency character, and the medium frequency character in the initial sequence may be acquired by a local or other device. After the code sequence is acquired, the code sequence may be pushed onto a stack. The last code generated bit in the code sequence is at the top of the stack.
Step 602, sequentially acquiring coding parameters from one end of a parameter sequence, and determining the first X bits in the coding sequence based on the currently acquired coding parameter every time one coding parameter is acquired, and if the binary value formed by the first X bits is determined to be the fourth binary value, determining the character corresponding to the currently acquired coding parameter in the initial sequence as the first character, and updating the first X bits to be 1.
Wherein the first character is not a high frequency character in the initial sequence. The binary value of the first X bits is not less than M+1, and the binary value of the first X-1 bits is less than M+1, M being the currently acquired coding parameter.
Step 602 is described in the following:
step 6021, starting from one end of the parameter sequence, sequentially acquiring the coding parameters.
When the coding parameters are acquired in the parameter sequence, the characters corresponding to the coding parameters acquired for the first time in the initial sequence are coded last.
Step 6022, determining the first X bits in the code sequence based on the currently acquired code parameter and determining whether the binary value of the first X bits is the fourth binary value or not, whenever one code parameter is acquired.
In the case where the initial sequence is a binary character sequence and the first preset value used in encoding is 1, the processing in step 6022 may be as follows:
if the front in the coding sequenceThe binary value of the individual bit components is not less than M+1, the former ++is determined in the coding sequence>And a number of bits. If the front in the coding sequenceThe binary value of the individual bit components is less than M+1, the preceding is determined in the code sequenceAnd a number of bits.
Thus, the value of X can meet that the binary value formed by the first X bits in the coding sequence is not less than M+1, and the binary value formed by the first X-1 bits in the coding sequence is less than M+1. That is, the value of X is thus determined, so that the first X bits determined this time are binary values written into the code sequence when the corresponding character in the initial sequence is coded. For example, when any character in the initial sequence is encoded, the first X bits of the encoded sequence are updated to 1010, and when the character is decoded, the first X bits determined in the encoded sequence are 1010.
In the case where the initial sequence is a ternary character sequence and the first preset value used in encoding is 2, the process of step 6022 may be as follows:
if the front in the coding sequenceThe binary value of the individual bit components is not less than M+2, the former ++is determined in the coding sequence>And a number of bits. If the front in the coding sequenceThe binary value of the individual bit components is smaller than M+2, the former +.>And a number of bits.
Thus, the value of X can meet that the binary value formed by the first X bits in the coding sequence is not less than M+2, and the binary value formed by the first X-1 bits in the coding sequence is less than M+2.
After the first X bits of the code sequence are determined, it is determined whether the binary value of the first X bits is the fourth binary value. Wherein the value of the fourth binary value is related to the currently acquired coding parameter and the type of the initial sequence. For example, in the case where the initial sequence is a binary character sequence, the fourth binary value may be 2m+1, m being the currently acquired encoding parameter. In the case where the initial sequence is a ternary character sequence, the fourth binary value may be 2m+2.
Step 6023, if it is determined that the binary value formed by the first X bits is the fourth binary value, determining that the character corresponding to the currently acquired coding parameter in the initial sequence is the first character, and updating the first X bits to 1.
If the binary number value formed by the first X bits is the fourth binary number value, the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be a low-frequency character, and then the first X bits in the coding sequence are updated to be 1.
For example, assume that the fourth binary value is (2M+1) 2 The low frequency character is 1. Before determining the first X ratiosThe binary value of the special composition is (2M+1) 2 In the case of (2), it is determined that the character corresponding to the currently acquired encoding parameter in the initial sequence is 1, and the first X bits are updated to 1.
If the binary value of the first X bits is the fourth binary value, the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be an intermediate frequency character, and then the first X bits in the coding sequence are updated to be 1.
For example, assume that the fourth binary value is (2M+2) 2 The intermediate frequency character is 1. The binary value of the first X bits was (2m+2) before determining 2 In the case of (2), it is determined that the character corresponding to the currently acquired encoding parameter in the initial sequence is 1, and the first X bits are updated to 1.
The method of updating the first X bits in the coding sequence to 1 may be as follows:
method one, pop the first X bits in the coding sequence from the stack and push 1 onto the stack.
And subtracting 1 from the fourth binary value to obtain a difference value, and subtracting the difference value from the binary value formed by the first X bits in the coding sequence in a stack to update the first X bits in the coding sequence to 1.
Step 603, if it is determined that the binary value of the first X bits is smaller than the fourth binary value, determining that the character corresponding to the coding parameter in the initial sequence is the second character, and updating the first X bits to the second binary value.
Wherein the binary value of the first X bits is the sum of a second binary value and the first predetermined value, and the second character is a high frequency character in the initial sequence.
In an implementation, if it is determined that the binary value of the first X bits in the code sequence is smaller than the fourth binary value, then determining that the character corresponding to the code parameter in the initial sequence is a high frequency character in the initial sequence, and updating the first X bits to the second binary value. The first preset value may be 1 in the case where the initial sequence is a binary character sequence, and 2 in the case where the initial sequence is a ternary character sequence.
The method of updating the first X bits in the code sequence to the second binary value may be as follows:
the method comprises the following steps:
the first X bits of the coding sequence are popped from the stack, and the second binary value is pushed into the stack, so that the first X bits are updated to the second binary value.
There are a number of ways to determine the second binary value, several of which are described below:
(1) The second binary value is determined by a look-up table method.
Specifically, a codeword table corresponding to the currently acquired coding parameter may be acquired, and the second binary value is determined by querying the codeword table.
The codeword table obtaining method is the same as that provided by the method one in step 4023, and will not be described herein.
Taking the above table 1 as an example of a codeword table corresponding to the currently acquired coding parameter, binary values composed of the first X bits in the coding sequence correspond to the third column in the above table 1. And inquiring the table 1 according to binary values formed by the first X bits in the coding sequence to obtain corresponding second binary values. Let the binary value of the first X bits in the coding sequence be (2m+2) 2 By looking up Table 1, it can be determined that the corresponding second binary value is (M+1) 2
(2) And subtracting the binary value formed by the first X bits in the coding sequence by a first preset value to obtain a second binary value.
For example, the first X bits in the coding sequence are (M+2) 2 The first preset value is 1, will be (M+2) 2 Subtracting 1 to obtain a second binary value of (M+1) 2
The second method is as follows:
in the stack, the first X bits of the code sequence form binary values minus a first preset value, thereby realizing the updating of the first X bits of the code sequence to a second binary value.
In the case that the initial sequence is a ternary character sequence, if it is determined that the binary value consisting of the first X bits is greater than the fourth binary value, the pre-coding character corresponding to the coding parameter is determined to be a low-frequency character in the initial sequence, and the first X bits are updated to 1. Specifically, the updating method in this case is the same as the updating method in step 6023, and will not be described here.
After determining the character corresponding to the last coding parameter in the initial sequence, decoding is completed.
The method for encoding data provided in the embodiments of the present application will be described below with reference to an example. In this example, the initial sequence is a binary character sequence. Referring to fig. 7, assuming that the initial sequence is (0, 1, 0), the parameter sequence is (5,3,3,4), the first preset value is 1, the initial code sequence is 100 from the last character of the initial sequence. The data encoding flow of this initial sequence is described below with reference to fig. 7:
step 701, determining that the high frequency character in the initial sequence is 0 and the low frequency character is 1. The characters are acquired sequentially starting from the last character of the initial sequence.
Step 702, when the last character 0 is obtained, determining 0 as the high frequency character in the initial sequence, and determining the front in the coding sequenceThe binary value of the bit composition is 100 and is equal to the corresponding coding parameter 4 (4 is a decimal value and the corresponding binary value is 100). The first 3 bits are updated to the binary value 101 (i.e., the binary value 100 of the first 3 bits plus 1). After updating, the coding sequence becomes 101.
Step 703, when the last-to-last character 1 is obtained, determining 1 as the low-frequency character in the initial sequence, and updating the first bit in the code sequence to a binary value (2×3+1) based on the corresponding coding parameter 3 2 111. After updating, the coding sequence becomes 11101.
Step 704, when the last character 0 is obtained, determining 0 as the high frequency character in the initial sequence, and determining the front in the coding sequenceThe binary value of the bit composition is 11, which is equal to the corresponding coding parameter 3 (3 is a decimal value, and the corresponding binary value is 11). The first 2 bits are updated to a binary value of 100 (i.e., the binary value of 11, which consists of the first 2 bits, plus 1). After updating, the coding sequence becomes 100101.
Step 705, when the last character 0 is obtained, determining 0 as the high frequency character in the initial sequence, and determining the front in the coding sequenceThe binary value of the bit composition is 100, which is smaller than the corresponding coding parameter 5 (5 is a decimal value, and the corresponding binary value is 101). Then, the first ++in the coding sequence is determined>And a number of bits. The first 4 bits are updated to binary value 1010 (i.e., binary value 1001 of the first 4 bits plus 1). After updating, the coding sequence becomes 101001. Thus, the code sequence corresponding to the initial sequence (0, 1, 0) is 101001.
The method for decoding data provided in the embodiments of the present application will be described below with reference to an example. Referring to fig. 8, this example corresponds to the example shown in fig. 7, in which the code sequence is 101001, the parameter sequence is (5,3,3,4), the first preset value is 1,0 is a high frequency character, 1 is a low frequency character, and decoding is started from the head end of the code sequence. The data encoding flow of this initial sequence is described below with reference to fig. 8:
step 801, starting from the head end of the parameter sequence, the coding parameters are acquired in turn.
Step 802, determining the previous sequence in the code sequence when the first coding parameter 5 is obtainedThe binary value of the individual bit components is 101, which is smaller than 6 (coding parameter 4+1). Then, the front in the coding sequence is determinedThe binary value of the individual bit composition is 1010. If the binary value 1010 is determined to be less than 2×5+1=11 (2×coding parameter+1), the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be 0. That is, the first character in the initial sequence is 0. The first 4 bits of the code sequence are then updated to the binary value 1001 (the binary value 1010 of the first 4 bits minus 1). After updating, the coding sequence becomes 100101.
Step 803, when the second coding parameter 3 is obtained, determining the previous sequence in the coding sequence The binary value of the individual bit component is 100, which is equal to 4 (coding parameter 3+1). Then, if it is determined that the binary value 100 is less than 2×3+1=7 (2×coding parameter+1), it is determined that the character corresponding to the currently acquired coding parameter in the initial sequence is 0. That is, the second character in the initial sequence is 0. The first 3 bits of the code sequence are then updated to the binary value 11 (the binary value 100 of the first 3 bits minus 1). After updating, the coding sequence becomes 11101.
Step 804, determining the front in the code sequence when the third code parameter 3 is acquiredThe binary value of the individual bit components is 111, which is greater than 4 (coding parameter 3+1). Then, it is determined that the binary value 111 is equal to 2×3+1=7 (2×coding parameter+1), and the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be 1. That is, the third character in the initial sequence is 1. The first 3 bits of the code sequence are then updated to a binary value of 1 (the binary value 100 consisting of the first 3 bits minus the binary value 11). After updating, the coding sequence becomes 101.
Step 805, determining the previous in the code sequence when the fourth coding parameter 4 is obtainedThe binary value of the individual bit component is 101, which is equal to 5 (coding parameter 4+1). Then, if the binary value 101 is determined to be less than 2×4+1=9 (2×coding parameter+1), the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be 0. That is, the fourth character in the initial sequence is 0. The first 3 bits of the code sequence are then updated to a binary value of 100 (binary value 101 of the first 3 bits minus 1). After updating, the coding sequence becomes 100.
Thus, the initial sequence (0, 1, 0) can be decoded.
The method for encoding data provided in the embodiments of the present application will be described below with reference to another example. In this example, the initial sequence is a ternary character sequence. Referring to fig. 9, assuming that the initial sequence is (0, -1, 0), the parameter sequence is (5,3,3,4), the first preset value is 2 (2 is a decimal value, and the corresponding binary value is 10), the code starts from the last character of the initial sequence, and the initial code sequence in the code sequence is 100. The data encoding flow of this initial sequence is described below with reference to fig. 9:
step 901, determining that a high frequency character in an initial sequence is 0, a medium frequency character is 1, and a low frequency character is-1. The characters are acquired sequentially starting from the last character of the initial sequence.
Step 902, when the last character 0 is obtained, determining 0 as the high frequency character in the initial sequence, and determining the front in the coding sequenceThe binary value of the bit composition is 100 and is equal to the corresponding coding parameter 4 (4 is a decimal value and the corresponding binary value is 100). The first 3 bits are updated to the binary value 110 (i.e., the binary value 100 of the first 3 bits plus the binary value 10). After updating, the coding sequence becomes 110.
Step (a)903. When the last-to-last character 1 is acquired, determining 1 as an intermediate frequency character in the initial sequence, and updating the first bit in the code sequence into a binary value (2 x 3+2) based on the corresponding code parameter 3 2 I.e. 1000. After updating, the coding sequence becomes 100010.
Step 904, when the third last character-1 is obtained, determining that-1 is the low frequency character in the initial sequence, and updating the first bit in the code sequence into a binary value (2×3+3) based on the corresponding coding parameter 3 2 I.e., 1001. After updating, the coding sequence becomes 100100010.
Step 905, when the last-last character 0 is obtained, determining 0 as the high-frequency character in the initial sequence, and determining the front in the coding sequenceThe binary value of the bit composition is 100, which is smaller than the corresponding coding parameter 5 (5 is a decimal value, and the corresponding binary value is 101). Then, the first ++in the coding sequence is determined>And a number of bits. The first 4 bits are updated to a binary value 1011 (i.e., binary value 1001 of the first 4 bits plus binary value 10). After updating, the coding sequence becomes 101100010. Thus, the initial sequence (0, -1, 0) was obtained as a corresponding code sequence 101100010.
The method for decoding data provided in the embodiments of the present application will be described below with reference to another example. Referring to fig. 10, this example corresponds to the example shown in fig. 9, in which the code sequence is 101000010, the parameter sequence is (5,3,3,4), the first preset value is 2,0 is a high frequency character, 1 is an intermediate frequency character, and-1 is a low frequency character, and decoding is started from the head end of the code sequence. The data encoding flow of this initial sequence is described below with reference to fig. 10:
step 1001, starting from the head end of the parameter sequence, sequentially acquiring coding parameters.
Step 1002, determining the code sequence when the first coding parameter 5 is obtainedFront of (2)The binary value of the individual bit components is 101, which is smaller than 7 (coding parameter 5+2). Then, the front in the coding sequence is determinedThe binary value of the individual bit composition is 1011. If the binary value 1011 is determined to be less than 2×5+2=12 (2×coding parameter+2), the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be 0. That is, the first character in the initial sequence is 0. The first 4 bits of the code sequence are then updated to a binary value of 1000 (binary value 1011, which consists of the first 4 bits, minus binary value 10). After updating, the coding sequence becomes 100100010.
Step 1003, determining the front in the code sequence when the second code parameter 3 is acquiredThe binary value of the individual bit components is 100, which is less than 5 (coding parameter 3+2). Then, the front of the coding sequence is determinedThe binary value of each bit is 1001, which is greater than 2×3+2=8 (2×coding parameter+2), and the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be-1. That is, the second character in the initial sequence is-1. The first 4 bits of the code sequence are then updated to 1 (the binary value 1001 of the first 3 bits minus 1000). After updating, the coding sequence becomes 100010.
Step 1004, when the third coding parameter 3 is obtained, determining the front in the coding sequenceThe binary value of the individual bit components is 100, which is less than 5 (coding parameter 3+2). Then, the front of the coding sequence is determinedThe binary value of each bit is 1000, which is equal to 2×3+2=8 (2×coding parameter+2), and the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be 1. That is, the third character in the initial sequence is 1. The first 4 bits of the code sequence are then updated to a binary value of 1 (the binary value 1000 of the first 4 bits minus the binary value 111). After updating, the coding sequence becomes 110.
Step 1005, determining the front in the code sequence when the fourth code parameter 4 is obtainedThe binary value of the individual bit component is 110, which is equal to 6 (coding parameter 4+2). Then, if the binary value 110 is determined to be less than 2×4+2=10 (2×coding parameter+2), the character corresponding to the currently acquired coding parameter in the initial sequence is determined to be 0. That is, the fourth character in the initial sequence is 0. The first 3 bits of the code sequence are then updated to a binary value of 100 (the binary value 110 of the first 3 bits minus the binary value 10). After updating, the coding sequence becomes 100.
Thus, the initial sequence (0, -1, 0) can be decoded.
It should be noted that the examples shown in fig. 7 and fig. 9 are only for describing the encoding process, and the compression effect cannot be represented due to the short initial sequence length, and the following table 3 is a comparison between the scheme provided by the present application and the data encoding and decoding performed by using the existing encoding and decoding scheme. The comparison items comprise the size of the coded sequence after coding compression, coding throughput and decoding throughput.
TABLE 3 Table 3
The data are obtained by encoding the same initial sequence under the same test environment by the scheme provided by the application and the existing coding and decoding scheme. Compared with the prior art, the scheme provided by the application is superior to the prior scheme in compression effect and coding and decoding throughput.
Based on the same technical concept, the embodiment of the present application further provides an apparatus for encoding data, referring to fig. 11, the apparatus includes an acquisition module 1110 and an encoding module 1120, where:
an obtaining module 1110, configured to obtain an initial sequence to be encoded and a parameter sequence, where the parameter sequence includes an encoding parameter corresponding to each character in the initial sequence;
the encoding module 1120 is configured to sequentially obtain, from one end of the initial sequence, each time a character in the initial sequence is obtained, if it is determined that the currently obtained character is a high-frequency character in the initial sequence, determine, based on a first encoding parameter corresponding to the currently obtained character in the parameter sequence, first N bits in the encoding sequence, and update the first N bits to a first binary value, where a second binary value formed by the first N bits is not less than the first encoding parameter, and a third binary value formed by the first N-1 bits is less than the first encoding parameter, and the first binary value is equal to a sum of the second binary value and a first preset value; if it is determined that the currently acquired character is not a high frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value, wherein the fourth binary value is positively correlated with the first encoding parameter.
In one possible implementation, the coding parameters are used to describe a prediction probability at the time of character generation at a corresponding position in the initial sequence.
In one possible implementation, the coding parameters are used to describe a probability distribution of high frequency characters in the initial sequence.
In one possible implementation, the encoding module 1120 is configured to:
if the preceding in the coding sequenceIndividual bit compositionThe binary value of (2) is not less than M, then in said coding sequence the front +.>A number of bits, wherein M is the first encoding parameter;
if the preceding in the coding sequenceThe binary value of the individual bit components is smaller than M, the front ++is determined in the coding sequence>And a number of bits.
In one possible implementation, the initial sequence is a binary character sequence.
In one possible implementation, the first preset value is 1.
In one possible implementation, the encoding module 1120 is configured to:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+1, wherein M is the first coding parameter.
In one possible implementation, the initial sequence is a ternary character sequence.
In one possible implementation, the first preset value is 2.
In one possible implementation, the encoding module 1120 is configured to:
determining that the currently acquired character is an intermediate frequency character in the initial sequence;
the encoding module 1120 is configured to:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+2, wherein M is the first coding parameter.
In one possible implementation, the encoding module 1120 is configured to:
determining that the currently acquired character is a low frequency character in the initial sequence;
the updating the first bit in the code sequence to a fourth binary value includes:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+3, wherein M is the first coding parameter.
According to the scheme, each character in the initial sequence to be coded is coded respectively, and when each character is coded, coding is performed according to coding parameters corresponding to the character. While the conventional Golomb (Golomb) coding scheme is performed, it is required to convert an initial sequence to be coded into an integer sequence (a plurality of consecutive and identical characters are converted into an integer during conversion) according to a run-length coding, and then, further, a fixed coding parameter is used to code each integer in the integer sequence. In the image compression scene based on AI prediction, coding is required to be performed for each character in the initial sequence, and obviously, the existing Golomb coding cannot meet the requirement, but the scheme provided by the embodiment of the application can better meet the requirement, and the coding parameters of each character in the scheme provided by the embodiment of the application are not limited, and can be the same or different, so that the coding scheme has stronger adaptability. In addition, in the scheme provided by the embodiment of the application, other parameters are not introduced only according to the coding parameters corresponding to the characters during coding, so that the coding scheme has higher certainty.
It should be noted that: in the data encoding apparatus provided in the foregoing embodiments, only the division of the functional modules is used for illustration, and in practical application, the functional allocation may be performed by different functional modules according to needs, that is, the internal structure of the electronic device is divided into different functional modules, so as to complete all or part of the functions described above. In addition, the apparatus for encoding data provided in the foregoing embodiments and the method embodiment for encoding data belong to the same concept, and specific implementation processes of the apparatus for encoding data are detailed in the method embodiment and are not described herein again.
Based on the same technical concept, the application embodiment further provides a device for decoding data, referring to fig. 12, the device includes an acquisition module 1210 and a decryption module 1220, where:
an obtaining module 1210, configured to obtain a coding sequence and a parameter sequence, where the coding sequence is obtained by coding an initial sequence, and the parameter sequence includes a coding parameter corresponding to each character in the initial sequence;
a decoding module 1220, configured to sequentially obtain coding parameters from one end of the parameter sequence, each time a coding parameter is obtained, determine, based on a currently obtained coding parameter, a first X bits in the coding sequence, and if it is determined that a binary value formed by the first X bits is a fourth binary value, determine a character corresponding to the currently obtained coding parameter in the initial sequence as a first character, and update the first X bits as 1, where the fourth binary value is positively correlated with the currently obtained coding parameter, the first character is not a high-frequency character in the initial sequence, a binary value formed by the first X bits is not less than a target value, and a binary value formed by the first X-1 bits is less than the target value, where the target value is determined according to the currently obtained coding parameter and a type of the initial sequence; and if the binary value formed by the first X bits is smaller than the fourth binary value, determining that the character corresponding to the coding parameter in the initial sequence is a second character, and updating the first X bits to a second binary value, wherein the binary value formed by the first X bits is the sum of the second binary value and a first preset value, and the second character is a high-frequency character in the initial sequence.
In one possible implementation, the coding parameters are used to describe a prediction probability at the time of character generation at a corresponding position in the initial sequence.
In one possible implementation, the coding parameters are used to describe a probability distribution of high frequency characters in the initial sequence.
In one possible implementation, the initial sequence is a binary character sequence.
In one possible implementation, the target value is m+1, and the decoding module 1220 is configured to:
if the preceding in the coding sequenceThe binary value of the individual bit components is not less than M+1, the former ++is determined in the coding sequence>A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequenceThe binary value of the individual bit components is smaller than M+1, the former +.>And a number of bits.
In one possible implementation, the first preset value is 1.
In one possible implementation, the fourth binary value is a binary value corresponding to 2m+1.
In one possible implementation, the initial sequence is a ternary character sequence.
In one possible implementation, the target value is m+2, and the decoding module 1220 is configured to:
If the preceding in the coding sequenceThe binary value of the individual bit components is not less than M+2, the former ++is determined in the coding sequence>A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequenceBinary values of the individual bit components are smaller than M+2, the former +.>And a number of bits.
In one possible implementation, the first preset value is 2.
In one possible implementation manner, the first character is an intermediate frequency character in the initial sequence, and the fourth binary value is a binary value corresponding to 2m+2, where M is the currently acquired coding parameter.
In one possible implementation, the decoding module 1220 is further configured to:
and if the binary value formed by the first N bits is larger than the fourth binary value, determining that the pre-coding character corresponding to the coding parameter is a third character, and updating the first N bits to 1, wherein the third character is a low-frequency character in the pre-coding character sequence.
In one possible implementation manner, the character corresponding to the first acquired coding parameter in the initial sequence is the character that is encoded last in the initial sequence, and the first N bits determined in the coding sequence for the first time are the bits obtained by last encoding in the coding sequence.
It should be noted that: in the data decoding device provided in the foregoing embodiment, only the division of the functional modules is used for illustration, and in practical application, the functional allocation may be performed by different functional modules according to needs, that is, the internal structure of the electronic device is divided into different functional modules, so as to complete all or part of the functions described above. In addition, the apparatus for decoding data provided in the foregoing embodiments and the method embodiment for decoding data belong to the same concept, and specific implementation processes of the apparatus for decoding data are detailed in the method embodiment, which is not described herein again.
Referring to FIG. 13, an embodiment of the present application provides a schematic diagram of a computer device, computer device 1300 optionally implemented by a general bus architecture. The computer device 1300 includes at least one processor 1301, a communication bus 1302, a memory 1303, and at least one network interface 1304. The computer device with the structure shown in fig. 13 may be a notebook computer, a desktop computer, or a server.
Processor 1301 is, for example, a general-purpose central processing unit (central processing unit, CPU), a network processor (network processer, NP), a graphics processor (Graphics Processing Unit, GPU), a neural-network processor (neural-network processing units, NPU), a data processing unit (Data Processing Unit, DPU), a microprocessor, or one or more integrated circuits for implementing the aspects of the present application. For example, processor 1301 includes an application-specific integrated circuit (ASIC), a programmable logic device (programmable logic device, PLD), or a combination thereof. PLDs are, for example, complex programmable logic devices (complex programmable logic device, CPLD), field-programmable gate arrays (field-programmable gate array, FPGA), general-purpose array logic (generic array logic, GAL), or any combination thereof.
Communication bus 1302 is used to transfer information between the above-described components. The communication bus 1302 can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is shown in fig. 13, but not only one bus or one type of bus.
The Memory 1303 is, for example, but not limited to, a read-only Memory (ROM) or other type of static storage device that can store static information and instructions, a random access Memory (random access Memory, RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only Memory (electrically erasable programmable read-only Memory, EEPROM), a compact disc (compact disc read-only Memory) or other optical disc storage, a compact disc storage (including compact disc, laser disc, optical disc, digital versatile disc, blu-ray disc, etc.), a magnetic disk storage medium, or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and that can be accessed by a computer. The memory 1303 is, for example, independent and is connected to the processor 1301 through the communication bus 1302. Memory 1303 may also be integrated with processor 1301.
The network interface 1304 uses any transceiver-like device for communicating with other devices or communication networks. Network interface 1304 includes a wired network interface and may also include a wireless network interface. The wired network interface may be, for example, an ethernet interface. The ethernet interface may be an optical interface, an electrical interface, or a combination thereof. The wireless network interface may be a wireless local area network (wireless local area networks, WLAN) interface, a network interface of a cellular network, a combination thereof, or the like.
In a particular implementation, processor 1301 may include one or more CPUs, as an example.
In a particular implementation, as an example, computer device 1300 may include multiple processors. Each of these processors may be a single-core processor (single-CPU) or a multi-core processor (multi-CPU). A processor herein may refer to one or more devices, circuits, and/or processing cores for processing data (e.g., computer program instructions).
In a particular implementation, as an example, computer device 1300 may also include an output device and an input device. An output device communicates with processor 1301 and can display information in a variety of ways. For example, the output device may be a liquid crystal display (liquid crystal display, LCD), a light emitting diode (light emitting diode, LED) display device, a Cathode Ray Tube (CRT) display device, or a projector (projector), or the like. An input device communicates with processor 1301 to receive user input in a variety of ways. For example, the input device may be a mouse, a keyboard, a touch screen device, a sensing device, or the like.
In some embodiments, the memory 1303 is configured to store program codes 13031 for performing data encoding and/or data decoding in the present application, and the processor 1301 executes the program codes 13031 stored in the memory 1303. That is, the computer apparatus 1300 may implement the data encoding method and/or the data decoding method provided by the method embodiment through the processor 1301 and the program code 1303 in the memory 1303.
Referring to fig. 14, a block diagram of an electronic device 1400 provided in an exemplary embodiment of the present application is shown. The electronic device 1400 may be a portable mobile terminal such as: a smart phone, a tablet computer, a dynamic video expert compression standard audio layer 3 (Moving Picture Experts Group Audio Layer III, MP 3) player, a dynamic video expert compression standard audio layer 4 (Moving Picture Experts Group Audio Layer IV, MP 4) player, a notebook computer, or a desktop computer. Electronic device 1400 may also be referred to by other names of user devices, portable terminals, laptop terminals, desktop terminals, and the like.
In general, the electronic device 1400 includes: a processor 1401 and a memory 1402.
Processor 1401 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and the like. The processor 1401 may be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), programmable logic array (Programmable Logic Array, PLA). The processor 1401 may also include a main processor, which is a processor for processing data in an awake state, also referred to as a central processor (Central Processing Unit, CPU), and a coprocessor; a coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 1401 may be integrated with an image processor (Graphics Processing Unit, GPU) for use in connection with rendering and rendering of content to be displayed by the display screen. In some embodiments, the processor 1401 may also include an artificial intelligence (Artificial Intelligence, AI) processor for processing computing operations related to machine learning.
Memory 1402 may include one or more computer-readable storage media, which may be non-transitory. Memory 1402 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In some embodiments, a non-transitory computer readable storage medium in memory 1402 is used to store at least one instruction for execution by processor 1401 to implement the methods of data encoding and/or data decoding provided by the method embodiments herein.
In some embodiments, the electronic device 1400 may further optionally include: a peripheral interface 1403 and at least one peripheral. The processor 1401, memory 1402, and peripheral interface 1403 may be connected by a bus or signal lines. The individual peripheral devices may be connected to the peripheral device interface 1403 via buses, signal lines or a circuit board. Specifically, the peripheral device includes: at least one of radio frequency circuitry 1404, a display screen 1405, a camera assembly 1406, an audio circuit 1407, a positioning assembly 1408, and a power source 1409.
Peripheral interface 1403 may be used to connect at least one Input/Output (I/O) related peripheral device to processor 1401 and memory 1402. In some embodiments, processor 1401, memory 1402, and peripheral interface 1403 are integrated on the same chip or circuit board; in some other embodiments, either or both of processor 1401, memory 1402, and peripheral interface 1403 may be implemented on separate chips or circuit boards, which is not limited in this embodiment.
The Radio Frequency circuit 1404 is configured to receive and transmit Radio Frequency (RF) signals, also known as electromagnetic signals. The radio frequency circuit 1404 communicates with a communication network and other communication devices via electromagnetic signals. The radio frequency circuit 1404 converts an electrical signal into an electromagnetic signal for transmission, or converts a received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 1404 includes: antenna systems, RF transceivers, one or more amplifiers, tuners, oscillators, digital signal processors, codec chipsets, subscriber identity module cards, and so forth. The radio frequency circuit 1404 may communicate with other terminals via at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: the world wide web, metropolitan area networks, intranets, generation mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and/or wireless fidelity (Wireless Fidelity, wiFi) networks. In some embodiments, the radio frequency circuit 1404 may also include circuitry related to near field wireless communication (Near Field Communication, NFC), which is not limited in this application.
The display screen 1405 is used to display UI (User Interface). The UI may include graphics, text, icons, video, and any combination thereof. When the display screen 1405 is a touch display screen, the display screen 1405 also has the ability to collect touch signals at or above the surface of the display screen 1405. The touch signal may be input to the processor 1401 as a control signal for processing. At this time, the display 1405 may also be used to provide virtual buttons and/or a virtual keyboard, also referred to as soft buttons and/or a soft keyboard. In some embodiments, the display 1405 may be one, disposed on the front panel of the electronic device 1400; in other embodiments, the display 1405 may be at least two, respectively disposed on different surfaces of the electronic device 1400 or in a folded design; in other embodiments, the display 1405 may be a flexible display disposed on a curved surface or a folded surface of the electronic device 1400. Even more, the display 1405 may be arranged in a non-rectangular irregular pattern, i.e. a shaped screen. The display 1405 may be made of a material such as a liquid crystal display (Liquid Crystal Display, LCD) or an Organic Light-Emitting Diode (OLED).
The camera component 1406 is used to capture images or video. Optionally, camera assembly 1406 includes a front camera and a rear camera. Typically, the front camera is disposed on the front panel of the terminal and the rear camera is disposed on the rear surface of the terminal. In some embodiments, the at least two rear cameras are any one of a main camera, a depth camera, a wide-angle camera and a tele camera, so as to realize that the main camera and the depth camera are fused to realize a background blurring function, and the main camera and the wide-angle camera are fused to realize a panoramic shooting and Virtual Reality (VR) shooting function or other fusion shooting functions. In some embodiments, camera assembly 1406 may also include a flash. The flash lamp can be a single-color temperature flash lamp or a double-color temperature flash lamp. The dual-color temperature flash lamp refers to a combination of a warm light flash lamp and a cold light flash lamp, and can be used for light compensation under different color temperatures.
The audio circuitry 1407 may include a microphone and a speaker. The microphone is used for collecting sound waves of users and the environment, converting the sound waves into electric signals, and inputting the electric signals to the processor 1401 for processing, or inputting the electric signals to the radio frequency circuit 1404 for voice communication. For purposes of stereo acquisition or noise reduction, the microphone may be multiple, and disposed at different locations of the electronic device 1400. The microphone may also be an array microphone or an omni-directional pickup microphone. The speaker is used to convert electrical signals from the processor 1401 or the radio frequency circuit 1404 into sound waves. The speaker may be a conventional thin film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, not only the electric signal can be converted into a sound wave audible to humans, but also the electric signal can be converted into a sound wave inaudible to humans for ranging and other purposes. In some embodiments, audio circuitry 1407 may also include a headphone jack.
The positioning component 1408 is used to locate the current geographic location of the electronic device 1400 to enable navigation or location-based services (Location Based Service, LBS). The positioning component 1408 may be a global positioning system (Global Positioning System, GPS), beidou system or galileo system based positioning component.
The power supply 1409 is used to power the various components in the electronic device 1400. The power supply 1409 may be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 1409 includes a rechargeable battery, the rechargeable battery may be a wired rechargeable battery or a wireless rechargeable battery. The wired rechargeable battery is a battery charged through a wired line, and the wireless rechargeable battery is a battery charged through a wireless coil. The rechargeable battery may also be used to support fast charge technology.
Those skilled in the art will appreciate that the structure shown in fig. 14 is not limiting of the electronic device 1400 and may include more or fewer components than shown, or may combine certain components, or may employ a different arrangement of components.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof, and when implemented in software, it may be implemented in whole or in part in the form of a computer program product. The computer program product comprises one or more computer instructions that, when loaded and executed on a device, produce, in whole or in part, a process or function in accordance with embodiments of the present application. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by a wired (e.g., coaxial cable, fiber optic, digital subscriber line), or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer readable storage medium may be any available medium that can be accessed by a device or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape, etc.), an optical medium (such as a digital video disk (Digital Video Disk, DVD), etc.), or a semiconductor medium (such as a solid state disk, etc.).
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and the storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The foregoing description is provided for the purpose of illustration only and is not intended to limit the invention to the particular embodiments disclosed, but on the contrary, the intention is to cover all modifications, equivalents, alternatives, and alternatives falling within the spirit and scope of the invention.

Claims (30)

1. A method of data encoding, the method comprising:
acquiring an initial sequence and a parameter sequence to be encoded, wherein the parameter sequence comprises encoding parameters corresponding to each character in the initial sequence;
sequentially acquiring characters in the initial sequence from one end of the initial sequence, if one character is acquired, determining the first N bits in the code sequence based on a first code parameter corresponding to the currently acquired character in the parameter sequence if the currently acquired character is determined to be a high-frequency character in the initial sequence, and updating the first N bits into a first binary value, wherein a second binary value formed by the first N bits is not smaller than the first code parameter, a third binary value formed by the first N-1 bits is smaller than the first code parameter, and the first binary value is equal to the sum of the second binary value and a first preset value;
If it is determined that the currently acquired character is not a high frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value, wherein the fourth binary value is positively correlated with the first encoding parameter.
2. The method of claim 1, wherein the encoding parameters are used to describe a predicted probability at the time of character generation at corresponding positions in the initial sequence.
3. The method of claim 1, wherein the encoding parameters are used to describe a probability distribution of high frequency characters in the initial sequence.
4. A method according to any of claims 1-3, wherein said determining the first N bits in the encoded sequence based on the corresponding first encoding parameter of the currently acquired character in the parameter sequence comprises:
if the preceding in the coding sequenceThe binary value of the individual bit components is not less than M, the former ++is determined in the coding sequence>A number of bits, wherein M is the first encoding parameter;
if the preceding in the coding sequenceThe binary value of the individual bit components is smaller than M, the front ++is determined in the coding sequence >And a number of bits.
5. The method of any one of claims 1-4, wherein the initial sequence is a binary character sequence.
6. The method of claim 5, wherein the first predetermined value is 1.
7. The method of claim 5 or 6, wherein said updating the first bit in the encoded sequence to a fourth binary value comprises:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+1, wherein M is the first coding parameter.
8. The method of any one of claims 1-4, wherein the initial sequence is a ternary character sequence.
9. The method of claim 8, wherein the first predetermined value is 2.
10. The method according to claim 8 or 9, wherein said determining that the currently acquired character is not a high frequency character in the initial sequence comprises:
determining that the currently acquired character is an intermediate frequency character in the initial sequence;
the updating the first bit in the code sequence to a fourth binary value includes:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+2, wherein M is the first coding parameter.
11. The method according to any of claims 8-10, wherein said determining that the currently acquired character is not a high frequency character in the initial sequence comprises:
determining that the currently acquired character is a low frequency character in the initial sequence;
the updating the first bit in the code sequence to a fourth binary value includes:
and updating the first bit in the coding sequence to a fourth binary value corresponding to 2M+3, wherein M is the first coding parameter.
12. A method of data decoding, the method comprising:
acquiring a coding sequence and a parameter sequence, wherein the coding sequence is obtained by coding an initial sequence, and the parameter sequence comprises coding parameters corresponding to each character in the initial sequence;
sequentially acquiring coding parameters from one end of the parameter sequence, determining the first X bits in the coding sequence based on the currently acquired coding parameters, if the binary value formed by the first X bits is a fourth binary value, determining the corresponding character of the currently acquired coding parameters in the initial sequence as a first character, and updating the first X bits as 1, wherein the fourth binary value is positively correlated with the currently acquired coding parameters, the first character is not a high-frequency character in the initial sequence, the binary value formed by the first X bits is not less than a target value, and the binary value formed by the first X-1 bits is less than the target value, and the target value is determined according to the currently acquired coding parameters and the type of the initial sequence;
And if the binary value formed by the first X bits is smaller than the fourth binary value, determining that the character corresponding to the coding parameter in the initial sequence is a second character, and updating the first X bits to a second binary value, wherein the binary value formed by the first X bits is the sum of the second binary value and a first preset value, and the second character is a high-frequency character in the initial sequence.
13. The method of claim 12, wherein the encoding parameters are used to describe a predicted probability at the time of character generation at corresponding positions in the initial sequence.
14. The method of claim 12, wherein the encoding parameters are used to describe a probability distribution of high frequency characters in the initial sequence.
15. The method of any one of claims 12-14, wherein the initial sequence is a binary character sequence.
16. The method of claim 15, wherein the target value is m+1, and wherein the determining the first X bits in the encoded sequence based on the currently acquired encoding parameters comprises:
If the preceding in the coding sequenceThe binary value of the individual bit components is not less than M+1, the former ++is determined in the coding sequence>A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequenceThe binary value of the individual bit components is smaller than M+1, the former +.>And a number of bits.
17. The method according to claim 15 or 16, wherein the first preset value is 1.
18. The method according to any one of claims 15-17, wherein the fourth binary value is a 2m+1 corresponding binary value.
19. The method of any one of claims 12-15, wherein the initial sequence is a ternary character sequence.
20. The method of claim 19, wherein the target value is m+2, and wherein the determining the first X bits in the encoded sequence based on the currently acquired encoding parameters comprises:
if the preceding in the coding sequenceThe binary value of the individual bit components is not less than M+2, the former ++is determined in the coding sequence>A number of bits, where M is the currently acquired encoding parameter;
if the preceding in the coding sequence Binary values of the individual bit components are smaller than M+2, the former +.>And a number of bits.
21. The method of claim 20, wherein the first predetermined value is 2.
22. The method according to any of claims 19-21, wherein the first character is an intermediate frequency character in the initial sequence and the fourth binary value is a 2m+2 corresponding binary value, where M is the currently acquired encoding parameter.
23. The method of claim 22, wherein the method further comprises:
and if the binary value formed by the first X bits is larger than the fourth binary value, determining that the pre-coding character corresponding to the coding parameter is a third character, and updating the first X bits to 1, wherein the third character is a low-frequency character in the pre-coding character sequence.
24. The method according to any of claims 12-23, wherein the character in the initial sequence corresponding to the first acquired coding parameter is the last character encoded in the initial sequence, and the first X bits determined in the coding sequence for the first time are the last encoded bits in the coding sequence.
25. An apparatus for encoding data, the apparatus comprising:
the acquisition module is used for acquiring an initial sequence to be coded and a parameter sequence, wherein the parameter sequence comprises coding parameters corresponding to each character in the initial sequence;
the coding module is used for sequentially acquiring characters in the initial sequence from one end of the initial sequence, and if one character is acquired, determining that the currently acquired character is a high-frequency character in the initial sequence, based on a first coding parameter corresponding to the currently acquired character in the parameter sequence, determining first N bits in the coding sequence, and updating the first N bits into a first binary value, wherein a second binary value formed by the first N bits is not smaller than the first coding parameter, a third binary value formed by the first N-1 bits is smaller than the first coding parameter, and the first binary value is equal to the sum of the second binary value and a first preset value; if it is determined that the currently acquired character is not a high frequency character in the initial sequence, the first bit in the encoded sequence is updated to a fourth binary value, wherein the fourth binary value is positively correlated with the first encoding parameter.
26. An apparatus for decoding data, the apparatus comprising:
the acquisition module is used for acquiring a coding sequence and a parameter sequence, wherein the coding sequence is obtained by coding an initial sequence, and the parameter sequence comprises coding parameters corresponding to each character in the initial sequence;
the decoding module is used for sequentially acquiring coding parameters from one end of the parameter sequence, determining the first X bits in the coding sequence based on the currently acquired coding parameters, determining that a character corresponding to the currently acquired coding parameters in the initial sequence is a first character if the binary value formed by the first X bits is a fourth binary value, and updating the first X bits to 1, wherein the fourth binary value is positively correlated with the currently acquired coding parameters, the first character is not a high-frequency character in the initial sequence, the binary value formed by the first X bits is not less than a target value, and the binary value formed by the first X-1 bits is less than the target value, and the target value is determined according to the currently acquired coding parameters and the type of the initial sequence; and if the binary value formed by the first X bits is smaller than the fourth binary value, determining that the character corresponding to the coding parameter in the initial sequence is a second character, and updating the first X bits to a second binary value, wherein the binary value formed by the first X bits is the sum of the second binary value and a first preset value, and the second character is a high-frequency character in the initial sequence.
27. An electronic device comprising a processor and a memory for storing at least one piece of program code, the at least one piece of program code being loaded by the processor and performing the method of data encoding according to any one of claims 1 to 11.
28. An electronic device comprising a processor and a memory for storing at least one piece of program code, the at least one piece of program code being loaded by the processor and performing the method of data decoding according to any one of claims 12 to 24.
29. A computer readable storage medium for storing at least one piece of program code for performing the method of data encoding according to any one of claims 1 to 11.
30. A computer readable storage medium storing at least one piece of program code for performing the method of data decoding according to any one of claims 12 to 24.
CN202211148922.8A 2022-09-20 2022-09-20 Method, device and equipment for data coding and data decoding Pending CN117793361A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202211148922.8A CN117793361A (en) 2022-09-20 2022-09-20 Method, device and equipment for data coding and data decoding
PCT/CN2023/119240 WO2024061138A1 (en) 2022-09-20 2023-09-15 Data coding and data decoding method and apparatus, and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211148922.8A CN117793361A (en) 2022-09-20 2022-09-20 Method, device and equipment for data coding and data decoding

Publications (1)

Publication Number Publication Date
CN117793361A true CN117793361A (en) 2024-03-29

Family

ID=90385507

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211148922.8A Pending CN117793361A (en) 2022-09-20 2022-09-20 Method, device and equipment for data coding and data decoding

Country Status (2)

Country Link
CN (1) CN117793361A (en)
WO (1) WO2024061138A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118396992B (en) * 2024-06-26 2024-10-11 爱芯元智半导体股份有限公司 Apparatus, method and device for adaptively checking bit width of data

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6633242B2 (en) * 2001-02-08 2003-10-14 Sun Microsystems, Inc. Entropy coding using adaptable prefix codes
JP6511752B2 (en) * 2014-09-19 2019-05-15 カシオ計算機株式会社 Encoding apparatus, encoding method, decoding apparatus, decoding method, and program
CN109450596B (en) * 2018-11-12 2022-02-01 湖南瑞利德信息科技有限公司 Encoding method, decoding method, encoding device, decoding device, storage medium, and terminal
CN114626338A (en) * 2022-03-01 2022-06-14 杭州趣链科技有限公司 Character encoding method, character decoding method, character encoding system, character decoding system, character encoding device, character decoding device, and storage medium

Also Published As

Publication number Publication date
WO2024061138A1 (en) 2024-03-28

Similar Documents

Publication Publication Date Title
CN110363279B (en) Image processing method and device based on convolutional neural network model
US20210326118A1 (en) Chip including multiply-accumulate module, control method, electronic device, and storage medium
TWI383682B (en) Method, device and system for effectively coding and decoding of video data
CN111767025B (en) Chip comprising multiply accumulator, terminal and floating point operation control method
CN112449192A (en) Decoding method, encoding method and device
KR20160012903A (en) Compression techniques for dynamically-generated graphics resources
KR20140130196A (en) System, method, and computer program product for decompression of block compressed images
WO2024061138A1 (en) Data coding and data decoding method and apparatus, and device
CN109151477B (en) Image data encoding and decoding methods and devices
EP4318307A1 (en) Two-dimensional code encoding and decoding methods, electronic device
JP6745020B2 (en) Method, computer program, computer-readable recording medium and device
US20230328233A1 (en) Reference frame selection method and apparatus, device, and medium
CN111598919B (en) Motion estimation method, motion estimation device, storage medium and electronic equipment
CN112416294B (en) Processor, binary accumulation method thereof, and computer readable medium
CN113918246B (en) Function control method, function control device, storage medium, and electronic apparatus
CN111783962B (en) Data processing method, data processing device, storage medium and electronic equipment
EP3618445A1 (en) Method for performing motion estimation, apparatus, device and storage medium
CN113657584B (en) Neural network model calculation method, data processing method, electronic device and medium
CN111104566B (en) Feature index encoding method, device, electronic equipment and storage medium
CN116432737A (en) Model compression training method, device and equipment based on deep learning
CN112054804A (en) Method and device for compressing data and method and device for decompressing data
CN110969217A (en) Method and device for processing image based on convolutional neural network
CN111382325B (en) Pattern string allocation method and device for pattern string allocation
CN113658283B (en) Image processing method, device, electronic equipment and storage medium
CN110381146B (en) Batch operation processing method and device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication