Image encoding method, readable medium and electronic device thereof
By performing recombination calculation and one-dimensional DCT transformation on the residual blocks of the video data stream, the problem of high complexity of the existing video encoding medium-rate distortion optimization calculation is solved, and the encoding efficiency improvement and robustness maintenance with low complexity is achieved.
Patent Information
- Application Number
- CN202210711387.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-22
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2042-06-22
AI Technical Summary
The rate distortion optimization methods in existing video encoding have high computational complexity, making it difficult to design low-complexity computing models to improve coding efficiency.
By recombining the residual blocks of the video data stream, one-dimensional DCT row transformation and one-dimensional DCT column transformation are used instead of the traditional two-dimensional DCT transformation, reducing the calculation amount and maintaining a certain accuracy, and selecting the appropriate prediction encoding mode for encoding .
The complexity of the rate distortion optimization method is reduced, the encoding efficiency is improved, and the encoder is maintained, achieving the optimal balance between bit rate and distortion.
Smart Images

Figure CN115118976B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to an image encoding method, a readable medium and an electronic device thereof. Background Art
[0002] In modern life, it is often necessary to transmit and store huge video data streams in limited channels. Therefore, it is necessary to use lossy compression to compress (encode) the video data stream. However, this method introduces distortion while reducing the bit rate (the amount of data required for encoding). Rate Distortion Optimization (RDO) is a method that balances bit rate and distortion to achieve an optimal balance point, that is, an optimization method for improving video compression performance. This method is applied to encoders including video compression, as well as various other multimedia encodings including video, audio, etc. That is to say, if the picture quality and file size need to be considered at the same time during encoding, the RDO method can be used.
[0003] When using the RDO method, each block of the video screen needs to be calculated through an entropy encoder to measure the actual bit cost, which is a complex and large amount of calculation. Therefore, how to design a lower-complexity and less-calculated RDO calculation model is an important part of the encoder hardware implementation process. Summary of the invention
[0004] The purpose of the present application is to provide an image coding method, a readable medium and an electronic device thereof, through which the complexity of the existing video coding RDO method can be reduced while the encoder maintains a high robustness. The image coding method of the present application can not only be applied to encoders of various video contents, but also effectively improve the coding efficiency.
[0005] A first aspect of the present application provides an image encoding method for an electronic device, the method comprising:
[0006] Obtaining an image to be encoded, and dividing the image to be encoded into a plurality of blocks to be encoded;
[0007] Calculate the rate-distortion cost of each block to be encoded;
[0008] Selecting a prediction coding mode for encoding based on the rate-distortion cost of each block to be encoded;
[0009] The calculation of the rate-distortion cost of each block to be encoded includes:
[0010] Obtaining a first residual block of a block to be encoded;
[0011] Performing DCT transformation on the first residual block to obtain a second transformation block, wherein the DCT transformation includes multiple one-dimensional DCT row transformations and multiple one-dimensional DCT column transformations, and the number of one-dimensional DCT row transformations is not equal to the number of one-dimensional DCT column transformations;
[0012] Calculating a distortion value of the block to be encoded according to the second transform block;
[0013] The rate-distortion cost of the block to be encoded is determined according to the distortion value.
[0014] In a possible implementation of the first aspect, the step of obtaining a first residual block of a block to be encoded includes:
[0015] Performing directional prediction calculation on the initial residual block of the block to be encoded to obtain a directional result, where the directional result includes a horizontal direction or a vertical direction;
[0016] A data mapping calculation is performed according to the direction result to obtain a first residual block.
[0017] In a possible implementation of the first aspect, the step of performing directional prediction calculation on an initial residual block of a block to be encoded to obtain a directional result includes:
[0018] Perform n-times row horizontal gradient calculation on the pixels in the initial residual block according to the row sequence number, and accumulate the results of the row horizontal gradient calculation to obtain the horizontal gradient value;
[0019] Perform n column longitudinal gradient calculations on the pixels in the initial residual block in sequence according to the column numbers, and accumulate the results of the column longitudinal gradient calculations to obtain the longitudinal gradient value;
[0020] Compare the magnitude of the transverse gradient value and the longitudinal gradient value;
[0021] If the horizontal gradient value is greater than the vertical gradient value, the direction is determined to be the horizontal direction;
[0022] Otherwise, the direction is determined to be the longitudinal direction;
[0023] Here, n is a natural number greater than or equal to 1.
[0024] In a possible implementation of the first aspect, the step of performing data mapping calculation according to the direction result to obtain the first residual block includes:
[0025] If the direction result is the horizontal direction, the initial residual block is matrix transposed to obtain the first residual block.
[0026] If the direction result is the vertical direction, the first residual block is the initial residual block.
[0027] In a possible implementation of the first aspect, the step of performing DCT transformation on the first residual block to obtain the second transformed block includes:
[0028] If the first residual block is an m×m matrix, performing one-dimensional DCT row transform on m rows in the first residual block in sequence to obtain a first transform block;
[0029] Performing one-dimensional DCT column transformation on g columns whose column numbers are not m in the first transformation block in sequence to obtain a second transformation block;
[0030] Among them, the value range of the row number of the first residual block is [1, m], the value range of the column number of the first residual block is [1, m], m is 2 to the power of k, m is a natural number greater than or equal to 4, k is a natural number greater than or equal to 2, g is a natural number greater than or equal to 1, and the value range of g is [1, m-1].
[0031] In a possible implementation of the first aspect, the step of performing data mapping calculation according to the direction result to obtain the first residual block includes:
[0032] If the direction result is the longitudinal direction, the initial residual block is subjected to matrix transposition to obtain the first residual block.
[0033] If the direction result is the horizontal direction, the first residual block is the initial residual block.
[0034] In a possible implementation of the first aspect, the step of performing DCT transformation on the first residual block to obtain the second transformed block includes:
[0035] If the first residual block is an m×m matrix, performing one-dimensional DCT column transform on m columns in the first residual block in sequence to obtain a first transform block;
[0036] Performing one-dimensional DCT row transform on g rows whose row numbers are not m in the first transform block in sequence to obtain a second transform block;
[0037] Among them, the value range of the row number of the first residual block is [1, m], the value range of the column number of the first residual block is [1, m], m is 2 to the power of k, m is a natural number greater than or equal to 4, k is a natural number greater than or equal to 2, g is a natural number greater than or equal to 1, and the value range of g is [1, m-1].
[0038] In a possible implementation of the first aspect above, the electronic device includes a processor, and the method is implemented by the processor.
[0039] In a second aspect, an embodiment of the present application provides an electronic device, including:
[0040] An acquisition unit, used for acquiring an image to be encoded and dividing the image to be encoded into a plurality of blocks to be encoded;
[0041] A calculation unit, used for calculating the rate distortion cost of each block to be encoded;
[0042] and a coding unit, configured to select a prediction coding mode for coding based on the rate-distortion cost of each block to be coded;
[0043] The calculation unit calculates the rate-distortion cost of each block to be encoded in the following manner:
[0044] Obtaining a first residual block of a block to be encoded;
[0045] Performing DCT transformation on the first residual block to obtain a second transformation block, wherein the DCT transformation includes multiple one-dimensional DCT row transformations and multiple one-dimensional DCT column transformations, and the number of one-dimensional DCT row transformations is not equal to the number of one-dimensional DCT column transformations;
[0046] Calculating a distortion value of the block to be encoded according to the second transform block;
[0047] The rate-distortion cost of the block to be encoded is determined according to the distortion value.
[0048] In a third aspect, an embodiment of the present application provides a readable medium having instructions stored thereon, which, when executed on an electronic device, causes the electronic device to execute the above-mentioned first aspect and any one of the image encoding methods in various possible implementations of the first aspect.
[0049] In a fourth aspect, an embodiment of the present application provides an electronic device, including:
[0050] a memory for storing instructions to be executed by one or more processors of the electronic device, and
[0051] The processor is one of the processors of the electronic device, and is used to execute the above-mentioned first aspect and any one of the image encoding methods in various possible implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 According to an embodiment of the present application, an image coding scene graph is shown;
[0053] Figure 2 According to an embodiment of the present application, a flow chart of an RDO method for image encoding is shown;
[0054] Figure 3 According to an embodiment of the present application, a flowchart of a method for image encoding is shown;
[0055] Figure 4 According to an embodiment of the present application, a flow chart of a method for reorganizing and calculating an initial residual block to obtain a first residual block is shown;
[0056] Figure 5 According to an embodiment of the present application, a flowchart of another RDO method for image encoding is shown;
[0057] Figure 6 According to an embodiment of the present application, a schematic diagram of a method for performing one-dimensional DCT column transform calculation on an input matrix is shown;
[0058] Figure 7 A block diagram of an electronic device is shown according to an embodiment of the present application;
[0059] Figure 8 A block diagram of another electronic device is shown according to an embodiment of the present application;
[0060] Fig. 9 A block diagram of a system on chip is shown according to an embodiment of the present application. DETAILED DESCRIPTION
[0061] Embodiments of the present application include but are not limited to an image encoding method, a readable medium and an electronic device thereof.
[0062] The embodiment of the present application relates to an image coding method, which reorganizes and calculates the residual block of the input video data stream and then sequentially inputs the updated residual block into a DCT converter, a quantizer, an entropy encoder, etc. for calculation. After obtaining the rate distortion cost (RD Cost), a prediction coding mode is selected according to the rate distortion cost for encoding. The rate distortion optimization algorithm adopted in the present application first updates the initial residual block, and its purpose is to use the updated residual block to replace the initial residual block for DCT transformation, so as to reduce the amount of calculation while ensuring the accuracy of the calculation to a certain extent. The updating method of the residual block may include methods such as directional prediction and data mapping. The directional prediction can judge the directional result of the initial residual block according to the horizontal gradient value and the vertical gradient value of the initial residual block. If it is determined that the initial residual block is in a horizontal direction, the initial residual block is subjected to operations such as matrix transposition to obtain an updated residual block, and if it is determined that the initial residual block is in a vertical direction, the initial residual block is retained, that is, the initial residual block is an updated residual block, then after obtaining the updated residual block, one-dimensional DCT row transform and one-dimensional DCT column transform are used to replace the existing two-dimensional DCT transform, including first inputting all rows of the updated residual block in the one-dimensional DCT row transform calculation for calculation, and then inputting part of the columns except the last column in the one-dimensional DCT column transform for calculation; if it is determined that the initial residual block is in a vertical direction, the initial residual block is subjected to operations such as matrix transposition to obtain an updated residual block, and if it is determined that the initial residual block is in a horizontal direction, the initial residual block is retained, that is, the initial residual block is an updated residual block, then firstly all columns of the initial residual block are input in the one-dimensional DCT column transform calculation for calculation, and then in the one-dimensional DCT row transform, part of the rows except the last row are input for calculation. For example, the left half of the columns of the updated residual block can be used for one-dimensional DCT column transformation or the upper left row of the updated residual block can be used for one-dimensional DCT row transformation. Different from the existing DCT transformation, only one-dimensional DCT column transformation calculation of a part of the columns or one-dimensional DCT row transformation calculation of a part of the rows is performed, which reduces the amount of calculation originally using all columns or all rows to participate in the calculation. At the same time, relying on the reorganization calculation of the residual block, it ensures the degree of accuracy reduction caused by reducing the participation of some columns or some rows in the RDO calculation. Finally, the DCT transformation result is input into the quantizer, etc. to obtain the RD Cost, and then the appropriate prediction coding mode can be selected for encoding according to the RD Cost. Using part of the data of the updated residual block to replace all the data of the original residual block for rate-distortion optimization calculation reduces the amount of calculation of the traditional rate-distortion optimization algorithm, reduces the complexity of the existing RDO method, and effectively improves the coding efficiency, so that the encoder maintains a high robustness.
[0063] In order to better illustrate the technical solution of this application, the technologies or technical terms involved are now explained as follows:
[0064] Video data stream: The video data stream in this application refers to the stream data that has not been compressed by a compression algorithm, which is the decoded stream data, also known as the original stream. However, in actual situations, the video data stream can also represent the stream data that has been compressed by a compression algorithm, also known as the encoded stream.
[0065] Frame: A frame is the smallest unit of a single image in a video stream. Video encoding / compression technology uses the smallest possible space to store a group of temporally continuous frame data. A frame is a rectangle composed of pixels. For example, a 4×4 image is composed of 16 pixels.
[0066] Bit rate (BPS): The full name is Bits Per Second, which refers to the number of data bits transmitted per second.
[0067] I frame (Intra picture): also known as intra-frame coding frame, i.e. key frame. Generally speaking, I frame does not need to rely on the information of previous and next frames and can be decoded independently. I frame compression only compresses the redundant information in space.
[0068] P frame (Predictive picture): also known as forward prediction coding frame, also known as inter-frame prediction coding frame. P frame needs to rely on the previous I frame or P frame for encoding and decoding, because generally speaking, P frame stores the difference between the current frame and the previous frame (the previous frame may be an I frame or a P frame), compressing the temporal redundant information, or extracting the motion characteristics.
[0069] B frame (Bi-directional Prediction Frame): also known as bidirectional prediction interpolation coding frame, abbreviated as bidirectional prediction coding frame, stores the difference between the current frame and the previous and next frames.
[0070] Intra Prediction: In the previous H.26x series and MPEG-X series standards, intra prediction, that is, spatial prediction, is used. For example, for each 4×4 block (except for special treatment of edge blocks), each pixel can be predicted by the different weighted sums (some weights can be 0) of the 17 closest previously encoded pixels in the upper left corner of the block where the pixel is located. This predictive coding algorithm based on spatial domain entropy can remove the spatial redundancy between adjacent blocks and achieve more effective compression, which is also called spatial prediction.
[0071] Inter Prediction: refers to the use of the correlation between video frames to remove the temporal redundant information between video frames. The basic principle is to find the reference block with the smallest difference from the current block from the adjacent reference reconstructed frames through motion estimation, and use its reconstructed value as the prediction block of the current block, which is also called temporal prediction or motion prediction.
[0072] Entropy coding: The entropy coding of context-based binary arithmetic coding (CBAC) mainly includes three processes: binarization of the syntax elements to be encoded, context modeling and binary arithmetic coding.
[0073] Predictive coding is one of the most important coding methods in video coding technology. It is described in international video coding standards such as MPEG1 / 2 / 4, H.264, VC-1 standard, coding systems based on On2 technologies such as VP-6, VP-7 and VP-8, Dirac codec and Theora video codec. Predictive coding refers to obtaining a predicted value of a true value through some information known to both the codec and the decoder, and reducing the bit rate by encoding the residual between the true value and the predicted value. When decoding, only the residual and the predicted value of the true value need to be decoded to decode the true value. Predictive coding includes intra-frame predictive coding and inter-frame predictive coding. In the coding technology, the video data stream to be encoded includes multiple frames, each of which represents a video image at a different time. Each frame is divided into macroblocks (MB), and the macroblocks are divided into blocks, each of which includes multiple pixels. Each frame can also be divided into independently decodable slices, each of which includes one or more macroblocks. The encoder processes the video data stream block by block, and the size of the video block (that is, macroblock) is N×M (for example, N=M=16, N=M=8, N=M=4, etc.). The input video block can be intra-frame predicted and / or inter-frame predicted to obtain a prediction block, and a summer is used to generate a residual signal representing the difference between the original block to be encoded and the predicted block, which is then encoded through a transformer, quantizer, and entropy encoder. The optimal prediction mode does not necessarily satisfy the minimum final residual obtained by the prediction, but refers to the optimal final coding performance after the residual signal passes through other coding modules, such as transformation, quantization, and entropy coding. The purpose of using the rate-distortion optimization method in predictive coding technology is to select the prediction mode with the best final coding performance.
[0074] Rate-distortion optimization (RDO): is a method of improving video quality in video compression. The amount of distortion (loss of video quality) is optimized for the amount of data (rate) required to encode the video. RDO is primarily used by video encoders and can be used to improve quality in any video encoding situation where decisions must be made that affect both file size and quality.
[0075] Discrete Cosine Transform (DCT): It is a transform related to Fourier transform, similar to discrete Fourier transform, but only uses real numbers. Discrete cosine transform is equivalent to a discrete Fourier transform of about twice its length. The generation of integer DCT transform involved in this application solves the problems of large calculation accuracy error and low coding efficiency. Its characteristics are to replace the floating point transformation matrix of DCT with integer transformation matrix, so that the transformation process is completely integer operation, there is no accuracy error, and the reversibility of coding is guaranteed. At the same time, integer multiplication can be replaced by addition, subtraction and shift operation, and the amount of operation is greatly reduced. The low-complexity RDO method for video coding of this application can be applied to scenarios where video data encoding is required. For example, the scheme of this application can be applied to video conferencing, video phone, Internet broadband video service, digital video broadcasting wireless broadband multimedia communication, virtual reality and augmented reality and video surveillance. The following is an example of the implementation process of the rate-distortion optimization method.
[0076] It can be understood that there are many scenarios where video encoding is required. In addition to the common video shooting and data compression storage through smartphones, video encoding is also required in scenarios such as video conferencing, digital TV, and storing compressed video on digital media including CDs, DVDs, memory sticks, etc.
[0077] Figure 1 According to an embodiment of the present application, a scene graph for image coding is shown. Figure 1 The scenario includes: an electronic device 10 and an electronic device 30, and the electronic device 10 and the electronic device 30 may be connected via one or more networks.
[0078] In some embodiments of the present application, the electronic device 10 can encode the video data stream and send the compressed video data to the electronic device 30, and the electronic device 30 can decode the received video data and implement the application. It can be understood that the electronic device 10 can directly encode the video data stream. However, due to the huge amount of video data stream in the actual scene, the use of encoding to compress the video stream data can undoubtedly save a huge amount of storage space. At the same time, the consequence is that the higher the degree of data compression, the higher the distortion. The role of the RDO algorithm model in the electronic device 10 includes: under a certain bit rate limit, reducing data distortion and improving the subjective quality of the video, that is, improving the user's experience; and compressing the video stream data to a minimum, that is, the minimum bit rate, while allowing a certain amount of distortion.
[0079] In some embodiments, the electronic device 10 or the electronic device 30 may include but is not limited to smart phones, vehicle-mounted devices, personal computers, artificial intelligence devices, tablet computers, personal digital assistants, smart wearable devices (such as smart watches or bracelets, smart glasses), smart TVs (or smart large screens, smart screens, or large-screen TVs, etc.), virtual reality / mixed reality / augmented display devices, servers, etc.
[0080] Figure 2 According to an embodiment of the present application, a flow chart of an RDO method for image coding is shown. Figure 2 As shown, the electronic device 10 is used to implement the RDO method in video coding. In actual application scenarios, the video data stream to be encoded includes multiple frames of video images, and each frame of video image corresponds to a specific moment. The frame types of the image may include I frames, P frames, and B frames. The images of the I frame type may adopt the intra-frame prediction coding mode, and the images of the other types may adopt the inter-frame prediction coding mode. Each frame of the video image may be divided into multiple macroblocks (MBs), and the size of each macroblock is N×N, (N is 2 to the power of n, n is a natural number greater than or equal to 2, then N can be equal to 4, 8, 16, etc.), it can be understood that according to the actual application needs, when the image is divided, the size of the macroblock is not specifically limited.
[0081] The electronic device 10 can perform intra-frame prediction and / or inter-frame prediction on the input macroblock to extract the data information of the macroblock to obtain a prediction block, and generate a residual signal representing the difference between the original macroblock to be encoded and the prediction block through the summer in the electronic device 10, which is the initial residual block. The electronic device 10 calculates the sum of square errors (SSE) of the data obtained by performing DCT transformation calculation, quantization calculation, and inverse quantization calculation on the input initial residual block and the data after performing DCT transformation calculation and quantization calculation on the input initial residual block, that is, obtains the distortion of the input video block. The bit rate of the video data stream can be obtained by performing DCT transformation calculation and quantization calculation on the input initial residual block to obtain quantization coefficients, and then performing entropy coding on the quantization coefficients. After the distortion and bit rate are obtained, the rate-distortion cost (RD Cost) can be calculated according to the rate-distortion cost formula (1) J=D+λR, where D is the distortion, R is the bit rate, λ is the Lagrangian coefficient, and J is the RD Cost. The purpose of the rate-distortion optimization method is to select the prediction coding mode that minimizes the RD Cost as the final coding mode. When the RD Cost is the smallest, the bit rate required for coding and the distortion caused by coding are in the best balance state, that is, both the bit rate size is taken into account and a relatively better distortion state is maintained, achieving the best balance between the bit rate and the user experience. It is understandable that the RD Cost will change accordingly with the actual needs of the user and the actual state of the electronic device at the user end.
[0082] Combine the following Figures 3 to 5 The process of the method for performing image encoding by the electronic device 10 of the present application is described in detail.
[0083] Figure 3 is a flowchart of an image encoding method according to an embodiment of the present application. Figure 5 FIG. 1 is a flow chart of another RDO method for image coding according to an embodiment of the present application. Figure 3 and Figure 5 As shown, as an example but not a limitation, the above method may include the following steps:
[0084] S100, the electronic device 10 obtains an image to be encoded, and divides the image to be encoded into a plurality of blocks to be encoded;
[0085] S200, the electronic device 10 calculates the rate-distortion cost of each of the blocks to be encoded;
[0086] S300, the electronic device 10 selects a prediction coding mode for encoding based on the rate-distortion cost of each block to be encoded;
[0087] In step S200, the electronic device 10 calculates the rate-distortion cost of each of the above blocks to be encoded, including:
[0088] S210, the electronic device 10 obtains a first residual block of the block to be encoded;
[0089] S220, the electronic device 10 performs DCT transformation on the first residual block to obtain a second transformation block, wherein the DCT transformation includes multiple one-dimensional DCT row transformations and multiple one-dimensional DCT column transformations, and the number of the one-dimensional DCT row transformations is not equal to the number of the one-dimensional DCT column transformations;
[0090] S230, the electronic device 10 calculates the distortion value of the block to be encoded according to the second transform block;
[0091] S240: The electronic device 10 determines a rate-distortion cost of the block to be encoded according to the distortion value.
[0092] In this embodiment, after acquiring the coded image, the electronic device 10 divides it into a plurality of coded blocks. After acquiring the first residual block of the coded block, one-dimensional DCT row transform and one-dimensional DCT column transform are used to replace the two-dimensional DCT transform, and the number of one-dimensional DCT column transforms is not equal to the number of one-dimensional DCT row transforms, which can reduce the amount of calculation required for all columns to participate in the one-dimensional DCT column transform or all rows to participate in the one-dimensional DCT row transform in the original rate-distortion optimization calculation. The first residual block obtained above is used for transformation calculation, which ensures a certain accuracy while reducing the amount of calculation. The specific contents of obtaining the first residual block and DCT transformation calculation are described in the following description of step S210 and step S220.
[0093] The electronic device 10 can calculate the sum of square errors (SSE) of the data obtained by performing DCT transformation calculation, quantization calculation, and inverse quantization calculation on the input first residual block and the data after performing DCT transformation calculation and quantization calculation on the input first initial residual block, and obtain the distortion of the input video block. The electronic device 10 can obtain the quantization coefficient by performing DCT transformation calculation and quantization calculation on the input initial residual block in sequence, and then obtain the bit rate of the video data stream by entropy coding the quantization coefficient. The obtained bit rate and the above distortion are brought into the rate-distortion cost formula to obtain the rate-distortion cost (RD Cost). The rate-distortion cost formula here is J=D+λR, where D is the distortion, R is the bit rate, λ is the Lagrangian coefficient, and J is the RD Cost. The method for obtaining the Lagrangian coefficient and the specific value are not limited here.
[0094] Figure 4FIG. 1 is a flow chart of a method for recombining and calculating an initial residual block to obtain a first residual block according to an embodiment of the present application. Figure 4 As shown, preferably, in step S210, the step of the electronic device 10 obtaining the first residual block of the block to be encoded includes:
[0095] S211, the electronic device 10 performs directional prediction calculation on the initial residual block of the block to be encoded to obtain a directional result, where the directional result includes a horizontal direction or a vertical direction;
[0096] S212: The electronic device 10 performs data mapping calculation according to the above direction result to obtain a first residual block.
[0097] In this embodiment, the direction result of the initial residual block can be determined by performing directional prediction estimation on the initial residual block, so as to provide a basis for subsequent data mapping calculation and transformation processing.
[0098] Preferably, in step 211, the method in which the electronic device 10 performs directional prediction calculation on the initial residual block of the block to be encoded to obtain a directional result includes:
[0099] S2111, the electronic device 10 performs n-times row horizontal gradient calculation on the pixels in the initial residual block according to the row sequence number, and accumulates the results of the row horizontal gradient calculation to obtain a horizontal gradient value;
[0100] S2112, the electronic device 10 performs n column longitudinal gradient calculations on the pixels in the initial residual block in sequence according to the column numbers, and accumulates the results of the column longitudinal gradient calculations to obtain a longitudinal gradient value;
[0101] S2113, the electronic device 10 compares the horizontal gradient value and the vertical gradient value;
[0102] S2114, if the horizontal gradient value is greater than the vertical gradient value, the electronic device 10 determines that the direction result is a horizontal direction;
[0103] S2115, otherwise, the electronic device 10 determines that the direction result is a vertical direction;
[0104] Here, n is a natural number greater than or equal to 1.
[0105] After obtaining the horizontal gradient value and the vertical gradient value of the first residual block, the gradient direction of the initial residual block can be determined, and then the initial residual block is converted into the first residual block through data mapping calculation.
[0106] Preferably, in the first possibility:
[0107] In step 212, the electronic device 10 performs data mapping calculation according to the above direction result to obtain a first residual block, including:
[0108] S2121: If the direction result is a horizontal direction, the electronic device 10 performs a matrix transposition on the initial residual block to obtain a first residual block.
[0109] S2122: If the direction result is a vertical direction, the first residual block is the initial residual block.
[0110] The magnitude of the horizontal gradient value and the vertical gradient value here reflect the distribution position of the coefficients obtained after the subsequent DCT transformation of the pixel values in the initial residual block, that is, when a one-dimensional DCT horizontal transformation is performed followed by a one-dimensional DCT column transformation, if the horizontal gradient value is greater than the vertical gradient value, the calculated transformation coefficients are mainly distributed in the upper half of the transformation block.
[0111] According to step S2121 and step S2122, in step S220, the method in which the electronic device 10 performs DCT transformation on the first residual block to obtain a second transformation block includes:
[0112] S2201A, if the first residual block is an m×m matrix, the electronic device 10 sequentially performs a one-dimensional DCT row transform on the m rows in the first residual block to obtain a first transform block;
[0113] S2201B, the electronic device 10 sequentially performs one-dimensional DCT column transformation on the g columns whose column numbers are not m in the first transformation block to obtain a second transformation block;
[0114] Among them, the value range of the row number of the above-mentioned first residual block is [1, m], the value range of the column number of the above-mentioned first residual block is [1, m], m is 2 to the power of k, m is a natural number greater than or equal to 4, k is a natural number greater than or equal to 2, g is a natural number greater than or equal to 1, and the value range of g is [1, m-1].
[0115] Preferably, in the second possibility:
[0116] In step 212, the electronic device 10 performs data mapping calculation according to the above direction result to obtain a first residual block, including:
[0117] S2123: If the direction result is a vertical direction, the electronic device 10 performs matrix transposition on the initial residual block to obtain a first residual block.
[0118] S2124: If the direction result is a horizontal direction, the first residual block is the initial residual block.
[0119] The magnitude of the horizontal gradient value and the vertical gradient value here reflect the distribution position of the coefficients obtained after the subsequent DCT transformation of the pixel values in the initial residual block, that is, when a one-dimensional DCT column transformation is performed followed by a one-dimensional DCT row transformation, if the vertical gradient value is greater than the horizontal gradient value, the calculated transformation coefficients are mainly distributed in the left half of the transformation block.
[0120] According to step S2123 and step S2124, in step S220, the method in which the electronic device 10 performs DCT transformation on the first residual block to obtain a second transformation block includes:
[0121] S2201C: if the first residual block is an m×m matrix, the electronic device 10 sequentially performs a one-dimensional DCT column transform on the m columns in the first residual block to obtain a first transform block;
[0122] S2201D, the electronic device 10 sequentially performs one-dimensional DCT row transform on g rows whose row numbers are not m in the first transform block to obtain a second transform block;
[0123] Among them, the value range of the row number of the above-mentioned first residual block is [1, m], the value range of the column number of the above-mentioned first residual block is [1, m], m is 2 to the power of k, m is a natural number greater than or equal to 4, k is a natural number greater than or equal to 2, g is a natural number greater than or equal to 1, and the value range of g is [1, m-1].
[0124] In the present application, the method for calculating the horizontal gradient value and the vertical gradient value of the initial residual block can be adjusted accordingly according to actual needs. For example, if the size of the initial residual block is an m×m matrix, and m is a natural number greater than or equal to 4, the pixel value of the fourth row can be subtracted from the pixel value of the third row, and the absolute values of the four values obtained are taken, the pixel value of the third row can be subtracted from the pixel value of the second row, and the absolute values of the four values obtained are taken, the pixel value of the second row can be subtracted from the pixel value of the first row, and the absolute values of the four values obtained are taken, and then all the obtained results are accumulated and summed to obtain the horizontal gradient value of the initial residual block. Here, the pixel values of the fourth row can be subtracted from the pixel values of the second row, and the absolute values of the four values obtained are taken, the pixel values of the third row can be subtracted from the pixel values of the first row, and the absolute values of the four values obtained are taken, and then the obtained results are accumulated and summed to obtain the horizontal gradient value of the initial residual block; the pixel values of the fourth row can also be subtracted from the pixel values of the first row, and the absolute values of the four values obtained are taken, and then all the results are accumulated and summed to obtain the horizontal gradient value of the initial residual block; the calculation method of the vertical gradient value is similar to the horizontal gradient value, and will not be described further here. The specific method of obtaining the horizontal gradient value and the vertical gradient value will not be limited in this application.
[0125] In traditional rate-distortion optimization, a two-dimensional DCT transform method is usually used to transform and calculate the residual block. In this application, a two-step one-dimensional DCT transform method is used to replace the two-dimensional DCT transform method, including a one-dimensional DCT row transform method in the first step and a one-dimensional DCT column transform method in the second step.
[0126] The two-dimensional integer DCT transform can be expressed by formula (2):
[0127] Y=C*X*C T (2)
[0128] Where X is the input matrix for the two-dimensional integer discrete cosine transform, C represents the coefficient matrix of the integer discrete cosine transform, * represents matrix multiplication, and C T represents the transposed matrix of C, and Y represents the calculation result of the two-dimensional integer discrete cosine transform. The size of the matrices C, X, and Y in this application can be 2 2 ×2 2 , 2 3 ×2 3 , 2 4 ×2 4 ,etc.
[0129] According to the properties of matrix operations, we can transform formula (2) to obtain:
[0130] Y=((X*C T ) T *C T ) T (3)
[0131] If the order
[0132] D=(X*C T ) T (4)
[0133] So
[0134] Y=(D*C T ) T (5)
[0135] In this way, the two-dimensional integer DCT transform can be converted into two one-dimensional integer DCT transforms. Formula (4) means that all coefficients of each row of matrix Y are first subjected to a one-dimensional integer discrete cosine transform and the matrix obtained by the transform is transposed, that is, a one-dimensional DCT row transform. Formula (5) means that a one-dimensional integer discrete cosine transform is performed on matrix D and the transform result is transposed, that is, a one-dimensional DCT column transform. The operation result Y is also the operation result of the two-dimensional integer discrete cosine transform.
[0136] S320, the electronic device 10 performs one-dimensional DCT column transformation on the g columns whose column numbers are not m in the first transformation block to obtain a second transformation block.
[0137] Among them, the value range of the row number of the above-mentioned first residual block is [1, m], the value range of the column number of the above-mentioned first residual block is [1, m], m is 2 to the power of k, m is a natural number greater than or equal to 4, k is a natural number greater than or equal to 2, g is a natural number greater than or equal to 1, and the value range of g is [1, m-1].
[0138] Butterfly operation can be used to perform one-dimensional DCT row transform and one-dimensional DCT column transform. Figure 6 FIG. 1 is a schematic diagram of a method for performing one-dimensional DCT column transform calculation on an input matrix according to an embodiment of the present application, as shown in FIG. Figure 6 As shown,
[0139] For example, butterfly operation is used to perform one-dimensional column transformation on the input matrix D:
[0140] Among them, x n , n = 0, 1, 2, 3 are the elements of any column in the input matrix D, and the result of the one-dimensional column transformation is p n , n = 0, 1, 2, 3, for a 4×4 matrix, if all columns are transformed into one-dimensional DCT columns, four butterfly operations are required, namely:
[0141] The first butterfly operation input is x0 = x 00 , x1=x 10 , x2=x 20 , x3=x 30 , the output is p0=p 00 , p1=p 10 , p2=p 20 , p3=p 30 ;
[0142] The second butterfly operation input is x0 = x 01 , x1=x 11 , x2=x 21 , x3=x 31 , the output is p0=p 01 , p1=p 11 , p2=p 21 , p3=p 31 ;
[0143] The first butterfly operation input is x0 = x 02 , x1=x 12 , x2=x 22 , x3=x 32 , the output is p0=p 02 , p1=p12 , p2=p 22 , p3=p 32 ;
[0144] The first butterfly operation input is x0 = x 03 , x1=x 13 , x2=x 23 , x3=x 33 , the output is p0=p 03 , p1=p 13 , p2=p 23 , p3=p 33 ;
[0145] The result of four one-dimensional column transformations is a 4×4 matrix P, where x 00 , x 10 , x 20 , x 30 is the first column of the input matrix D, x 01 , x 11 , x 21 , x 31 is the second column of the input matrix D, x 02 , x 12 , x 22 , x 32 The third column of the input matrix D, x 03 , x 13 , x 23 , x 33 is the fourth column of the input matrix D; p 00 , p 10 , p 20 , p 30 is the first column of the matrix P, p 01 , p 11 , p 21 , p 31 is the second column of the matrix P, p 02 , p 12 , p 22 , p 32 is the third column of the matrix P, p 03 , p 13 , p 23 , p 33 is the fourth column of the matrix P.
[0146] In the first possibility, the magnitude of the horizontal gradient value and the vertical gradient value reflects the distribution position of the coefficients obtained by the pixel values in the initial residual block after the subsequent DCT transformation, that is, when the horizontal gradient value is greater than the vertical gradient value after the horizontal transformation and then the column transformation, the transformation coefficients generated by the calculation are mainly distributed in the upper half of the transformation block. At this time, the initial residual block is transposed to obtain the first residual block, or if the vertical gradient value is greater than or equal to the horizontal gradient value, the initial residual block is used as the first residual block. The first residual block is subjected to a one-dimensional DCT row transformation for all rows, and then the first residual block is no longer subjected to a one-dimensional DCT column transformation calculation, but the first residual block is selected from the left to the right, except for the last column, and the other columns are subjected to a one-dimensional DCT column transformation, such as only the left half of the columns, or 3 / 4 of the columns from the left to the right, or the other columns from the left to the right, except for the last column, are subjected to a one-dimensional DCT column transformation. That is to say, all or part of the columns except the last column in the matrix D are transformed into a one-dimensional DCT column, and then the obtained results are quantized, dequantized, and other calculations. Compared with the existing DCT transformation calculation, the fact that some columns do not participate in the one-dimensional DCT column transformation not only reduces the calculation steps, but also, because the transformation coefficients generated subsequently have been mainly concentrated in the left half of the transformation block through the aforementioned reorganization calculation, even if some columns on the right do not participate in the one-dimensional DCT column transformation, the calculation accuracy is guaranteed to a certain extent. It should be noted that the selection of columns for one-dimensional DCT column transformation can be adjusted accordingly according to actual needs. For example, for some small electronic devices, such as watches, the columns of the left half of the first residual block can be taken to participate in the calculation, while for some large electronic devices, such as televisions, which require higher accuracy, more columns of the first residual block can be selected as much as possible to participate in the calculation.
[0147] Similarly, in the second possibility mentioned above, the magnitude of the horizontal gradient value and the vertical gradient value reflects the distribution position of the coefficients obtained by the pixel values in the initial residual block after the subsequent DCT transformation, that is, when the one-dimensional DCT column transformation is performed and then the one-dimensional DCT row transformation is performed, if the vertical gradient value is greater than the horizontal gradient value, the calculated transformation coefficients are mainly distributed in the left half of the transformation block. At this time, the initial residual block is transposed to obtain the first residual block, or if the horizontal gradient value is greater than or equal to the vertical gradient value, the initial residual block is used as the first residual block. The one-dimensional DCT column transformation is performed on all columns of the first residual block, and then the one-dimensional DCT row transformation calculation is no longer performed on all rows of the first residual block, but the other rows of the first residual block, which are counted from top to bottom and excluding the last row, are selected for one-dimensional DCT row transformation, such as taking only the upper half of the rows, or 3 / 4 of the rows counted from top to bottom, or the other rows counted from top to bottom and excluding the last row, are subjected to one-dimensional DCT row transformation. That is to say, one-dimensional DCT row transformation is performed on all or part of the rows except the last row in the matrix D, and then the obtained results are quantized, dequantized, and other calculations are performed. Compared with the existing DCT transformation calculation, the fact that some rows do not participate in the one-dimensional DCT column transformation not only reduces the calculation steps, but also, because the transformation coefficients generated subsequently have been mainly concentrated in the upper half of the transformation block through the aforementioned reorganization calculation, even if the lower part of the rows do not participate in the one-dimensional DCT row transformation, the calculation accuracy is guaranteed to a certain extent. It should be noted that the selection of rows for one-dimensional DCT row transformation can be adjusted accordingly according to actual needs. For example, for some small electronic devices, such as watches, the rows of the upper half of the first residual block can be taken to participate in the calculation, while for some large electronic devices, such as televisions, which require higher accuracy, more rows of the first residual block can be selected as much as possible to participate in the calculation.
[0148] Preferably, in the step S240, the method in which the electronic device 10 determines the rate-distortion cost of the block to be encoded according to the distortion value is:
[0149] According to formula (1), the rate distortion cost is obtained:
[0150] J=D+λR (1),
[0151] Among them, J is the rate-distortion cost, D is the distortion, R is the bit rate, and λ is the Lagrangian coefficient.
[0152] After the distortion and bit rate are obtained, the final rate-distortion cost RDCost can be obtained according to the rate-distortion cost formula. The Lagrangian coefficient here can obtain different parameter values according to actual needs, which will not be limited in this application.
[0153] Table 1 is a BD-rate table obtained by directly performing RDO calculation on the initial residual block of the input test video sequence and selecting the final prediction mode according to the RDO calculation result. Table 2 is a BD-rate table obtained by converting the initial residual block of the input test video sequence into the first residual block using the first possible method in the present application, performing a one-dimensional DCT row transform on the first residual block and performing a one-dimensional DCT column transform on the left half of the columns in the first residual block, and selecting the final prediction mode according to the RDO calculation result.
[0154] Table 1:
[0155] Category Y_BD-rate M 0.03% S -1.73% B -0.78% C -0.21% E 0.04% G -0.04% N -1.02%
[0156] Table 2:
[0157]
[0158]
[0159] Among them, M, S, B, C, E, G, and N in Table 1 and Table 2 represent different types of test video sets, and Y_BD-rate is the BE-rate gain of the brightness of the test video set. When BD-rate is a negative value, it means that under the same PSNR condition, the bit rate is reduced and the performance is increased, and when BD-rate is a positive value, it means that under the same PSNR condition, the bit rate is increased and the performance is reduced. It can be seen from Table 1 and Table 2 that the technical solution in this application has a significant effect on improving the brightness of various types of test video sets.
[0160] Figure 7 Shown is a block diagram of an electronic device 70 according to an embodiment of the present application. Figure 7 An example electronic device 70 according to multiple embodiments is schematically shown. In one embodiment, the electronic device 70 may include an acquisition unit 1510, a calculation unit 1520 and an encoding unit 1530, wherein the acquisition unit 1510 is used to acquire an image to be encoded and divide the image to be encoded into multiple blocks to be encoded; the calculation unit 1520 is used to calculate the rate-distortion cost of each block to be encoded; and the encoding unit 1530 is used to select a prediction coding mode for encoding based on the rate-distortion cost of each block to be encoded; here, the above-mentioned calculation unit 1530 calculates the rate-distortion cost of each block to be encoded in the following manner: acquiring a first residual block of the block to be encoded; performing a DCT transform on the first residual block to obtain a second transform block, wherein the DCT transform includes multiple one-dimensional DCT row transforms and multiple one-dimensional DCT column transforms, and the number of one-dimensional DCT row transforms is not equal to the number of one-dimensional DCT column transforms; calculating the distortion value of the block to be encoded according to the second transform block; and determining the rate-distortion cost of the block to be encoded according to the distortion value.
[0161] Figure 8 FIG. 1 is a block diagram of another electronic device 10 according to an embodiment of the present application. Figure 8 An example electronic device 10 is schematically shown in accordance with various embodiments. In one embodiment, the electronic device 10 may include one or more processors 1604, system control logic 1608 connected to at least one of the processors 1604, system memory 1612 connected to the system control logic 1608, non-volatile memory (NVM) 1616 connected to the system control logic 1608, and a network interface 1620 connected to the system control logic 1608.
[0162] In some embodiments, the processor 1604 may include one or more single-core or multi-core processors. In some embodiments, the processor 1604 may include any combination of a general-purpose processor and a dedicated processor (e.g., a graphics processor, an application processor, a baseband processor, etc.). In an embodiment where the electronic device 10 uses an eNB (Evolved Node B) or a RAN (Radio Access Network) controller, the processor 1604 may be configured to execute various embodiments, such as Figures 3 to 5 One or more of the multiple embodiments shown.
[0163] In some embodiments, system control logic 1608 may include any suitable interface controller to provide any suitable interface to at least one of processors 1604 and / or any suitable device or component in communication with system control logic 1608 .
[0164] In some embodiments, the system control logic 1608 may include one or more memory controllers to provide an interface to the system memory 1612. The system memory 1612 may be used to load and store data and / or instructions. In some embodiments, the memory 1612 of the system 1600 may include any suitable volatile memory, such as a suitable dynamic random access memory (DRAM).
[0165] NVM 1616 may include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, NVM 1616 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as at least one of a HDD (Hard Disk Drive), a CD (CompactDisc) drive, and a DVD (Digital Versatile Disc) drive.
[0166] NVM 1616 may include a portion of storage resources on the device on which electronic device 10 is installed, or it may be accessible by the device but not necessarily a portion of the device. For example, NVM 1616 may be accessed over a network via network interface 1620.
[0167] In particular, system memory 1612 and NVM 1616 may include, respectively, a temporary copy and a permanent copy of instructions 1624. Instructions 1624 may include instructions that, when executed by at least one of processors 1604, cause electronic device 10 to implement the following: Figure 5 In some embodiments, instructions 1624, hardware, firmware, and / or software components thereof may additionally / alternatively be placed in system control logic 1608, network interface 1620, and / or processor 1604.
[0168] The network interface 1620 may include a transceiver for providing a radio interface for the electronic device 10, thereby communicating with any other suitable device (such as a front-end module, an antenna, etc.) through one or more networks. In some embodiments, the network interface 1620 may be integrated with other components of the electronic device 10. For example, the network interface 1620 may be integrated with at least one of the processor 1604, the system memory 1612, the NVM 1616, and a firmware device (not shown) having instructions. When at least one of the processors 1604 executes the above instructions, the electronic device 10 implements the following. Figures 3 to 6 The method shown.
[0169] The network interface 1620 may further include any suitable hardware and / or firmware to provide a multiple-input multiple-output radio interface. For example, the network interface 1620 may be a network adapter, a wireless network adapter, a telephone modem and / or a wireless modem.
[0170] In one embodiment, at least one of the processors 1604 may be packaged together with logic for one or more controllers of the system control logic 1608 to form a system in package (SiP). In one embodiment, at least one of the processors 1604 may be integrated on the same die with logic for one or more controllers of the system control logic 1608 to form a system on a chip (SoC).
[0171] The electronic device 10 may further include an input / output (I / O) device 1632 .
[0172] According to an embodiment of the present application, Fig. 9 1 shows a block diagram of a SoC (System on Chip) 1700. The SOC 1700 is provided in the electronic device 10. Fig. 9In the drawings, similar parts have the same reference numerals. Fig. 9 In the embodiment, SoC 1700 includes: an interconnect unit 1750, which is coupled to an application processor 1710; a system agent unit 1770; a bus controller unit 1780; an integrated memory controller unit 1740; a video processor 1720, which also includes an entropy coding module 20; a static random access memory (SRAM) unit 1730; and a direct memory access (DMA) unit 1760. In one embodiment, SoC 1700 may also include, for example, a network or communication processor, a compression engine, a GPU, a high throughput MIC processor, or an embedded processor.
[0173] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.
[0174] Program code can be applied to input instructions to perform the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0175] Program code can be implemented with high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.
[0176] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, instructions may be distributed over a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including, but not limited to, floppy disks, optical disks, optical disks, read-only memories (CD-ROMs), magneto-optical disks, read-only memories (ROMs), random access memories (RAMs), erasable programmable read-only memories (EPROMs), electrically erasable programmable read-only memories (EEPROMs), magnetic or optical cards, flash memory, or a tangible machine-readable memory for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Therefore, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a machine (e.g., computer) readable form.
[0177] In the accompanying drawings, some structural or method features may be shown in a particular arrangement and / or order. However, it should be understood that such a particular arrangement and / or order may not be required, but rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular figure does not imply that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.
[0178] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.
[0179] It should be noted that in the examples and description of this patent, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one" do not exclude the existence of other identical elements in the process, method, article or device including the above elements.
[0180] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be apparent to those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present application.
Claims
1. An image encoding method, used in electronic equipment, characterized in that: include: Acquire an image to be encoded, and divide the image to be encoded into a plurality of blocks to be encoded; Calculating the rate-distortion cost of each of the blocks to be encoded; Selecting a prediction coding mode for encoding based on the rate distortion cost of each block to be encoded; The calculating of the rate-distortion cost of each block to be encoded includes: Obtaining a first residual block of the block to be encoded; Performing DCT transformation on the first residual block to obtain a second transformation block, wherein the DCT transformation includes multiple one-dimensional DCT row transformations and multiple one-dimensional DCT column transformations, and the number of the one-dimensional DCT row transformations is not equal to the number of the one-dimensional DCT column transformations; Calculating a distortion value of the block to be encoded according to the second transform block; Determining a rate-distortion cost of the block to be encoded according to the distortion value; The obtaining the first residual block of the block to be encoded includes: Performing directional prediction calculation on the initial residual block of the block to be encoded to obtain a directional result, where the directional result includes a horizontal direction or a vertical direction; Perform data mapping calculation according to the direction result to obtain a first residual block; The performing data mapping calculation according to the direction result to obtain a first residual block includes: If the direction result is a horizontal direction, the initial residual block is subjected to matrix transposition to obtain a first residual block; if the direction result is a vertical direction, the first residual block is the initial residual block; The step of performing DCT transformation on the first residual block to obtain a second transformed block includes: If the first residual block is an m×m matrix, performing one-dimensional DCT row transform on m rows in the first residual block in sequence to obtain a first transform block; A second transform block is obtained by sequentially performing one-dimensional DCT column transform on g columns whose column numbers are not m in the first transform block; wherein the value range of the row number of the first residual block is [1, m], the value range of the column number of the first residual block is [1, m], m is 2 to the power of k, m is a natural number greater than or equal to 4, k is a natural number greater than or equal to 2, g is a natural number greater than or equal to 1, and the value range of g is [1, m-1].
2. The image encoding method according to claim 1, characterized in that The step of performing directional prediction calculation on the initial residual block of the block to be encoded to obtain a directional result comprises: Performing n-times row horizontal gradient calculations on the pixels in the initial residual block according to the row sequence numbers, and accumulating the results of the row horizontal gradient calculations to obtain a horizontal gradient value; Performing n column longitudinal gradient calculations on the pixels in the initial residual block in sequence according to the column numbers, and accumulating the results of the column longitudinal gradient calculations to obtain a longitudinal gradient value; Comparing the magnitudes of the transverse gradient value and the longitudinal gradient value; If the transverse gradient value is greater than the longitudinal gradient value, the direction result is determined to be a transverse direction; Otherwise, it is determined that the direction is a longitudinal direction; Wherein, n is a natural number greater than or equal to 1.
3. The image encoding method according to claim 1, characterized in that: The step of performing data mapping calculation according to the direction result to obtain a first residual block includes: If the direction result is a vertical direction, the initial residual block is subjected to matrix transposition to obtain a first residual block; if the direction result is a horizontal direction, the first residual block is the initial residual block.
4. The image encoding method according to claim 3, characterized in that: The step of performing DCT transformation on the first residual block to obtain a second transformed block comprises: If the first residual block is an m×m matrix, performing one-dimensional DCT column transform on m columns in the first residual block in sequence to obtain a first transform block; A second transform block is obtained by sequentially performing one-dimensional DCT row transform on g rows whose row numbers are not m in the first transform block; wherein the value range of the row number of the first residual block is [1, m], the value range of the column number of the first residual block is [1, m], m is 2 to the kth power, m is a natural number greater than or equal to 4, k is a natural number greater than or equal to 2, g is a natural number greater than or equal to 1, and the value range of g is [1, m-1].
5. The image encoding method according to claim 1, characterized in that: The electronic device includes a processor, and the method is implemented by the processor.
6. A readable medium, characterized in that: The readable medium of the electronic device stores instructions, which, when executed on the electronic device, enable the electronic device to execute the image encoding method according to any one of claims 1 to 5.
7. An electronic device comprising: A memory for storing instructions to be executed by one or more processors of an electronic device, and a plurality of processors for running the instructions in the memory to execute the image encoding method according to any one of claims 1 to 5.
