Encoding and decoding method, code stream, encoder, decoder and storage medium

CN120548705APending Publication Date: 2025-08-26GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202480007897.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-01-19
Filing Date
2024-01-19
Publication Date
2025-08-26

AI Technical Summary

Technical Problem

Existing intra-frame template matching prediction technology has low prediction accuracy in certain scenarios, resulting in poor encoding and decoding performance.

Method used

By determining the model parameters between the current block and the reference template, filtering is performed to correct the reconstructed pixels of the reference block, thereby improving the accuracy of the prediction value, and applying this method on the encoding and decoding ends to improve encoding and decoding performance.

Benefits of technology

It improves the accuracy of intra-frame template matching prediction, saves code rate, improves encoding and decoding efficiency, and improves overall encoding and decoding performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120548705A_ABST
    Figure CN120548705A_ABST
Patent Text Reader

Abstract

The invention discloses a coding and decoding method, a code stream, a coder, a decoder and a storage medium, and the method comprises the steps: determining a first template of a current block, and determining a reference template and a reference block; when the reference template meets a first preset condition, performing first processing on an adjacent region of the reference template, determining a matching template, and determining model parameters according to the first template and the matching template; filtering the reference block according to the model parameters, and determining the filtered reference block; determining a predicted value of the current block according to the filtered reference block; and determining a reconstruction value of the current block according to the prediction value of the current block. Therefore, the prediction accuracy can be improved, the code rate can be saved, and the coding and decoding performance can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Coding and decoding method, code stream, encoder, decoder and storage medium

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS

[0002] This application claims priority to the Chinese patent application filed with the China Patent Office on January 19, 2023, with application number 202310141452.0 and application name “Coding and decoding method, code stream, encoder, decoder and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0003] The present application relates to the field of video coding and decoding technology, and in particular to a coding and decoding method, a bit stream, an encoder, a decoder, and a storage medium. Background Art

[0004] Intra Template Matching Prediction (Intra TMP) technology uses the template of the coding block to search for the matching template with the minimum cost according to a preset cost function within a predefined search range in the current image, and uses the best matching reconstructed block corresponding to the matching template as the prediction block of the current coding block.

[0005] However, in the actual encoding process, related technologies usually directly use the reconstructed pixels of the best matching reconstructed block as the predicted pixels of the current encoding block. However, due to incomplete consideration, there will be large deviations in some scenarios, resulting in low prediction accuracy.

[0006] Summary of the Invention

[0007] The present application provides a coding and decoding method, a code stream, an encoder, a decoder, and a storage medium, which can improve the accuracy of frame prediction and thus enhance coding and decoding performance.

[0008] The technical solution of this application can be implemented as follows:

[0009] In a first aspect, an embodiment of the present application provides a decoding method, applied to a decoder, the method comprising:

[0010] Determining a first template for a current block, and determining a reference template and a reference block;

[0011] When the reference template meets the first preset condition, performing a first processing on an adjacent area of ​​the reference template to determine a matching template, and determining model parameters based on the first template and the matching template;

[0012] Performing filtering on the reference block according to the model parameters to determine a filtered reference block;

[0013] Determine the prediction value of the current block based on the filtered reference block;

[0014] Determine the reconstructed value of the current block according to the predicted value of the current block.

[0015] In a second aspect, an embodiment of the present application provides an encoding method, applied to an encoder, the method comprising:

[0016] Determining a first template for a current block, and determining a reference template and a reference block;

[0017] When the reference template meets the first preset condition, performing a first processing on an adjacent area of ​​the reference template to determine a matching template, and determining model parameters based on the first template and the matching template;

[0018] Performing filtering on the reference block according to the model parameters to determine a filtered reference block;

[0019] Determine the prediction value of the current block based on the filtered reference block;

[0020] Determine the prediction difference value of the current block according to the prediction value of the current block.

[0021] In a third aspect, an embodiment of the present application provides a code stream, which is generated by bit encoding based on information to be encoded; wherein the information to be encoded includes at least one of the following:

[0022] The prediction difference value of the current block, the number of coefficients of the target filter, the shape of the target filter, the value of the first syntax element identification information, and the value of the second syntax element identification information; wherein the first syntax element identification information is used to indicate whether intra-frame template matching is applied to the current block, and the second syntax element identification information is used to indicate whether the filter model is applied to the current block.

[0023] In a fourth aspect, an embodiment of the present application provides an encoder, comprising a first determination unit, a first filtering unit, and a first prediction unit; wherein:

[0024] a first determining unit configured to determine a first template of the current block, and to determine a reference template and a reference block; and further configured to, when the reference template satisfies a first preset condition, perform a first processing on an adjacent area of ​​the reference template to determine a matching template, and determine model parameters based on the first template and the matching template;

[0025] a first filtering unit configured to perform filtering processing on the reference block according to the model parameters to determine a filtered reference block;

[0026] a first prediction unit configured to determine a prediction value of a current block based on the filtered reference block;

[0027] The first determining unit is further configured to determine a prediction difference value of the current block according to the prediction value of the current block.

[0028] In a fifth aspect, an embodiment of the present application provides an encoder, comprising a first memory and a first processor; wherein:

[0029] a first memory for storing a computer program capable of running on the first processor;

[0030] The first processor is configured to execute the method according to the second aspect when running a computer program.

[0031] In a sixth aspect, an embodiment of the present application provides a decoder, comprising a second determination unit, a second filtering unit, and a second prediction unit; wherein:

[0032] a second determining unit configured to determine a first template of the current block, and to determine a reference template and a reference block; and further configured to perform a first processing on an adjacent area of ​​the reference template when the reference template satisfies a first preset condition, to determine a matching template, and to determine model parameters based on the first template and the matching template;

[0033] a second filtering unit configured to filter the reference block according to the model parameters to determine a filtered reference block;

[0034] a second prediction unit configured to determine a prediction value of a current block based on the filtered reference block;

[0035] The second determining unit is further configured to determine a reconstructed value of the current block according to the predicted value of the current block.

[0036] In a seventh aspect, an embodiment of the present application provides a decoder, comprising a second memory and a second processor; wherein:

[0037] a second memory for storing a computer program capable of running on the second processor;

[0038] The second processor is configured to execute the method according to the first aspect when running a computer program.

[0039] In an eighth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed, implements the method described in the first aspect or the method described in the second aspect.

[0040] The embodiments of the present application provide a coding and decoding method, a bitstream, an encoder, a decoder, and a storage medium. Whether at the encoding or decoding end, a first template of a current block is determined, as well as a reference template and a reference block. When the reference template meets a first preset condition, a first processing is performed on an adjacent area of ​​the reference template to determine a matching template, and model parameters are determined based on the first template and the matching template. The reference block is filtered based on the model parameters to determine a filtered reference block. A prediction value of the current block is determined based on the filtered reference block. In this way, the encoding end can determine a prediction difference value of the current block based on the prediction value of the current block, so that at the decoding end, a reconstructed value of the current block can be determined based on the prediction value of the current block. That is, the model parameters are determined based on the first template and the matching template. The model parameters fully reflect the correlation between the matching template and the first template of the current block. This correlation is applied to the reference block, and the reconstructed pixels are filtered and corrected. The filtered reconstructed pixels are then used as the predicted pixels of the current block. This improves prediction accuracy, saves bit rate, and improves coding and decoding efficiency, thereby enhancing coding and decoding performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] FIG1 is a schematic diagram of a prediction process of an Intra TMP technology;

[0042] FIG2 is a schematic diagram of a prediction process based on the Intra TMP technology;

[0043] FIG3 is a schematic diagram of a template type of Intra TMP technology;

[0044] FIG4A is a schematic block diagram of an encoder provided in an embodiment of the present application;

[0045] FIG4B is a schematic block diagram of a decoder according to an embodiment of the present application;

[0046] FIG5 is a schematic diagram of a network architecture of a coding and decoding system provided in an embodiment of the present application;

[0047] FIG6 is a schematic diagram of a flow chart of a decoding method provided in an embodiment of the present application;

[0048] FIG7 is a schematic diagram of dividing a search area into different sub-areas according to an embodiment of the present application;

[0049] FIG8 is a schematic diagram of a prediction process based on the Intra TMP-FLM technology provided in an embodiment of the present application;

[0050] FIG9 is a schematic diagram of a search process based on the Intra TMP technology provided in an embodiment of the present application;

[0051] FIG10A is a schematic diagram of parameter definition of a current block and its template provided in an embodiment of the present application;

[0052] FIG10B is a schematic diagram of filling a reference block and its adjacent template area provided by an embodiment of the present application;

[0053] FIG11 is a schematic diagram of a template search area provided in an embodiment of the present application;

[0054] FIG12 is a schematic diagram of a specific search area determination process provided in an embodiment of the present application;

[0055] FIG13 is a flowchart of a search process provided in an embodiment of the present application;

[0056] FIG14 is a schematic diagram of the shape of a filter provided in an embodiment of the present application;

[0057] FIG15 is a schematic diagram of a flow chart of calculating filter coefficients according to an embodiment of the present application;

[0058] FIG16A is a schematic diagram of the composition of a filter coefficient provided in an embodiment of the present application;

[0059] FIG16B is a schematic diagram of the composition of a predicted pixel provided in an embodiment of the present application;

[0060] FIG17 is a schematic diagram of another specific search area determination process provided in an embodiment of the present application;

[0061] FIG18 is a schematic diagram of a process for determining another specific search area provided in an embodiment of the present application;

[0062] FIG19 is a schematic diagram of a process for determining another specific search area provided in an embodiment of the present application;

[0063] FIG20 is a schematic diagram of a flow chart of an encoding method provided in an embodiment of the present application;

[0064] FIG21 is a schematic diagram of the structure of an encoder provided in an embodiment of the present application;

[0065] FIG22 is a schematic diagram of a specific hardware structure of an encoder provided in an embodiment of the present application;

[0066] FIG23 is a schematic diagram of the structure of a decoder provided in an embodiment of the present application;

[0067] FIG24 is a schematic diagram of a specific hardware structure of a decoder provided in an embodiment of the present application;

[0068] FIG25 is a schematic diagram of the composition structure of a coding and decoding system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0069] In order to enable a more detailed understanding of the features and technical contents of the embodiments of the present application, the implementation of the embodiments of the present application is described in detail below with reference to the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present application.

[0070] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.

[0071] In the following description, reference is made to "some embodiments," which describe a subset of all possible embodiments. However, it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. It should also be noted that the terms "first, second, and third" in the embodiments of the present application are only used to distinguish similar objects and do not represent a specific ordering of the objects. It is understood that "first, second, and third" may be interchanged in a specific order or sequential order where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0072] Before further explaining the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained first. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations:

[0073] Coding Block (CB);

[0074] Block Matching (BM);

[0075] Coding Unit (CU);

[0076] Block Vector (BV);

[0077] Sum of Absolute Difference (SAD);

[0078] Sum of Absolute Transformed Difference (SATD);

[0079] Mean Square Error (MSE);

[0080] Sum of Squared Differences (SSD);

[0081] Mean Absolute Deviation (MAD);

[0082] Mean Square Differences (MSD);

[0083] Normalized Correlation Coefficient (NCC);

[0084] H.266 / Versatile Video Coding (VVC);

[0085] VVC Test Model (VTM), a reference software testing platform for VVC;

[0086] Intra Template Matching Prediction (Intra TMP);

[0087] Beyond VVC's reference software testing platform (Enhanced Compression Model, ECM).

[0088] It can be understood that in a video image, a first color component, a second color component, and a third color component are generally used to represent a coding block. These three color components are a luminance component, a blue chrominance component, and a red chrominance component. Specifically, the luminance component is usually represented by the symbol Y, the blue chrominance component is usually represented by the symbol Cb or U, and the red chrominance component is usually represented by the symbol Cr or V. Thus, a video image can be represented in either the YCbCr format or the YUV format.

[0089] It can also be understood that Intra TMP is a special intra-frame prediction mode. Both the encoder and decoder use the template (T) of the coding block to search for the matching template (T_BEST) with the minimum cost within a predefined search range in the current image according to a preset cost function. The offset of the best matching template relative to the current coding block template is the best block vector (BEST Block Vector, BV_BEST). The reconstructed block (Ref Block) corresponding to the matching template is then used as the prediction block for the current coding block (Cur Block). The template of the coding block is usually selected from the adjacent reconstructed area of ​​the current coding block.

[0090] For example, taking the adjacent reconstructed area of ​​the current block as an example, as shown in Figure 1, the area filled with dark color represents the reconstructed area, the block filled with grid is the current block, and the adjacent area of ​​the current block is the first template (T); the block filled with slashes is the reference block, and the adjacent area of ​​the reference block is the second template (i.e., "reference template" or "matching template", T_BEST); wherein, the offset of the second template relative to the first template is the best block vector (BV_BEST), at this time, the reference block can be block copied as the prediction block of the current block.

[0091] In an embodiment of the present application, the preset cost function can be the sum of absolute error SAD, the sum of absolute transformation difference SATD, the mean square error MSE, the sum of squared errors SSD, the mean absolute difference MAD, the mean sum of squared errors MSD, the normalized correlation coefficient NCC, etc., which is not specifically limited here.

[0092] For example, taking absolute error and SAD as examples, the cost function at this time is as follows:

[0093] Among them, T i is the template in the search process, and M represents the number of pixels in the template.

[0094] The following is a detailed introduction to the prediction process of the Intra TMP technology in the related art.

[0095] The input of the Intra TMP technology: the position of the current block (xTbCmp, yTbCmp), the width of the current block nTbW, and the height of the current block nTbH.

[0096] Output of the Intra TMP technique: predicted value predSamples[x][y] of the current block, where x = 0..nTbW-1, y = 0..nTbH–1.

[0097] Specifically, the Intra TMP prediction process can be divided into four steps: determining the current template type, obtaining the reconstructed pixels of the current template, determining the block vector within a predefined search range, and generating the predicted value. This process yields the predicted value for the current block. It's important to note that Intra TMP can be used to predict both luma and chroma components, and this is not specifically limited here.

[0098] Refer to Figure 2, which shows a schematic diagram of a prediction process based on the Intra TMP technology. As shown in Figure 2, the process may include:

[0099] S201: Determine the current template type.

[0100] It should be noted that the Intra TMP technology uses the adjacent reconstructed pixels of the current block as templates to search for matching templates within a predefined search area, where the adjacent reconstructed pixels can be the upper reference pixel, upper left reference pixel, upper right reference pixel, left reference pixel, lower left reference pixel, etc. of the current block. Therefore, the template type can be classified and the corresponding template type can be determined based on the availability of the adjacent reconstructed pixels.

[0101] It should also be noted that refTemplateType can be used to represent a template type. Figure 3 shows a schematic diagram of template types for the Intra TMP technology. As shown in Figure 3, the block filled with a grid is the current block, and the adjacent area of ​​the current block is the template T. Six template types are shown here.

[0102] For example, the six template types are as follows:

[0103] When the upper left reference pixel, the upper reference pixel, and the left reference pixel are all available, the value of refTemplateType is 1, and the template shape is as shown in (a) of Figure 3;

[0104] When only the left reference pixel is available, the value of refTemplateType is 2, and the template shape is shown in (b) in Figure 3;

[0105] When only the upper reference pixel is available, the value of refTemplateType is 3, and the template shape is shown in (c) in Figure 3;

[0106] When only the left reference pixel and the upper left reference pixel are available, the value of refTemplateType is 4, and the template shape is shown in (d) in Figure 3;

[0107] When only the left reference pixel and the lower left reference pixel are available, the value of refTemplateType is 5, and the template shape is shown in (e) of Figure 3;

[0108] When only the upper reference pixel and the upper right reference pixel are available, the value of refTemplateType is 6, and the template shape is shown in (f) in Figure 3.

[0109] S202: Obtain current template pixels.

[0110] It should be noted that the Intra TMP template can be composed of reconstructed pixels from one or more of the following regions: the top, upper right, left, lower left, or upper left of the current block. Furthermore, the template size can be pre-set. For example, when obtaining the left template, the template width (templateW_size) can be set to 4, and when obtaining the top template, the template height (templateH_size) can be set to 4.

[0111] It should also be noted that the portion of the reconstructed pixels to be obtained can be determined by the value of refTemplateType. For example, when the value of refTemplateType is 1, the reconstructed pixels of the left, upper-left, and upper sides of the current block are obtained; or, when the value of refTemplateType is 2, only the reconstructed pixels of the four left columns of the current block are obtained; or, when the value of refTemplateType is 3, only the reconstructed pixels of the four upper rows of the current block are obtained.

[0112] S203: Determine a block vector within a predefined search range.

[0113] It should be noted that the search process of the Intra TMP technology is mainly divided into an initialization process, determining a search area of ​​the template in the current frame, and searching and determining the best block vector in the search area.

[0114] It should also be noted that when searching for the best matching template in the search area, a search strategy of coarse search first and then fine search may be adopted, or only fine search or only coarse search may be performed, which is not specifically limited here.

[0115] In an embodiment of the present application, the coarse search here can specifically be: determining the best coarse matching template in the search area with a first preset step size (for example, 2), or using a downsampled template (for example, a downsampling factor of 2) to determine the best coarse matching template in the search area.

[0116] In the embodiment of the present application, the fine search here may specifically be: determining the best fine matching template in the search area with a second preset step size (eg, 1), or determining the best fine matching template near the best coarse matching template after completing the coarse search.

[0117] In an embodiment of the present application, a coarse search is performed first, followed by a fine search. Specifically, the best coarse matching template is determined in the search area with a first preset step size (for example, 2), and then the best fine matching template is determined near the best coarse matching template with a second preset step size (for example, 1).

[0118] In this way, after completing the above operations, the optimal block vector BV_BEST (pX_BEST, pY_BEST) can be obtained, where pX_BEST and pY_BEST are the horizontal and vertical offsets of the best matching template relative to the current block template, respectively, and are also the horizontal and vertical offsets of the best matching reconstructed block relative to the current block.

[0119] S204: Generate a predicted value.

[0120] Here, we can use simple translation copy to achieve it. The specific operation is:

[0121] For x=0...nTbW-1, y=0...nTbH-1; predSamples[x][y]=recSamples[x+pX_BEST][y+pY_BEST] (2)

[0122] Among them, recSamples represents the reconstructed pixels of the current frame.

[0123] In simple terms, the Intra TMP technique, as used in related technologies, uses the template of the current block to search for the matching template with the lowest cost within a predefined search range in the current image according to a preset cost function. The best matching reconstructed block (Ref Block) corresponding to the matching template is used as the prediction block for the current block (Cur Block). The template of the current block can usually be selected from the reconstructed area adjacent to the current block.

[0124] However, in the actual encoding process, the related technology of directly using the reconstructed pixels of the best matching reconstructed block as the predicted pixels of the current block is not the optimal solution in some cases. For example, when there is a linear illumination change between the best matching reconstructed block and the current block, if the reconstructed pixels of the best matching reconstructed block are directly used as the predicted pixels of the current block, there will be a large deviation, resulting in low prediction accuracy and failure to achieve the optimal prediction effect.

[0125] Based on this, an embodiment of the present application provides an encoding method to determine a first template of a current block, as well as a matching template and a reference block; determine model parameters based on the first template and the matching template; filter the reference block based on the model parameters to determine a filtered reference block; determine a prediction value of the current block based on the filtered reference block; and determine a prediction difference value of the current block based on the prediction value of the current block.

[0126] An embodiment of the present application also provides a decoding method, which determines a first template of a current block, as well as a matching template and a reference block; determines model parameters based on the first template and the matching template; filters the reference block based on the model parameters to determine a filtered reference block; determines a predicted value of the current block based on the filtered reference block; and determines a reconstructed value of the current block based on the predicted value of the current block.

[0127] In this way, whether it is the encoding end or the decoding end, the first template and the matching template are used to determine the model parameters. The model parameters fully reflect the correlation between the matching template and the first template of the current block, and this correlation is applied to the reference block. By filtering and correcting its reconstructed pixels, and then using the filtered reconstructed pixels as the predicted pixels of the current block, the predicted value of the intra-frame template matching technology can be effectively corrected, the prediction accuracy is improved, the bit rate is saved, and the encoding and decoding efficiency can be improved, thereby improving the encoding and decoding performance.

[0128] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0129] Referring to FIG4A , which shows a schematic block diagram of the composition of an encoder provided in an embodiment of the present application. As shown in FIG4A , the encoder (specifically, a “video encoder”) 100 may include a transform and quantization unit 101, an intra-frame estimation unit 102, an intra-frame prediction unit 103, a motion compensation unit 104, a motion estimation unit 105, an inverse transform and inverse quantization unit 106, a filter control analysis unit 107, a filtering unit 108, an encoding unit 109, and a decoded image cache unit 110, etc., wherein the filtering unit 108 can implement deblocking filtering and sample adaptive offset (SAO) filtering, and the encoding unit 109 can implement header information encoding and context-based adaptive binary arithmetic coding (CABAC).For the input original video signal, a video coding block can be obtained by dividing the coding tree unit (CTU). Then, the residual pixel information obtained after intra-frame or inter-frame prediction is transformed by the transformation and quantization unit 101, including transforming the residual information from the pixel domain to the transform domain and quantizing the obtained transform coefficients to further reduce the bit rate; the intra-frame estimation unit 102 and the intra-frame prediction unit 103 are used to perform intra-frame prediction on the video coding block. Specifically, the intra-frame estimation unit 102 and the intra-frame prediction unit 103 are used to determine the intra-frame prediction mode to be used to encode the video coding block; the motion compensation unit 104 and the motion estimation unit 105 are used to perform inter-frame prediction coding on the received video coding block relative to one or more blocks in one or more reference frames to provide temporal prediction information; the motion estimation performed by the motion estimation unit 105 is the process of generating a motion vector, which can estimate the motion of the video coding block. The motion compensation unit 104 then calculates the motion vector based on the motion vector determined by the motion estimation unit 105. After determining the intra-frame prediction mode, the intra-frame prediction unit 103 is further configured to provide the selected intra-frame prediction data to the encoding unit 109, and the motion estimation unit 105 also sends the calculated motion vector data to the encoding unit 109. In addition, the inverse transform and inverse quantization unit 106 is configured to reconstruct the video coding block and reconstruct a residual block in the pixel domain. The reconstructed residual block is subjected to the filter control analysis unit 107 and the filtering unit 108 to remove the block effect artifacts. The reconstructed residual block is then added to a predictive block in the frame of the decoded image buffer unit 110 to generate a reconstructed video coding block. The encoding unit 109 is configured to encode various coding parameters and quantized transform coefficients. In the CABAC-based coding algorithm, the context content can be based on adjacent coding blocks and can be used to encode information indicating the determined intra-frame prediction mode, and output the code stream of the video signal. The decoded image buffer unit 110 is configured to store the reconstructed video coding block for prediction reference. As the video image encoding proceeds, new reconstructed video encoding blocks are continuously generated, and these reconstructed video encoding blocks are stored in the decoded image buffer unit 110 .

[0130] Referring to FIG4B , which shows a block diagram of a decoder provided in an embodiment of the present application, as shown in FIG4B , the decoder (specifically, a "video decoder") 200 includes a decoding unit 201, an inverse transform and inverse quantization unit 202, an intra-frame prediction unit 203, a motion compensation unit 204, a filtering unit 205, and a decoded image buffer unit 206. The decoding unit 201 can implement header information decoding and CABAC decoding, and the filtering unit 205 can implement deblocking filtering and SAO filtering. After the input video signal is encoded as shown in FIG4A , a code stream of the video signal is output; the code stream is input to the decoder 200 and first passes through the decoding unit 201 to obtain decoded transform coefficients; the transform coefficients are processed by the inverse transform and inverse quantization unit 202 to generate a residual block in the pixel domain; the intra-frame prediction unit 203 can be used to generate prediction data for the current video decoding block based on the determined intra-frame prediction mode and data from the previously decoded block of the current frame or picture; the motion compensation unit 204 determines the prediction information for the video decoding block by analyzing the motion vector and other associated syntax elements, and uses The prediction information is used to generate a predictive block for the video decoding block being decoded; a decoded video block is formed by summing the residual block from the inverse transform and inverse quantization unit 202 with the corresponding predictive block generated by the intra-frame prediction unit 203 or the motion compensation unit 204; the decoded video signal passes through the filtering unit 205 to remove blocking artifacts, thereby improving video quality; the decoded video block is then stored in the decoded image buffer unit 206, which stores reference images used for subsequent intra-frame prediction or motion compensation, and is also used for outputting the video signal, thereby obtaining the restored original video signal.

[0131] Furthermore, an embodiment of the present application also provides a network architecture of a coding and decoding system including an encoder and a decoder, wherein FIG5 shows a schematic diagram of a network architecture of a coding and decoding system provided by an embodiment of the present application. As shown in FIG5 , the network architecture includes one or more electronic devices 13 to 1N and a communication network 01, wherein the electronic devices 13 to 1N can perform video interaction through the communication network 01. During implementation, the electronic device can be various types of devices with video coding and decoding functions. For example, the electronic device can include a smart phone, a tablet computer, a personal computer, a personal digital assistant, a navigator, a digital phone, a video phone, a television, a sensing device, a server, etc., which are not specifically limited here. In addition, the decoder or encoder described in the embodiment of the present application can be the above-mentioned electronic device.

[0132] It should be noted that the method of the embodiment of the present application is mainly applied to the intra-frame prediction unit 103 shown in Figure 4A and the intra-frame prediction unit 203 shown in Figure 4B. In other words, the embodiment of the present application can be applied to both the encoder and the decoder, or even to both the encoder and the decoder at the same time, but the embodiment of the present application is not specifically limited thereto.

[0133] It should also be noted that, when applied to the intra-frame prediction unit 103, the "current block" specifically refers to the coding block currently to be intra-frame predicted; when applied to the intra-frame prediction unit 203, the "current block" specifically refers to the decoding block currently to be intra-frame predicted.

[0134] In one embodiment of the present application, referring to FIG6 , a flowchart of a decoding method provided by an embodiment of the present application is shown. As shown in FIG6 , the method may include:

[0135] S601: Determine a first template for a current block, and determine a reference template and a reference block.

[0136] It should be noted that the decoding method of the embodiment of the present application is applied to a decoder. In addition, the decoding method may specifically refer to an intra-frame prediction method, more specifically, an intra-frame prediction method based on an intra-frame template matching technology based on a linear filter model (Intra Template Matching Prediction based on Filter-based Linear Model, Intra TMP-FLM). Among them, the video image can be divided into multiple decoding blocks, and the current block in the embodiment of the present application refers to the decoding block in the video image that is currently to be intra-frame predicted. In addition, the decoding method of the embodiment of the present application can be used to predict both the luminance component and the chrominance component, which is not specifically limited here.

[0137] It should also be noted that, in the embodiments of the present application, it is first necessary to determine the first template of the current block so that the reference template and the reference block can be determined based on the first template. In some embodiments, determining the first template of the current block may include:

[0138] Determine the template type of the current block;

[0139] Determine the first template of the current block according to the template type of the current block.

[0140] The template type can be represented by refTemplateType. In some embodiments, determining the template type of the current block may include: determining the template type of the current block according to reference pixels of the current block.

[0141] Among them, the reference pixels of the current block include at least one of the following: the left adjacent reference pixel of the current block, the upper adjacent reference pixel of the current block, the upper left adjacent reference pixel of the current block, the lower left adjacent reference pixel of the current block, and the upper right adjacent reference pixel of the current block.

[0142] That is, in an embodiment of the present application, the reference pixels of the current block are determined based on the adjacent reconstructed areas of the current block. The adjacent reconstructed areas of the current block include at least one of the following: a left adjacent area, an upper adjacent area, an upper left adjacent area, a lower left adjacent area, and an upper right adjacent area. For example, the left adjacent reference pixels of the current block may be determined by at least one column of reconstructed pixels in the left adjacent area, the upper adjacent reference pixels of the current block may be determined by at least one row of reconstructed pixels in the upper adjacent area, the lower left adjacent reference pixels of the current block may be determined by at least one column of reconstructed pixels in the lower left adjacent area, and so on. This is not specifically limited here.

[0143] Furthermore, the template type can be classified according to whether the adjacent reference pixels are available and the template type of the current block can be determined. In some embodiments, determining the template type of the current block can include:

[0144] If the left adjacent reference pixel of the current block, the upper adjacent reference pixel of the current block, and the upper left adjacent reference pixel of the current block are all available, determining that the template type of the current block is the first value;

[0145] If the left adjacent reference pixel of the current block is available, determining the template type of the current block to be a second value;

[0146] If the upper adjacent reference pixel of the current block is available, determining the template type of the current block to be a third value;

[0147] If both the left adjacent reference pixel of the current block and the upper left adjacent reference pixel of the current block are available, determining that the template type of the current block is a fourth value;

[0148] If both the left adjacent reference pixel of the current block and the lower left adjacent reference pixel of the current block are available, determining that the template type of the current block is the fifth value;

[0149] If both the upper adjacent reference pixels of the current block and the upper right adjacent reference pixels of the current block are available, the template type of the current block is determined to be a sixth value.

[0150] In the embodiment of the present application, the first value, the second value, the third value, the fourth value, the fifth value, and the sixth value may be different. For example, the first value may be set to 1, the second value may be set to 2, the third value may be set to 3, the fourth value may be set to 4, the fifth value may be set to 5, and the sixth value may be set to 6. For details of these six template types, see (a), (b), (c), (d), (e), and (f) in FIG. 3 .

[0151] In some embodiments, determining the first template of the current block according to the template type of the current block may include: obtaining the template pixels of the current block according to the template type of the current block and the corresponding template size; and determining the template pixels of the current block as the first template of the current block.

[0152] In the embodiment of the present application, the template size may be pre-set, or may be determined according to the size of the current block, or may even be related to the template type of the current block, which is not specifically limited here.

[0153] For example, if the template type indicates that only the left template is to be obtained, the template width templateW_size may be set to 4; if the template type indicates that only the upper template is to be obtained, the template height templateH_size may be set to 4.

[0154] In addition, the value of the template type can determine which part of the reconstructed pixels the first template obtains. For example, when the value of refTemplateType is 1, the left, upper left, and upper reconstructed pixels of the current block are obtained; when the value of refTemplateType is 2, only the left four columns of reconstructed pixels of the current block are obtained; when the value of refTemplateType is 3, only the upper four rows of reconstructed pixels of the current block are obtained.

[0155] Regarding the reference template and the reference block, in one possible implementation, determining the reference template and the reference block may include: decoding a code stream to determine motion parameters; determining a reference block based on the motion parameters; and determining a reference template based on the first template and the reference block.

[0156] That is, the reference block of the current block may be determined according to the motion parameters (eg, BV) obtained from the decoded code stream, and the reference template may be determined from the reference block according to the first template of the current block.

[0157] Regarding the reference template and the reference block, in another possible implementation, determining the reference template and the reference block may include: performing template matching within a preset search area based on the first template to determine the reference template; and determining the reference block based on the reference template.

[0158] In some embodiments, performing template matching within a preset search area based on the first template to determine a reference template may include: searching within the preset search area based on the first template to determine a target block vector, and determining the reference template based on the target block vector.

[0159] That is, a search can be performed within a preset search area based on the first template, and a matching template with the minimum cost can be found based on a preset cost function. By traversing all search points within the preset search area, one or more candidate block vectors can be obtained, and these one or more candidate block vectors can indicate one or more candidate matching templates. Cost calculations are performed on these vectors and compared with the first template of the current block, resulting in a search point with the minimum cost. The candidate block vector corresponding to the candidate block vector is the best block vector (i.e., the target block vector, BV_BEST). The candidate matching template corresponding to the candidate block vector is the best matching template (i.e., the reference template described in this embodiment, T_BEST). Based on the best matching template, a reference block can be determined.

[0160] In an embodiment of the present application, the preset cost function can be the sum of absolute error SAD, the sum of absolute transformation difference SATD, the mean square error MSE, the sum of squared errors SSD, the mean absolute difference MAD, the mean sum of squared errors MSD, the normalized correlation coefficient NCC, etc., which is not specifically limited here.

[0161] It is understandable that the search process within the preset search area may be a coarse search, or a fine search, or a coarse search first and then a fine search; the details are as follows:

[0162] In a possible implementation, searching within a preset search area based on the first template to determine the target block vector may include: performing a first search within the preset search area to determine the target block vector.

[0163] In another possible implementation, searching within a preset search area based on the first template to determine the target block vector may include: performing a second search within the preset search area to determine the target block vector.

[0164] In another possible implementation, searching within a preset search area based on the first template to determine the target block vector may include: performing a first search within the preset search area to determine the first block vector and determining an initial matching template based on the first block vector; determining a first search area based on the initial matching template, and performing a second search within the first search area to determine the target block vector.

[0165] It should be noted that, in the embodiment of the present application, the search step size corresponding to the first search is greater than the search step size corresponding to the second search. For example, the search step size corresponding to the first search is 2, and the search step size corresponding to the second search is 1. Alternatively, the downsampling factor corresponding to the first search is greater than the downsampling factor corresponding to the second search. For example, the downsampling factor corresponding to the first search is 4, and the downsampling factor corresponding to the second search is 2. In other words, the first search is a coarse search, and the second search is a fine search. Any method that can reflect the coarsening of the first search over the second search is acceptable, and no specific limitation is imposed here.

[0166] It should also be noted that when performing the first search followed by the second search, not only is the search step size corresponding to the first search larger than the search step size corresponding to the second search, but the first search area is also smaller than the preset search area. The first search area is the search area near the initial matching template. For example, the best coarse matching template can be determined within the preset search area with a step size of 2. Then, the best fine matching template (i.e., the final reference template) can be determined near the best coarse matching template with a step size of 1.

[0167] In yet another possible implementation, the preset search area may include at least one sub-search area; and searching within the preset search area based on the first template to determine the target block vector may include:

[0168] Searching in at least one sub-search area respectively to determine the best block vector and the corresponding matching cost value of each sub-search area;

[0169] Determine the optimal block vector corresponding to the minimum matching cost value based on the optimal block vector and the corresponding matching cost value of each sub-search area;

[0170] The best block vector corresponding to the minimum matching cost value is used as the target block vector.

[0171] It should be noted that in this embodiment of the present application, the search area for the current block template can be the reconstructed portion of the CTB where the current block is located, or it can be another reconstructed CTB area. The search area here is actually the set of all search points. Because the shape of this area is often not representable by a single rectangular area, in a specific implementation, multiple rectangular areas can be searched, and the search results from different areas can be combined to obtain the final optimal reference block and optimal block vector.

[0172] Refer to Figure 7, which shows a schematic diagram of different sub-region divisions of a search area provided by an embodiment of the present application. As shown in Figure 7, 8 different sub-region division methods are shown here. Among them, the background block filled with black is the current block; the five division methods (a), (b), (c), (d), and (f) all divide the search area into four sub-search areas, and the three division methods (e), (g), and (h) all divide the search area into three sub-search areas, where different filling patterns represent a sub-search area. Among them, in Figure 7, (a), (b), (c), and (d) take into account all available search ranges, and (e), (f), (g), and (h) do not search the area directly above and the area directly to the left.

[0173] It should also be noted that, using (f) in Figure 7 as an example, the preset search area is divided into four sub-search areas, each denoted by regionId, which can take values ​​of 0, 1, 2, or 3. Using the search points (iPosHor, iPoxVer) within each sub-search area, i.e., each block vector BV (consisting of horizontal and vertical components: (pX, pY), where pX = iPosHor - xTbCmp and pY = iPosVer - yTbCmp, with pX between bvXMins and bvXMaxs, and pY between bvYMins and bvYMaxs), a reference block matching the current block can be found in the reconstructed area. The adjacent reconstructed pixels of the reference block serve as the reference template. This allows the matching cost between the first template of the current block and the reference template to be calculated, denoted as pDiff.

[0174] In this way, all search points in all search ranges (regionId = 0, 1, 2, 3) are traversed and compared to obtain the search point with the smallest matching cost pDiff. Its corresponding matching cost is recorded as pDiff_BEST, and its corresponding block vector is recorded as the best block vector BV_BEST (pX_BEST, pY_BEST), which is also the target block vector described in this embodiment; its corresponding best matching template T_BEST is the reference template ultimately required.

[0175] S602: When the reference template meets the first preset condition, perform a first process on the adjacent area of ​​the reference template to determine a matching template, and determine model parameters according to the first template and the matching template.

[0176] It should be noted that, in the embodiment of the present application, the model parameters may include coefficients of the target filter. In some embodiments, the method may further include: determining the coefficients of the target filter based on the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template.

[0177] It should also be noted that, in the embodiment of the present application, the matching template may include: sampling points in the reference template and sampling points in an adjacent area of ​​the reference template.

[0178] In some embodiments, the method may further include: if sampling points outside the reference template are used, determining that the reference template satisfies a first preset condition. That is, if the reference template is at an image boundary, sampling points outside the reference template need to be used. Specifically, for sampling points of the reference template near the boundary, adjacent pixels need to be used. These adjacent pixels may be outside the boundary. In this case, the reference template is determined to satisfy the first preset condition, and the adjacent region of the reference template needs to be subjected to the first processing.

[0179] In some embodiments, when the reference template meets the first preset condition, performing the first processing on the adjacent area of ​​the reference template may include: if sampling points outside the reference template are used, filling the sampling points of the adjacent area of ​​the reference template.

[0180] In some embodiments, filling the sampling points of the adjacent area of ​​the reference template may include:

[0181] Determine whether the sampling points in the adjacent area of ​​the reference template are available;

[0182] If the sampling points of the adjacent area of ​​the reference template are available, the sampling points of the adjacent area of ​​the reference template are directly used;

[0183] If the sampling points of the adjacent area of ​​the reference template are not available, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0184] In some embodiments, the sampling points of the adjacent area of ​​the reference template are available and may include at least one of the following:

[0185] The sampling point is within the image boundary;

[0186] The sampling point is within the tile boundary;

[0187] The sampling points have been rebuilt.

[0188] In some embodiments, filling the sampling points of the adjacent area of ​​the reference template may include:

[0189] Determine whether the sampling points of the adjacent area of ​​the reference template exceed the preset search range;

[0190] If the sampling points of the adjacent area of ​​the reference template do not exceed the preset search range, the sampling points of the adjacent area of ​​the reference template are directly used;

[0191] If the sampling points of the adjacent area of ​​the reference template exceed the preset search range, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0192] In some embodiments, the method may further include: when the reference template meets a second preset condition, using the reference template directly as a matching template, and executing the step of determining model parameters based on the first template and the matching template.

[0193] In some embodiments, the reference template satisfies the second preset condition, including: the reference template does not satisfy the first preset condition.

[0194] In some embodiments, the reference template satisfies a second preset condition, including at least one of the following:

[0195] The reference template is not at the image boundary;

[0196] The reference template does not exceed the preset search range;

[0197] The sampling points in the reference template have been reconstructed;

[0198] The sampling points in the reference template and the current block are in the same tile;

[0199] Sampling points outside the reference template are not used.

[0200] That is to say, in the embodiment of the present application, if the sampling points of the adjacent area of ​​the reference template need to be used, the sampling points of the adjacent area of ​​the reference template need to be filled.

[0201] It should also be noted that, in embodiments of the present application, the coefficients of the target filter may be determined by solving an optimization problem. Accordingly, in some embodiments, the method may further include: the coefficients of the target filter are the coefficients used by the target filter when a first error between an output value of a pixel reference value in the matching template after being processed by the target filter and a pixel reference value in the first template satisfies a first condition.

[0202] It should be understood that for the first error to satisfy the first condition, in one possible implementation, the first condition is that the first error is minimized. Alternatively, in another possible implementation, the first condition is that the first error is within a first preset threshold range. Alternatively, in yet another possible implementation, the first condition is that the change in the first error is within a second preset threshold range.

[0203] It should also be understood that the first preset threshold range and the second preset threshold range are both metrics preset by the decoding end for determining whether the first error satisfies the first condition. Furthermore, the first error herein may be a mean square error (MSE), or may be a sum of squared error (SSE), or may be a sum of absolute error (SAD), or may be a sum of absolute error (SATD) after a Hadamard-transformed error (HATD), or may be a mean absolute error (MAE), etc., and this embodiment of the present application does not specifically limit this.

[0204] In some embodiments, determining coefficients of a target filter based on pixel reference values ​​in the first template and pixel reference values ​​in the matching template may include:

[0205] Determining autocorrelation parameters based on pixel reference values ​​in the matching template;

[0206] determining a cross-correlation parameter based on the pixel reference value in the first template and the pixel reference value in the matching template;

[0207] The coefficients of the target filter are determined according to the autocorrelation parameters and the cross-correlation parameters.

[0208] It should be noted that, in the embodiment of the present application, the pixel reference value includes at least one of the following: a pixel reconstruction value, a pixel gradient value, and pixel position information.

[0209] That is, in the embodiment of the present application, the target filter is used as the filter model of the embodiment of the present application, and the input information of the target filter is the pixel reference value in the matching template. Here, the coefficient of the target filter can be expressed as c k,l , which may also be referred to as filter coefficients in this embodiment. The input information used to calculate the filter coefficients may be the available reconstructed pixels of the matching template; or, the gradient of each reconstructed pixel in the matching template, including but not limited to horizontal gradients and vertical gradients, may be calculated, and the calculated gradients may be used as the input information for calculating the filter coefficients; or, the position information of each reconstructed pixel may be used as the input information for calculating the filter coefficients. The position information may be the absolute position information of each reconstructed pixel in the entire image, or the relative position information of each reconstructed pixel relative to a reference point; this is not specifically limited here.

[0210] In a specific embodiment, a reconstruction region R for calculating the filter coefficients is first determined. Then, by minimizing the MSE between the reconstructed pixels in the region R and the reconstructed pixels of the first template, a set of filter coefficients can be derived, namely: MSE = E[(predTemp[i][j] - recTemp[i][j]) 2 ] =E[(∑ k,l=-1~1 c k,l·refTemp[i+k][j+l]-recTemp[i][j]) 2 ] (3)

[0211] Where refTemp[i][j] represents the input reconstructed pixel value, recTemp[i][j] represents the reconstructed pixel value of the current block template, (i,j) represents the coordinate position, (i,j)∈R, k,l represents the coordinate offset of the filter coefficient position relative to the filter center position, where k and l are between -1 and 1, and the values ​​of (k,l) can include (0,0), (0,-1), (-1,0), (0,1), (1,0), c k,l Indicates the required filter coefficient. In addition, E represents the operation of calculating the average value. The calculation formula at this time is as follows:

[0212] Among them, N pos Refers to the calculation of |predTemp[i][j]-recTemp[i][j]| 2 For example, if there are 5 (i, j) pairs involved in the operation, then N pos The value of is equal to 5.

[0213] Furthermore, the process of minimizing MSE to derive the filter coefficients is as follows:

[0214] First, for c k,l Find the partial derivative and make it 0, that is: E[2(∑ k,l=-1~1 c k,l ·refTemp[i+k][j+l]-recTemp[i][j])·refTemp[i+m][j+n]]=0 (6)

[0215] Among them, k and l are between -1 and 1, and m and n are between -1 and 1.

[0216] Secondly, according to formula (5) and formula (6), we can get: ∑ k,l=-1~1 c k,l ·E(refTemp[i+k][j+l]·refTemp[i+m][j+n]) =E(recTemp[i][j]·refTemp[i+m][j+n]) (7)

[0217] Once again, after determining the reconstruction region R, the obtained equation (7) is expanded into a matrix form, as follows:

[0218] Among them, for A, the pixel reference value in the matching template is represented by refTemp[i][j], and A represents the autocorrelation parameter of refTemp[i][j], as follows

[0219] For B, the pixel reference value in the first template is represented by recTemp[i][j], and B represents the cross-correlation parameter of recTemp[i][j] and refTemp[i][j], as follows:

[0220] That is to say, since the autocorrelation matrix of refTemp and the cross-correlation vector of refTemp and recTemp in the reconstruction area R are known, the filter coefficient c can be calculated by solving the equation group shown in formula (7): k,l , for the filter coefficient c k,l It can be fixed-point or not.

[0221] In the embodiment of the present application, for the target filter, it is also necessary to determine the number of coefficients of the target filter and the shape of the target filter, etc. The number of coefficients of the target filter and the shape of the target filter can be preset fixed values ​​or directly determined by the decoded code stream.

[0222] In some embodiments, for the number of coefficients of the target filter, the method may further include: the number of coefficients of the target filter is equal to a first preset value.

[0223] In some embodiments, for the number of coefficients of the target filter, the method may further include: decoding the code stream to determine the number of coefficients of the target filter.

[0224] It should be noted that the number of coefficients of the target filter can be represented by nTap. For example, the value of nTap can be 4, 5, 6, 7, 8, 9, etc., but is not specifically limited.

[0225] It should also be noted that the number of coefficients of the target filter can also be called the target filter tap number. Here, the number of coefficients of the target filter can be a preset constant value, or it can be determined by decoding the code stream, or even determined based on the syntax element identification information of the current block.

[0226] In some embodiments, regarding the shape of the target filter, the method may further include: the target filter is a one-dimensional or two-dimensional filter of a preset shape.

[0227] In some embodiments, regarding the shape of the target filter, the method may further include: decoding the code stream to determine the shape of the target filter.

[0228] In some embodiments, regarding the shape of the target filter, the method may further include: decoding the code stream, and determining a value of a filter shape parameter, wherein the filter shape parameter indicates the shape of the target filter.

[0229] It should be noted that the filter shape parameter can be represented by FilterIdx, which is used to indicate the shape of the target filter. For example, the shape of the target filter can be diamond, rectangle, cross, stripe, or even a one-dimensional filter or a two-dimensional filter, but is not specifically limited thereto.

[0230] Exemplarily, if the value of FilterIdx is equal to 0, the shape of the target filter is determined to be a diamond; if the value of FilterIdx is equal to 1, the shape of the target filter is determined to be a cross; if the value of FilterIdx is equal to 2, the shape of the target filter is determined to be a rectangle.

[0231] It should also be noted that the shape of the target filter may be a preset shape, or may be determined by decoding a code stream, or may even be determined according to syntax element identification information of the current block.

[0232] S603: Filter the reference block according to the model parameters to determine a filtered reference block.

[0233] S604: Determine a prediction value of the current block according to the filtered reference block.

[0234] It should be noted that in the embodiment of the present application, after the model parameters are determined, the prediction value of the current block can be determined based on the model parameters and the reference block. Specifically, the reference block is filtered according to the model parameters, and the prediction value of the current block is determined based on the filtered reference block.

[0235] In some embodiments, filtering the reference block according to the model parameters to determine the filtered reference block may include: filtering the reference block according to the model parameters to determine the first output value of the target filter; and determining the filtered reference block based on the first output value of the target filter.

[0236] In some embodiments, filtering the reference block according to the model parameters to determine the filtered reference block may include: if sampling points of an adjacent region of the reference block are used, then padding the sampling points of the adjacent region of the reference block. In other words, in the embodiments of the present application, if sampling points of an adjacent region of the reference block are used, padding the sampling points of the adjacent region of the reference block is required.

[0237] In the embodiment of the present application, a first output value of the target filter can be calculated based on the pixel reconstruction values ​​of the reference block and the coefficients of the target filter in the model parameters. Then, based on the first output value of the target filter, the filtered reference block can be determined. The target filter can be a linear or nonlinear filter model, without specific limitation.

[0238] In one possible implementation, filtering the reference block according to the model parameters to determine the first output value of the target filter may include:

[0239] Calculating the product of the pixel reconstruction value of the reference block and the coefficient of the corresponding target filter;

[0240] The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter and n is a positive integer.

[0241] It should be noted that the target filter in the embodiment of the present application is a linear filter model. The first output value of the target filter can be calculated by the following formula: pred [i][j]=∑ k ∑ l ref[i+k][j+l]×C k,l (11)

[0242] Where ref[i+k][j+l] represents the pixel reconstruction value of the reference block, C k,l Represents the coefficients of the target filter.

[0243] In another possible implementation, filtering the reference block according to the model parameters to determine the first output value of the target filter may include:

[0244] Determine a first value of a pixel reconstruction value of the reference block under a first mapping relationship;

[0245] Calculating the product of the first value and the coefficient of the corresponding target filter;

[0246] The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter and n is a positive integer.

[0247] It should be noted that the target filter in the embodiment of the present application is a nonlinear filter model. For example, when minimizing the MSE of the filter coefficients, the calculation formula is adjusted as follows: MSE = E[(predTemp[i][j] - recTemp[i][j]) 2 ] =E[(∑ k,l=-1~1 c k,l(refTemp[i+k][j+l]) 2 -recTemp[i][j]) 2 ] (12)

[0248] Then the first output value of the target filter can be calculated by the following formula: pred [i][j]=∑ k ∑ l (ref[i+k][j+l]) 2 ×C k,l (13)

[0249] Where ref[i+k][j+l] represents the pixel reconstruction value of the reference block, C k,l Represents the coefficients of the target filter.

[0250] It should also be noted that, in the embodiment of the present application, the filtered reference block is determined based on the first output value of the target filter. The first output value of the target filter can be directly set as the filtered reference block; or the first output value of the target filter can be subjected to a first filtering to obtain the filtered reference block; the first filtering here can be a low-pass filter, an up / down sampling filter, etc., which is not specifically limited here.

[0251] It should also be noted that, in the embodiment of the present application, after determining the first output value of the target filter, a first offset value (expressed as bias) may be added to the first output value to determine a filtered reference block.

[0252] In some embodiments, determining a filtered reference block based on a first output value of a target filter may include: determining a first offset value; and performing an addition operation based on the first output value and the first offset value to determine the filtered reference block.

[0253] In a possible implementation, determining the first offset value may include: setting the first offset value to be equal to a second preset value.

[0254] In another possible implementation, determining the first offset value may include: if the number of coefficients of the target filter is n, determining the n+1th coefficient of the target filter; and determining the first offset value based on the n+1th coefficient and the second offset value.

[0255] In an embodiment of the present application, for the second offset value, the method may further include: setting the second offset value equal to a third preset value; or setting the second offset value equal to the value of the pixel reconstruction value of the reference block under the second mapping relationship.

[0256] It should be noted that in the embodiments of the present application, the calculated filter coefficients are used as the number of taps corresponding to the filter template, that is, the number of filter coefficients is equal to the number of taps nTap of the filter template. In addition, several bias terms bias can be added to the filter template. Exemplarily, in the embodiments of the present application, when nTap = 5, the filter coefficients at this time are the tap coefficients c0 to c4 corresponding to the filter template, and the predicted value at the (i, j) position in the filtered reference block is calculated as follows:

[0257] At this time, a bias term can be added as shown in the following formula:

[0258] In the embodiments of the present application, c n = c i,j,k,l . Here, Constant can be a fixed constant, for example, Constant = 1 << (BitDepth - 1), or it can be a number related to the reconstructed pixel value at the (i, j) position in the reference block, for example, Constant = f(ref[i][j]), or it can be a number related to the reconstructed pixel value corresponding to a certain tap in the filter template except for the (i, j) position, for example, Constant = f(ref[k][l]). Among them, Constant = f(ref[i][j]) or Constant = f(ref[k][l]) can be a linear mapping relationship or a non-linear mapping relationship. One or more bias terms can be added, and no specific limitation is made here.

[0259] Further, in some embodiments, determining the predicted value of the current block according to the filtered reference block may include: performing a second process on the filtered reference block to obtain the predicted value of the current block.

[0260] In the embodiments of the present application, for the second process, the second process can be setting the predicted value of the current block to be equal to the filtered reference block; or, the second process can be a clamping (clip) operation that limits the filtered reference block within a preset numerical range, or, the second process can also be other operations, which are not specifically limited here.

[0261] Here, for the clip operation, the preset numerical range here can be: between 0 and (1 << BitDepth) - 1, where BitDepth represents the bit depth. If the value of the filtered reference block exceeds the取值范围 of this preset numerical range, then the filtered reference block needs to be corrected accordingly. Exemplarily, the filtered reference block can also be represented by Y pred [i][j], and at this time, a correction operation can be performed on Y pred [i][j] as follows:

[0262] When Y pred [i][j] is less than 0, set it to 0;

[0263] When Y pred [i][j] is greater than or equal to 0 and less than or equal to (1 << BitDepth) - 1, it is equal to Y pred [i][j];

[0264] When Y pred [i][j] is greater than (1 << BitDepth) - 1, set it to (1 << BitDepth) - 1.

[0265] In this way, after performing the correction operation on Y pred [i][j], it can be ensured that all pixel values in the filtered reference block are between 0 and (1 << BitDepth) - 1.

[0266] Furthermore, the number of filter models can be expanded. In addition to establishing only one filter model, multiple filter models can also be established. Therefore, in some embodiments, the method may further include:

[0267] Determine multiple sets of model parameters according to the first template and the matching template;

[0268] Construct multiple filter models according to multiple sets of model parameters, perform filtering processing on the reference block according to multiple filter models respectively, and determine multiple filtered reference blocks;

[0269] Determine the predicted value of the current block according to multiple filtered reference blocks.

[0270] In some embodiments, determining multiple sets of model parameters according to the first template and the matching template may include: classifying the reconstructed pixels in the first template and the matching template respectively in a preset manner to obtain multiple sets of sub - templates and multiple sets of sub - matching templates; determining multiple sets of model parameters according to multiple sets of sub - templates and multiple sets of sub - matching templates.

[0271] It should be noted that in the embodiments of the present application, the preset manner here may be the magnitude of the reconstructed pixel value, or it may also be the position information of the reconstructed pixel, or it may also be the shape of the filter, etc., which is not limited herein. Among them, after classifying in the preset manner, each set of sub - templates and the corresponding sub - matching templates can calculate a set of model parameters, and each set of model parameters can determine a filter model, so that multiple filter models can be constructed.

[0272] In a possible implementation, the method may further include: decoding the code stream to determine the target model index value; determining the corresponding target filter from multiple filter models based on the target model index value; filtering the reference block according to the target filter to determine the prediction value of the current block.

[0273] In another possible implementation, multiple filtered reference blocks may be determined by filtering the reference blocks according to multiple filter models. In some embodiments, determining the prediction value of the current block based on the multiple filtered reference blocks may include performing a weighted calculation on the multiple filtered reference blocks to determine the prediction value of the current block.

[0274] It should also be noted that if the weights of each filtered reference block are equal and equal to the inverse of the number of reference blocks, then the weighted calculation here can also be regarded as an averaging calculation. In other words, the average of multiple filtered reference blocks is calculated to determine the prediction value of the current block.

[0275] Exemplarily, the input information for calculating the filter coefficients is classified, and a filter model is established for each category of input information. For example, when using reconstruction information to establish a filter model, one possible implementation is to classify by the mean of the reconstruction information, establishing a filter model for reconstruction information greater than the mean, and establishing a filter model for reconstruction information less than the mean. Another possible implementation is to classify by the position of the reconstruction information. For example, a filter model can be established using the available reconstruction information on the left and upper sides, and a second filter model can be established using the available reconstruction information on the left and upper left sides. The encoder decides which model to use. One possible implementation is for the encoder to determine which model to use through rate-distortion optimization and transmit corresponding decoding parameters to the decoder so that the decoder clearly selects which filter model. Another possible implementation is to classify by filter shape. Multiple filters of different shapes can be used, and a filter model is established for each filter shape. The encoder decides which filter shape to use. One possible implementation is for the encoder to determine which filter to use through rate-distortion optimization and transmit corresponding decoding parameters to the decoder so that the decoder clearly selects which filter model.

[0276] S605: Determine a reconstructed value of the current block according to the predicted value of the current block.

[0277] It should be noted that in an embodiment of the present application, after determining the predicted value of the current block, the reconstructed value of the current block can also be restored. In some embodiments, determining the reconstructed value of the current block based on the predicted value of the current block can include: decoding the code stream to determine the predicted residual value of the current block; and determining the reconstructed value of the current block based on the predicted value of the current block and the predicted residual value of the current block.

[0278] In a specific embodiment, determining the reconstruction value of the current block based on the prediction value of the current block and the prediction difference value of the current block may include: adding the prediction value of the current block and the prediction difference value of the current block to determine the reconstruction value of the current block.

[0279] It should also be noted that, in the embodiment of the present application, whether the current block applies intra-frame template matching or whether it is used for a filter model can be determined by different syntax element identification information. In some embodiments, the method may further include: decoding the bitstream, determining the value of the first syntax element identification information;

[0280] If the first syntax element identification information is used to indicate that intra template matching is applied to the current block, decoding the bitstream to determine the value of the second syntax element identification information;

[0281] If the second syntax element identification information is used to indicate that a filter model is applied to the current block, the steps of filtering the reference block according to the model parameters to determine a filtered reference block and determining a prediction value of the current block according to the filtered reference block are performed.

[0282] Furthermore, in some embodiments, the method may further include: if the second syntax element identification information is used to indicate that the filter model is not applied to the current block, using the reconstructed pixel value in the reference block as the prediction value of the current block.

[0283] In an embodiment of the present application, for the first syntax element identification information, if the value of the first syntax element identification information is a first value, it is determined that the first syntax element identification information is used to indicate that intra template matching is applied to the current block; or, if the value of the first syntax element identification information is a second value, it is determined that the first syntax element identification information is used to indicate that intra template matching is not applied to the current block.

[0284] In an embodiment of the present application, for the second syntax element identification information, if the value of the second syntax element identification information is a first value, it is determined that the second syntax element identification information is used to indicate that the filter model is applied to the current block; or, if the value of the second syntax element identification information is a second value, it is determined that the second syntax element identification information is used to indicate that the filter model is not applied to the current block.

[0285] It should be noted that in the embodiment of the present application, the first value and the second value are different, and the first value and the second value can be in parameter form or in numerical form. Specifically, the first syntax element identification information and the second syntax element identification information can be parameters written in the profile or the value of a flag, which is not specifically limited here.

[0286] For example, for the first value and the second value, the first value may be set to 1 and the second value may be set to 0; or, the first value may be set to true and the second value may be set to false; however, this is not specifically limited here.

[0287] It should also be noted that in the embodiment of the present application, whether the current block uses the filtered reference block as the final prediction value is determined by certain conditions, but is not limited to the following three methods. For example, these three methods can be as follows:

[0288] Method 1: Determine whether to filter the matching template by comparing the distortion of the matching template and the current block template, such as SAD, MSE, SATD, or SSE, with the threshold T_Distortion1;

[0289] Method 2: Based on the condition that the filter model is used in Method 1, the distortion between the filtered matching template and the template of the current block, such as SAD, MSE, SATD, or SSE, and the threshold T_Distortion2, is used to determine whether to filter the reference block.

[0290] Method three: The encoder transmits a Flag to indicate whether to apply the filter model. tmpFlag indicates whether the current block applies intra-frame template matching, and filterFlag indicates whether the current block applies the filter model. When tmpFlag is 1, the encoder decides whether to filter the reference block by comparing the distortion between the reference block and the current block before and after filtering, such as SAD or MSE or SATD or SSE. If the distortion after filtering is less than the distortion before filtering, filterFlag is 1, and the current block uses the reference block after filtering as the prediction block; otherwise, filterFlag is 0, and the current block uses the reference block before filtering as the prediction block. The encoder transmits filterFlag to the decoder. There are many ways to implement the encoding of filterFlag. One feasible way is to use equal probability coding; another feasible way is to use context coding. The default context initial state and context update rate can be used, or the context initial state and context update rate can be determined by statistics.

[0291] This embodiment provides a decoding method that determines a first template for a current block, as well as a matching template and a reference block; determines model parameters based on the first template and the matching template; filters the reference block based on the model parameters to determine a filtered reference block; determines a prediction value for the current block based on the filtered reference block; and determines a reconstructed value for the current block based on the prediction value of the current block. In this way, the model parameters are determined based on the first template and the matching template, and the model parameters fully reflect the correlation between the matching template and the first template of the current block. This correlation is applied to the reference block, and its reconstructed pixels are filtered and corrected. The filtered reconstructed pixels are then used as the predicted pixels for the current block, thereby improving prediction accuracy, saving bit rate, and improving encoding and decoding efficiency, thereby enhancing encoding and decoding performance.

[0292] In another embodiment of the present application, based on the decoding method described in the aforementioned embodiment, during the prediction process of the Intra TMP technology, it is proposed to correct the best matching reconstructed block (i.e., the reference block) and use the corrected reconstructed pixels as the predicted pixels of the current block. Specifically, a linear filter model is established using the pixels of the matching template and the current block template, and the linear filter model is applied to the reference block, and the filtered pixels are used as the final predicted pixels. The technical solution of the embodiment of the present application can be referred to as Intra Template Matching based on Filter-based linear model (Intra TMP-FLM).

[0293] The following is a detailed introduction to the prediction process of the Intra TMP-FLM technology.

[0294] The input of the Intra TMP-FLM technology: the position of the current block (xTbCmp, yTbCmp), the width of the current block nTbW, and the height of the current prediction block nTbH.

[0295] Output of the Intra TMP-FLM technology: the predicted value predSamples[x][y] of the current block, where x = 0..nTbW–1, y = 0..nTbH–1.

[0296] Specifically, the Intra TMP-FLM prediction process can be divided into five steps: determining the current template type, obtaining the reconstructed pixels of the current template, determining the block vector within a predefined search range, establishing a linear filter model, and generating the predicted value. It is important to note that Intra TMP-FLM can be used to predict both luma and chroma components, and this is not specifically limited here.

[0297] Referring to FIG8 , which shows a schematic diagram of a prediction process based on the intra TMP-FLM technology provided in an embodiment of the present application. As shown in FIG8 , the process may include:

[0298] S801: Determine the current template type.

[0299] It should be noted that the Intra TMP-FLM technology uses the adjacent reconstructed pixels of the current block as templates to search for matching templates within a predefined search area, where the adjacent reconstructed pixels can be the upper reference pixel, upper left reference pixel, upper right reference pixel, left reference pixel, lower left reference pixel, etc. of the current block. Therefore, the template type can be classified and the corresponding template type can be determined according to the availability of the adjacent reconstructed pixels.

[0300] It should also be noted that refTemplateType can be used to represent the template type. As shown in FIG3 , the block filled with the grid is the current block, and the adjacent area of ​​the current block is the template T. Six template types are shown here.

[0301] For example, the six template types are as follows:

[0302] When the upper left reference pixel, the upper reference pixel, and the left reference pixel are all available, the value of refTemplateType is 1, and the template shape is as shown in (a) of Figure 3;

[0303] When only the left reference pixel is available, the value of refTemplateType is 2, and the template shape is shown in (b) in Figure 3;

[0304] When only the upper reference pixel is available, the value of refTemplateType is 3, and the template shape is shown in (c) in Figure 3;

[0305] When only the left reference pixel and the upper left reference pixel are available, the value of refTemplateType is 4, and the template shape is shown in (d) in Figure 3;

[0306] When only the left reference pixel and the lower left reference pixel are available, the value of refTemplateType is 5, and the template shape is shown in (e) of Figure 3;

[0307] When only the upper reference pixel and the upper right reference pixel are available, the value of refTemplateType is 6, and the template shape is shown in (f) in Figure 3.

[0308] S802: Obtain current template pixels.

[0309] It should be noted that the template for the Intra TMP-FLM technique can be composed of reconstructed pixels from one or more of the following regions: the top, upper right, left, lower left, or upper left of the current block. Furthermore, the template size can be pre-set. For example, when obtaining the left template, the template width (templateW_size) can be set to 4, and when obtaining the top template, the template height (templateH_size) can be set to 4.

[0310] It should also be noted that the portion of the reconstructed pixels to be obtained can be determined by the value of refTemplateType. For example, when the value of refTemplateType is 1, the reconstructed pixels of the left, upper-left, and upper sides of the current block are obtained; or, when the value of refTemplateType is 2, only the reconstructed pixels of the four left columns of the current block are obtained; or, when the value of refTemplateType is 3, only the reconstructed pixels of the four upper rows of the current block are obtained.

[0311] S803: Determine a block vector within a predefined search range.

[0312] It should be noted that the search process of the Intra TMP-FLM technology is mainly divided into an initialization process, determining a search area of ​​the template in the current frame, and searching and determining the optimal block vector in the search area.

[0313] It should also be noted that when searching for the best matching template in the search area, a search strategy of coarse search first and then fine search may be adopted, or only fine search or only coarse search may be performed, which is not specifically limited here.

[0314] In an embodiment of the present application, the coarse search here can specifically be: determining the best coarse matching template in the search area with a first preset step size (for example, 2), or using a downsampled template (for example, a downsampling factor of 2) to determine the best coarse matching template in the search area.

[0315] In the embodiment of the present application, the fine search here may specifically be: determining the best fine matching template in the search area with a second preset step size (eg, 1), or determining the best fine matching template near the best coarse matching template after completing the coarse search.

[0316] Referring to FIG9 , which shows a schematic diagram of a search process based on the Intra TMP technology provided by an embodiment of the present application. As shown in FIG9 , the process may include:

[0317] S901: Initialize parameters.

[0318] It should be noted that uiPatchWidth is initialized to nTbW + templateW_size, and uiPatchHeight is initialized to nTbH + templateH_size. TemplateW_size and templateH_size can be fixed constants or dynamically adjusted according to the size of the current block. In addition, templateW_size and templateH_size can be equal or unequal. For example, templateW_size = 4, templateH_size = 4; or, when the width of the current block is greater than 8, set templateW_size = 4; when the width of the current block is less than or equal to 8, set templateW_size = 2; when the height of the current block is greater than 8, set templateH_size = 4; when the height of the current block is less than or equal to 8, set templateH_size = 2.

[0319] For example, Figure 10A shows a schematic diagram of parameter definitions for a current block and its template, as provided in an embodiment of the present application. As shown in Figure 10A , the specific meanings of the parameters are as follows: nTbW and nTbH represent the size of the current block, templateW_size and templateH_size represent the template size, and uiPatchWidth and uiPatchHeight represent the size of the block containing the current block and its template.

[0320] In addition, Figure 10B shows a filling schematic diagram of a reference block and its template adjacent area provided in an embodiment of the present application. As shown in Figure 10B, the grid filling part is the template adjacent area; if the reference template is in the boundary area, then the sampling points of the template adjacent area need to be filled.

[0321] Furthermore, the cost threshold between the initialization templates is represented by diffThreshold. For example, when the cost function is SAD, the threshold can be: diffThreshold = ((1 <<bitDepth)> >2)×(uiPatchHeight×uiPatchWidth-nTbH×nTbW). When the image bit depth bitDepth is 10, diffThreshold indicates that the maximum distortion of each pixel in the template area is 256.

[0322] Furthermore, the position of the coding tree block CTB where the current block CB is located is initialized: ctbRsX, ctbRsY.

[0323] Furthermore, the position offset of the current block CB in the current CTB is initialized: offsetLCBY=yTbCmp−ctbRsY, offsetLCBX=xTbCmp−ctbRsX.

[0324] Furthermore, initialize iTemplateSizeH=templateH_size and iTemplateSizeW=templateW_size.

[0325] Furthermore, iBvShift is initialized, where iBvShift is the precision of the block vector BV. For example, the precision of BV can be integer pixel precision, in which case iBvShift is 0; the precision of BV can also be sub-pixel precision, for example, iBvShift of 1 indicates 1 / 2 pixel precision, and iBvShift of 2 indicates 1 / 4 pixel precision. This is not specifically limited here.

[0326] Furthermore, the preset search range of the template is initialized. The preset search range of the template can be set to a fixed size or dynamically adjusted according to the encoding block size. For example, searchRangeWidth = TMP_SEARCH_RANGE_MULT_FACTOR × nTbW, searchRangeHeight = TMP_SEARCH_RANGE_MULT_FACTOR × nTbH; where the value of TMP_SEARCH_RANGE_MULT_FACTOR can be a preset value, such as 5.

[0327] S902: Determine a search area of ​​the template in the current frame.

[0328] It should be noted that the Intra TMP search area is the reconstructed portion of the current image and is limited by the search range. As shown in Figure 11, the dark-filled background area represents the reconstructed area, the black-filled background block represents the current block, and the dashed box represents the search range window. Therefore, the Intra TMP search area is no larger than the overlap between the reconstructed area represented by the dark background and the area marked by the dashed box.

[0329] As can be seen, the search area for the current block template can be the reconstructed portion of the CTB where the current block resides, or it can be another reconstructed CTB area. The search area here is actually the set of all search points. Because the shape of this area is often not representable by a single rectangular region, in practice, multiple rectangular regions can be searched, and the search results from these different regions can be combined to obtain the final best matching block and best block vector.

[0330] For example, using Figure 7 as an example, eight different sub-region division methods are shown. The black-filled background block is the current block; (a), (b), (c), (d), and (f) all divide the search area into four sub-search areas, and (e), (g), and (h) all divide the search area into three sub-search areas. Here, different fill patterns represent a sub-search area.

[0331] In Figure 7, (a), (b), (c), and (d) consider all available search ranges, and (e), (f), (g), and (h) do not search the area directly above and to the left.

[0332] For example, assuming that different sub-search regions are represented by regionId, and considering that the template pixels of the current block need to be retrieved in the image reconstruction region and the pixels of the reconstructed block corresponding to the template also need to be retrieved in the reconstruction region, it is necessary to further determine the positions that can be searched within the sub-search regions represented by different regionIds based on the current block position (xTbCmp, yTbCmp), the current block size (nTbW, nTbH), the current image size (picWidth, picHeight), the size of the CTB in which the current block is located (CtbSizeW, CtbSizeH), the preset search range of the template (searchRangeWidth, searchRangeHeight), and the position offset of the current block within the current CTB (offsetLCBY, offsetLCBX), thereby determining the block vector BV. Specifically, iVerMin and iVerMax represent the absolute coordinate positions that can be searched at least and at most in the vertical direction, respectively, and iHorMin and iHorMax represent the absolute coordinate positions that can be searched at least and at most in the horizontal direction, respectively. The values ​​of iVerMin, iVerMax, iHorMin, and iHorMax are different in the search areas represented by different regionIds.

[0333] Taking (f) in FIG. 7 as an example, the search area is divided into four sub-search areas, which are implemented as follows:

[0334] When regionId is equal to 0, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0335] iHorMax0=min((xTbCmp+searchRangeWidth)< <iBvShift,((picWidth-nTbW)<<iBvShift));

[0336] iHorMin0=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0337] iVerMax0=(yTbCmp-nTbH-offsetLCBY)< <iBvShift;

[0338] iVerMin0=max(((iTemplateSizeH)< <iBvShift),((yTbCmp-searchRangeHeight)<<iBvShift))。

[0339] When regionId is equal to 1, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0340] iHorMin1=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0341] iHorMax1=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

[0342] iVerMin1=(yTbCmp+1)< <iBvShift;

[0343] iVerMax1=min(picHeight-nTbH,(yTbCmp-offsetLCBY+CtbSizeH-nTbH)< <iBvShift)。

[0344] When regionId is equal to 2, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0345] iHorMax2=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

[0346] iHorMin2=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0347] iVerMin2=max((iTemplateSizeH)< <iBvShift,(yTbCmp-nTbH-offsetLCBY)<<iBvShift);

[0348] iVerMax2=(yTbCmp)< <iBvShift。

[0349] When regionId is equal to 3, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0350] iHorMin3=max((iTemplateSizeW)< <iBvShift,(xTbCmp-offsetLCBX-nTbW+1)<<iBvShift);

[0351] iHorMax3=(xTbCmp-nTbW)< <iBvShift;

[0352] iVerMin3=max(((iTemplateSizeH)< <iBvShift),(yTbCmp-offsetLCBY-nTbH+1)<<iBvShift);

[0353] iVerMax3=(yTbCmp-nTbH)< <iBvShift。

[0354] In practical applications, the iHorMin regionId 、iHorMax regionId 、iVerMin regionId 、iVerMax regionId Represent the left edge, right edge, top edge and bottom edge of different sub-search areas respectively.

[0355] To intuitively illustrate the different sub-search regions corresponding to different regionIds, see Figure 12, which shows a schematic diagram of the specific search region determination process provided by an embodiment of the present application. As shown in Figure 12, R1, R2, R3, and R4 represent four different sub-search regions. Note that Figure 12 represents the pixel range that can be aligned with the upper left corner pixel of the block.

[0356] S903: Search and determine the best block vector BV in the search area.

[0357] It should be noted that bvXMins and bvXMaxs represent the minimum offset and maximum offset of the block vector in the horizontal direction respectively; bvYMins and bvYMaxs represent the minimum offset and maximum offset of the block vector in the vertical direction respectively.

[0358] bvXMins regionId 、bvXMaxs regionId 、bvYMins regionId 、bvYMaxs regionId iVerMin determined in step S902 regionId 、iVerMax regionId 、iHorMin regionId 、iHorMax regionId Calculation yields:

[0359] bvXMins regionId =iHorMin regionId –xTbCmp;

[0360] bvXMaxs regionId =iHorMax regionId –xTbCmp;

[0361] bvYMins regionId =iVerMin regionId –yTbCmp;

[0362] bvYMaxs regionId =iVerMax regionId –yTbCmp.

[0363] Among them, bvXMins regionId 、bvXMaxs regionId 、bvYMins regionId and bvYMaxs regionId The horizontal and vertical offset ranges of the search point relative to the current block, ie, the range of the block vector BV, are determined.

[0364] It should also be noted that, through the search points (iPosHor, iPoxVer) in each search area, that is, each block vector BV (composed of horizontal and vertical components: (pX, pY), where pX = iPosHor-xTbCmp, pY = iPosVer-yTbCmp, then pX is between bvXMins and bvXMaxs, and pY is between bvYMins and bvYMaxs; in this way, a matching reconstructed block of the current block can be found in the reconstructed area, and the adjacent reconstructed pixels of the matching reconstructed block are the matching template (that is, the second template mentioned above). Therefore, the matching cost value of the adjacent template of the current block and the adjacent template of the matching reconstructed block can be calculated, which is recorded as pDiff.

[0365] Furthermore, all search points in all search ranges (regionId = 0, 1, 2, 3) are traversed, and the search point with the smallest matching cost value pDiff is obtained by comparison. Its corresponding matching cost value is recorded as pDiff_BEST, its corresponding block vector BV is recorded as the best block vector BV_BEST (pX_BEST, pY_BEST), and its corresponding matching template is the best matching template T_BEST.

[0366] In one possible implementation, if the search strategy is to perform only a coarse search, the specific implementation is as follows:

[0367] In each region at pX within bvXMins regionId with bvXMaxs regionId Between, pY is in bvYMins regionId with bvYMaxs regionId Within the search range between , a coarse search is performed with a step size greater than 1, for example, a coarse search is performed with a step size of 2. The best matching cost value obtained by template matching is recorded as pDiff_BEST, and its corresponding block vector BV is recorded as the best block vector BV_BEST (pX_BEST, pY_BEST).

[0368] In another possible implementation, if the search strategy is to perform only detailed search, the specific implementation is as follows:

[0369] In each region at pX within bvXMins regionId with bvXMaxs regionId Between, pY is in bvYMins regionId with bvYMaxs regionId Within the search range between, for example, a fine search is performed with a step size of 1 to record the optimal matching cost value obtained by template matching, pDiff_BEST, and its corresponding block vector BV is recorded as the best block vector BV_BEST (pX_BEST, pY_BEST).

[0370] In another possible implementation, if the search strategy is: perform a coarse search first and then a fine search; as shown in FIG13 , the specific process is as follows:

[0371] S1301: Determine the best coarse matching template in the search area with a step size of 2.

[0372] S1302: Determine the best fine matching template near the best coarse matching template with a step size of 1.

[0373] It should be noted that, for step S1301, in the coarse search phase:

[0374] In each region at pX within bvXMins regionIdwith bvXMaxs regionId Between, pY is in bvYMins regionId with bvYMaxs regionId Within the search range between , a coarse search is performed with a step size greater than 1. For example, the best matching cost obtained by performing a coarse search with a step size of 2 is recorded as pDiff1_BEST, and its corresponding block vector BV is recorded as the best block vector BV1_BEST(pX1_BEST, pY1_BEST), and the search region where the best matching search point is located is bestRegionId.

[0375] It should also be noted that, for step S1302, in the detailed search phase:

[0376] A further search is performed near the best block vector BV1_BEST obtained from the coarse search. Specifically, a refined search range TmpRefineRange is first determined. The refined search range can be a fixed size or related to the current block size, for example, min(nTbW, nTbH) / 2. The position of the best matching reconstructed block obtained from the coarse search is then calculated as the reference position of the fine search area: BestPosX = xTbCmp + pX1_BEST, BestPosY = yTbCmp + pY1_BEST.

[0377] First, obtain the values ​​of iVerMinbestRegionId, iVerMaxbestRegionId, iHorMinbestRegionId, and iHorMaxbestRegionId calculated in step S902 according to the value of bestRegionId, and then obtain the new search range iVerMinbestRegionId according to the optimal matching block position obtained by the rough search. refine 、iVerMax refine 、iHorMin refine 、iHorMax refine , the acquisition method is as follows:

[0378] iHorMin refine =max(iHorMinbestRegionId,BestPosX-TmpRefineRange);

[0379] iHorMax refine =min(iHorMaxbestRegionId,BestPosX+TmpRefineRange);

[0380] iVerMin refine=max(iVerMinbestRegionId,BestPosY-TmpRefineRange);

[0381] iVerMax refine =min(iVerMaxbestRegionId,BestPosY+TmpRefineRange);

[0382] Then, the adjusted block vectors BVbvXMins, bvXMaxs, bvYMins, bvYMaxs can be obtained by iVerMin refine 、iVerMax refine 、iHorMin refine 、iHorMax refine Calculation yields:

[0383] bvXMins=iHorMin refine –xTbCmp;

[0384] bvXMaxs=iHorMax refine –xTbCmp;

[0385] bvYMins=iVerMin refine –yTbCmp;

[0386] bvYMaxs=iVerMax refine –yTbCmp;

[0387] Thus, the fine search is performed at pX within bvXMins refine with bvXMaxs refine Between, pY is in bvYMins refine with bvYMaxs refine For example, the search is performed with a step size of 1, and the best matching cost obtained by template matching is recorded as pDiff_BEST, and its corresponding block vector BV is recorded as the best block vector BV_BEST (pX_BEST, pY_BEST).

[0388] After completing the above operations, the best block vector BV_BEST (pX_BEST, pY_BEST) can be obtained, where pX_BEST and pY_BEST are the horizontal offset and vertical offset of the best matching template relative to the current block template, respectively, and are also the horizontal offset and vertical offset of the best matching reconstructed block relative to the current block.

[0389] S804: Establish a linear filtering model.

[0390] It should be noted that the linear filtering model is established using the best matching template and the current block template searched in step S803, which mainly includes the following two processes: determining the reconstruction area for calculating the filter coefficients, and calculating the filter coefficients.

[0391] It should also be noted that the number of filter taps is defined as nTap. nTap can be a constant or a variable; for example, the number of filter taps can be dynamically adjusted based on the current block size. In the embodiments of the present application, filters of various shapes can be used. For example, a fixed-shape filter such as that shown in FIG14 can be used, where the number of filter taps nTap is 5 and the filter coefficients are C0, C1, C2, C3, and C4, respectively.

[0392] Referring to Figure 15, it shows a schematic diagram of a process for calculating filter coefficients provided by an embodiment of the present application. As shown in Figure 15, the process may include:

[0393] S1501: Determine a reconstruction area for calculating filter coefficients.

[0394] It should be noted that, in an embodiment of the present application, the available reconstructed pixels are determined according to the template type refTemplateType. For example, when the template type refTemplateType is 1, as shown in the aforementioned FIG10 , it indicates that the adjacent left reconstructed pixels, the upper left reconstructed pixels and the upper reconstructed pixels are all available. At this time, the number of available reconstructed pixels on the left is templateW_size×nTbH, the number of available reconstructed pixels on the upper side is templateH_size×nTbW, and the number of available reconstructed pixels on the upper left is templateW_size×templateH_size.

[0395] It should also be noted that in the embodiment of the present application, if sampling points outside the reference template are used, the sampling points in the adjacent area of ​​the reference template are filled in. Alternatively, if sampling points in the adjacent area of ​​the reference block are used, the sampling points in the adjacent area of ​​the reference block are filled in.

[0396] In a possible implementation, filling the sampling points of the adjacent area of ​​the reference template may include:

[0397] Determine whether the sampling points in the adjacent area of ​​the reference template are available;

[0398] If the sampling points of the adjacent area of ​​the reference template are available, the sampling points of the adjacent area of ​​the reference template are directly used;

[0399] If the sampling points of the adjacent area of ​​the reference template are not available, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0400] In this embodiment of the present application, the sampling points of the adjacent area of ​​the reference template are available, and may include at least one of the following:

[0401] The sampling point is within the image boundary;

[0402] The sampling point is within the tile boundary;

[0403] The sampling points have been rebuilt.

[0404] In another possible implementation, filling the sampling points of the adjacent area of ​​the reference template may include:

[0405] Determine whether the sampling points of the adjacent area of ​​the reference template exceed the preset search range;

[0406] If the sampling points of the adjacent area of ​​the reference template do not exceed the preset search range, the sampling points of the adjacent area of ​​the reference template are directly used;

[0407] If the sampling points of the adjacent area of ​​the reference template exceed the preset search range, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0408] That is to say, in the embodiment of the present application, considering that the filter may use reconstructed sampling points outside the reference template and reference block, it is necessary to fill the boundary sampling points. One boundary filling implementation method is shown in Figure 10B, and the grid area is the area that needs to be filled.

[0409] In one embodiment, the filling method is to determine whether the sampling points of the grid area are available one by one. If available, the reconstructed pixels are directly used; if not available, the reconstructed pixels of the nearest reference template or reference block are copied to fill the grid area.

[0410] The methods for determining whether it is applicable include but are not limited to the following conditions being met, or multiple conditions being met simultaneously:

[0411] The sampling point is within the image boundary;

[0412] The sampling point is within the Tile boundary;

[0413] The sampling points have been rebuilt.

[0414] In one embodiment, the filling method is to determine whether the position of the filling area exceeds the search range of the BV (i.e., the "preset search area" in the aforementioned embodiment). If it does not exceed the search range, the reconstructed sampling points are directly used. If it exceeds the search range, the reconstructed sampling points of the adjacent reference template or reference block are copied to fill the grid area. Specifically, the boundary needs to be filled based on iVerMin, iVerMax, iHorMin, and iHorMax derived in step S902:

[0415] The leftPadding, rightPadding, topPadding and bottomPadding are used to indicate whether the left grid area, right grid area, upper grid area and lower grid area copy the most recently reconstructed sampling point, i.e.

[0416] leftPadding=! (pX_Best>iHorMin);

[0417] rightPadding=!(pX_Best <iHorMax);

[0418] topPadding=! (pY_Best>iVerMin);

[0419] bottomPadding=!(pY_Best <iverMax)。

[0420] If leftPadding is true, it means that the pixels in the left grid area are beyond the BV search range, and the reconstructed sampling points of the nearest adjacent reference template are copied, otherwise, the reconstructed pixels at that position are used directly. If rightPadding is true, it means that the pixels in the right grid area are beyond the BV search range, and the reconstructed sampling points of the nearest adjacent reference template or reference block are copied, otherwise, the reconstructed sampling points at that position are used directly. If topPadding is true, it means that the pixels in the upper grid area are beyond the BV search range, and the reconstructed sampling points of the nearest adjacent reference template are copied, otherwise, the reconstructed sampling points at that position are used directly. If bottomPadding is true, it means that the pixels in the lower grid area are beyond the BV search range, and the reconstructed sampling points of the adjacent reference template or reference block are copied, otherwise, the reconstructed sampling points at that position are used directly.

[0421] It should be noted that in the embodiment of the present application, whether the boundary sampling points are filled has a great impact on the encoding performance. Taking the KristenAndSara and CatRobot sequences in the CTC test as an example, the boundary sampling points use available reconstructed sampling points to fill the adjacent nearest sampling points rather than the boundary sampling points to obtain a bdrate gain of -0.09%. The boundary pixels of the FourPeople and RitualDance sequences use available reconstructed sampling points to fill the adjacent nearest pixels rather than the boundary sampling points to obtain a bdrate gain of -0.08%. That is, for a 300Mbps video sequence, about 250Kbps of bandwidth can be saved.

[0422] It should also be noted that in the embodiments of the present application, after determining the number of available reconstructed pixels, a reconstruction region for calculating filter coefficients is determined based on the available reconstructed pixels. This region may be referred to as R, and R typically includes all available reconstructed pixels in the template. For example, when refTemplateType is 1, R may include all available reconstructed pixels on the left, upper left, and upper sides.

[0423] S1502: Calculate filter coefficients based on the reconstructed area.

[0424] It should be noted that in the embodiment of the present application, after determining the reconstruction area R for calculating the filter coefficients, a set of filter coefficients can be derived by minimizing the MSE between the reconstructed pixels in the reconstruction area R and the reconstructed pixels in the template of the current block, that is: MSE = E[(predTemp[i][j] - recTemp[i][j]) 2 ] =E[(∑ k,l=-1~1 c k,l ·refTemp[i+k][j+l]-recTemp[i][j]) 2 ] (16)

[0425] Where refTemp[i][j] represents the input reconstructed pixel value, recTemp[i][j] represents the reconstructed pixel value of the current block template, (i, j) represents the coordinate position, (i, j)∈R, k, l represents the coordinate offset of the filter coefficient position relative to the filter center position, taking Figure 14 as an example, k and l are between -1 and 1, and the values ​​of (k, l) can include (0, 0), (0, -1), (-1, 0), (0, 1), (1, 0), c k,l Indicates the required filter coefficient. In addition, E represents the operation of calculating the average value. The calculation formula at this time is as follows:

[0426] Among them, N posRefers to the calculation of |predTemp[i][j]-recTemp[i][j]| 2 For example, still taking Figure 14 as an example, if there are 5 (i, j) pairs involved in the operation, then N pos The value of is equal to 5.

[0427] Furthermore, the process of minimizing MSE to derive the filter coefficients is as follows:

[0428] First, for c k,l Find the partial derivative and make it 0, that is: E[2(∑ k,l=-1~1 c k,l ·refTemp[i+k][j+l]-recTemp[i][j])·refTemp[i+m][j+n]]=0 (19)

[0429] Among them, k and l are between -1 and 1, and m and n are between -1 and 1.

[0430] Here, according to formula (18) and formula (19), we can get: ∑ k,l=-1~1 c k,l ·E(refTemp[i+k][j+l]·refTemp[i+m][j+n])=E(recTemp[i][j]·refTemp[i+m][j+n]) (20)

[0431] Secondly, after determining the reconstruction area R, the obtained equation is expanded into a matrix form as follows:

[0432] Again, since the autocorrelation matrix of refTemp in the reconstruction area R and the cross-correlation vector of refTemp and recTemp are known, the filter coefficient c can be calculated by solving the equation group (20): k,l , for the filter coefficient c k,l It can be fixed-point or not.

[0433] It should also be noted that in the process of solving the equations, the autocorrelation matrix of the reconstructed pixel refTemp in the reconstructed area R is first calculated, and then the cross-correlation vector between refTemp and the reconstructed pixel recTemp of the current template is calculated. Then, the autocorrelation matrix is ​​decomposed by Cholesky or LDL, and finally, each filter coefficient c is calculated in turn by reverse recursion. n , the set of filter coefficients can be fixed-point or not.

[0434] S805: Generate a predicted value.

[0435] It should be noted that for each current block, a set of filter coefficients can be obtained by the above method, and the filter coefficients are c0, c1, c2...c nTap-1 Then, the best matching reconstructed block is filtered according to the filter shape and filter coefficients, that is, the filter coefficients and the reference pixels at the corresponding position are weighted and summed to obtain the current pixel to be predicted. Let ref be the best matching reconstructed block, which is defined as follows: ref[i][j] = recSamples[i+pX_BEST][j+pY_BEST] (22)

[0436] Where i = 0, ..., nTbW-1, j = 0, ..., nTbH-1, recSamples are the reconstructed pixels of the current image, and pX_BEST and pY_BEST are the horizontal and vertical components of the optimal block vector.

[0437] It should also be noted that, in the embodiment of the present application, the sampling points of the adjacent areas of the reference block need to be used, that is, the sampling points of the adjacent areas of the reference block need to be filled.

[0438] It should also be noted that the specific calculation process of the predicted value is as follows:

[0439] Assuming that the number of filter taps nTap is 5, the shape of the filter (or called "filter template") is shown in Figure 16A, where C0 to C4 are the tap coefficients of the filter. The dot in the grid corresponding to the tap coefficient C0 is the current pixel to be predicted Y pred [i][j] are the reconstructed pixels ref[i][j] at the corresponding positions in the best matching block (i.e., the aforementioned reference block); the remaining white-filled dots are the reconstructed pixels adjacent to the current spatial position in the best matching block. Thus, according to the filter in FIG16A , the predicted pixel Y is finally obtained. pred [i][j] are indicated by the black filled dots in FIG16B .

[0440] The specific prediction value calculation process is as follows:

[0441] For each current pixel to be predicted (i, j), the pixel position in the filter template is defined as (k, l), then the corresponding reconstructed pixel in the best matching block during filtering is defined as ref[i+k][j+l], and each filter coefficient at the position (k, l) in the filter template is defined as c k,l : c k,l =c n (twenty three)

[0442] Wherein, n=0,…,nTap-1, k and l are between -1 and 1.

[0443] For i=0,…,nTbW-1,j=0,…,nTbH-1: Y pred [i][j]=∑ k ∑ l ref[i+k][j+l]×c k,l (twenty four)

[0444] Furthermore, Y pred [i][j] sets the clamping operation within the preset value range to obtain the final predicted pixel. The details are as follows: predSamples[i][j]=Clip3(0,(1<<BitDepth)-1,Y pred [i][j]) (25)

[0445] Among them, for the clip function, the details are as follows:

[0446] It can be understood that in the embodiment of the present application, a linear filtering model is established between the best matching template obtained by searching and the current block template, the filter coefficient is obtained by minimizing the MSE calculation between the prediction template (prediction template = filter coefficient × matching template) and the current block template, the best matching block is filtered and corrected, and the reconstructed pixel after filtering is used as the final prediction pixel.

[0447] In some embodiments, the input information used to calculate the filter coefficients in the aforementioned embodiments can be expanded. The input information used to calculate the filter coefficients can be available reconstructed pixels of the matching template; alternatively, the gradient of each pixel in the matching template can be calculated, including but not limited to horizontal gradients and vertical gradients, and the calculated gradients can be used as input information for calculating the filter coefficients; alternatively, the position information of each pixel can be used as input information for calculating the filter, and the position information can be the absolute position information of each pixel in the entire image, or the relative position information of each pixel relative to a reference point.

[0448] In some embodiments, the implementation method for calculating the filter coefficients in the aforementioned embodiment can be expanded. The filter coefficients finally calculated are the tap coefficients corresponding to the filter template, that is, the number of filter coefficients is equal to the number of filter template taps nTap. In addition, several bias terms bias can be added to the filter template. For example, in the aforementioned embodiment, when nTap = 5, the filter coefficients are the tap coefficients c0 to c4 corresponding to the filter template, and the predicted value obtained by calculating the (i, j) position is:

[0449] At this time, the bias term can be added, as shown below:

[0450] Among them, c n =c i,j,k,l . In addition, Constant can be a fixed constant, such as Constant = 1 < < (BitDepth-1); it can also be a number related to the reconstructed pixel value at position (i, j) in the reference block, such as Constant = f(ref[i][j]); it can also be a number related to the reconstructed pixel value corresponding to a tap in the filter template other than position (i, j), such as Constant = f(ref[k][l]). Among them, Constant = f(ref[i][j]) or Constant = f(ref[k][l]) can be a linear mapping relationship or a nonlinear mapping relationship. One or more bias terms can be added.

[0451] In some embodiments, the number of filter models in the aforementioned embodiments can be expanded. Specifically, only one linear filter model can be established, or multiple linear filter models can be established. Here, the input information for calculating the filter coefficients is classified, and a filter model is established for each category of input information. For example, when using reconstruction information to establish a filter model, one possible implementation is to classify the information by the mean of the reconstruction information, establishing a model for reconstruction information greater than the mean, and establishing a model for reconstruction information less than the mean.

[0452] Another feasible method is to use the position of the reconstruction information for classification. For example, a model can be established using the available reconstruction information on the left and upper sides, and a second model can be established using the available reconstruction information on the left and upper left sides, and so on. The encoder decides which model to use. One feasible decision-making method is that the encoder decides which model to use through rate-distortion optimization and transmits the corresponding decoding parameters (such as a flag) to the decoder.

[0453] Another possible implementation is to classify filters by shape. Multiple filters of different shapes can be used, and filter models are established for each shape. The encoder decides which filter shape to use. One possible implementation is for the encoder to determine the filter shape through rate-distortion optimization and transmit the corresponding decoding parameters (e.g., a flag) to the decoder.

[0454] In some embodiments, the type of filtering model in the aforementioned embodiment can be expanded. Among them, a linear filtering model can be established, and a nonlinear filtering model can also be established for filtering. One feasible way is to introduce a quadratic term to establish a nonlinear filtering model. For example, when minimizing the MSE of the filter coefficient, the calculation formula is changed to the following: MSE = E[(predTemp[i][j] - recTemp[i][j]) 2 ] =E[(∑ k,l=-1~1 c k,l (refTemp[i+k][j+l]) 2 -recTemp[i][j]) 2 ] (29)

[0455] At this time, the calculation formula for the predicted value is modified as follows: pred [i][j]=∑ k ∑ l (ref[i+k][j+l]) 2 ×C k,l (30)

[0456] In some embodiments, the calculation of the prediction value in the above embodiment can be expanded. In this embodiment, it is determined by certain conditions whether the current block uses the filtered reference block as the final prediction value. For example, there are the following methods:

[0457] Method 1: Determine whether to filter the matching template by comparing the distortion of the matching template and the current block template, such as SAD, MSE, SATD, or SSE, with the threshold T_Distortion1;

[0458] Method 2: Based on the condition that the filter model is used in Method 1, the distortion between the filtered matching template and the current block template, such as SAD, MSE, SATD, or SSE, and the threshold T_Distortion2, is used to determine whether to filter the reference block.

[0459] Method three: The encoding end transmits a Flag to indicate whether to apply the filter model. tmpFlag indicates whether the current coding block applies intra-frame template matching, and filterFlag indicates whether the current block applies the filter model. When tmpFlag is 1, the encoding end decides whether to filter the reference block by comparing the distortion between the reference block and the original block before and after filtering, such as SAD or MSE or SATD or SSE. If the distortion after filtering is less than the distortion before filtering, filterFlag is 1, and the current block uses the reference block after filtering as the prediction block; otherwise, filterFlag is 0, and the current block uses the reference block before filtering as the prediction block. The encoding end transmits filterFlag to the decoding end. There are many ways to implement the encoding of filterFlag. One feasible way is to use equal probability coding; another feasible way is to use context coding. The default context initial state and context update rate can be used, or the context initial state and context update rate can be determined by statistics.

[0460] In some embodiments, an implementation of (a) in FIG. 7 is performed, where four sub-search areas are used for implementation:

[0461] When regionId is equal to 0, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0462] iHorMax=min((xTbCmp+searchRangeWidth)< <iBvShift,((picWidth-nTbW)<<iBvShift));

[0463] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0464] iVerMax=(yTbCmp-nTbH-offsetLCBY)< <iBvShift;

[0465] iVerMin=max(((iTemplateSizeH)< <iBvShift),((yTbCmp-searchRangeHeight)<<iBvShift))。

[0466] When regionId is equal to 1, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0467] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0468] iHorMax=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

[0469] iVerMin=(yTbCmp+1)< <iBvShift;

[0470] iVerMax=min(picHeight-nTbH,(yTbCmp-offsetLCBY+CtbSizeH-nTbH)< <iBvShift)。

[0471] When regionId is equal to 2, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0472] iHorMax=(xTbCmp-nTbW)< <iBvShift;

[0473] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0474] iVerMin=max((iTemplateSizeH)< <iBvShift,(yTbCmp-nTbH)<<iBvShift);

[0475] iVerMax=(yTbCmp)< <iBvShift。

[0476] When regionId is equal to 3, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0477] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0478] iHorMax=(xTbCmp)< <iBvShift;

[0479] iVerMin=max(((iTemplateSizeH)< <iBvShift),(yTbCmp-offsetLCBY-nTbH+1)<<iBvShift);

[0480] iVerMax=(yTbCmp-nTbH)< <iBvShift。

[0481] In practical applications, iHorMin, iHorMax, iVerMin, and iVerMax here represent the left edge, right edge, upper edge, and lower edge of different search areas, respectively.

[0482] To intuitively illustrate the different sub-search regions corresponding to different regionIds, see Figure 17, which shows another schematic diagram of the process for determining a specific search region according to an embodiment of the present application. As shown in Figure 17, R1, R2, R3, and R4 represent four different sub-search regions. Note that Figure 17 represents the pixel range that can be aligned with the upper left corner pixel of the block.

[0483] In some embodiments, the search area for the template within the current frame provided here may be different from the search area for the template within the current frame determined in the existing Intra TMP technology. Here, another implementation of (b) in FIG. 7 is performed, with four sub-search areas:

[0484] When regionId is equal to 0, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0485] iHorMax=min((xTbCmp+searchRangeWidth)< <iBvShift,((picWidth-nTbW)<<iBvShift));

[0486] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0487] iVerMax=(yTbCmp-nTbH-offsetLCBY)< <iBvShift;

[0488] iVerMin=max(((iTemplateSizeH)< <iBvShift),((yTbCmp-searchRangeHeight)<<iBvShift))。

[0489] When regionId is equal to 1, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0490] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0491] iHorMax=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

[0492] iVerMin=(yTbCmp+1)< <iBvShift;

[0493] iVerMax=min(picHeight-nTbH,(yTbCmp-offsetLCBY+CtbSizeH-nTbH)< <iBvShift)。

[0494] When regionId is equal to 2, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0495] iHorMax=(xTbCmp-nTbW)< <iBvShift;

[0496] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0497] iVerMin=max((iTemplateSizeH)< <iBvShift,(yTbCmp-nTbH-offsetLCBY)<<iBvShift);

[0498] iVerMax=(yTbCmp)< <iBvShift。

[0499] When regionId is equal to 3, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0500] iHorMin=max((iTemplateSizeW)< <iBvShift,(xTbCmp-nTbW+1)<<iBvShift);

[0501] iHorMax=(xTbCmp)< <iBvShift;

[0502] iVerMin=max(((iTemplateSizeH)< <iBvShift),(yTbCmp-offsetLCBY-nTbH+1)<<iBvShift);

[0503] iVerMax=(yTbCmp-nTbH)< <iBvShift。

[0504] In practical applications, iHorMin, iHorMax, iVerMin, and iVerMax here represent the left edge, right edge, upper edge, and lower edge of different search areas, respectively.

[0505] To intuitively illustrate the different sub-search regions corresponding to different regionIds, see Figure 18, which shows another schematic diagram of the specific search region determination process provided by an embodiment of the present application. As shown in Figure 18, R1, R2, R3, and R4 represent four different sub-search regions. Note that Figure 18 represents the pixel range that can be aligned with the upper left corner pixel of the block.

[0506] In some embodiments, the coarse search process can be consistent with the above embodiment, while the fine search process can be performed by using the method of each area boundary, that is, the technical solution of performing fine search across the boundaries between various search areas is expanded here. In the embodiment of the present application, the method can also include:

[0507] Perform a first search in at least one sub-search area to determine the best block vector for each sub-search area and the corresponding second search area;

[0508] Performing region judgment based on the best block vector of each sub-search region and the corresponding second search region to determine at least two target sub-search regions participating in the second search;

[0509] Perform a second search in at least two target sub-search areas to determine the best block vectors corresponding to the at least two target sub-search areas;

[0510] The best block vectors corresponding to at least two target sub-search areas are used as target block vectors.

[0511] For example, taking (a) in FIG. 7 as an example, another implementation is provided here, specifically by dividing the search into four sub-search areas:

[0512] When regionId is equal to 0, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0513] iHorMax0=min((xTbCmp+searchRangeWidth)< <iBvShift,((picWidth-nTbW)<<iBvShift));

[0514] iHorMin0=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0515] iVerMax0=(yTbCmp-nTbH-offsetLCBY)< <iBvShift;

[0516] iVerMin0=max(((iTemplateSizeH)< <iBvShift),((yTbCmp-searchRangeHeight)<<iBvShift))。

[0517] When regionId is equal to 1, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0518] iHorMin1=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0519] iHorMax1=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

[0520] iVerMin1=(yTbCmp+1)< <iBvShift;

[0521] iVerMax1=min(picHeight-nTbH,(yTbCmp-offsetLCBY+CtbSizeH-nTbH)< <iBvShift)。

[0522] When regionId is equal to 2, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0523] iHorMax2=(xTbCmp-nTbW)< <iBvShift;

[0524] iHorMin2=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0525] iVerMin2=max((iTemplateSizeH)< <iBvShift,(yTbCmp-nTbH)<<iBvShift);

[0526] iVerMax2=(yTbCmp)< <iBvShift。

[0527] When regionId is equal to 3, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows:

[0528] iHorMin3=max((iTemplateSizeW)< <iBvShift,(xTbCmp-searchRangeWidth)<<iBvShift);

[0529] iHorMax3=(xTbCmp)< <iBvShift;

[0530] iVerMin3=max(((iTemplateSizeH)< <iBvShift),(yTbCmp-offsetLCBY-nTbH+1)<<iBvShift);

[0531] iVerMax3=(yTbCmp-nTbH)< <iBvShift。

[0532] In practical applications, iHorMin, iHorMax, iVerMin, and iVerMax here represent the left edge, right edge, upper edge, and lower edge of different search areas, respectively.

[0533] To intuitively illustrate the different sub-search regions corresponding to different regionIds, see Figure 19, which shows another schematic diagram of the process for determining a specific search region provided by an embodiment of the present application. As shown in Figure 19, R1, R2, R3, and R4 represent four different sub-search regions, and detailed searches are performed across the boundaries of each sub-search region. It should be noted that Figure 19 is represented by a pixel range that can be aligned with the upper left corner pixel of the block.

[0534] In the fine search phase, a search is performed near each block vector obtained by the coarse search:

[0535] Furthermore, the best block vector BV1_BEST obtained in the coarse searchk Specifically, first determine the refinement search range TmpRefineRange, which can be a fixed size or related to the size of the current block, for example, it can be set to min(nTbW,nTbH) / 2, and then calculate the position of the best matching reconstructed block obtained by the coarse search as the reference position of the fine search area: BestPosX k =xTbCmp+pX1_BEST k ,BestPosY k =yTbCmp+pY1_BEST k .

[0536] Furthermore, according to each BestPosX k The implemented fine search can be performed across multiple areas:

[0537] Determine the value of bestRegionId involved in the calculation: For regionId = 0, 1, 2, 3, judge in turn:

[0538] If BestPosY k -TmpRefineRange>=iVerMin regionId , and BestPosY k -TmpRefineRange<=iVerMax regionId ,

[0539] or BestPosY k +TmpRefineRange>=iVerMin regionId , and BestPosY k +TmpRefineRange<=iVerMax regionId ,

[0540] or BestPosY k -TmpRefineRange<=iVerMin regionId , and BestPosY k +TmpRefineRange>=iVerMax regionId ,

[0541] Then the regionId sets the corresponding bestSearchFlag regionId is 1.

[0542] Among them, for each bestSearchFlag regionId For a search region with a value of 1, set bestRegionId to the regionId of the region and perform the following detailed searches:

[0543] First, according to the value of bestRegionId, first obtain the values ​​of iVerMinbestRegionId, iVerMaxbestRegionId, iHorMinbestRegionId, and iHorMaxbestRegionId calculated above, and then obtain the new search range iVerMin according to the optimal matching block position obtained by the rough search. refine 、iVerMax refine 、iHorMin refine 、iHorMax refine , and the method of obtaining it is as follows:

[0544] iHorMin refine =max(iHorMinbestRegionId,BestPosX-TmpRefineRange);

[0545] iHorMax refine =min(iHorMaxbestRegionId,BestPosX+TmpRefineRange);

[0546] iVerMin refine =max(iVerMinbestRegionId,BestPosY-TmpRefineRange);

[0547] iVerMax refine =min(iVerMaxbestRegionId,BestPosY+TmpRefineRange);

[0548] Then, the adjusted block vectors BVbvXMins, bvXMaxs, bvYMins, bvYMaxs can be obtained by iVerMin refine 、iVerMax refine 、iHorMin refine 、iHorMax refine Calculation yields:

[0549] bvXMins=iHorMin refine –xTbCmp;

[0550] bvXMaxs=iHorMax refine –xTbCmp;

[0551] bvYMins=iVerMin refine –yTbCmp;

[0552] bvYMaxs=iVerMax refine –yTbCmp;

[0553] Thus, the fine search is performed when pX is within bvXMins refine with bvXMaxs refine Between, pY is in bvYMins refine with bvYMaxs refine For example, the search is performed with a step size of 1, and the best matching cost obtained by template matching is recorded as pDiff_BEST. The corresponding block vector BV is recorded as the best block vector BV_BEST (pX_BEST, pY_BEST); and the total best block vector of multiple search areas is obtained.

[0554] After completing the above operations, the component block vector BV_BEST (pX_BEST, pY_BEST) can be obtained, where pX_BEST and pY_BEST are the horizontal offset and vertical offset of the best matching template relative to the current block template, respectively, and are also the horizontal offset and vertical offset of the best matching block relative to the current block.

[0555] In summary, the embodiments of the present application propose an intra-frame template matching (Intra TMP-FLM) technology based on a linear filtering model, which uses the template information of the matching template and the current block to establish a linear filtering model, fully utilizes the correlation between the matching template and the current coding block template, and filters and corrects the reconstructed pixels of the best matching block (i.e., the reference block). The filtered reconstructed pixels are used as predicted pixels, which improves the prediction accuracy to a certain extent and effectively solves the problem of linear changes between the best matching block and the current block.

[0556] In the embodiments of the present application, the specific implementation of the aforementioned embodiments is described in detail through the aforementioned embodiments. It can be seen that according to the technical solution of the aforementioned embodiments, the prediction value of the intra-frame template matching technology can be effectively corrected, thereby improving the prediction accuracy. Specifically, a linear filtering model is established between the best matching template obtained by searching and the template of the current block, and the filter coefficient is calculated by minimizing the MSE between the prediction template (prediction template = filter coefficient × matching template) and the current coding block template. The filter coefficient fully reflects the correlation between the matching template and the template of the current block, and this correlation is applied to the best matching block, and its reconstructed pixels are filtered and corrected. Finally, the reconstructed pixels after filtering are used as prediction pixels, thereby improving the prediction accuracy.

[0557] In another embodiment of the present application, referring to FIG20 , a schematic flow chart of an encoding method provided by an embodiment of the present application is shown. As shown in FIG20 , the method may include:

[0558] S2001: Determine a first template for a current block, and determine a reference template and a reference block.

[0559] It should be noted that the encoding method of the embodiment of the present application is applied to an encoder. In addition, the encoding method can specifically refer to an intra-frame prediction method, more specifically, an intra-frame prediction method based on the Intra TMP-FLM technology. A video image can be divided into multiple coding blocks, and the current block in the embodiment of the present application refers to the coding block in the video image that is currently to be intra-frame predicted. In addition, the encoding method of the embodiment of the present application can be used to predict both luminance components and chrominance components, without specific limitation here.

[0560] It should also be noted that, in the embodiment of the present application, it is first necessary to determine the first template of the current block. In some embodiments, determining the first template of the current block may include:

[0561] Determine the template type of the current block;

[0562] Determine the first template of the current block according to the template type of the current block.

[0563] The template type can be represented by refTemplateType. In some embodiments, determining the template type of the current block may include: determining the template type of the current block according to reference pixels of the current block.

[0564] Among them, the reference pixels of the current block include at least one of the following: the left adjacent reference pixel of the current block, the upper adjacent reference pixel of the current block, the upper left adjacent reference pixel of the current block, the lower left adjacent reference pixel of the current block, and the upper right adjacent reference pixel of the current block.

[0565] Furthermore, the template type can be classified according to whether the adjacent reference pixels are available and the template type of the current block can be determined. In some embodiments, determining the template type of the current block can include:

[0566] If the left adjacent reference pixel of the current block, the upper adjacent reference pixel of the current block, and the upper left adjacent reference pixel of the current block are all available, determining that the template type of the current block is the first value;

[0567] If the left adjacent reference pixel of the current block is available, determining the template type of the current block to be a second value;

[0568] If the upper adjacent reference pixel of the current block is available, determining the template type of the current block to be a third value;

[0569] If both the left adjacent reference pixel of the current block and the upper left adjacent reference pixel of the current block are available, determining that the template type of the current block is a fourth value;

[0570] If both the left adjacent reference pixel of the current block and the lower left adjacent reference pixel of the current block are available, determining that the template type of the current block is the fifth value;

[0571] If both the upper adjacent reference pixels of the current block and the upper right adjacent reference pixels of the current block are available, the template type of the current block is determined to be a sixth value.

[0572] In the embodiment of the present application, the first value, the second value, the third value, the fourth value, the fifth value, and the sixth value may be different. For example, the first value may be set to 1, the second value may be set to 2, the third value may be set to 3, the fourth value may be set to 4, the fifth value may be set to 5, and the sixth value may be set to 6. For details of these six template types, see (a), (b), (c), (d), (e), and (f) in FIG. 3 .

[0573] In some embodiments, determining the first template of the current block according to the template type of the current block may include: obtaining the template pixels of the current block according to the template type of the current block and the corresponding template size; and determining the template pixels of the current block as the first template of the current block.

[0574] In the embodiments of the present application, the template size can be pre-set, determined based on the size of the current block, or even related to the template type of the current block, which is not specifically limited here. For example, if the template type indicates that only the left template is to be obtained, the template width templateW_size can be set to 4; if the template type indicates that only the top template is to be obtained, the template height templateH_size can be set to 4.

[0575] In this embodiment of the present application, the value of the template type determines which portion of the reconstructed pixels the first template retrieves. For example, when the value of refTemplateType is 1, the left, upper-left, and upper reconstructed pixels of the current block are retrieved; when the value of refTemplateType is 2, only the left four columns of reconstructed pixels of the current block are retrieved; and when the value of refTemplateType is 3, only the upper four rows of reconstructed pixels of the current block are retrieved.

[0576] Regarding the reference template and the reference block, in a possible implementation, determining the reference template and the reference block may include: determining motion parameters and corresponding reference blocks; and determining the reference template according to the first template and the reference block.

[0577] Accordingly, in some embodiments, the method may further include encoding the motion parameters and writing the resulting coded bits into the bitstream. That is, after the encoder determines the motion parameters (e.g., BV), it may write them into the bitstream. Subsequently, the decoder may directly determine the motion parameters based on the decoded bitstream, thereby determining a reference block for the current block. The reference template may then be determined from the reference block based on the first template of the current block.

[0578] Regarding the reference template and the reference block, in another possible implementation, determining the reference template and the reference block may include: performing template matching within a preset search area based on the first template to determine the reference template; and determining the reference block based on the reference template.

[0579] In some embodiments, performing template matching within a preset search area based on the first template to determine a reference template may include: searching within the preset search area based on the first template to determine a target block vector, and determining the reference template based on the target block vector.

[0580] That is, a search can be performed within a preset search area based on the first template, and a matching template with the minimum cost can be found based on a preset cost function. By traversing all search points within the preset search area, one or more candidate block vectors can be obtained, and these one or more candidate block vectors can indicate one or more candidate matching templates. Cost calculations are performed on these vectors and compared with the first template of the current block, resulting in a search point with the minimum cost. The candidate block vector corresponding to the candidate block vector is the best block vector (i.e., the target block vector, BV_BEST). The candidate matching template corresponding to the candidate block vector is the best matching template (i.e., the reference template described in this embodiment, T_BEST). Based on the best matching template, a reference block can be determined.

[0581] In an embodiment of the present application, the preset cost function can be the sum of absolute error SAD, the sum of absolute transformation difference SATD, the mean square error MSE, the sum of squared errors SSD, the mean absolute difference MAD, the mean sum of squared errors MSD, the normalized correlation coefficient NCC, etc., which is not specifically limited here.

[0582] It is understandable that the search process within the preset search area may be a coarse search, or a fine search, or a coarse search first and then a fine search; the details are as follows:

[0583] In a possible implementation, searching within a preset search area based on the first template to determine the target block vector may include: performing a first search within the preset search area to determine the target block vector.

[0584] In another possible implementation, searching within a preset search area based on the first template to determine the target block vector may include: performing a second search within the preset search area to determine the target block vector.

[0585] In another possible implementation, searching within a preset search area based on the first template to determine the target block vector may include: performing a first search within the preset search area to determine the first block vector and determining an initial matching template based on the first block vector; determining a first search area based on the initial matching template, and performing a second search within the first search area to determine the target block vector.

[0586] It should be noted that, in the embodiment of the present application, the search step size corresponding to the first search is greater than the search step size corresponding to the second search. For example, the search step size corresponding to the first search is 2, and the search step size corresponding to the second search is 1. Alternatively, the downsampling factor corresponding to the first search is greater than the downsampling factor corresponding to the second search. For example, the downsampling factor corresponding to the first search is 4, and the downsampling factor corresponding to the second search is 2. In other words, the first search is a coarse search, and the second search is a fine search. Any method that can reflect the coarsening of the first search over the second search is acceptable, and no specific limitation is imposed here.

[0587] It should also be noted that when performing the first search followed by the second search, not only is the search step size corresponding to the first search larger than the search step size corresponding to the second search, but the first search area is also smaller than the preset search area. The first search area is the search area near the initial matching template. For example, the best coarse matching template can be determined within the preset search area with a step size of 2. Then, the best fine matching template (i.e., the final reference template) can be determined near the best coarse matching template with a step size of 1.

[0588] In yet another possible implementation, the preset search area may include at least one sub-search area; and searching within the preset search area based on the first template to determine the target block vector may include:

[0589] Searching in at least one sub-search area respectively to determine the best block vector and the corresponding matching cost value of each sub-search area;

[0590] Determine the optimal block vector corresponding to the minimum matching cost value based on the optimal block vector and the corresponding matching cost value of each sub-search area;

[0591] The best block vector corresponding to the minimum matching cost value is used as the target block vector.

[0592] In another possible implementation, the preset search area may include at least one sub-search area; and searching within the preset search area based on the first template to determine the target block vector may include:

[0593] Perform a first search in at least one sub-search area to determine the best block vector for each sub-search area and the corresponding second search area;

[0594] Performing region judgment based on the best block vector of each sub-search region and the corresponding second search region to determine at least two target sub-search regions participating in the second search;

[0595] Perform a second search in at least two target sub-search areas to determine the best block vectors corresponding to the at least two target sub-search areas;

[0596] The best block vectors corresponding to at least two target sub-search areas are used as target block vectors.

[0597] It should be noted that in this embodiment of the present application, the search area for the current block template can be the reconstructed portion of the CTB where the current block is located, or it can be another reconstructed CTB area. The search area here is actually the set of all search points. Because the shape of this area is often not representable by a single rectangular area, in a specific implementation, multiple rectangular areas can be searched, and the search results from different areas can be combined to obtain the final optimal reference block and optimal block vector.

[0598] It should also be noted that in the embodiment of the present application, still taking (f) in Figure 7 as an example, the preset search area is divided into four sub-search areas, each of which is represented by regionId, and the value of regionId can be equal to 0, 1, 2, or 3. Through the search points (iPosHor, iPoxVer) within each sub-search area, that is, each block vector BV (composed of horizontal and vertical components: (pX, pY), where pX = iPosHor - xTbCmp, pY = iPosVer - yTbCmp, pX is between bvXMins and bvXMaxs, and pY is between bvYMins and bvYMaxs), a reference block that matches the current block can be found in the reconstructed area. The adjacent reconstructed pixels of the reference block are the reference template. This allows the matching cost between the first template of the current block and the reference template to be calculated, denoted as pDiff.

[0599] In this way, all search points in all search ranges (regionId = 0, 1, 2, 3) are traversed and compared to obtain the search point with the smallest matching cost pDiff. Its corresponding matching cost is recorded as pDiff_BEST, and its corresponding block vector is recorded as the best block vector BV_BEST (pX_BEST, pY_BEST), which is also the target block vector described in this embodiment; its corresponding best matching template T_BEST is the reference template ultimately required.

[0600] S2002: When the reference template meets a first preset condition, perform a first processing on an adjacent area of ​​the reference template to determine a matching template, and determine model parameters based on the first template and the matching template.

[0601] It should be noted that, in the embodiment of the present application, the model parameters may include coefficients of the target filter. In some embodiments, the method may further include: determining the coefficients of the target filter based on the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template.

[0602] It should also be noted that, in the embodiment of the present application, the matching template may include: sampling points in the reference template and sampling points in an adjacent area of ​​the reference template.

[0603] In some embodiments, the method may further include: if sampling points outside the reference template are used, determining that the reference template satisfies a first preset condition. That is, if the reference template is at an image boundary, sampling points outside the reference template need to be used. Specifically, for sampling points of the reference template near the boundary, adjacent pixels need to be used. These adjacent pixels may be outside the boundary. In this case, the reference template is determined to satisfy the first preset condition, and the adjacent region of the reference template needs to be subjected to the first processing.

[0604] In some embodiments, when the reference template meets the first preset condition, performing the first processing on the adjacent area of ​​the reference template may include: if sampling points outside the reference template are used, filling the sampling points of the adjacent area of ​​the reference template.

[0605] In some embodiments, filling the sampling points of the adjacent area of ​​the reference template may include:

[0606] Determine whether the sampling points in the adjacent area of ​​the reference template are available;

[0607] If the sampling points of the adjacent area of ​​the reference template are available, the sampling points of the adjacent area of ​​the reference template are directly used;

[0608] If the sampling points of the adjacent area of ​​the reference template are not available, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0609] In some embodiments, the sampling points of the adjacent area of ​​the reference template are available and may include at least one of the following:

[0610] The sampling point is within the image boundary;

[0611] The sampling point is within the tile boundary;

[0612] The sampling points have been rebuilt.

[0613] In some embodiments, filling the sampling points of the adjacent area of ​​the reference template may include:

[0614] Determine whether the sampling points of the adjacent area of ​​the reference template exceed the preset search range;

[0615] If the sampling points of the adjacent area of ​​the reference template do not exceed the preset search range, the sampling points of the adjacent area of ​​the reference template are directly used;

[0616] If the sampling points of the adjacent area of ​​the reference template exceed the preset search range, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0617] In some embodiments, the method may further include: when the reference template meets a second preset condition, using the reference template directly as a matching template, and executing the step of determining model parameters based on the first template and the matching template.

[0618] In some embodiments, the reference template satisfies the second preset condition, including: the reference template does not satisfy the first preset condition.

[0619] In some embodiments, the reference template satisfies a second preset condition, including at least one of the following:

[0620] The reference template is not at the image boundary;

[0621] The reference template does not exceed the preset search range;

[0622] The sampling points in the reference template have been reconstructed;

[0623] The sampling points in the reference template and the current block are in the same tile;

[0624] Sampling points outside the reference template are not used.

[0625] That is to say, in the embodiment of the present application, if the sampling points of the adjacent area of ​​the reference template need to be used, the sampling points of the adjacent area of ​​the reference template need to be filled.

[0626] It should also be noted that, in embodiments of the present application, the coefficients of the target filter may be determined by solving an optimization problem. Accordingly, in some embodiments, the method may further include: the coefficients of the target filter are the coefficients used by the target filter when a first error between an output value of a pixel reference value in the matching template after being processed by the target filter and a pixel reference value in the first template satisfies a first condition.

[0627] It should be understood that for the first error to satisfy the first condition, in one possible implementation, the first condition is that the first error is minimized. Alternatively, in another possible implementation, the first condition is that the first error is within a first preset threshold range. Alternatively, in yet another possible implementation, the first condition is that the change in the first error is within a second preset threshold range.

[0628] It should also be understood that the first preset threshold range and the second preset threshold range are both metrics preset by the decoding end for determining whether the first error satisfies the first condition. Furthermore, the first error herein may be a mean square error (MSE), or may be a sum of squared error (SSE), or may be a sum of absolute error (SAD), or may be a sum of absolute error (SATD) after a Hadamard-transformed error (HATD), or may be a mean absolute error (MAE), etc., and this embodiment of the present application does not specifically limit this.

[0629] In some embodiments, determining coefficients of a target filter based on pixel reference values ​​in the first template and pixel reference values ​​in the matching template may include:

[0630] Determining autocorrelation parameters based on pixel reference values ​​in the matching template;

[0631] determining a cross-correlation parameter based on the pixel reference value in the first template and the pixel reference value in the matching template;

[0632] The coefficients of the target filter are determined according to the autocorrelation parameters and the cross-correlation parameters.

[0633] It should be noted that, in the embodiment of the present application, the pixel reference value includes at least one of the following: a pixel reconstruction value, a pixel gradient value, and pixel position information.

[0634] That is, in the embodiment of the present application, the target filter is used as the filter model of the embodiment of the present application, and the input information of the target filter is the pixel reference value in the matching template. Here, the coefficient of the target filter can be expressed as c k,l, which may also be referred to as filter coefficients in this embodiment. The input information used to calculate the filter coefficients may be the available reconstructed pixels of the matching template; or, the gradient of each reconstructed pixel in the matching template, including but not limited to horizontal gradients and vertical gradients, may be calculated, and the calculated gradients may be used as the input information for calculating the filter coefficients; or, the position information of each reconstructed pixel may be used as the input information for calculating the filter coefficients. The position information may be the absolute position information of each reconstructed pixel in the entire image, or the relative position information of each reconstructed pixel relative to a reference point; this is not specifically limited here.

[0635] In a specific embodiment, a reconstruction region R for calculating the filter coefficients is first determined, and then a set of filter coefficients can be derived by minimizing the MSE between the reconstructed pixels in the region R and the reconstructed pixels of the first template, as shown in the aforementioned equations (3) and (4).

[0636] Furthermore, the process of minimizing MSE to derive the filter coefficients is as follows:

[0637] First, for c k,l Find the partial derivative and make it equal to 0, which is shown in the above equations (5) and (6); where k and l are between -1 and 1, and m and n are between -1 and 1.

[0638] Next, according to equations (5) and (6), we can obtain the equation shown in equation (7).

[0639] Once again, after the reconstruction region R is determined, Equation (7) is expanded into a matrix form, as shown in Equations (8) to (10).

[0640] In this way, since the autocorrelation matrix of refTemp and the cross-correlation vector of refTemp and recTemp in the reconstruction area R are known, the filter coefficient c can be calculated by solving the equation group shown in formula (7): k,l , for the filter coefficient c k,l It can be fixed-point or not.

[0641] In addition, in the embodiment of the present application, for the target filter, it is also necessary to determine the number of coefficients of the target filter and the shape of the target filter, etc. The number of coefficients of the target filter and the shape of the target filter can be preset fixed values ​​or have an associated relationship with the size of the current block.

[0642] In some embodiments, for the number of coefficients of the target filter, the method may further include: the number of coefficients of the target filter is equal to a first preset value.

[0643] In some embodiments, for the number of coefficients of the target filter, the method may further include: determining the number of coefficients of the target filter; encoding the number of coefficients of the target filter, and writing the obtained coded bits into the bitstream.

[0644] It should be noted that the number of coefficients of the target filter can be represented by nTap. For example, the value of nTap can be 4, 5, 6, 7, 8, 9, etc., but is not specifically limited.

[0645] It should also be noted that the number of coefficients of the target filter can also be called the number of taps of the target filter. Here, the number of coefficients of the target filter can be a preset constant value or can be determined according to the size of the current block, which is not specifically limited here.

[0646] In some embodiments, regarding the shape of the target filter, the method may further include: the target filter is a one-dimensional or two-dimensional filter of a preset shape.

[0647] In some embodiments, regarding the shape of the target filter, the method may further include: determining the shape of the target filter; encoding the shape of the target filter, and writing the obtained encoded bits into the bitstream.

[0648] In some embodiments, the method may further include: determining a value of a filter shape parameter, wherein the filter shape parameter indicates a shape of a target filter. Further, the method may further include: encoding the value of the filter shape parameter and writing the obtained encoded bits into a bitstream.

[0649] It should be noted that the filter shape parameter can be represented by FilterIdx, which is used to indicate the shape of the target filter. For example, the shape of the target filter can be diamond, rectangle, cross, stripe, or even a one-dimensional filter or a two-dimensional filter, but is not specifically limited thereto.

[0650] Exemplarily, if the value of FilterIdx is equal to 0, the shape of the target filter is determined to be a diamond; if the value of FilterIdx is equal to 1, the shape of the target filter is determined to be a cross; if the value of FilterIdx is equal to 2, the shape of the target filter is determined to be a rectangle.

[0651] It should also be noted that the shape of the target filter can be a preset shape, or can be determined by the value of the filter shape parameter, or can even be determined according to the size of the current block, which is not specifically limited here.

[0652] S2003: Filter the reference block according to the model parameters to determine a filtered reference block.

[0653] S2004: Determine a prediction value of the current block based on the filtered reference block.

[0654] It should be noted that in the embodiment of the present application, after the model parameters are determined, the prediction value of the current block can be determined based on the model parameters and the reference block. Specifically, the reference block is filtered according to the model parameters, and the prediction value of the current block is determined based on the filtered reference block.

[0655] In some embodiments, filtering the reference block according to the model parameters to determine the filtered reference block may include: if sampling points of an adjacent region of the reference block are used, then padding the sampling points of the adjacent region of the reference block. In other words, in the embodiments of the present application, if sampling points of an adjacent region of the reference block are used, padding the sampling points of the adjacent region of the reference block is required.

[0656] In some embodiments, filtering the reference block according to the model parameters to determine the filtered reference block may include: filtering the reference block according to the model parameters to determine the first output value of the target filter; and determining the filtered reference block based on the first output value of the target filter.

[0657] In the embodiment of the present application, a first output value of the target filter can be calculated based on the pixel reconstruction values ​​of the reference block and the coefficients of the target filter in the model parameters. Then, based on the first output value of the target filter, the filtered reference block can be determined. The target filter can be a linear or nonlinear filter model, without specific limitation.

[0658] In one possible implementation, filtering the reference block according to the model parameters to determine the first output value of the target filter may include:

[0659] Calculating the product of the pixel reconstruction value of the reference block and the coefficient of the corresponding target filter;

[0660] The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter and n is a positive integer.

[0661] It should be noted that the target filter in the embodiment of the present application is a linear filter model. The first output value of the target filter can be calculated using the aforementioned formula (11).

[0662] In another possible implementation, filtering the reference block according to the model parameters to determine the first output value of the target filter may include:

[0663] Determine a first value of a pixel reconstruction value of the reference block under a first mapping relationship;

[0664] Calculating the product of the first value and the coefficient of the corresponding target filter;

[0665] The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter and n is a positive integer.

[0666] It should be noted that the target filter in the embodiment of the present application is a nonlinear filter model. For example, when minimizing the MSE of the filter coefficients, it can be calculated using the aforementioned formulas (12) and (13).

[0667] It should also be noted that, in the embodiment of the present application, the filtered reference block is determined based on the first output value of the target filter. The first output value of the target filter can be directly set as the filtered reference block; or the first output value of the target filter can be subjected to a first filtering to obtain the filtered reference block; the first filtering here can be a low-pass filter, an up / down sampling filter, etc., which is not specifically limited here.

[0668] It should also be noted that, in the embodiment of the present application, after determining the first output value of the target filter, a first offset value (expressed as bias) may be added to the first output value to determine a filtered reference block.

[0669] In some embodiments, determining a filtered reference block based on a first output value of a target filter may include: determining a first offset value; and performing an addition operation based on the first output value and the first offset value to determine the filtered reference block.

[0670] In a possible implementation, determining the first offset value may include: setting the first offset value to be equal to a second preset value.

[0671] In another possible implementation, determining the first offset value may include: if the number of coefficients of the target filter is n, determining the n+1th coefficient of the target filter; and determining the first offset value based on the n+1th coefficient and the second offset value.

[0672] In an embodiment of the present application, for the second offset value, the method may further include: setting the second offset value equal to a third preset value; or setting the second offset value equal to the value of the pixel reconstruction value of the reference block under the second mapping relationship.

[0673] Note that, in the embodiments of the present application, the calculated filter coefficients are used as the number of taps corresponding to the filter template, that is, the number of filter coefficients is equal to the number of taps nTap of the filter template. In addition, several bias terms bias can be added to the filter template. Exemplarily, in the embodiments of the present application, when nTap = 5, the filter coefficients are the tap coefficients c0 to c4 corresponding to the filter template, and the predicted value at the position (i, j) in the filtered reference block is calculated as shown in the aforementioned equations (14) and (15).

[0674] Further, in some embodiments, determining the predicted value of the current block according to the filtered reference block may include: performing a second process on the filtered reference block to obtain the predicted value of the current block.

[0675] In the embodiments of the present application, for the second process, the second process may be to set the predicted value of the current block to be equal to the filtered reference block; or, the second process may be a clamping (clip) operation that limits the filtered reference block within a preset numerical range, or the second process may also be other operations, which are not specifically limited here.

[0676] Here, for the clip operation, the preset numerical range may be: between 0 and (1 << BitDepth) - 1, where BitDepth represents the bit depth. If the value of the filtered reference block exceeds the取值范围 of this preset numerical range, then corresponding correction operations need to be performed on the filtered reference block. Exemplarily, the filtered reference block can also be represented by Y pred [i][j], and at this time, correction operations can be performed on Y pred [i][j] as follows:

[0677] When the value of Y pred [i][j] is less than 0, set it to 0;

[0678] When the value of Y pred [i][j] is greater than or equal to 0 and less than or equal to (1 << BitDepth) - 1, it is equal to Y pred [i][j];

[0679] When the value of Y pred [i][j] is greater than (1 << BitDepth) - 1, set it to (1 << BitDepth) - 1.

[0680] In this way, after performing correction operations on Y pred [i][j], it can be ensured that all pixel values in the filtered reference block are between 0 and (1 << BitDepth) - 1.

[0681] Furthermore, the number of filter models can be expanded. In addition to establishing only one filter model, multiple filter models can also be established. Therefore, in some embodiments, the method may further include:

[0682] determining multiple sets of model parameters based on the first template and the matching template;

[0683] Constructing multiple filter models according to multiple groups of model parameters, filtering the reference blocks according to the multiple filter models, and determining multiple filtered reference blocks;

[0684] A prediction value of a current block is determined based on the plurality of filtered reference blocks.

[0685] In some embodiments, determining multiple sets of model parameters based on the first template and the matching template may include: classifying the reconstructed pixels in the first template and the matching template according to a preset method to obtain multiple sets of sub-templates and multiple sets of sub-matching templates; and determining multiple sets of model parameters based on the multiple sets of sub-templates and the multiple sets of sub-matching templates.

[0686] It should be noted that in the embodiments of the present application, the preset method can be the size of the reconstructed pixel value, or the position information of the reconstructed pixel, or the shape of the filter, etc., and is not limited to this. After classification according to the preset method, each group of sub-templates and the corresponding sub-matching template can calculate a set of model parameters, and each set of model parameters can determine a filter model, thereby constructing multiple filter models.

[0687] In a possible implementation, the method may further include: determining a target filter from a plurality of filter models; and filtering a reference block according to the target filter to determine a prediction value of the current block.

[0688] Furthermore, in some embodiments, the method may also include: determining a target model index value, wherein the target model index value is used to indicate the index number of the target filter in multiple filter models; encoding the target model index value, and writing the obtained encoded bits into the bitstream.

[0689] Furthermore, in some embodiments, determining a target filter from a plurality of filter models may include: determining an original value of a current block; performing rate-distortion cost calculations based on the original value of the current block and a plurality of initial prediction values ​​of the current block to determine a rate-distortion cost value for each of the plurality of initial prediction values; determining a minimum rate-distortion cost value from the rate-distortion cost values ​​for each of the plurality of initial prediction values; and using the filter model corresponding to the minimum rate-distortion cost value as the target filter.

[0690] In another possible implementation, multiple filtered reference blocks may be determined by filtering the reference blocks according to multiple filter models. In some embodiments, determining the prediction value of the current block based on the multiple filtered reference blocks may include performing a weighted calculation on the multiple filtered reference blocks to determine the prediction value of the current block.

[0691] It should be noted that if the weights of each filtered reference block are equal and equal to the inverse of the number of reference blocks, then the weighted calculation here can also be regarded as an averaging calculation. In other words, the average of multiple filtered reference blocks is calculated to determine the prediction value of the current block.

[0692] Exemplarily, the input information for calculating the filter coefficients is classified, and a filter model is established for each category of input information. For example, when using reconstruction information to establish a filter model, one possible implementation is to classify by the mean of the reconstruction information, establishing a filter model for reconstruction information greater than the mean, and establishing a filter model for reconstruction information less than the mean. Another possible implementation is to classify by the position of the reconstruction information. For example, a filter model can be established using the available reconstruction information on the left and upper sides, and a second filter model can be established using the available reconstruction information on the left and upper left sides. The encoder decides which model to use. One possible implementation is for the encoder to determine which model to use through rate-distortion optimization and transmit corresponding decoding parameters to the decoder so that the decoder can subsequently clearly select which filter model. Another possible implementation is to classify by filter shape. Multiple filters of different shapes can be used, and a filter model is established for each filter shape. The encoder decides which filter shape to use. One possible implementation is for the encoder to determine which filter to use through rate-distortion optimization and transmit corresponding decoding parameters to the decoder so that the decoder can subsequently clearly select which filter model.

[0693] S2005: Determine the prediction difference value of the current block according to the prediction value of the current block.

[0694] It should be noted that in an embodiment of the present application, after determining the prediction value of the current block, the prediction difference value of the current block can also be calculated. In some embodiments, determining the prediction difference value of the current block based on the prediction value of the current block can include: determining the original value of the current block; and determining the prediction difference value of the current block based on the original value of the current block and the prediction value of the current block.

[0695] In a specific embodiment, determining the predicted difference value of the current block according to the original value of the current block and the predicted value of the current block may include: performing a subtraction operation on the original value of the current block and the predicted value of the current block to determine the reconstructed value of the current block.

[0696] It should also be noted that in the embodiments of the present application, whether intra-frame template matching is applied to the current block or whether a filter model is applied can be determined by different syntax element identification information. In some embodiments, the method may further include: determining a value of first syntax element identification information, wherein the first syntax element identification information is used to indicate whether intra-frame template matching is applied to the current block; encoding the value of the first syntax element identification information, and writing the resulting coded bits into the bitstream.

[0697] In an embodiment of the present application, determining the value of the first syntax element identification information may include: if the current block applies intra-frame template matching, determining the value of the first syntax element identification information to be a first value; or if the current block does not apply intra-frame template matching, determining the value of the first syntax element identification information to be a second value.

[0698] Furthermore, in some embodiments, when the first syntax element identification information is used to indicate that the current block applies intra-frame template matching, the method may also include: determining a value of the second syntax element identification information, wherein the second syntax element identification information is used to indicate whether the current block applies a filter model; encoding the value of the second syntax element identification information, and writing the obtained coded bits into the bitstream.

[0699] In an embodiment of the present application, determining the value of the second syntax element identification information may include: if the current block applies a filter model, determining the value of the second syntax element identification information to be a first value; or if the current block does not apply a filter model, determining the value of the second syntax element identification information to be a second value.

[0700] Furthermore, in some embodiments, the method may further include:

[0701] If the current block applies a filter model, performing filtering processing on the reference block according to the model parameters to determine a filtered reference block; and determining a prediction value of the current block according to the filtered reference block;

[0702] If the filter model is not applied to the current block, the reconstructed pixel values ​​in the reference block are used as the prediction values ​​of the current block.

[0703] It should be noted that in the embodiment of the present application, the first value and the second value are different, and the first value and the second value can be in parameter form or in digital form. Specifically, the first syntax element identification information and the second syntax element identification information can be parameters written in the profile or the value of a flag, which is not specifically limited here. Exemplarily, for the first value and the second value, the first value can be set to 1 and the second value can be set to 0; or the first value can also be set to true and the second value can also be set to false; however, this is not specifically limited here.

[0704] It should also be noted that in the embodiment of the present application, whether the current block uses the filtered reference block as the final prediction value is determined by certain conditions, but is not limited to the following three methods. For example, these three methods can be as follows:

[0705] Method 1: Determine whether to filter the matching template by comparing the distortion of the matching template and the current block template, such as SAD, MSE, SATD, or SSE, with the threshold T_Distortion1;

[0706] Method 2: Based on the condition that the filter model is used in Method 1, the distortion between the filtered matching template and the template of the current block, such as SAD, MSE, SATD, or SSE, and the threshold T_Distortion2, is used to determine whether to filter the reference block.

[0707] Method three: The encoder transmits a Flag to indicate whether to apply the filter model. tmpFlag indicates whether the current block applies intra-frame template matching, and filterFlag indicates whether the current block applies the filter model. When tmpFlag is 1, the encoder decides whether to filter the reference block by comparing the distortion between the reference block and the current block before and after filtering, such as SAD or MSE or SATD or SSE. If the distortion after filtering is less than the distortion before filtering, filterFlag is 1, and the current block uses the reference block after filtering as the prediction block; otherwise, filterFlag is 0, and the current block uses the reference block before filtering as the prediction block. The encoder transmits filterFlag to the decoder. There are many ways to implement the encoding of filterFlag. One feasible way is to use equal probability coding; another feasible way is to use context coding. The default context initial state and context update rate can be used, or the context initial state and context update rate can be determined by statistics.

[0708] Furthermore, an embodiment of the present application also provides a code stream, which is generated by bit encoding based on the information to be encoded; wherein the information to be encoded includes at least one of the following: a prediction difference value of the current block, the number of coefficients of the target filter, the shape of the target filter, the value of the first syntax element identification information, and the value of the second syntax element identification information.

[0709] In an embodiment of the present application, the first syntax element identification information is used to indicate whether intra-frame template matching is applied to the current block, and the second syntax element identification information is used to indicate whether a filter model is applied to the current block.

[0710] This embodiment provides an encoding method, which determines a first template for a current block, as well as a matching template and a reference block; determines model parameters based on the first template and the matching template; filters the reference block based on the model parameters to determine a filtered reference block; determines a prediction value for the current block based on the filtered reference block; and determines a prediction difference for the current block based on the prediction value of the current block. In this way, the model parameters are determined based on the first template and the matching template, and the model parameters fully reflect the correlation between the matching template and the first template of the current block. This correlation is applied to the reference block, and its reconstructed pixels are filtered and corrected. The filtered reconstructed pixels are then used as the predicted pixels for the current block, thereby improving prediction accuracy, saving bit rate, and improving encoding and decoding efficiency, thereby enhancing encoding and decoding performance.

[0711] In another embodiment of the present application, based on the same inventive concept as the above embodiment, see Figure 21, which shows a schematic diagram of the composition structure of an encoder provided by an embodiment of the present application. As shown in Figure 21, the encoder 210 may include: a first determination unit 2101, a first filtering unit 2102 and a first prediction unit 2103; wherein,

[0712] A first determining unit 2101 is configured to determine a first template of a current block, and to determine a reference template and a reference block; and further configured to, when the reference template satisfies a first preset condition, perform a first processing on an adjacent region of the reference template to determine a matching template, and determine model parameters based on the first template and the matching template;

[0713] A first filtering unit 2102 is configured to perform filtering processing on the reference block according to the model parameters to determine a filtered reference block;

[0714] A first prediction unit 2103 is configured to determine a prediction value of a current block based on the filtered reference block;

[0715] The first determining unit 2101 is further configured to determine a prediction difference value of the current block according to the prediction value of the current block.

[0716] In some embodiments, the matching template includes: sampling points in the reference template and sampling points in an adjacent area of ​​the reference template.

[0717] In some embodiments, the first determining unit 2101 is further configured to determine that the reference template satisfies a first preset condition if a sampling point outside the reference template is used.

[0718] In some embodiments, the first determining unit 2101 is further configured to perform filling processing on the sampling points in the adjacent area of ​​the reference template if sampling points outside the reference template are used.

[0719] In some embodiments, the first determining unit 2101 is further configured to determine whether the sampling points of the adjacent area of ​​the reference template are available; if the sampling points of the adjacent area of ​​the reference template are available, the sampling points of the adjacent area of ​​the reference template are directly used; if the sampling points of the adjacent area of ​​the reference template are not available, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points, so as to obtain the sampling points of the adjacent area of ​​the reference template.

[0720] In some embodiments, the first determining unit 2101 is further configured to determine whether the sampling points of the adjacent area of ​​the reference template are available, including at least one of the following:

[0721] The sampling point is within the image boundary;

[0722] The sampling point is within the tile boundary;

[0723] The sampling points have been rebuilt.

[0724] In some embodiments, the first determining unit 2101 is further configured to determine whether the sampling points of the adjacent area of ​​the reference template exceed a preset search range; if the sampling points of the adjacent area of ​​the reference template do not exceed the preset search range, the sampling points of the adjacent area of ​​the reference template are directly used; if the sampling points of the adjacent area of ​​the reference template exceed the preset search range, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0725] In some embodiments, the first determining unit 2101 is further configured to use the reference template directly as the matching template when the reference template meets the second preset condition, and perform the step of determining the model parameters according to the first template and the matching template.

[0726] In some embodiments, the second determining unit 2301 is further configured to determine whether the reference template satisfies a second preset condition, including: the reference template does not satisfy the first preset condition.

[0727] In some embodiments, the first determining unit 2101 is further configured to: the reference template satisfies a second preset condition, including at least one of the following:

[0728] The reference template is not at the image boundary;

[0729] The reference template does not exceed the preset search range;

[0730] The sampling points in the reference template have been reconstructed;

[0731] The sampling points in the reference template and the current block are in the same tile;

[0732] Sampling points outside the reference template are not used.

[0733] In some embodiments, the first determining unit 2101 is further configured to perform padding processing on the sampling points in the adjacent area of ​​the reference block if the sampling points in the adjacent area of ​​the reference block are used.

[0734] In some embodiments, the first determining unit 2101 is further configured to determine a template type of the current block; and determine a first template of the current block according to the template type of the current block.

[0735] In some embodiments, the first determination unit 2101 is further configured to determine the template type of the current block based on the reference pixels of the current block; wherein the reference pixels of the current block include at least one of the following: the left adjacent reference pixels of the current block, the upper adjacent reference pixels of the current block, the upper left adjacent reference pixels of the current block, the lower left adjacent reference pixels of the current block, and the upper right adjacent reference pixels of the current block.

[0736] In some embodiments, the first determination unit 2101 is further configured to determine that the template type of the current block is a first value if the left adjacent reference pixels of the current block, the upper adjacent reference pixels of the current block and the upper-left adjacent reference pixels of the current block are all available; and if the left adjacent reference pixels of the current block are available, determine that the template type of the current block is a second value; and if the upper adjacent reference pixels of the current block are available, determine that the template type of the current block is a third value; and if the left adjacent reference pixels of the current block and the upper-left adjacent reference pixels of the current block are both available, determine that the template type of the current block is a fourth value; and if the left adjacent reference pixels of the current block and the lower-left adjacent reference pixels of the current block are both available, determine that the template type of the current block is a fifth value; and if the upper adjacent reference pixels of the current block and the upper-right adjacent reference pixels of the current block are both available, determine that the template type of the current block is a sixth value.

[0737] In some embodiments, the first determining unit 2101 is further configured to perform template matching within a preset search area according to the first template to determine a reference template; and determine a reference block according to the reference template.

[0738] In some embodiments, the first determining unit 2101 is further configured to search within a preset search area based on the first template, determine a target block vector, and determine a reference template according to the target block vector.

[0739] In some embodiments, the first determining unit 2101 is further configured to determine motion parameters and corresponding reference blocks; determine a reference template based on the first template and the reference block; and encode the motion parameters and write the obtained coded bits into the bitstream.

[0740] In some embodiments, the first determination unit 2101 is further configured to perform a first search within a preset search area to determine the target block vector; or to perform a second search within the preset search area to determine the target block vector; wherein the search step size corresponding to the first search is greater than the search step size corresponding to the second search.

[0741] In some embodiments, the first determination unit 2101 is further configured to perform a first search within a preset search area, determine a first block vector and determine an initial matching template based on the first block vector; and determine the first search area based on the initial matching template, and perform a second search within the first search area to determine a target block vector; wherein the search step size corresponding to the first search is greater than the search step size corresponding to the second search, and the first search area is smaller than the preset search area.

[0742] In some embodiments, the preset search area includes at least one sub-search area; the first determination unit 2101 is further configured to perform searches within the at least one sub-search area to determine the best block vector and the corresponding matching cost value for each sub-search area; and determine the best block vector corresponding to the minimum matching cost value based on the best block vector and the corresponding matching cost value for each sub-search area; and use the best block vector corresponding to the minimum matching cost value as the target block vector.

[0743] In some embodiments, the first determination unit 2101 is further configured to perform a first search within at least one sub-search area to determine the best block vector of each sub-search area and the corresponding second search area; perform area judgment based on the best block vector of each sub-search area and the corresponding second search area to determine at least two target sub-search areas to participate in the second search; perform a second search within at least two target sub-search areas to determine the best block vectors corresponding to the at least two target sub-search areas; and use the best block vectors corresponding to the at least two target sub-search areas as the target block vectors.

[0744] In some embodiments, the first determining unit 2101 is further configured so that the model parameters include coefficients of the target filter.

[0745] In some embodiments, the first determining unit 2101 is further configured to determine coefficients of the target filter according to the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template.

[0746] In some embodiments, the first determining unit 2101 is further configured to fill the sampling points of the adjacent area of ​​the matching template when the sampling points of the adjacent area of ​​the matching template are used.

[0747] In some embodiments, the first determination unit 2101 is further configured so that the coefficient of the target filter is the coefficient used by the target filter when the first error between the output value of the pixel reference value in the matching template after being processed by the target filter and the pixel reference value in the first template meets the first condition.

[0748] In some embodiments, the first determining unit 2101 is further configured such that the first condition is that the first error is minimized.

[0749] In some embodiments, the first determining unit 2101 is further configured such that the first condition is that the first error is within a first preset threshold range.

[0750] In some embodiments, the first determining unit 2101 is further configured such that the first condition is that the variation of the first error is within a second preset threshold range.

[0751] In some embodiments, the first determination unit 2101 is further configured to determine the autocorrelation parameters based on the pixel reference values ​​in the matching template; and determine the cross-correlation parameters based on the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template; and determine the coefficients of the target filter based on the autocorrelation parameters and the cross-correlation parameters.

[0752] In some embodiments, the first determining unit 2101 is further configured so that the pixel reference value includes at least one of the following: a pixel reconstruction value, a pixel gradient value, and pixel position information.

[0753] In some embodiments, the first determining unit 2101 is further configured to set the number of coefficients of the target filter to be equal to a first preset value.

[0754] In some embodiments, the first determining unit 2101 is further configured to determine the number of coefficients of the target filter; and encode the number of coefficients of the target filter, and write the obtained coded bits into the bitstream.

[0755] In some embodiments, the first determining unit 2101 is further configured such that the target filter is a one-dimensional or two-dimensional filter of a preset shape.

[0756] In some embodiments, the first determining unit 2101 is further configured to determine a shape of a target filter; and encode the shape of the target filter, and write the obtained coded bits into the bitstream.

[0757] In some embodiments, the first filtering unit 2102 is further configured to filter the reference block according to the model parameters to determine a first output value of the target filter; and determine a filtered reference block based on the first output value of the target filter.

[0758] In some embodiments, the first filtering unit 2102 is further configured to fill the sampling points of the adjacent area of ​​the reference block when the sampling points of the adjacent area of ​​the reference block need to be used.

[0759] In some embodiments, the first filtering unit 2102 is further configured to calculate the product of the pixel reconstruction value of the reference block and the coefficient of the corresponding target filter; and set the first output value of the target filter to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

[0760] In some embodiments, the first filtering unit 2102 is further configured to determine a first value of the pixel reconstruction value of the reference block under the first mapping relationship; and calculate the product of the first value and the coefficient of the corresponding target filter; and set the first output value of the target filter to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

[0761] In some embodiments, the first filtering unit 2102 is further configured to determine a first offset value; and perform an addition operation based on the first output value and the first offset value to determine a filtered reference block.

[0762] In some embodiments, the first filtering unit 2102 is further configured to set the first offset value to be equal to the second preset value.

[0763] In some embodiments, the first filtering unit 2102 is further configured to determine the n+1th coefficient of the target filter if the number of coefficients of the target filter is n; and determine the first offset value based on the n+1th coefficient and the second offset value.

[0764] In some embodiments, the first filtering unit 2102 is further configured to set the second offset value to be equal to a third preset value; or, set the second offset value to be equal to a value of the pixel reconstruction value of the reference block under the second mapping relationship.

[0765] In some embodiments, the first prediction unit 2103 is further configured to perform a second process on the filtered reference block to obtain a prediction value of the current block.

[0766] In some embodiments, the first prediction unit 2103 is further configured such that the second processing is to set the prediction value of the current block to be equal to the filtered reference block.

[0767] In some embodiments, the first prediction unit 2103 is further configured so that the second processing is a clamping operation for limiting the filtered reference block to a preset value range.

[0768] In some embodiments, the first prediction unit 2103 is further configured to determine multiple sets of model parameters based on the first template and the matching template; and construct multiple filter models based on the multiple sets of model parameters, filter the reference blocks according to the multiple filter models respectively, and determine multiple filtered reference blocks; and determine the prediction value of the current block based on the multiple filtered reference blocks.

[0769] In some embodiments, the first prediction unit 2103 is further configured to perform weighted calculation on multiple filtered reference blocks to determine a prediction value of the current block.

[0770] In some embodiments, the first prediction unit 2103 is further configured to determine a target filter from a plurality of filter models; and perform filtering processing on the reference block according to the target filter to determine a prediction value of the current block.

[0771] In some embodiments, the first prediction unit 2103 is further configured to determine a target model index value, wherein the target model index value is used to indicate the index number of the target filter in multiple filter models; and encode the target model index value and write the obtained encoded bits into the bitstream.

[0772] In some embodiments, the first prediction unit 2103 is further configured to determine the original value of the current block; and perform rate-distortion cost calculations based on the original value of the current block and multiple initial prediction values ​​of the current block to determine the rate-distortion cost values ​​of each of the multiple initial prediction values; and determine the minimum rate-distortion cost value from the rate-distortion cost values ​​of each of the multiple initial prediction values; and use the filter model corresponding to the minimum rate-distortion cost value as the target filter.

[0773] In some embodiments, the first prediction unit 2103 is further configured to classify the reconstructed pixels in the first template and the matching template according to a preset method to obtain multiple groups of sub-templates and multiple groups of sub-matching templates; and determine multiple groups of model parameters based on the multiple groups of sub-templates and multiple groups of sub-matching templates.

[0774] In some embodiments, the first determination unit 2101 is further configured to determine a value of first syntax element identification information, wherein the first syntax element identification information is used to indicate whether intra-frame template matching is applied to the current block; and encode the value of the first syntax element identification information and write the obtained coded bits into the bitstream.

[0775] In some embodiments, the first determination unit 2101 is further configured to determine that the value of the first syntax element identification information is a first value if the current block applies intra-frame template matching; if the current block does not apply intra-frame template matching, determine that the value of the first syntax element identification information is a second value.

[0776] In some embodiments, the first determination unit 2101 is further configured to determine a value of second syntax element identification information, wherein the second syntax element identification information is used to indicate whether a filter model is applied to the current block; and encode the value of the second syntax element identification information and write the obtained coded bits into the bitstream.

[0777] In some embodiments, the first determination unit 2101 is further configured to determine that the value of the second syntax element identification information is the first value if the current block applies the filter model; if the current block does not apply the filter model, determine that the value of the second syntax element identification information is the second value.

[0778] In some embodiments, the first determination unit 2101 is further configured to, if the current block applies a filter model, perform filtering processing on the reference block according to the model parameters to determine the filtered reference block; and determine the prediction value of the current block based on the filtered reference block; and if the current block does not apply the filter model, use the reconstructed pixel value in the reference block as the prediction value of the current block.

[0779] In some embodiments, the first determining unit 2101 is further configured to determine an original value of the current block; and determine a prediction difference value of the current block according to the original value of the current block and the prediction value of the current block.

[0780] It is understandable that in the embodiments of the present application, a "unit" can be a portion of a circuit, a portion of a processor, a portion of a program or software, etc., and of course it can also be a module, or it can be non-modular. Moreover, the various components in this embodiment can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into a single unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional modules.

[0781] If the integrated unit is implemented as a software functional module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment, or the portion that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of the method described in this embodiment. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0782] Therefore, an embodiment of the present application provides a computer-readable storage medium, which is applied to the encoder 210. The computer-readable storage medium stores a computer program, and when the computer program is executed by the first processor, it implements the encoding method described in any one of the aforementioned embodiments.

[0783] Based on the composition of the encoder 210 and the computer-readable storage medium, refer to Figure 22, which shows a specific hardware structure diagram of the encoder 210 provided in an embodiment of the present application. As shown in Figure 22, the encoder 210 may include: a first communication interface 2201, a first memory 2202 and a first processor 2203; each component is coupled together through a first bus system 2204. It can be understood that the first bus system 2204 is used to achieve connection and communication between these components. In addition to the data bus, the first bus system 2204 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, various buses are labeled as the first bus system 2204 in Figure 22. Among them,

[0784] The first communication interface 2201 is used to receive and send signals when sending and receiving information with other external network elements;

[0785] A first memory 2202 is used to store computer programs that can be run on the first processor 2103;

[0786] The first processor 2203 is configured to, when running the computer program, execute:

[0787] Determining a first template for a current block, and determining a reference template and a reference block;

[0788] When the reference template meets the first preset condition, performing a first processing on an adjacent area of ​​the reference template to determine a matching template, and determining model parameters based on the first template and the matching template;

[0789] Performing filtering on the reference block according to the model parameters to determine a filtered reference block;

[0790] Determine the prediction value of the current block based on the filtered reference block;

[0791] Determine the prediction difference value of the current block according to the prediction value of the current block.

[0792] It is understood that the first memory 2202 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DRRAM). The first memory 2202 of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0793] The first processor 2203 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits or software instructions in the first processor 2203. The above-mentioned first processor 2203 can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of this application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly implemented as a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, registers, etc. The storage medium is located in the first memory 2202 , and the first processor 2203 reads the information in the first memory 2202 and completes the steps of the above method in combination with its hardware.

[0794] It is to be understood that these embodiments described in the present application can be implemented with hardware, software, firmware, middleware, microcode or its combination.For hardware implementation, the processing unit can be implemented in one or more application specific integrated circuits (Application Specific Integrated Circuits, ASIC), digital signal processor (Digital Signal Processing, DSP), digital signal processing equipment (DSP Device, DSPD), programmable logic device (Programmable Logic Device, PLD), field programmable gate array (Field-Programmable Gate Array, FPGA), general-purpose processor, controller, microcontroller, microprocessor, other electronic units for performing functions described in the present application or its combination.For software implementation, the technology described in the present application can be realized by the module (such as process, function etc.) that performs functions described in the present application. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.

[0795] Optionally, as another embodiment, the first processor 2203 is further configured to execute the encoding method described in any one of the aforementioned embodiments when running the computer program.

[0796] This embodiment provides an encoder, for which model parameters are determined based on the first template and the matching template. The model parameters fully reflect the correlation between the matching template and the first template of the current block, and this correlation is applied to the reference block. The predicted value of the intra-frame template matching technology can be effectively corrected, thereby improving the prediction accuracy, saving bit rate, and improving the encoding and decoding efficiency, thereby improving the encoding and decoding performance.

[0797] In another embodiment of the present application, based on the same inventive concept as the above embodiment, refer to FIG23 , which shows a schematic diagram of the structure of a decoder 230 provided by the embodiment of the present application. As shown in FIG23 , the decoder 230 may include: a second determination unit 2301, a second filtering unit 2302, and a second prediction unit 2303; wherein,

[0798] The second determining unit 2301 is configured to determine a first template of the current block, and to determine a reference template and a reference block; and further configured to perform a first processing on an adjacent area of ​​the reference template when the reference template meets a first preset condition, determine a matching template, and determine model parameters based on the first template and the matching template;

[0799] The second filtering unit 2302 is configured to perform filtering on the reference block according to the model parameters to determine a filtered reference block;

[0800] The second prediction unit 2303 is configured to determine a prediction value of the current block based on the filtered reference block;

[0801] The second determining unit 2301 is further configured to determine a reconstructed value of the current block according to the predicted value of the current block.

[0802] In some embodiments, the matching template includes: sampling points in the reference template and sampling points in an adjacent area of ​​the reference template.

[0803] In some embodiments, the second determining unit 2301 is further configured to determine whether the reference template satisfies the first preset condition if a sampling point outside the reference template is used.

[0804] In some embodiments, the second determining unit 2301 is further configured to perform filling processing on the sampling points in the adjacent area of ​​the reference template if sampling points outside the reference template are used.

[0805] In some embodiments, the second determining unit 2301 is further configured to determine whether the sampling points of the adjacent area of ​​the reference template are available; if the sampling points of the adjacent area of ​​the reference template are available, the sampling points of the adjacent area of ​​the reference template are directly used; if the sampling points of the adjacent area of ​​the reference template are not available, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0806] In some embodiments, the second determining unit 2301 is further configured to determine whether the sampling points of the adjacent area of ​​the reference template are available, including at least one of the following:

[0807] The sampling point is within the image boundary;

[0808] The sampling point is within the tile boundary;

[0809] The sampling points have been rebuilt.

[0810] In some embodiments, the second determining unit 2301 is further configured to determine whether the sampling points of the adjacent area of ​​the reference template exceed a preset search range; if the sampling points of the adjacent area of ​​the reference template do not exceed the preset search range, the sampling points of the adjacent area of ​​the reference template are directly used; if the sampling points of the adjacent area of ​​the reference template exceed the preset search range, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

[0811] In some embodiments, the second determining unit 2301 is further configured to use the reference template directly as the matching template when the reference template meets the second preset condition, and perform the step of determining the model parameters according to the first template and the matching template.

[0812] In some embodiments, the second determining unit 2301 is further configured to determine whether the reference template satisfies a second preset condition, including: the reference template does not satisfy the first preset condition.

[0813] In some embodiments, the second determining unit 2301 is further configured to determine that the reference template satisfies a second preset condition, including at least one of the following:

[0814] The reference template is not at the image boundary;

[0815] The reference template does not exceed the preset search range;

[0816] The sampling points in the reference template have been reconstructed;

[0817] The sampling points in the reference template and the current block are in the same tile;

[0818] Sampling points outside the reference template are not used.

[0819] In some embodiments, the second determining unit 2301 is further configured to perform padding processing on the sampling points in the adjacent area of ​​the reference block if the sampling points in the adjacent area of ​​the reference block are used.

[0820] In some embodiments, the second determining unit 2301 is further configured to determine a template type of the current block; and determine a first template of the current block according to the template type of the current block.

[0821] In some embodiments, the second determination unit 2301 is further configured to determine the template type of the current block based on the reference pixels of the current block; wherein the reference pixels of the current block include at least one of the following: the left adjacent reference pixels of the current block, the upper adjacent reference pixels of the current block, the upper left adjacent reference pixels of the current block, the lower left adjacent reference pixels of the current block, and the upper right adjacent reference pixels of the current block.

[0822] In some embodiments, the second determination unit 2301 is further configured to determine that the template type of the current block is a first value if the left adjacent reference pixels of the current block, the upper adjacent reference pixels of the current block and the upper-left adjacent reference pixels of the current block are all available; and if the left adjacent reference pixels of the current block are available, determine that the template type of the current block is a second value; and if the upper adjacent reference pixels of the current block are available, determine that the template type of the current block is a third value; and if the left adjacent reference pixels of the current block and the upper-left adjacent reference pixels of the current block are both available, determine that the template type of the current block is a fourth value; and if the left adjacent reference pixels of the current block and the lower-left adjacent reference pixels of the current block are both available, determine that the template type of the current block is a fifth value; and if the upper adjacent reference pixels of the current block and the upper-right adjacent reference pixels of the current block are both available, determine that the template type of the current block is a sixth value.

[0823] In some embodiments, the second determining unit 2301 is further configured to perform template matching within a preset search area according to the first template to determine a reference template; and determine a reference block according to the reference template.

[0824] In some embodiments, the second determining unit 2301 is further configured to search within a preset search area based on the first template, determine a target block vector, and determine a reference template according to the target block vector.

[0825] In some embodiments, the second determining unit 2301 is further configured to decode the code stream and determine motion parameters; determine a reference block according to the motion parameters; and determine a reference template according to the first template and the reference block.

[0826] In some embodiments, the second determination unit 2301 is further configured to perform a first search within a preset search area to determine the target block vector; or to perform a second search within the preset search area to determine the target block vector; wherein the search step size corresponding to the first search is greater than the search step size corresponding to the second search.

[0827] In some embodiments, the second determination unit 2301 is further configured to perform a first search within a preset search area, determine a first block vector and determine an initial matching template based on the first block vector; and determine a first search area based on the initial matching template, and perform a second search within the first search area to determine a target block vector; wherein the search step size corresponding to the first search is greater than the search step size corresponding to the second search, and the first search area is smaller than the preset search area.

[0828] In some embodiments, the preset search area includes at least one sub-search area; the second determination unit 2301 is further configured to perform searches within the at least one sub-search area respectively to determine the best block vector and the corresponding matching cost value of each sub-search area; and determine the best block vector corresponding to the minimum matching cost value based on the best block vector and the corresponding matching cost value of each sub-search area; and use the best block vector corresponding to the minimum matching cost value as the target block vector.

[0829] In some embodiments, the second determination unit 2301 is further configured to perform a first search within at least one sub-search area to determine the best block vector of each sub-search area and the corresponding second search area; perform area judgment based on the best block vector of each sub-search area and the corresponding second search area to determine at least two target sub-search areas to participate in the second search; perform a second search within at least two target sub-search areas to determine the best block vectors corresponding to the at least two target sub-search areas; and use the best block vectors corresponding to the at least two target sub-search areas as the target block vector.

[0830] In some embodiments, the second determining unit 2301 is further configured to fill the sampling points in the adjacent area of ​​the matching template when the sampling points in the adjacent area of ​​the matching template need to be used.

[0831] In some embodiments, the second determining unit 2301 is further configured so that the model parameters include coefficients of the target filter.

[0832] In some embodiments, the second determining unit 2301 is further configured to determine coefficients of the target filter according to the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template.

[0833] In some embodiments, the second determination unit 2301 is further configured so that the coefficient of the target filter is the coefficient used by the target filter when the first error between the output value of the pixel reference value in the matching template after being processed by the target filter and the pixel reference value in the first template meets the first condition.

[0834] In some embodiments, the second determining unit 2301 is further configured such that the first condition is that the first error is minimized.

[0835] In some embodiments, the second determining unit 2301 is further configured such that the first condition is that the first error is within a first preset threshold range.

[0836] In some embodiments, the second determining unit 2301 is further configured such that the first condition is that the variation of the first error is within a second preset threshold range.

[0837] In some embodiments, the second determination unit 2301 is further configured to determine the autocorrelation parameters based on the pixel reference values ​​in the matching template; and determine the cross-correlation parameters based on the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template; and determine the coefficients of the target filter based on the autocorrelation parameters and the cross-correlation parameters.

[0838] In some embodiments, the second determining unit 2301 is further configured so that the pixel reference value includes at least one of the following: a pixel reconstruction value, a pixel gradient value, and pixel position information.

[0839] In some embodiments, the second determining unit 2301 is further configured to set the number of coefficients of the target filter to be equal to a first preset value.

[0840] In some embodiments, the second determining unit 2301 is further configured to decode the code stream and determine the number of coefficients of the target filter.

[0841] In some embodiments, the second determining unit 2301 is further configured such that the target filter is a one-dimensional or two-dimensional filter of a preset shape.

[0842] In some embodiments, the second determining unit 2301 is further configured to decode the code stream and determine the shape of the target filter.

[0843] In some embodiments, the second filtering unit 2302 is further configured to filter the reference block according to the model parameters to determine a first output value of the target filter; and determine a filtered reference block based on the first output value of the target filter.

[0844] In some embodiments, the second filtering unit 2302 is further configured to fill the sampling points of the adjacent area of ​​the reference block when the sampling points of the adjacent area of ​​the reference block need to be used.

[0845] In some embodiments, the second filtering unit 2302 is further configured to calculate the product of the pixel reconstruction value of the reference block and the coefficient of the corresponding target filter; and set the first output value of the target filter to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

[0846] In some embodiments, the second filtering unit 2302 is further configured to determine a first value of the pixel reconstruction value of the reference block under the first mapping relationship; and calculate the product of the first value and the coefficient of the corresponding target filter; and set the first output value of the target filter to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

[0847] In some embodiments, the second filtering unit 2302 is further configured to determine a first offset value; and perform an addition operation based on the first output value and the first offset value to determine a filtered reference block.

[0848] In some embodiments, the second filtering unit 2302 is further configured to set the first offset value to be equal to a second preset value.

[0849] In some embodiments, the second filtering unit 2302 is further configured to determine the n+1th coefficient of the target filter if the number of coefficients of the target filter is n; and determine the first offset value based on the n+1th coefficient and the second offset value.

[0850] In some embodiments, the second filtering unit 2302 is further configured to set the second offset value to be equal to a third preset value; or, set the second offset value to be equal to a value of the pixel reconstruction value of the reference block under the second mapping relationship.

[0851] In some embodiments, the second prediction unit 2303 is further configured to perform a second process on the filtered reference block to obtain a prediction value of the current block.

[0852] In some embodiments, the second prediction unit 2303 is further configured such that the second processing is to set the prediction value of the current block to be equal to the filtered reference block.

[0853] In some embodiments, the second prediction unit 2303 is further configured so that the second processing is a clamping operation that limits the filtered reference block to a preset value range.

[0854] In some embodiments, the second prediction unit 2303 is further configured to determine multiple sets of model parameters based on the first template and the matching template; and construct multiple filter models based on the multiple sets of model parameters, filter the reference blocks according to the multiple filter models respectively, and determine multiple filtered reference blocks; and determine the prediction value of the current block based on the multiple filtered reference blocks.

[0855] In some embodiments, the second prediction unit 2303 is further configured to perform weighted calculation on multiple filtered reference blocks to determine a prediction value of the current block.

[0856] In some embodiments, the second prediction unit 2303 is further configured to decode the code stream and determine the target model index value; and determine the corresponding target filter from multiple filter models based on the target model index value; and filter the reference block according to the target filter to determine the prediction value of the current block.

[0857] In some embodiments, the second prediction unit 2303 is further configured to classify the reconstructed pixels in the first template and the matching template according to a preset method to obtain multiple groups of sub-templates and multiple groups of sub-matching templates; and determine multiple groups of model parameters based on the multiple groups of sub-templates and multiple groups of sub-matching templates.

[0858] In some embodiments, the second determination unit 2301 is further configured to decode the code stream and determine the value of the first syntax element identification information; and if the first syntax element identification information is used to indicate that the current block applies intra-frame template matching, decode the code stream and determine the value of the second syntax element identification information; and if the second syntax element identification information is used to indicate that the current block applies a filter model, perform filtering processing on the reference block according to the model parameters to determine the filtered reference block; and determine the prediction value of the current block based on the filtered reference block.

[0859] In some embodiments, the second determining unit 2301 is further configured to use the reconstructed pixel value in the reference block as the prediction value of the current block if the second syntax element identification information is used to indicate that the filter model is not applied to the current block.

[0860] In some embodiments, the second determining unit 2301 is further configured to decode the code stream to determine a prediction residual of the current block; and determine a reconstructed value of the current block according to the prediction value of the current block and the prediction residual of the current block.

[0861] It is understood that in this embodiment, a "unit" can be a portion of a circuit, a portion of a processor, a portion of a program or software, etc., and can also be a module or a non-modular system. Furthermore, the various components in this embodiment can be integrated into a single processing unit, or each unit can exist physically separately, or two or more units can be integrated into a single unit. The aforementioned integrated units can be implemented in the form of hardware or software functional modules.

[0862] If the integrated unit is implemented as a software functional module and not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, this embodiment provides a computer-readable storage medium for use in decoder 230. The computer-readable storage medium stores a computer program that, when executed by the second processor, implements any of the decoding methods described in the aforementioned embodiments.

[0863] Based on the composition of the decoder 230 and the computer-readable storage medium, refer to Figure 24, which shows a specific hardware structure diagram of the decoder 230 provided in an embodiment of the present application. As shown in Figure 24, the decoder 230 may include: a second communication interface 2401, a second memory 2402 and a second processor 2403; each component is coupled together through a second bus system 2404. It can be understood that the second bus system 2404 is used to achieve connection and communication between these components. In addition to the data bus, the second bus system 2404 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, various buses are labeled as the second bus system 2404 in Figure 24. Among them,

[0864] The second communication interface 2401 is used to receive and send signals during the process of sending and receiving information between other external network elements;

[0865] The second memory 2402 is used to store computer programs that can be run on the second processor 2403;

[0866] The second processor 2403 is configured to, when running the computer program, execute:

[0867] Determining a first template for a current block, and determining a reference template and a reference block;

[0868] When the reference template meets the first preset condition, performing a first processing on an adjacent area of ​​the reference template to determine a matching template, and determining model parameters based on the first template and the matching template;

[0869] Performing filtering on the reference block according to the model parameters to determine a filtered reference block;

[0870] Determine the prediction value of the current block based on the filtered reference block;

[0871] Determine the reconstructed value of the current block according to the predicted value of the current block.

[0872] Optionally, as another embodiment, the second processor 2403 is further configured to execute the decoding method described in any one of the aforementioned embodiments when running the computer program.

[0873] It can be understood that the hardware functions of the second memory 2402 and the first memory 2202 are similar, and the hardware functions of the second processor 2403 and the first processor 2203 are similar; they will not be described in detail here.

[0874] This embodiment provides a decoder. For this decoder, model parameters are determined based on the first template and the matching template. The model parameters fully reflect the correlation between the matching template and the first template of the current block, and this correlation is applied to the reference block. It can effectively correct the prediction value of the intra-frame template matching technology, thereby improving the prediction accuracy, saving bit rate, and improving the encoding and decoding efficiency, thereby improving the encoding and decoding performance.

[0875] In yet another embodiment of the present application, referring to FIG25 , a schematic diagram of the structure of a coding and decoding system provided by an embodiment of the present application is shown. As shown in FIG25 , the coding and decoding system 250 may include an encoder 2501 and a decoder 2502 .

[0876] In the embodiment of the present application, the encoder 2501 may be the encoder described in any one of the aforementioned embodiments, and the decoder 2502 may be the decoder described in any one of the aforementioned embodiments.

[0877] It should be noted that, in this application, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.

[0878] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0879] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0880] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.

[0881] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.

[0882] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims. Industrial Applicability

[0883] Whether on the encoding or decoding end, the first template of the current block is determined, as well as the reference template and reference block. When the reference template meets the first preset condition, the adjacent area of ​​the reference template is first processed to determine the matching template, and model parameters are determined based on the first template and the matching template. The reference block is filtered based on the model parameters to determine the filtered reference block. The prediction value of the current block is determined based on the filtered reference block. In this way, the encoding end can determine the prediction difference of the current block based on the prediction value of the current block; so that on the decoding end, the reconstruction value of the current block can be determined based on the prediction value of the current block. In other words, the model parameters are determined based on the first template and the matching template. The model parameters fully reflect the correlation between the matching template and the first template of the current block, and this correlation is applied to the reference block. By filtering and correcting its reconstructed pixels, the filtered reconstructed pixels are then used as the predicted pixels of the current block. This can improve prediction accuracy, save bit rate, and improve encoding and decoding efficiency, thereby improving encoding and decoding performance.

Claims

1. A decoding method, applied to a decoder, the method comprising: Determine a first template of the current block, and determine a reference template and a reference block; When the reference template meets a first preset condition, performing a first processing on an adjacent area of ​​the reference template to determine a matching template, and determining a model parameter according to the first template and the matching template; Performing filtering on the reference block according to the model parameters to determine a filtered reference block; Determining a prediction value of the current block according to the filtered reference block; A reconstructed value of the current block is determined according to the predicted value of the current block.

2. The method according to claim 1, wherein: The matching template includes: sampling points in the reference template and sampling points in an adjacent area of ​​the reference template.

3. The method according to claim 1, wherein: The method further comprises: If sampling points outside the reference template are used, it is determined that the reference template meets the first preset condition.

4. The method according to claim 3, wherein: When the reference template meets a first preset condition, performing a first process on an adjacent area of ​​the reference template includes: If sampling points outside the reference template are used, the sampling points in the adjacent area of ​​the reference template are filled.

5. The method according to claim 4, wherein: The filling process of the sampling points of the adjacent area of ​​the reference template includes: Determining whether sampling points in an adjacent area of ​​the reference template are available; If the sampling points of the adjacent area of ​​the reference template are available, directly using the sampling points of the adjacent area of ​​the reference template; If the sampling points of the adjacent area of ​​the reference template are not available, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

6. The method according to claim 5, wherein: The sampling points of the adjacent area of ​​the reference template are available, including at least one of the following: The sampling point is within the image boundary; The sampling point is within the boundary of the tile; The sampling points have been reconstructed.

7. The method according to claim 4 or 5, wherein: The filling process of the sampling points of the adjacent area of ​​the reference template includes: Determining whether the sampling points of the adjacent area of ​​the reference template exceed a preset search range; If the sampling points of the adjacent area of ​​the reference template do not exceed the preset search range, directly using the sampling points of the adjacent area of ​​the reference template; If the sampling points of the adjacent area of ​​the reference template exceed the preset search range, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

8. The method according to claim 1, wherein: The method further comprises: When the reference template meets the second preset condition, the reference template is directly used as the matching template, and the step of determining model parameters according to the first template and the matching template is performed.

9. The method according to claim 8, wherein: The reference template satisfies the second preset condition, including: the reference template does not satisfy the first preset condition.

10. The method according to claim 8, wherein: The reference template satisfies a second preset condition, including at least one of the following: The reference template is not at the image boundary; The reference template does not exceed the preset search range; The sampling points in the reference template have all been reconstructed; The sampling point in the reference template and the current block are in the same tile; Sampling points outside the reference template are not used.

11. The method according to claim 1, wherein: The filtering the reference block according to the model parameters to determine the filtered reference block includes: If the sampling points of the adjacent area of ​​the reference block are used, the sampling points of the adjacent area of ​​the reference block are filled.

12. The method according to claim 1, wherein: The determining of the first template of the current block comprises: Determining a template type of the current block; A first template of the current block is determined according to the template type of the current block.

13. The method according to claim 12, wherein: The determining the template type of the current block includes: Determining a template type of the current block according to a reference pixel of the current block; Among them, the reference pixels of the current block include at least one of the following: the left adjacent reference pixels of the current block, the upper adjacent reference pixels of the current block, the upper left adjacent reference pixels of the current block, the lower left adjacent reference pixels of the current block, and the upper right adjacent reference pixels of the current block.

14. The method according to claim 13, wherein: The determining the template type of the current block includes: If the left adjacent reference pixel of the current block, the upper adjacent reference pixel of the current block, and the upper left adjacent reference pixel of the current block are all available, determining that the template type of the current block is a first value; If the left adjacent reference pixel of the current block is available, determining the template type of the current block to be a second value; If the upper adjacent reference pixel of the current block is available, determining the template type of the current block to be a third value; If both the left adjacent reference pixel of the current block and the upper left adjacent reference pixel of the current block are available, determining that the template type of the current block is a fourth value; If both the left adjacent reference pixel of the current block and the lower left adjacent reference pixel of the current block are available, determining that the template type of the current block is a fifth value; If both the upper neighboring reference pixels of the current block and the upper right neighboring reference pixels of the current block are available, the template type of the current block is determined to be a sixth value.

15. The method according to claim 1, wherein: The determining of the reference template and the reference block comprises: Performing template matching in a preset search area according to the first template to determine the reference template; The reference block is determined according to the reference template.

16. The method according to claim 15, wherein: The performing template matching in a preset search area according to the first template to determine the reference template includes: A search is performed in the preset search area based on the first template to determine a target block vector, and the reference template is determined according to the target block vector.

17. The method according to claim 1, wherein: The determining of the reference template and the reference block comprises: Decode the bitstream and determine motion parameters; Determining the reference block according to the motion parameter; The reference template is determined according to the first template and the reference block.

18. The method according to claim 16, wherein: The searching within the preset search area based on the first template to determine the target block vector includes: Perform a first search in the preset search area to determine the target block vector; or, Perform a second search in the preset search area to determine the target block vector; The search step length corresponding to the first search is greater than the search step length corresponding to the second search.

19. The method according to claim 16, wherein: The searching within the preset search area based on the first template to determine the target block vector includes: Perform a first search in the preset search area to determine a first block vector and determine an initial matching template according to the first block vector; Determining a first search area according to the initial matching template, and performing a second search within the first search area to determine the target block vector; The search step size corresponding to the first search is larger than the search step size corresponding to the second search, and the first search area is smaller than the preset search area.

20. The method according to claim 16, wherein: The preset search area includes at least one sub-search area; and searching within the preset search area based on the first template to determine the target block vector includes: Searching in the at least one sub-search area respectively to determine the best block vector and the corresponding matching cost value of each sub-search area; Determine the best block vector corresponding to the minimum matching cost value according to the best block vector and the corresponding matching cost value of each sub-search area; The best block vector corresponding to the minimum matching cost value is used as the target block vector.

21. The method according to claim 20, wherein: The searching within the preset search area based on the first template to determine the target block vector includes: Perform a first search in the at least one sub-search area to determine the best block vector of each sub-search area and the corresponding second search area; Performing region judgment according to the best block vector of each sub-search region and the corresponding second search region to determine at least two target sub-search regions participating in the second search; Perform a second search in the at least two target sub-search areas to determine the best block vectors corresponding to the at least two target sub-search areas; The best block vectors corresponding to the at least two target sub-search areas are used as the target block vector.

22. The method according to claim 1, wherein: The determining of model parameters according to the first template and the matching template includes: The model parameters include coefficients of the target filter.

23. The method according to claim 22, wherein: The method further comprises: The coefficients of the target filter are determined according to the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template.

24. The method according to claim 23, wherein: The method further comprises: The coefficients of the target filter are coefficients used by the target filter when a first error between an output value of a pixel reference value in the matching template after being processed by the target filter and a pixel reference value in the first template satisfies a first condition.

25. The method according to claim 24, wherein: The method further comprises: The first condition is that the first error is minimum.

26. The method according to claim 24, wherein: The method further comprises: The first condition is that the first error is within a first preset threshold range.

27. The method according to claim 24, wherein: The method further comprises: The first condition is that the change in the first error is within a second preset threshold range.

28. The method of claim 23, wherein: The step of determining the coefficient of the target filter according to the pixel reference value in the first template and the pixel reference value in the matching template comprises: Determining an autocorrelation parameter according to a pixel reference value in the matching template; Determining a cross-correlation parameter according to a pixel reference value in the first template and a pixel reference value in the matching template; The coefficients of the target filter are determined according to the autocorrelation parameters and the cross-correlation parameters.

29. The method of claim 23, wherein: The pixel reference value includes at least one of the following: a pixel reconstruction value, a pixel gradient value, and pixel position information.

30. The method of claim 22, wherein: The number of coefficients of the target filter is equal to a first preset value.

31. The method of claim 22, wherein: The method further comprises: The code stream is decoded to determine the number of coefficients of the target filter.

32. The method of claim 22, wherein: The target filter is a one-dimensional or two-dimensional filter of a preset shape.

33. The method of claim 22, wherein: The method further comprises: The code stream is decoded to determine the shape of the target filter.

34. The method of claim 22, wherein: The filtering the reference block according to the model parameters to determine the filtered reference block includes: Performing filtering processing on the reference block according to the model parameters to determine a first output value of the target filter; The filtered reference block is determined based on a first output value of the target filter.

35. The method of claim 34, wherein: The filtering process is performed on the reference block according to the model parameters to determine the first output value of the target filter, comprising: Calculating the product of the pixel reconstruction value of the reference block and the corresponding coefficient of the target filter; The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

36. The method of claim 34, wherein: The filtering process is performed on the reference block according to the model parameters to determine the first output value of the target filter, comprising: Determine a first value of a pixel reconstruction value of the reference block under a first mapping relationship; Calculate the product of the first value and the corresponding coefficient of the target filter; The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

37. The method of claim 34, wherein: The step of determining the filtered reference block based on the first output value of the target filter comprises: determining a first offset value; An addition operation is performed according to the first output value and the first offset value to determine the filtered reference block.

38. The method of claim 37, wherein: The determining of the first offset value comprises: The first offset value is set equal to a second preset value.

39. The method of claim 37, wherein: The determining of the first offset value comprises: If the number of coefficients of the target filter is n, determining the n+1th coefficient of the target filter; The first offset value is determined according to the n+1th coefficient and the second offset value.

40. The method of claim 39, wherein: The method further comprises: setting the second offset value to be equal to a third preset value; or, The second offset value is set to be equal to the value of the pixel reconstruction value of the reference block under the second mapping relationship.

41. The method of claim 1, wherein: The step of determining the prediction value of the current block according to the filtered reference block comprises: The filtered reference block is subjected to a second process to obtain a prediction value of the current block.

42. The method according to claim 41, wherein: The method further comprises: The second process is to set the prediction value of the current block equal to the filtered reference block.

43. The method of claim 41, wherein: The method further comprises: The second processing is a clamping operation that limits the filtered reference block to a preset value range.

44. The method of claim 1, wherein: The method further comprises: Determining multiple groups of model parameters according to the first template and the matching template; Constructing a plurality of filter models according to the plurality of groups of model parameters, filtering the reference blocks respectively according to the plurality of filter models, and determining a plurality of filtered reference blocks; A prediction value of the current block is determined according to the multiple filtered reference blocks.

45. The method of claim 44, wherein: The step of determining the prediction value of the current block according to the plurality of filtered reference blocks comprises: A weighted calculation is performed on the multiple filtered reference blocks to determine a prediction value of the current block.

46. ​​The method of claim 44, wherein: The method further comprises: Decode the code stream and determine the target model index value; Determining a corresponding target filter from the plurality of filter models according to the target model index value; The reference block is filtered according to the target filter to determine a prediction value of the current block.

47. The method of claim 44, wherein: The step of determining multiple groups of model parameters according to the first template and the matching template includes: Classifying the reconstructed pixels in the first template and the matching template respectively according to a preset method to obtain multiple groups of sub-templates and multiple groups of sub-matching templates; The multiple groups of model parameters are determined according to the multiple groups of sub-templates and the multiple groups of sub-matching templates.

48. The method of claim 1, wherein: The method further comprises: Decoding the bitstream to determine a value of the first syntax element identification information; If the first syntax element identification information is used to indicate that intra template matching is applied to the current block, decoding the bitstream to determine a value of the second syntax element identification information; If the second syntax element identification information is used to indicate that a filter model is applied to the current block, the steps of filtering the reference block according to the model parameters to determine a filtered reference block; and determining a prediction value of the current block according to the filtered reference block are performed.

49. The method of claim 48, wherein: The method further comprises: If the second syntax element identification information is used to indicate that the filter model is not applied to the current block, the reconstructed pixel value in the reference block is used as the prediction value of the current block.

50. The method according to any one of claims 1 to 49, wherein: The step of determining the reconstruction value of the current block according to the prediction value of the current block includes: Decoding a bitstream to determine a prediction residual of the current block; A reconstructed value of the current block is determined according to the predicted value of the current block and the predicted difference value of the current block.

51. A coding method, applied to an encoder, the method comprising: Determine a first template of the current block, and determine a reference template and a reference block; When the reference template meets a first preset condition, performing a first processing on an adjacent area of ​​the reference template to determine a matching template, and determining a model parameter according to the first template and the matching template; Performing filtering on the reference block according to the model parameters to determine a filtered reference block; Determining a prediction value of the current block according to the filtered reference block; A prediction difference value of the current block is determined according to the prediction value of the current block.

52. The method of claim 51, wherein: The matching template includes: sampling points in the reference template and sampling points in an adjacent area of ​​the reference template.

53. The method of claim 51, wherein: The method further comprises: If sampling points outside the reference template are used, it is determined that the reference template meets the first preset condition.

54. The method of claim 53, wherein: When the reference template meets a first preset condition, performing a first process on an adjacent area of ​​the reference template includes: If sampling points outside the reference template are used, the sampling points in the adjacent area of ​​the reference template are filled.

55. The method of claim 54, wherein: The filling process of the sampling points of the adjacent area of ​​the reference template includes: Determining whether sampling points in an adjacent area of ​​the reference template are available; If the sampling points of the adjacent area of ​​the reference template are available, directly using the sampling points of the adjacent area of ​​the reference template; If the sampling points of the adjacent area of ​​the reference template are not available, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

56. The method of claim 55, wherein: The sampling points of the adjacent area of ​​the reference template are available, including at least one of the following: The sampling point is within the image boundary; The sampling point is within the boundary of the tile; The sampling points have been reconstructed.

57. The method of claim 54 or 55, wherein: The filling process of the sampling points of the adjacent area of ​​the reference template includes: Determining whether the sampling points of the adjacent area of ​​the reference template exceed a preset search range; If the sampling points of the adjacent area of ​​the reference template do not exceed the preset search range, directly using the sampling points of the adjacent area of ​​the reference template; If the sampling points of the adjacent area of ​​the reference template exceed the preset search range, the adjacent area of ​​the reference template is filled by copying the reconstructed sampling points in the target matching template or the target reference block that are closest to the sampling points to obtain the sampling points of the adjacent area of ​​the reference template.

58. The method of claim 51, wherein: The method further comprises: When the reference template meets the second preset condition, the reference template is directly used as the matching template, and the step of determining model parameters according to the first template and the matching template is performed.

59. The method of claim 58, wherein: The reference template satisfies the second preset condition, including: the reference template does not satisfy the first preset condition.

60. The method of claim 58, wherein: The reference template satisfies a second preset condition, including at least one of the following: The reference template is not at the image boundary; The reference template does not exceed the preset search range; The sampling points in the reference template have all been reconstructed; The sampling point in the reference template and the current block are in the same tile; Sampling points outside the reference template are not used.

61. The method of claim 51, wherein: The filtering the reference block according to the model parameters to determine the filtered reference block includes: If the sampling points of the adjacent area of ​​the reference block are used, the sampling points of the adjacent area of ​​the reference block are filled.

62. The method of claim 51, wherein: The determining of the first template of the current block comprises: Determining a template type of the current block; A first template of the current block is determined according to the template type of the current block.

63. The method of claim 62, wherein: The determining the template type of the current block includes: Determining a template type of the current block according to a reference pixel of the current block; Among them, the reference pixels of the current block include at least one of the following: the left adjacent reference pixels of the current block, the upper adjacent reference pixels of the current block, the upper left adjacent reference pixels of the current block, the lower left adjacent reference pixels of the current block, and the upper right adjacent reference pixels of the current block.

64. The method of claim 63, wherein: The determining the template type of the current block includes: If the left adjacent reference pixel of the current block, the upper adjacent reference pixel of the current block, and the upper left adjacent reference pixel of the current block are all available, determining that the template type of the current block is a first value; If the left adjacent reference pixel of the current block is available, determining the template type of the current block to be a second value; If the upper adjacent reference pixel of the current block is available, determining the template type of the current block to be a third value; If both the left adjacent reference pixel of the current block and the upper left adjacent reference pixel of the current block are available, determining that the template type of the current block is a fourth value; If both the left adjacent reference pixel of the current block and the lower left adjacent reference pixel of the current block are available, determining that the template type of the current block is a fifth value; If both the upper neighboring reference pixels of the current block and the upper right neighboring reference pixels of the current block are available, the template type of the current block is determined to be a sixth value.

65. The method of claim 51, wherein: The determining of the matching template and the reference block comprises: Performing template matching in a preset search area according to the first template to determine the matching template; The reference block is determined according to the matching template.

66. The method of claim 65, wherein: The performing template matching in a preset search area according to the first template to determine the matching template includes: A search is performed in the preset search area based on the first template to determine a target block vector, and the matching template is determined according to the target block vector.

67. The method of claim 51, wherein: The determining of the matching template and the reference block comprises: Determine motion parameters and corresponding reference blocks; Determine the matching template according to the first template and the reference block; Accordingly, the method further comprises: The motion parameters are encoded, and the obtained encoded bits are written into a bitstream.

68. The method of claim 66, wherein: The searching within the preset search area based on the first template to determine the target block vector includes: Perform a first search in the preset search area to determine the target block vector; or, Perform a second search in the preset search area to determine the target block vector; The search step length corresponding to the first search is greater than the search step length corresponding to the second search.

69. The method of claim 66, wherein: The searching within the preset search area based on the first template to determine the target block vector includes: Perform a first search in the preset search area to determine a first block vector and determine an initial matching template according to the first block vector; Determining a first search area according to the initial matching template, and performing a second search within the first search area to determine the target block vector; The search step size corresponding to the first search is larger than the search step size corresponding to the second search, and the first search area is smaller than the preset search area.

70. The method of claim 66, wherein: The preset search area includes at least one sub-search area; and searching within the preset search area based on the first template to determine the target block vector includes: Searching in the at least one sub-search area respectively to determine the best block vector and the corresponding matching cost value of each sub-search area; Determine the best block vector corresponding to the minimum matching cost value according to the best block vector and the corresponding matching cost value of each sub-search area; The best block vector corresponding to the minimum matching cost value is used as the target block vector.

71. The method of claim 70, wherein: The searching within the preset search area based on the first template to determine the target block vector includes: Perform a first search in the at least one sub-search area to determine the best block vector of each sub-search area and the corresponding second search area; Performing region judgment according to the best block vector of each sub-search region and the corresponding second search region to determine at least two target sub-search regions participating in the second search; Perform a second search in the at least two target sub-search areas to determine the best block vectors corresponding to the at least two target sub-search areas; The best block vectors corresponding to the at least two target sub-search areas are used as the target block vector.

72. The method of claim 51, wherein: The determining of model parameters according to the first template and the matching template includes: The model parameters include coefficients of the target filter.

73. The method of claim 72, wherein: The method further comprises: The coefficients of the target filter are determined according to the pixel reference values ​​in the first template and the pixel reference values ​​in the matching template.

74. The method of claim 73, wherein: The method further comprises: The coefficients of the target filter are coefficients used by the target filter when a first error between an output value of a pixel reference value in the matching template after being processed by the target filter and a pixel reference value in the first template satisfies a first condition.

75. The method of claim 74, wherein: The method further comprises: The first condition is that the first error is minimum.

76. The method of claim 74, wherein: The method further comprises: The first condition is that the first error is within a first preset threshold range.

77. The method of claim 74, wherein: The method further comprises: The first condition is that the change in the first error is within a second preset threshold range.

78. The method of claim 73, wherein: The step of determining the coefficient of the target filter according to the pixel reference value in the first template and the pixel reference value in the matching template comprises: Determining an autocorrelation parameter according to a pixel reference value in the matching template; Determining a cross-correlation parameter according to a pixel reference value in the first template and a pixel reference value in the matching template; The coefficients of the target filter are determined according to the autocorrelation parameters and the cross-correlation parameters.

79. The method of claim 73, wherein: The pixel reference value includes at least one of the following: a pixel reconstruction value, a pixel gradient value, and pixel position information.

80. The method of claim 72, wherein: The number of coefficients of the target filter is equal to a first preset value.

81. The method of claim 72, wherein: The method further comprises: Determining the number of coefficients of the target filter; The number of coefficients of the target filter is encoded, and the obtained encoded bits are written into a bit stream.

82. The method of claim 72, wherein: The target filter is a one-dimensional or two-dimensional filter of a preset shape.

83. The method of claim 72, wherein: The method further comprises: Determining the shape of the target filter; The shape of the target filter is encoded, and the obtained encoded bits are written into a bitstream.

84. The method of claim 72, wherein: The filtering the reference block according to the model parameters to determine the filtered reference block includes: Performing filtering processing on the reference block according to the model parameters to determine a first output value of the target filter; The filtered reference block is determined based on a first output value of the target filter.

85. The method of claim 84, wherein: The filtering process is performed on the reference block according to the model parameters to determine the first output value of the target filter, comprising: Calculating the product of the pixel reconstruction value of the reference block and the corresponding coefficient of the target filter; The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

86. The method of claim 84, wherein: The filtering process is performed on the reference block according to the model parameters to determine the first output value of the target filter, comprising: Determine a first value of a pixel reconstruction value of the reference block under a first mapping relationship; Calculate the product of the first value and the corresponding coefficient of the target filter; The first output value of the target filter is set to be equal to the sum of n products; wherein n represents the number of coefficients of the target filter, and n is a positive integer.

87. The method of claim 84, wherein: The step of determining the filtered reference block based on the first output value of the target filter comprises: determining a first offset value; An addition operation is performed according to the first output value and the first offset value to determine the filtered reference block.

88. The method of claim 87, wherein: The determining of the first offset value comprises: The first offset value is set equal to a second preset value.

89. The method of claim 87, wherein: The determining of the first offset value comprises: If the number of coefficients of the target filter is n, determining the n+1th coefficient of the target filter; The first offset value is determined according to the n+1th coefficient and the second offset value.

90. The method of claim 89, wherein: The method further comprises: setting the second offset value to be equal to a third preset value; or, The second offset value is set to be equal to the value of the pixel reconstruction value of the reference block under the second mapping relationship.

91. The method of claim 51, wherein: The step of determining the prediction value of the current block according to the filtered reference block comprises: The filtered reference block is subjected to a second process to obtain a prediction value of the current block.

92. The method of claim 91, wherein: The method further comprises: The second process is to set the prediction value of the current block equal to the filtered reference block.

93. The method of claim 91, wherein: The method further comprises: The second processing is a clamping operation that limits the filtered reference block to a preset value range.

94. The method of claim 51, wherein: The method further comprises: Determining multiple groups of model parameters according to the first template and the matching template; Constructing a plurality of filter models according to the plurality of groups of model parameters, filtering the reference blocks respectively according to the plurality of filter models, and determining a plurality of filtered reference blocks; A prediction value of the current block is determined according to the multiple filtered reference blocks.

95. The method of claim 94, wherein: The step of determining the prediction value of the current block according to the plurality of filtered reference blocks comprises: A weighted calculation is performed on the multiple filtered reference blocks to determine a prediction value of the current block.

96. The method of claim 94, wherein: The method further comprises: determining a target filter from a plurality of filter models; The reference block is filtered according to the target filter to determine a prediction value of the current block.

97. The method of claim 96, wherein: The method further comprises: Determine a target model index value, wherein the target model index value is used to indicate an index number of the target filter in the plurality of filter models; The target model index value is encoded, and the obtained encoded bits are written into a bitstream.

98. The method of claim 96, wherein: The determining of a target filter from a plurality of filter models comprises: Determining an original value of the current block; Performing rate-distortion cost calculations respectively according to the original value of the current block and a plurality of initial prediction values ​​of the current block, and determining rate-distortion cost values ​​of each of the plurality of initial prediction values; determining a minimum rate-distortion cost value from the rate-distortion cost values ​​of the respective multiple initial prediction values; The filter model corresponding to the minimum rate-distortion cost value is used as the target filter.

99. The method of claim 94, wherein: The step of determining multiple groups of model parameters according to the first template and the matching template includes: Classifying the reconstructed pixels in the first template and the matching template respectively according to a preset method to obtain multiple groups of sub-templates and multiple groups of sub-matching templates; The multiple groups of model parameters are determined according to the multiple groups of sub-templates and the multiple groups of sub-matching templates.

100. The method of claim 51, wherein: The method further comprises: Determine a value of first syntax element identification information, wherein the first syntax element identification information is used to indicate whether intra-frame template matching is applied to the current block; The value of the first syntax element identification information is encoded, and the obtained encoded bits are written into a bitstream.

101. The method according to claim 100, wherein: The determining a value of the first syntax element identification information includes: If intra template matching is applied to the current block, determining that the value of the first syntax element identification information is a first value; If intra template matching is not applied to the current block, it is determined that the value of the first syntax element identification information is a second value.

102. The method of claim 100, wherein: When the first syntax element identification information is used to indicate that intra template matching is applied to the current block, the method further includes: Determine a value of second syntax element identification information, wherein the second syntax element identification information is used to indicate whether a filter model is applied to the current block; The value of the second syntax element identification information is encoded, and the obtained encoded bits are written into a bitstream.

103. The method of claim 102, wherein: The determining a value of the second syntax element identification information includes: If the current block applies a filter model, determining that the value of the second syntax element identification information is a first value; If the filter model is not applied to the current block, it is determined that the value of the second syntax element identification information is a second value.

104. The method of claim 102, wherein: The method further comprises: If the current block applies a filter model, the steps of filtering the reference block according to the model parameters to determine a filtered reference block; and determining a prediction value of the current block according to the filtered reference block; If the filter model is not applied to the current block, the reconstructed pixel value in the reference block is used as the prediction value of the current block.

105. The method according to any one of claims 51 to 104, wherein: The step of determining the prediction difference value of the current block according to the prediction value of the current block includes: Determining an original value of the current block; A prediction difference value of the current block is determined according to the original value of the current block and the prediction value of the current block.

106. A code stream, wherein: The code stream is generated by bit encoding according to the information to be encoded; wherein the information to be encoded includes at least one of the following: The prediction difference value of the current block, the number of coefficients of the target filter, the shape of the target filter, the value of the first syntax element identification information, and the value of the second syntax element identification information; wherein the first syntax element identification information is used to indicate whether the current block applies intra-frame template matching, and the second syntax element identification information is used to indicate whether the current block applies a filter model.

107. An encoder, comprising a first determining unit, a first filtering unit and a first predicting unit; wherein: The first determination unit is configured to determine a first template of the current block, and to determine a reference template and a reference block; and is further configured to perform a first process on an adjacent area of ​​the reference template when the reference template meets a first preset condition, determine a matching template, and determine a model parameter based on the first template and the matching template; The first filtering unit is configured to perform filtering processing on the reference block according to the model parameters to determine a filtered reference block; The first prediction unit is configured to determine a prediction value of the current block according to the filtered reference block; The first determining unit is further configured to determine a prediction difference value of the current block according to the prediction value of the current block.

108. An encoder comprising a first memory and a first processor; wherein: The first memory is used to store a computer program that can be run on the first processor; The first processor is configured to execute the method as claimed in any one of claims 51 to 105 when running the computer program.

109. A decoder comprising a second determination unit, a second filtering unit and a second prediction unit; wherein: The second determination unit is configured to determine a first template of the current block, and to determine a reference template and a reference block; and is further configured to perform a first process on an adjacent area of ​​the reference template when the reference template meets a first preset condition, determine a matching template, and determine a model parameter based on the first template and the matching template; The second filtering unit is configured to filter the reference block according to the model parameters to determine a filtered reference block; The second prediction unit is configured to determine a prediction value of the current block according to the filtered reference block; The second determining unit is further configured to determine a reconstructed value of the current block according to the predicted value of the current block.

110. A decoder comprising a second memory and a second processor; wherein: The second memory is used to store a computer program that can be run on the second processor; The second processor is configured to execute the method according to any one of claims 1 to 50 when running the computer program.

111. A computer-readable storage medium, wherein: The computer-readable storage medium stores a computer program, and when the computer program is executed, it implements the method according to any one of claims 1 to 50, or implements the method according to any one of claims 51 to 105.