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

MYPI2025004337A0Undetermined Publication Date: 2024-07-20GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
MYPI2025004337
Authority / Receiving Office
MY · MY
Patent Type
Applications
Current Assignee / Owner
Filing Date
2023-01-20
Publication Date
2024-07-20

AI Technical Summary

Technical Problem

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

Method used

By determining the first template and the matching template of the current block, the model parameters are calculated, the reference block is filtered, and the prediction value is corrected to improve the prediction accuracy.

Benefits of technology

It improves frame prediction accuracy, saves bit rate, and improves encoding and decoding performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure PI2025004337_DRAWING_001
    Figure PI2025004337_DRAWING_001
  • Figure PI2025004337_DRAWING_002
    Figure PI2025004337_DRAWING_002
  • Figure PI2025004337_DRAWING_003
    Figure PI2025004337_DRAWING_003
Patent Text Reader

Abstract

The embodiments of the present disclosure disclose an encoding method and a decoding method, a bitstream, an encoder, a decoder and a storage medium, the method includes: determining a first template of a current block, and determining a matching template and a reference block; determining a model parameter according to the first template and the matching template; filtering the reference block according to the model parameter, to determine a filtered reference block; determining a prediction value of the current block according to the filtered reference block; and determining a reconstructed value of the current block according to the prediction value of the current block. In this way, not only prediction accuracy may be improved and bit rate may be saved, but also performance of encoding and decoding may be improved. Figure 6
Need to check novelty before this filing date? Find Prior Art

Description

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

[0001] 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

[0002] Template Matching (TM) prediction technology searches for a matching template with the minimum cost within a predefined search range using the template of the coding block according to a preset cost function, and uses the best matching reconstructed block corresponding to the matching template as the prediction block of the current coding block.

[0003] 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.

[0004] Summary of the Invention

[0005] 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 the coding and decoding performance.

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

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

[0008] Determining a first template of the current block, and determining a matching template and a reference block;

[0009] determining model parameters according to the first template and the matching template;

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

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

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

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

[0014] Determining a first template of the current block, and determining a matching template and a reference block;

[0015] determining model parameters according to the first template and the matching template;

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

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

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

[0019] 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:

[0020] 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, the value of the second syntax element identification information, and the value of the third syntax element identification information; wherein the first syntax element identification information is used to indicate whether intra template matching is applied to the current block, the second syntax element identification information is used to indicate whether a filter model is applied to the current block, and the third syntax element identification information is used to indicate a reference block for the current block.

[0021] 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:

[0022] A first determining unit is configured to determine a first template of the current block, and determine a matching template and a reference block; and further configured to determine a model parameter based on the first template and the matching template;

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

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

[0025] 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.

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

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

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

[0029] 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:

[0030] A second determining unit is configured to determine a first template of the current block, and determine a matching template and a reference block; and further configured to determine a model parameter based on the first template and the matching template;

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

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

[0033] 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.

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

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

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

[0037] 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.

[0038] The embodiments of the present application provide a coding and decoding method, a code stream, an encoder, a decoder, and a storage medium. Whether it is the encoding end or the decoding end, the first template of the current block is determined, as well as the matching template and the reference block; the model parameters are determined based on the first template and the matching template; the reference block is filtered according to the model parameters to determine the filtered reference block; and 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 at 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 used as the predicted pixels of the current block, thereby improving the prediction accuracy, saving the bit rate, and improving the coding and decoding efficiency, thereby improving the coding and decoding performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] FIG1A is a schematic diagram of the prediction process of an inter-frame TM technique.

[0040] FIG1B is a schematic diagram of a prediction process of an intra-frame TM technique;

[0041] FIG1C is a schematic diagram of the prediction process of another intra-frame TM technique;

[0042] FIG2 is a schematic diagram of a prediction process based on TM technology;

[0043] FIG3 is a schematic diagram of a template type of TM 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] FIG8A is a schematic diagram of a prediction process based on TM-FLM technology provided in an embodiment of the present application;

[0050] FIG8B is a schematic diagram showing the locations of spatially adjacent coding unit sources according to an embodiment of the present application;

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

[0052] FIG10 is a schematic diagram of parameter definition of a current block and its template provided in 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 a border filling area provided in an embodiment of the present application;

[0059] FIG16B is a schematic diagram of another border filling area provided in an embodiment of the present application;

[0060] FIG17 is a schematic diagram of a border filling area of ​​another template type provided in an embodiment of the present application;

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

[0062] FIG18B is a schematic diagram of the composition of a predicted pixel provided by an embodiment of the present application;

[0063] FIG19A is a first schematic diagram of a process for determining a specific search area according to an embodiment of the present application;

[0064] FIG19B is a second schematic diagram of a process for determining a specific search area provided in an embodiment of the present application;

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

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

[0067] FIG19E is a fifth schematic diagram of a process for determining a specific search area provided in an embodiment of the present application;

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

[0069] FIG19G is a seventh schematic diagram of a specific search area determination process according to an embodiment of the present application;

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

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

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

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

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

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

[0076] 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

[0077] 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.

[0078] 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.

[0079] 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.

[0080] 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:

[0081] Coding Block (CB);

[0082] Block Matching (BM);

[0083] Coding Unit (CU);

[0084] Block Vector (BV);

[0085] Motion Vector (MV);

[0086] Sum of Absolute Difference (SAD);

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

[0088] Mean Square Error (MSE);

[0089] Sum of Squared Differences (SSD);

[0090] Mean Absolute Deviation (MAD);

[0091] Mean Square Differences (MSD);

[0092] Normalized Correlation Coefficient (NCC);

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

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

[0095] Template Matching (TM);

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

[0097] Intra block copy (IBC);

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

[0099] 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.

[0100] Template Matching (TM) prediction technology is a motion vector (MV) or block vector (BV) refinement technique. 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 range near the initial MV / BV according to a preset cost function. The offset of the best matching template relative to the current coding block template is the best motion vector (MV_BEST) in inter-frame and the best block vector (BV_BEST) in intra-frame. The reconstructed block (Ref Block) pointed to by the best motion vector / block vector is then used as the prediction block for the current coding block (Cur Block). In other words, the reference block pointed to by the MV and the current coding block are in different frames, while the reference block pointed to by the BV and the current coding block are in the same frame.

[0101] MV is an inter-frame prediction coding technology, and IBC is an intra-frame prediction coding technology, but their TM-based vector refinement technology details are very similar.

[0102] It can also be understood that Intra TMP is a special intra-frame prediction mode. Both the encoder and the decoder use the template (T) of the coding block to search for the matching template (T_BEST) with the minimum cost according to the preset cost function within the predefined search range in the current image. The offset of the best matching template relative to the current coding block template is the best block vector (BEST Block Vector, BV_BEST), and then the reconstructed block (Ref Block) corresponding to the matching template is used as the prediction block of 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. IntraTMP is very similar to IBC, the difference is that the initial BV of IntraTMP can be regarded as 0, and the TM-based BV acquisition is its only source of BV.

[0103] For example, taking the adjacent reconstructed area of ​​the current block as an example, when the reference block and the current coding block are in different frames, the positions of the reference block and the matching block are shown in Figure 1A. The dark-filled area in the reference image represents the reconstructed area, the dotted box is the search area, the grid-filled block in the current image is the current block, and the adjacent area of ​​the current block is the first template (T). Based on the MV, the reference block is determined in the search area of ​​the reference image. The adjacent area of ​​the reference block is the second template (i.e., the "reference template" or "matching template", T_BEST). At this time, the reference block can be block-copied as the prediction block of the current block. The TM-based MV refinement search range: part or all of the reconstructed area within the reference image.

[0104] When the reference block and the current coding block are in the same frame, as shown in Figure 1B and Figure 1C, 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. As shown in Figure 1B, the TM-based BV refinement search range in IBC includes: search areas within multiple coded and reconstructed CTBs to the left and above. As shown in Figure 1C, the TM-based BV search range in IntraTMP includes: the reconstructed areas to the left and above the current block within a search window of a certain size

[0105] 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.

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

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

[0108] The following is a detailed introduction to the prediction process in template matching technology.

[0109] TM input: the position of the current block (xTbCmp, yTbCmp), the width of the current block nTbW, the height of the current block nTbH; the reconstructed pixel position and sampling point information of the reference area.

[0110] Output of TM: predicted value predSamples[x][y] of the current block, where x = 0..nTbW-1, y = 0..nTbH–1.

[0111] Specifically, the prediction process of TM technology can be divided into four steps:

[0112] The prediction process of TM's vector search technology consists of five steps: determining the initial MV / BV, determining the current template type, obtaining the reconstructed pixels of the current template, refining the MV / BV within a predefined search range near the initial vector, and generating the predicted value. This process yields the predicted value for the current prediction block. It's important to note that TM can be used to predict both luma and chroma components, and this is not specifically limited here.

[0113] See Figure 2, which shows a schematic diagram of a prediction process based on TM technology. As shown in Figure 2, the process may include:

[0114] S201: Determine initial MV / BV;

[0115] It should be noted that in MV technology, the initial MV can be the MV of inter-frame Merge or inter-frame AMVP, in IBC technology, the initial BV can be the BV in the candidate list of IBC Merge or IBC AMVP, and in IntraTMP technology, the initial BV can be regarded as 0 or non-existent.

[0116] S202: Determine the current template type.

[0117] It should be noted that the TM 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.

[0118] 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 TM 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.

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

[0120] 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;

[0121] 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;

[0122] 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;

[0123] 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;

[0124] 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;

[0125] 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.

[0126] S203: Obtain current template pixels.

[0127] It should be noted that the TM 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, transmitted via the bitstream, or adaptively selected based on information such as block size. 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.

[0128] 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.

[0129] S204: Refine the MV / BV within a predefined search range near the initial MV / BV to determine the optimal MV / BV.

[0130] It should be noted that the TM MV / BV refinement process primarily consists of initialization, determining the template search area, and searching and determining the optimal vector within the search area. Furthermore, the search for the optimal matching template within the search area can employ a coarse search followed by a fine search, or can employ only a fine search, or only a coarse search, without specific limitations here.

[0131] 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.

[0132] 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.

[0133] 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).

[0134] In this way, after completing the above operations, the optimal vector parameters MV_BEST / 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.

[0135] S205: Generate a predicted value.

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

[0137] For x = 0 ... nTbW-1, y = 0 ... nTbH-1;

[0138] predSamples[x][y]=recSamples[x+pX_BEST][y+pY_BEST] (2)

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

[0140] In simple terms, in related technologies, TM technology 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 adjacent reconstructed area of ​​the current block.

[0141] 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.

[0142] 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.

[0143] 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.

[0144] 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 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.

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

[0146] 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 .

[0147] 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.

[0148] 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.

[0149] It should be noted that the method of the embodiment of the present application is mainly applied to the intra-frame prediction unit 103 and the inter-frame prediction unit as shown in Figure 4A, and the intra-frame prediction unit 203 and the motion compensation unit 204 as shown in Figure 4B. In other words, the embodiment of the present application can be applied to both the encoder and the decoder, and can even be applied to both the encoder and the decoder simultaneously, but the embodiment of the present application is not specifically limited thereto.

[0150] It should also be noted that when applied to the encoding end, the "current block" specifically refers to the encoding block currently to be intra-frame predicted; when applied to the decoding end, the "current block" specifically refers to the decoding block currently to be intra-frame predicted.

[0151] 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:

[0152] S601: Determine a first template of a current block, and determine a matching template and a reference block.

[0153] It should be noted that the decoding method of the embodiment of the present application is applied to a decoder. The decoding method can be referred to as a template matching (TM-FLM) prediction method based on a linear filter model. In some embodiments, 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), or an intra-frame prediction method based on an intra-frame block copy (Intra Block Copy on Filter-based Linear Model, IBC-FLM) based on a linear filter model. 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-predicted, and the reference block is a reconstructed block in the current frame. In addition, the decoding method of the embodiment of the present application can be used to predict both luminance components and chrominance components, which is not specifically limited here.

[0154] In some embodiments, the decoding method may also be an inter-frame prediction method, more specifically, an inter-frame prediction method based on template matching of a linear filter model. The video image may be divided into 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 inter-frame predicted, and the reference block is a reconstructed block within a reference frame.

[0155] 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 a matching template can be determined based on the first template. In some embodiments, determining the first template of the current block may include: determining the template type of the current block; and determining the first template of the current block based on the template type of the current block. In some embodiments, determining the first template of the current block may include: decoding the code stream to determine the first template of the current block.

[0156] The template type can be represented by refTemplateType. In some embodiments, determining the template type of the current block can include one of the following: determining the template type of the current block based on reference pixels of the current block; or determining the template type of the current block by decoding the code stream; or determining the template type of the current block based on the size of the current block.

[0157] 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.

[0158] 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.

[0159] 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:

[0160] 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;

[0161] 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;

[0162] 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;

[0163] 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;

[0164] 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;

[0165] 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.

[0166] 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 .

[0167] 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.

[0168] 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.

[0169] 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.

[0170] 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.

[0171] For the matching template and the reference block, in a possible implementation, determining the matching template and the reference block may include: decoding the code stream to determine vector parameters; determining the reference block based on the vector parameters; and determining the matching template based on the first template and the reference block.

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

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

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

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

[0176] It should be noted that the vector parameters can be a motion vector including horizontal and vertical components. In MV technology, the initial MV can be the MV of inter-frame Merge or inter-frame AMVP. In IBC technology, the initial BV can be a BV in the candidate list of IBC Merge or IBC AMVP. In IntraTMP technology, the initial BV can be considered to be 0 or non-existent.

[0177] In one possible implementation, determining an initial vector parameter for a current block includes: determining, based on a prediction mode parameter for the current block, a vector parameter candidate list for constructing the current block; and determining the initial vector parameter based on the vector parameter candidate list. The prediction mode parameter is used to indicate parameters related to the prediction mode of the current block. In one possible implementation, determining the initial vector parameter based on the vector parameter candidate list includes: obtaining a vector parameter at a preset position (e.g., the first vector parameter) from the vector parameter candidate list as the initial vector parameter; or obtaining a vector parameter at a preset position from the vector parameter candidate list, decoding a bitstream to determine a vector parameter prediction difference, and determining the initial vector parameter based on the vector parameter at the preset position and the vector parameter prediction difference.

[0178] In one possible implementation, determining to construct a vector parameter candidate list for the current block based on the prediction mode parameters of the current block includes: determining to construct a merge vector parameter candidate list for the current block based on the prediction mode parameters of the current block; or determining to construct an AMVP vector parameter candidate list for the current block based on the prediction mode parameters of the current block.

[0179] In one possible implementation, an initial vector parameter for the current block is determined to be a preset vector parameter based on a prediction mode parameter of the current block. In some embodiments, the Intra TMP initial block vector parameter is 0. In another embodiment, the Intra TMP initial block vector parameter is a vector parameter obtained by a coarse search of the search area, and correspondingly, the target vector parameter is a vector parameter obtained by a fine search of the search area.

[0180] In one possible implementation, determining a search area based on the initial vector parameters includes determining the search area based on the initial vector parameters and a preset search range. Exemplarily, determining a reference block based on the initial vector parameters and the current block; and determining the search area based on the reference block and the preset search range. The search area includes reconstructed pixels.

[0181] It should be noted that the search range may be pre-set, or may be transmitted through a code stream, or may be adaptively selected based on information such as block size.

[0182] In one possible implementation, the method for determining the search range includes at least one of the following: using a preset horizontal component search range as the horizontal component search range of the preset search range; using a preset vertical component search range as the vertical component search range of the preset search range; decoding the code stream to determine the horizontal component search range and / or vertical component search range of the preset search range; determining the horizontal component search range and / or vertical component search range of the preset search range based on the size of the current block.

[0183] In one possible implementation, determining a search area based on initial vector parameters includes: determining an inter-frame prediction mode based on prediction mode parameters of the current block, and determining a search area based on the initial vector parameters in a reference image; determining an intra-frame prediction mode based on prediction mode parameters of the current block, and determining a search area based on the initial vector parameters in the current image.

[0184] In one possible implementation, the intra-frame prediction mode is determined according to the prediction mode parameters of the current block, and the search area includes at least one of the following: a partial area of ​​the reconstructed coding tree block of the current image, the entire area of ​​the reconstructed coding tree block of the current image, the entire reconstructed area of ​​the current coding tree block, and a reconstructed partial area of ​​the current coding tree block where the current block is located.

[0185] In one possible implementation, searching within a search area based on template matching to determine target vector parameters includes: searching within the search area to determine a reference template, calculating a matching cost between the reference template and a first template, and determining the vector parameter of the reference template corresponding to the minimum matching cost as the target vector parameter. Exemplarily, searching within the search area to determine an available reference template.

[0186] In a possible implementation, a condition for determining the availability of a reference template includes at least one of the following: a first sampling point in the template does not exceed a boundary of an image in which it is located; a second sampling point in a reference block corresponding to the template does not exceed a boundary of an image in which it is located; the first sampling point in the template does not exceed a search area; the second sampling point in the reference block corresponding to the template does not exceed a search area; all first sampling points in the template have been reconstructed; and all second sampling points in the reference block corresponding to the template have been reconstructed.

[0187] In one possible implementation, the reference template availability determination condition includes at least one of the following: a first sampling point within the template and the current block are within the same sub-image; a second sampling point within the reference block corresponding to the template and the current block are within the same sub-image; or the second sampling point within the reference block corresponding to the template is not within the current block. Exemplarily, a sub-image may include multiple coding tree units. Exemplarily, a sub-image may be a tile.

[0188] In a possible implementation, the first sampling points are sampling points in the template, or first identification sampling points are preset. The first identification sampling points include sampling points at at least one corner position in the template.

[0189] In one possible implementation, the second sampling points are sampling points within a reference block corresponding to the template, or preset second identification sampling points. The second identification sampling points include sampling points at at least one corner position within the reference block corresponding to the template. Specifically, whether the sampling point is located within the preset image can be determined by determining whether its coordinates are within a valid coordinate range of the preset image area.

[0190] It should be noted that the sampling points can be individual sampling points within the template or the reconstructed block corresponding to the template, or sampling points at preset specific locations. In some embodiments, the identified sampling points within the template refer to one or more sampling points located at the corners of the template area. For example, when only the upper template is present, the upper left and lower right sampling points of the upper template area; or only the lower right sampling point. The identified sampling points within the reconstructed block corresponding to the template refer to one or more sampling points located at the corners of the reconstructed block area. For example, the upper left and lower right sampling points of the reconstructed block area; or only the lower right sampling point of the reconstructed block area.

[0191] That is to say, a search can be performed in a preset search area based on the first template, and a matching template with the minimum cost can be searched according to a preset cost function. Among them, by traversing all search points in the preset search area, one or more candidate vector parameters can be obtained, and these one or more candidate vector parameters can indicate one or more candidate matching templates; the cost is calculated with the first template of the current block respectively, and the search point with the minimum cost is obtained by comparison, and its corresponding candidate vector parameter is the best vector parameter (i.e., the target vector parameter, BV_BEST); its corresponding candidate matching template is the best matching template (i.e., the matching template of this embodiment, T_BEST); and the reference block can be determined based on the best matching template. In the embodiment of the present application, the target vector parameter can be understood as the best vector parameter or the matching vector parameter. Exemplarily, the vector parameter for the inter-frame prediction mode can be MV, and the vector parameter for the intra-frame prediction mode can be BV.

[0192] 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.

[0193] 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:

[0194] In one possible implementation, searching within a search area based on template matching to determine target vector parameters may include: performing a first search within the search area to determine the target vector parameters; or performing a second search within the search area to determine the target vector parameters; wherein a search step size corresponding to the first search is greater than a search step size corresponding to the second search.

[0195] In another possible implementation, a search is performed within a search area based on template matching to determine target vector parameters, including: performing a first search within the search area to determine the first vector parameters and determining an initial matching template based on the first vector parameters; 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 vector parameters; wherein a search step size corresponding to the first search is larger than a search step size corresponding to the second search, and the first search area is smaller than a preset search area.

[0196] 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.

[0197] 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 matching template) can be determined within the vicinity of the best coarse matching template with a step size of 1.

[0198] In another possible implementation, the preset search area may include at least one sub-search area; the search area includes at least one sub-search area; searching within the search area based on template matching to determine the target vector parameter includes: searching within the at least one sub-search area separately to determine the optimal vector parameter and the corresponding matching cost value of each sub-search area; determining the optimal vector parameter corresponding to the minimum matching cost value based on the optimal vector parameter and the corresponding matching cost value of each sub-search area; and using the optimal vector parameter corresponding to the minimum matching cost value as the target vector parameter.

[0199] In one possible implementation, searching within a search area based on template matching to determine a target vector parameter includes: searching within the search area based on template matching to determine a first vector parameter; decoding a code stream to determine a vector parameter prediction difference; and determining a target vector parameter based on the first vector parameter and the vector parameter prediction difference.

[0200] In one possible implementation, searching within a search area based on template matching to determine a target vector parameter includes: performing a first search within at least one sub-search area to determine the optimal vector parameter of each sub-search area and the corresponding second search area; performing area judgment based on the optimal vector parameter 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; performing a second search within at least two target sub-search areas to determine the optimal vector parameters corresponding to the at least two target sub-search areas; and using the optimal vector parameters corresponding to the at least two target sub-search areas as the target vector parameters.

[0201] It should be noted that in some embodiments, the search area for the BV can be the reconstructed portion of the CTB containing the current block, 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 a specific implementation, multiple rectangular regions can be searched, and the search results from different regions can be combined to obtain the final optimal reference block and optimal block vector.

[0202] In some embodiments, the search process of the IBC technology may directly determine the availability of the search points in the search area and then perform a matching cost judgment, and determine the vector parameters of the reference template corresponding to the minimum matching cost value as the target vector parameters.

[0203] In some embodiments, the MV search process also searches for valid search points within the search area, and the valid search positions within the search area will not be judged as reconstructed, because all pixels in the reference image have been reconstructed.

[0204] 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.

[0205] 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 are the matching template. This allows the matching cost between the first template of the current block and the matching template to be calculated, denoted as pDiff.

[0206] 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 of this embodiment; its corresponding best matching template T_BEST is the final required matching template.

[0207] In a possible implementation, determining the reference block includes: determining the reference block according to a target vector parameter. Exemplarily, determining the reference block according to the current block and the target vector parameter.

[0208] In yet another possible implementation, the method further includes: decoding the code stream, and determining a value of first syntax element identification information; wherein the first syntax element identification information is used to indicate whether template matching is applied to the current block.

[0209] In yet another possible implementation, the method further includes: decoding the code stream, determining a value of third syntax element identification information; and determining a reference block of the current block according to the value of the third syntax element identification information.

[0210] In another possible implementation, the method further includes: the first syntax element identification information is used to indicate that template matching is applied to the current block, decoding the code stream, and determining the value of the third syntax element identification information; and determining the reference block of the current block according to the value of the third syntax element identification information.

[0211] It should be noted that the encoder transmits a flag indicating which filtered reference block is used as the final prediction block. tmpFlag indicates whether template matching is applied to the current coding block, and filterIdx indicates which reference block within the current search range is applied to the filter model. When tmpFlag is 1, the encoder compares the distortion (SAD, MSE, SATD, or SSE) between the reference blocks with applied filter coefficients within the search range and the current original block, selects the optimal reference block, and transmits the corresponding index to the decoder.

[0212] In another possible implementation, the method further includes: searching the search area for multiple reference templates, determining model parameters based on the first template and the reference template; filtering the reference template based on the model parameters to obtain a filtered reference template; calculating a matching cost between the filtered reference template and the first template; and determining a reference block of the reference template corresponding to a minimum matching cost as a reference block of the current block. The reference block of the reference template can be understood as a reconstructed block of the reference template.

[0213] It should be noted that the filter coefficients are solved and filtered for the templates within the search range, and the Cost is calculated with the current template to decide which template to use, that is, the filter coefficients are calculated for part or all of the templates to be searched in the search range, and then the filter coefficients are applied to the template to be searched, and the Cost thereof and the current template are calculated. The best matching template after filtering is selected according to the Cost, and the reference block corresponding to the best matching template is filtered and used as the final prediction value.

[0214] S602: Determine model parameters according to the first template and the matching template.

[0215] 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.

[0216] 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.

[0217] 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.

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

[0219] 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:

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

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

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

[0223] 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.

[0224] 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.

[0225] 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, namely:

[0226] 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)

[0227] 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:

[0228] Among them, Npos 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.

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

[0230] First, for c k,l Find the partial derivative and make it 0, that is:

[0231] E[2(∑ k,l=-1~1 c k,l ·refTemp[i+k][j+l]-recTemp[i][j])·refTemp[i+m][j+n]]=0 (6)

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

[0233] Secondly, according to formula (5) and formula (6), we can get:

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

[0235] 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

[0236] 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:

[0237] 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.

[0238] 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.

[0239] 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.

[0240] 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.

[0241] 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.

[0242] 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.

[0243] 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.

[0244] 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.

[0245] 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.

[0246] 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.

[0247] 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.

[0248] 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.

[0249] 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.

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

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

[0252] 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.

[0253] 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.

[0254] 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.

[0255] In one possible implementation, determining model parameters based on the first template and the matching template may include: calculating the product of the pixel reconstruction value of the reference block and the coefficient of the corresponding target filter; setting 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; and determining the filtered reference block based on the first output value of the target filter.

[0256] In one possible implementation, determining model parameters based on the first template and the matching template may also include: calculating the product of the pixel reference value of the second boundary filling area corresponding to the reference block and the coefficient of the corresponding target filter; and / or calculating the product of the pixel reference value of the reference template corresponding to the reference block and the coefficient of the corresponding target filter. Filling boundary pixels requires filling boundary pixels, considering that the filter may use reconstructed pixels outside the reference template and reference block. Depending on the filter shape, the area of ​​the boundary that needs to be filled varies. The filled boundary pixels can be used to determine model parameters and / or predict the current block.

[0257] 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:

[0258] Y pred [i][j]=∑ k ∑ l ref[i+k][j+l]×C k,l (11)

[0259] 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.

[0260] 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:

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

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

[0263] 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.

[0264] 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 coefficient, the calculation formula is adjusted as follows:

[0265] 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)

[0266] Then the first output value of the target filter can be calculated by the following formula:

[0267] Y pred [i][j]=∑ k ∑ l (ref[i+k][j+l]) 2 ×C k,l (13)

[0268] 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.

[0269] 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.

[0270] 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.

[0271] 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.

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

[0273] 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.

[0274] 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.

[0275] 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:

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

[0277] 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 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.

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

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

[0280] Here, for the clip operation, the preset numerical range here 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:

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

[0282] 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];

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

[0284] 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.

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

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

[0287] 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;

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

[0289] 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 according to a preset method 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.

[0290] It should be noted that in the embodiments of the present application, the preset method 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 according to the preset method, 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.

[0291] 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.

[0292] 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.

[0293] 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.

[0294] 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.

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

[0296] 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.

[0297] 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.

[0298] It should also be noted that, in 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: decoding the code stream and determining the value of first syntax element identification information; the first syntax element identification information is used to indicate whether template matching is applied to the current block. It should be noted that, in some embodiments, whether template matching is applied can be understood as whether a search area search is performed based on template matching to determine the optimal vector parameters, that is, the first syntax element identification information is used to indicate whether a search area search is performed based on template matching to determine the optimal vector parameters for the current block.

[0299] In a specific embodiment, the method further includes: decoding the bitstream to determine the 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, filtering the reference block according to the model parameters to determine a filtered reference block; and determining a prediction value of the current block based on the filtered reference block.

[0300] 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.

[0301] In a specific embodiment, the method further includes: the first syntax element identification information is used to indicate whether template matching is applied to the current block, decoding the code stream, and determining the value of the second syntax element identification information.

[0302] 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.

[0303] 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.

[0304] 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.

[0305] 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.

[0306] 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:

[0307] 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;

[0308] 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.

[0309] Method three: The encoding end 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 encoding end 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, MSE, 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.

[0310] It should be noted that in addition to calculating the filter coefficients for the best matching template after the search, and applying the filter coefficients to the best matching reference block, it is also possible to apply the filter coefficients to all or part of the reference blocks in the search area, and determine which filtered reference block to use as the final prediction block based on certain conditions. For example, there are the following methods:

[0311] Method 1: Calculate the filter coefficients for the templates within the search range and filter them, and then calculate the cost with the current template to decide which template to use. That is, calculate the filter coefficients for part or all of the templates to be searched in the search range, then apply the filter coefficients to the template to be searched, calculate the cost of the template and the current template, and select the best matching template after filtering based on the cost. Filter the reference block corresponding to the best matching template and use it as the final prediction value.

[0312] Method 2: The encoder transmits a flag indicating which filtered reference block is used as the final prediction block. tmpFlag indicates whether template matching is applied to the current coding block, and filterIdx indicates which reference block within the current search range is applied to the filter model. When tmpFlag is 1, the encoder compares the distortion (SAD, MSE, SATD, or SSE) between the reference blocks within the search range with the applied filter coefficients and the current original block, selects the optimal reference block, and transmits the corresponding index to the decoder.

[0313] 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 reconstruction 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.

[0314] In another embodiment of the present application, based on the decoding method of the aforementioned embodiment, in the prediction process of the template matching 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 called a template matching (TM-FLM) prediction method based on a linear filter model, which is used for intra-frame prediction and inter-frame prediction. The method can be 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), or an intra-frame prediction method based on an intra-frame block copy (Intra Block Copy on Filter-based Linear Model, IBC-FLM), or a template matching technology based on a linear filter model.

[0315] The following is a detailed introduction to the prediction process of TM-FLM technology.

[0316] The input of TM-FLM is: the position of the current block (xTbCmp, yTbCmp), the width of the current block nTbW, the height of the current block nTbH; the reconstructed pixel position and sampling point information of the reference area.

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

[0318] Specifically, the TM-FLM prediction process can be divided into six steps: determining the initial MV / BV, determining the current template type, obtaining the reconstructed pixels of the current template, refining the MV / BV within a predefined search range near the initial vector, establishing a linear filtering model, and generating predicted values, as shown in Figure 3. This process yields the predicted value for the current prediction block. TM can be used to predict both luma and chroma components, without specific limitations here.

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

[0320] S801: Determine initial MV / BV;

[0321] The initial MV may be the MV of inter-frame Merge or inter-frame AMVP, and the initial BV may be the BV in the candidate list of IBC Merge or IBC AMVP. In the IntraTMP technology, the initial BV may be regarded as 0 or non-existent.

[0322] It should be noted that the decoding end can determine whether to construct a Merge candidate list or an AMVP candidate list according to the prediction mode indicated by the prediction mode parameter.

[0323] The candidate list of MV inter-frame Merge and inter-frame AMVP is determined by spatially adjacent coding units (as shown in FIG8B ), temporally adjacent coding units, etc. For each MV in the candidate list, a template matching method can be used for a refined search.

[0324] The candidate lists of IBC intra-frame Merge and intra-frame AMVP of BV are constructed by spatially adjacent coding units (as shown in FIG8B ), historical information, etc. For each BV in the candidate list, a template matching method can also be used to perform a refined search.

[0325] This embodiment takes the first MV / BV in the Merge candidate list as the initial MV / BV as an example, and uses the first MV / BV in the Merge candidate list to initialize the horizontal initial MV mvXInit ( / BV bvXInit) and the vertical initial MV mvYInit ( / BV bvYInit).

[0326] S802: Determine the current template type.

[0327] It should be noted that the TM-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 and lower left reference pixel of the current block, etc. Therefore, the template type can be classified and the corresponding template type can be determined according to the availability of the adjacent reconstructed pixels.

[0328] 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.

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

[0330] 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;

[0331] 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;

[0332] 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;

[0333] 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;

[0334] 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;

[0335] 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.

[0336] S803: Obtain current template pixels.

[0337] It should be noted that the TM-FLM 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.

[0338] 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.

[0339] S804: Refine the MV / BV within a predefined search range near the initial MV / BV to determine a target MV / BV.

[0340] It should be noted that the TM-FLM search process is mainly divided into initialization, determining the template search area, and searching and determining the optimal block vector in the search area. The template search area is in the current image for intra prediction and in the reference image for inter prediction.

[0341] 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.

[0342] 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.

[0343] 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.

[0344] See Figure 9, which shows a schematic diagram of a search process based on TM technology provided in an embodiment of the present application. As shown in Figure 9, the process may include:

[0345] S901: Initialize parameters.

[0346] 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.

[0347] For example, Figure 10 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 10 , 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.

[0348] 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.

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

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

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

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

[0353] Furthermore, a preset search range of the template is initialized. The preset search range of the template can be set to a fixed size, or can be determined by the value of a syntax element in the bitstream, or can be dynamically adjusted according to the coding 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.

[0354] S902: Determine a search area for the template.

[0355] It should be noted that the search area of ​​TM is the adjacent area of ​​the reference block pointed to by the initial MV / BV, and the adjacent area is limited by the size of the search range.

[0356] In the inter-frame correlation technology, the reference block pointed to by the MV is a different image from the current coding block. At this time, the reference image has been completely reconstructed, and the search area can be any position in the reference image. The specific search area is determined by the initial MV. As shown in Figure 1A, the area on the left is the reconstructed reference image, the dotted box is the search area, and the grid area on the right is the current block. During the search process, it is necessary to judge the availability of the reference block. Since the reference image is a reconstructed image, if the search range does not exceed the image boundary, it means that all reference blocks in the search range are available. If the search range exceeds the image boundary, the reference blocks in the search range that exceed the image boundary are unavailable. In some implementations, when the reference block is available, the template corresponding to the reference block is also available. When the reference block is unavailable, the template corresponding to the reference block is also unavailable.

[0357] In IBC related technologies, the reference block pointed to by BV and the current coding block are in the same image. The search area can be the reconstructed part of the CTB where the current coding block is located, or it can be other reconstructed CTB areas. The specific search area is determined by the initial BV. During the search process, it is necessary to determine whether the pixels within the search range have been reconstructed. As shown in Figure 1B, the dark-filled background area is the reconstructed area of ​​the current image, the dotted box is the search area, and the grid area is the current block. During the search process, it is necessary to judge the availability of the reference block. In some embodiments, for each reference block within the search range, first determine whether the upper left corner pixel of the reference block has been reconstructed. If it is not available, it means that the reconstructed block is unavailable. Otherwise, further determine whether the lower right corner pixel of the reference block has been reconstructed. If it is not available, it means that the reconstructed block is unavailable. If the lower right corner pixel has also been reconstructed, it means that the reconstructed block is available.

[0358] The search area of ​​the Intra TMP technology is the reconstructed part of the current image and is limited by the size of the search range. As shown in Figure 11, the background area filled with dark color is the reconstructed area of ​​the current image, the background block filled with black is the current block, and the dotted box is the search range window. The reference block pointed to by BV and the current coding block are in the same image. When the initial BV is 0, the search area is a search window centered on the current block. The reconstructed sampling points in the search area may include the current CTB and multiple CTBs on the left, upper left, and upper sides, or all or part of the CTB area. Therefore, the search area of ​​the Intra TMP technology is no larger than the overlapping part of the reconstructed area represented by the dark background and the area marked by the dotted box.

[0359] 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.

[0360] 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.

[0361] 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.

[0362] 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[0384] 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.

[0385] 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.

[0386] S903: Search and determine the optimal vector parameters in the search area.

[0387] It should be noted that, taking the determination of the best MV as an example:

[0388] mvXMins and mvXMaxs represent the minimum offset and maximum offset of the motion vector in the horizontal direction respectively; mvYMins and vmYMaxs represent the minimum offset and maximum offset of the motion vector in the vertical direction respectively.

[0389] mvXMins, mvXMaxs, mvYMins, mvYMaxs can be determined by the initial MV / BV and the search range searchRangeWidth and searchRangeHeight:

[0390] mvXMins=(mvXInit–searchRangeWidth)< <iMvShift;

[0391] mvXMaxs=(mvXInit+searchRangeWidth)< <iMvShift;

[0392] mvYMins=(mvYInit–searchRangeHeight)< <iMvShift;

[0393] mvYMaxs=(mvYInit+searchRangeHeight)< <iMvShift;

[0394] mvXMins, mvXMaxs, mvYMins, and mvYMaxs determine the horizontal and vertical offset range of the search point relative to the current block, that is, the range of the motion vector.

[0395] Through the search points (iPosHor, iPoxVer) in each search area, that is, each motion vector MV (composed of horizontal and vertical components: (pX, pY), where pX = iPosHor-xTbCmp, pY = iPosVer-yTbCmp, then pX is between mvXMins and mvXMaxs, and pY is between mvYMins and mvYMaxs), a matching reconstructed block of the current block can be found in the reconstructed area. The adjacent reconstructed pixels of the matching reconstructed block are the matching template (that is, the second template mentioned above). The matching cost of the adjacent template of the current block and the adjacent template of the reconstructed block (that is, the reference block) can be calculated, which is recorded as pDiff.

[0396] Furthermore, all search points in all search ranges are traversed, and the search point with the smallest matching cost pDiff is obtained by comparison. Its corresponding matching cost is recorded as pDiff_BEST, and its corresponding vector parameters are recorded as the best vector parameters, MV_BEST or BV_BEST, specifically including (pX_BEST, pY_BEST), and its corresponding matching template is the best matching template T_BEST.

[0397] Traverse all search points in the search range, determine their availability, and compare to obtain the search point with the smallest matching cost pDiff. Its corresponding matching cost is recorded as pDiff_BEST, its corresponding motion vector MV is recorded as the best vector parameter MV_BEST (pX_BEST, pY_BEST), and its corresponding matching template is the best matching template T_BEST.

[0398] It should be noted that judging the availability of the search point can be understood as judging the availability of the reference block and the template.

[0399] In some embodiments, availability determination includes but is not limited to one or more of the following conditions being met simultaneously:

[0400] Each sampling point in the template does not exceed the valid coordinate range limited by the image sampling point boundary;

[0401] Each sampling point in the template corresponding to the reconstruction block does not exceed the valid coordinate range limited by the image sampling point boundary;

[0402] Each sampling point in the template and each sampling point in the corresponding reconstructed block does not exceed the specified range of the search window;

[0403] Whether each sampling point in the template is in the same sub-image (e.g., Tile) as the current encoding area;

[0404] Whether each sampling point in the reconstructed block corresponding to the template is in the same sub-image (e.g., Tile) as the current coding area (also called the current block);

[0405] Each sampling point in the template has been reconstructed;

[0406] Each sampling point in the reconstructed block corresponding to the template is not in the current coding area; the restrictions on intra-frame prediction do not apply to inter-frame prediction;

[0407] Each sampling point in the reconstruction block corresponding to the template has been reconstructed;

[0408] After completing the above operations, the optimal vector parameters (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 coding block template in the current image or reference image, respectively, and are also the horizontal offset and vertical offset of the best matching reconstructed block relative to the current coding block.

[0409] It should be noted that in the above one or more availability judgment conditions, "each sampling point in the template" is replaced by "identified sampling points in the template"; in the above one or more availability judgment conditions, "each sampling point in the corresponding reconstructed block of the template" is replaced by "identified sampling points in the corresponding reconstructed block of the template".

[0410] It should be noted that the identified sampling points can be sampling points at specific preset positions within the template or the reconstructed block corresponding to the template. In some embodiments, the identified sampling points within the template refer to one or more sampling points located at the corners of the template area. For example, when only the upper template is present, the upper left and lower right sampling points of the upper template area; or only the lower right sampling point. The identified sampling points within the reconstructed block corresponding to the template refer to one or more sampling points located at the corners of the reconstructed block area. For example, the upper left and lower right sampling points of the reconstructed block area; or only the lower right sampling point of the reconstructed block area.

[0411] Take the Intra-TMP technology to determine the optimal BV as an example: 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.

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

[0413] bvXMins regionId =iHorMin regionId –xTbCmp;

[0414] bvXMaxs regionId =iHorMax regionId –xTbCmp;

[0415] bvYMins regionId=iVerMin regionId –yTbCmp;

[0416] bvYMaxs regionId =iVerMax regionId –yTbCmp.

[0417] 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.

[0418] 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.

[0419] Furthermore, 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, 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.

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

[0421] 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).

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

[0423] 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).

[0424] 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:

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

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

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

[0428] 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, 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.

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

[0430] 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.

[0431] 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:

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

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

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

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

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

[0437] bvXMins=iHorMin refine –xTbCmp;

[0438] bvXMaxs=iHorMax refine –xTbCmp;

[0439] bvYMins=iVerMin refine –yTbCmp;

[0440] bvYMaxs=iVerMax refine –yTbCmp;

[0441] 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).

[0442] 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.

[0443] S805: Establish a linear filtering model.

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

[0445] 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 according to the size of the current block. In the embodiment of the present application, filters of various shapes can be selected. For example, the six fixed-shape filters shown in Figure 14 can be selected, wherein the number of filter taps nTap in Figure 14 (a) is 5, and the filter coefficients are: C0, C1, C2, C3, and C4 respectively. The number of filter taps nTap in Figure 14 (b) is 3, and the filter coefficients are: C0, C1, and C2 respectively. The number of filter taps nTap in Figure 14 (c) is 3, and the filter coefficients are: C0, C1, and C2 respectively. The number of filter taps nTap in Figure 14 (d) is 3, and the filter coefficients are: C0, C1, and C2 respectively. The number of filter taps nTap in Figure 14 (e) is 3, and the filter coefficients are: C0, C1, and C2 respectively. The number of filter taps nTap in FIG14(a) is 9, and the filter coefficients are C0, C1, C2, C3, C4, C5, C6, C7, and C8. The filter shapes and coefficients in FIG14 are for example only and are not intended to limit the embodiments of the present application.

[0446] 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:

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

[0448] 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.

[0449] 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.

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

[0451] 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, namely:

[0452] 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)

[0453] Wherein, 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, k, l are between -1 and 1, taking (a) in Figure 14 as an example, 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:

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

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

[0456] First, for c k,l Find the partial derivative and make it 0, that is:

[0457] E[2(∑ k,l=-1~1 c k,l ·refTemp[i+k][j+l]-recTemp[i][j])·refTemp[i+m][j+n]]=0 (19)

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

[0459] Here, according to formula (18) and formula (19), we can get:

[0460] ∑ 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)

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

[0462] 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.

[0463] 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.

[0464] In some embodiments, border pixels also need to be filled. This is because the filter may use reconstructed pixels outside the reference template and reference block. Depending on the filter shape, the area of ​​border that needs to be filled varies. This process primarily involves two steps: determining the border filling area between the reference block and the corresponding reference template; and filling the border pixels within the border filling area.

[0465] In some embodiments, the boundary filling area includes at least one of the following: an edge-adjacent area of ​​the matching template, a point-adjacent area of ​​the matching template, an edge-adjacent area of ​​the reference block, and a point-adjacent area of ​​the reference block.

[0466] In some embodiments, boundary pixel filling is performed on the boundary filling area, including: using adjacent pixel reconstruction values ​​within the matching template to fill the boundary pixels of the first boundary filling area corresponding to the matching template; and / or using adjacent pixel reconstruction values ​​within the reference block to fill the boundary pixels of the second boundary filling area corresponding to the reference template.

[0467] In some embodiments, it is determined that a sampling point at a first position within the boundary filling region is unavailable, and boundary pixel filling is performed on the first position within the boundary filling region.

[0468] In some embodiments, the sampling point availability judgment conditions include at least one of the following: the first position sampling point has been reconstructed; the first position is located in the search area; the first position is located in the image where the reference block is located; the first position is located in the sub-image where the reference block is located.

[0469] In some embodiments, filling the boundary pixels of the boundary filling area includes filling the boundary pixels of the boundary filling area with a preset pixel value. For example, the preset pixel value is 0, or a pixel value determined by the encoder.

[0470] In some embodiments, a boundary filling region is determined based on the filter shape. FIG16A is a schematic diagram of a boundary filling region, which fills the outer boundary region of a reference block and its reference template as a whole, including edge-adjacent regions and point-adjacent regions. FIG16B is a schematic diagram of a boundary filling region, which fills the outer boundary region of a reference block and its reference template.

[0471] It should be noted that the width of the outer boundary area is a preset width. Exemplarily, the width of the outer boundary area is measured in pixels or sub-pixels and can be any number from 1 to N.

[0472] Figure 17 is a schematic diagram of the border filling area of ​​other template types. When the value of refTemplateType is 4, the border filling area is shown in (a) and (d) of Figure 17; when the value of refTemplateType is 5, the border filling area is shown in (b) and (e) of Figure 17; when the value of refTemplateType is 6, the border filling area is shown in (c) and (f) of Figure 17.

[0473] There are also different ways to fill:

[0474] One filling method is to determine whether the sampling points in the outer boundary filling area are available. If available, the reconstructed pixels are directly used. If not available, the reconstructed pixels of the adjacent reference template or reference block are copied to fill the corresponding positions.

[0475] Another filling method is to determine whether the search sampling point is within the search range. If it is within the search range, the reconstructed pixels are used directly. If it exceeds the search area, the reconstructed pixels of the adjacent reference template or reference block are copied according to the direction beyond the search area to fill the corresponding position.

[0476] Another filling method is to directly copy the reconstructed pixels of the adjacent reference template or reference block to fill the blue area.

[0477] Alternatively, you can choose not to fill in the data and instead abandon the corresponding data for computation when encountering a boundary position. The availability of sampling points within the outer boundary filling area may include, but is not limited to, one or more of the following conditions: the sampling point at that location has been reconstructed; the location is within the MV / BV search range; the location is within the image boundary; or the location is within the tile boundary.

[0478] S806: Generate a predicted value.

[0479] 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 positions are weighted and summed to obtain the current pixel to be predicted. Ref is the best matching reconstructed block, which is defined as follows:

[0480] ref[i][j]=recSamples[i+pX_BEST][j+pY_BEST] (22)

[0481] Wherein, i=0,…,nTbW-1, j=0,…,nTbH-1, recSamples are the reconstructed pixels of the current image or the reference image, and pX_BEST and pY_BEST are the horizontal and vertical components of the best vector parameters.

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

[0483] Assuming that the number of filter taps nTap is 5, the shape of the filter (or called "filter template") is shown in Figure 18A, where C0 to C4 are the tap coefficients of the filter. The dot filled with 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 FIG18A , the predicted pixel Y is finally obtained. pred [i][j] are shown as black-filled dots in FIG18B .

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

[0485] 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 ck,l :

[0486] c k,l =c n (twenty three)

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

[0488] For i=0,…,nTbW-1,j=0,…,nTbH-1:

[0489] Y pred [i][j]=∑ k ∑ l ref[i+k][j+l]×c k,l (twenty four)

[0490] Furthermore, Y pred [i][j] Set the clamping operation within the preset value range to obtain the final predicted pixel. The details are as follows:

[0491] predSamples[i][j]=Clip3(0,(1< <BitDepth)-1,Y pred [i][j]) (25)

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

[0493] 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 near the initial vector parameters 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.

[0494] 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.

[0495] 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:

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

[0497] 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.

[0498] 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.

[0499] 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.

[0500] 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.

[0501] In some embodiments, the type of filtering model in the aforementioned embodiment can be expanded. A linear filtering model or a nonlinear filtering model can be established for filtering. One possible implementation is to introduce a quadratic term to establish a nonlinear filtering model. For example, when minimizing the MSE of the filter coefficients, the calculation formula is changed to the following:

[0502] 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)

[0503] At this time, the calculation formula for the predicted value is modified as follows:

[0504] Y pred [i][j]=∑ k ∑ l (ref[i+k][j+l]) 2 ×C k,l (30)

[0505] 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:

[0506] 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;

[0507] 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.

[0508] 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, MSE, 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[0530] 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.

[0531] To intuitively illustrate the different sub-search regions corresponding to different regionIds, see Figure 19A , 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 19A , R1, R2, R3, and R4 represent four different sub-search regions. Note that Figure 19A represents the pixel range that can be aligned with the upper left corner pixel of a block.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[0553] 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.

[0554] To intuitively illustrate the different sub-search regions corresponding to different regionIds, see Figure 19B , 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 19B , R1, R2, R3, and R4 represent four different sub-search regions. Note that Figure 19B represents the pixel range that can be aligned with the upper left corner pixel of the block.

[0555] 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:

[0556] 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;

[0557] 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;

[0558] 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;

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

[0560] 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:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[0581] 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.

[0582] To intuitively illustrate the different sub-search regions corresponding to different regionIds, see Figure 19C , which shows another schematic diagram of the specific search region determination process provided by an embodiment of the present application. As shown in Figure 19C , 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 19C represents the pixel range that can be aligned with the upper left corner pixel of the block.

[0583] In some embodiments, based on considerations of the full reconstruction search area and the area to be reconstructed, taking (a) in FIG. 7 as an example, the search area is divided into six sub-search areas, which are implemented as follows:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[0605] iHorMin=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

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

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

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

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

[0610] iHorMin=(xTbCmp)< <iBvShift;

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

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

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

[0614] 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.

[0615] To visually illustrate the different sub-search regions corresponding to different regionIds, Figure 19D shows a fourth schematic diagram of the search region determination process. As shown in Figure 19D , R1, R2, R3, R4, R5, and R6 represent six different sub-search regions. R1, R2, R3, and R4 are the full reconstruction search regions, while R5 and R6 are the pending reconstruction search regions. Note that Figure 19D represents the pixel range aligned with the top-left corner pixel of the block.

[0616] That is, in some embodiments, the search area can be divided into two types: one is a region in which all sampling points have been reconstructed (referred to as a full reconstruction search area), for example, including the four regions R1, R2, R3, and R4 in FIG19D ; the other is a region in which it is uncertain whether all sampling points have been reconstructed (referred to as a pending reconstruction search area), for example, including the two regions R5 and R6 in FIG19D .

[0617] To visually illustrate the different sub-search regions corresponding to different regionIds, Figure 19D shows the second schematic diagram of the search region determination process. As shown in Figure 19D, R1, R2, R3, R4, R5, and R6 represent six different sub-search regions. R1, R2, R3, and R4 are the full reconstruction search regions, while R5 and R6 are the pending reconstruction search regions. Note that Figure 19D represents the pixel range aligned with the top-left corner pixel of the block.

[0618] That is, in some embodiments, the search area can be divided into two types: one is a region in which all sampling points have been reconstructed (referred to as a full reconstruction search area), for example, including the four regions R1, R2, R3, and R4 in FIG19D ; the other is a region in which it is uncertain whether all sampling points have been reconstructed (referred to as a pending reconstruction search area), for example, including the two regions R5 and R6 in FIG19D .

[0619] In some embodiments, based on considerations of the full reconstruction search area and the area to be reconstructed, taking (b) in FIG. 7 as an example, the search area is divided into six sub-search areas, which are implemented as follows:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[0641] iHorMin=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

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

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

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

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

[0646] iHorMin=(xTbCmp)< <iBvShift;

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

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

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

[0650] In practical applications, iHorMinregionId, iHorMaxregionId, iVerMinregionId, and iVerMaxregionId here represent the left edge, right edge, upper edge, and lower edge of different sub-search regions, respectively.

[0651] To visually illustrate the different sub-search regions corresponding to different regionIds, Figure 19E shows a fifth schematic diagram of the search region determination process. As shown in Figure 19E , R1, R2, R3, R4, R5, and R6 represent six different sub-search regions. R1, R2, R3, and R4 are the full reconstruction search regions, while R5 and R6 are the pending reconstruction search regions. Note that Figure 19E represents the pixel range aligned with the top-left corner pixel of the block.

[0652] That is, in some embodiments, the search area can be divided into two types: one is a region in which all sampling points have been reconstructed (referred to as a full reconstruction search area), for example, including the four regions R1, R2, R3, and R4 in FIG19E ; the other is a region in which it is uncertain whether all sampling points have been reconstructed (referred to as a pending reconstruction search area), for example, including the two regions R5 and R6 in FIG19E .

[0653] In some embodiments, based on considerations of the full reconstruction search area and the area to be reconstructed, the search area is divided into six sub-search areas, taking (c) in Figure 7 as an example. To intuitively describe the different sub-search areas corresponding to different regionIds, Figure 19F is a sixth schematic diagram of the search area determination process. As shown in Figure 19F, R1, R2, R3, R4, R5, and R6 represent six different sub-search areas, where R1, R2, R3, and R4 are full reconstruction search areas, and R5 and R6 are to-be-determined reconstruction search areas. It should be noted that Figure 19F is represented by a pixel range that can be aligned with the upper left corner pixel of the block.

[0654] That is, in some embodiments, the search area can be divided into two types: one is a region in which all sampling points have been reconstructed (referred to as a full reconstruction search area), for example, including the four regions R1, R2, R3, and R4 in FIG19F ; the other is a region in which it is uncertain whether all sampling points have been reconstructed (referred to as a pending reconstruction search area), for example, including the two regions R5 and R6 in FIG19F .

[0655] In some embodiments, based on considerations of the full reconstruction search area and the area to be reconstructed, the search area is divided into six sub-search areas, taking (d) in Figure 7 as an example. To intuitively describe the different sub-search areas corresponding to different regionIds, Figure 19G is a seventh schematic diagram of the search area determination process. As shown in Figure 19G, R1, R2, R3, R4, R5, and R6 represent six different sub-search areas, where R1, R2, R3, and R4 are full reconstruction search areas, and R5 and R6 are to-be-determined reconstruction search areas. It should be noted that Figure 19G is represented by a pixel range that can be aligned with the upper left corner pixel of the block.

[0656] That is, in some embodiments, the search area can be divided into two types: one is a region in which all sampling points have been reconstructed (referred to as a full reconstruction search area), for example, including the four regions R1, R2, R3, and R4 in FIG19F ; the other is a region in which it is uncertain whether all sampling points have been reconstructed (referred to as a pending reconstruction search area), for example, including the two regions R5 and R6 in FIG19G .

[0657] Furthermore, in an embodiment of the present application, in order to achieve a smaller number of search areas and thus reduce the amount of code, part of the full reconstruction search area and part of the pending reconstruction search area can be selectively merged to form a new pending reconstruction search area, thereby reducing the number of search areas.

[0658] In some embodiments, based on considerations of the full reconstruction search area and the area to be reconstructed, taking (a) in FIG. 7 as an example, the search area is divided into seven sub-search areas, which are implemented as follows:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[0673] iVerMax=(yTbCmp)< <iBvShift;

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

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

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

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

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

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

[0680] iHorMin=(xTbCmp-offsetLCBX-nTbW)< <iBvShift;

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

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

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

[0684] When regionId is equal to 5, iVerMin, iVerMax, iHorMin, and iHorMax can be calculated as follows

[0685] iHorMin=(xTbCmp)< <iBvShift;

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

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

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

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

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

[0691] iHorMin=(xTbCmp-nTbW)< <iBvShift;

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

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

[0694] 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.

[0695] To visually illustrate the different sub-search regions corresponding to different regionIds, Figure 19H shows Schematic Diagram 8 of the search region determination process. As shown in Figure 19H , R1, R2, R3, R4, R5, R6, and R7 represent seven different sub-search regions. R1, R2, R3, R4, and R7 are the full reconstruction search regions, while R5 and R6 are the pending reconstruction search regions. Note that Figure 19H represents the pixel range aligned with the top-left corner pixel of the block.

[0696] It should be noted that, in the embodiment of the present application, for the search region R7, that is, when regionId is equal to 6, the search point at the lower right corner of R7 is skipped during the search process because this point coincides with the upper left corner of the current block.

[0697] For example, in this application, when determining the prediction value of the current block, for R1 to R6 that do not overlap with the current block, a simple translation copy can be used. The specific operation is:

[0698] For x=0…nTbW-1,y=0…nTbH-1,

[0699] predSamples[x][y]=recSamples[x+pX_BEST][y+pY_BEST]

[0700] Where recSamples represents the reconstructed pixels of the current frame.

[0701] For example, in one embodiment of the present application, when determining the prediction value of the current block, for R7 that overlaps with the current block, repeated copy filling can be used. The BV of this area meets the conditions pX_BEST = -nTbW + 1 ... 0, and pY_BEST = -nTbH + 1 ... 0, and pX_BEST and pY_BEST are not 0 at the same time. The specific operation is:

[0702] For x=0…-pX_BEST-1, y=0…-pY_BEST-1,

[0703] predSamples[x][y]=recSamples[x+pX_BEST][y+pY_BEST]

[0704] Where recSamples represents the reconstructed pixels of the current frame;

[0705] For x = pX_BEST-1…nTbW-1, y = pY_BEST-1…nTbH-1,

[0706] predSamples[x][y]=predSamples[x+pX_BEST][y+pY_BEST].

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

[0708] Furthermore, the best block vector BV1_BEST obtained in the coarse search k 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 .

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

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

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

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

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

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

[0715] 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:

[0716] 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 、iHorMaxrefine , and the method of obtaining it is as follows:

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

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

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

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

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

[0722] bvXMins=iHorMin refine –xTbCmp;

[0723] bvXMaxs=iHorMax refine –xTbCmp;

[0724] bvYMins=iVerMin refine –yTbCmp;

[0725] bvYMaxs=iVerMax refine –yTbCmp;

[0726] Thus, the fine search is performed when pX is within bvXMins refine with bvXMaxs refine Between, pY is in bvYMins refine with bvYMaxs refineFor 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.

[0727] 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.

[0728] 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.

[0729] In the embodiments of the present application, the specific implementation of the aforementioned embodiments is described in detail through the above embodiments. It can be seen that according to the technical solution of the aforementioned embodiments, the predicted value of the 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 the initial vector parameters 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 filtered reconstructed pixels are used as predicted pixels, thereby improving the prediction accuracy.

[0730] 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:

[0731] S2001: Determine a first template of a current block, and determine a matching template and a reference block.

[0732] 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 be referred to as a template matching (TM-FLM) prediction method based on a linear filter model. In some embodiments, the encoding method can 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), or an intra-frame prediction method based on an intra-frame block copy (Intra Block Copy on Filter-based Linear Model, IBC-FLM) based on a linear filter model. Among them, the 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-predicted, and the reference block is a reconstructed block in the current frame. In addition, the encoding 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.

[0733] 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. In some embodiments, determining the first template of the current block may include: determining the template type of the current block; and determining the first template of the current block based on the template type of the current block.

[0734] 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 based on reference pixels of the current block; or determining the template type of the current block by decoding a bitstream; or determining the template type of the current block based on the size of the current block.

[0735] 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.

[0736] 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:

[0737] 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;

[0738] 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;

[0739] 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;

[0740] 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;

[0741] 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;

[0742] 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.

[0743] 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 .

[0744] 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.

[0745] 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.

[0746] 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.

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

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

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

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

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

[0752] In one possible implementation, determining an initial vector parameter for a current block includes: determining, based on a prediction mode parameter for the current block, a vector parameter candidate list for constructing the current block; and determining the initial vector parameter based on the vector parameter candidate list. The prediction mode parameter is used to indicate parameters related to the prediction mode of the current block. In one possible implementation, determining the initial vector parameter based on the vector parameter candidate list includes: obtaining a vector parameter at a preset position (e.g., the first vector parameter) from the vector parameter candidate list as the initial vector parameter; or obtaining a vector parameter at a preset position from the vector parameter candidate list, decoding a bitstream to determine a vector parameter prediction difference, and determining the initial vector parameter based on the vector parameter at the preset position and the vector parameter prediction difference.

[0753] In one possible implementation, determining to construct a vector parameter candidate list for the current block based on the prediction mode parameters of the current block includes: determining to construct a merge vector parameter candidate list for the current block based on the prediction mode parameters of the current block; or determining to construct an AMVP vector parameter candidate list for the current block based on the prediction mode parameters of the current block.

[0754] In one possible implementation, an initial vector parameter for the current block is determined to be a preset vector parameter based on a prediction mode parameter of the current block. In some embodiments, the Intra TMP initial block vector parameter is 0. In another embodiment, the Intra TMP initial block vector parameter is a vector parameter obtained by a coarse search of the search area, and correspondingly, the target vector parameter is a vector parameter obtained by a fine search of the search area.

[0755] In one possible implementation, determining a search area based on the initial vector parameters includes determining the search area based on the initial vector parameters and a preset search range. Exemplarily, determining a reference block based on the initial vector parameters and the current block; and determining the search area based on the reference block and the preset search range. The search area includes reconstructed pixels.

[0756] It should be noted that the search range may be pre-set, or may be transmitted through a code stream, or may be adaptively selected based on information such as block size.

[0757] In one possible implementation, the method for determining the search range includes at least one of the following: using a preset horizontal component search range as the horizontal component search range of the preset search range; using a preset vertical component search range as the vertical component search range of the preset search range; decoding the code stream to determine the horizontal component search range and / or vertical component search range of the preset search range; determining the horizontal component search range and / or vertical component search range of the preset search range based on the size of the current block.

[0758] In one possible implementation, determining a search area based on initial vector parameters includes: determining an inter-frame prediction mode based on prediction mode parameters of the current block, and determining a search area based on the initial vector parameters in a reference image; determining an intra-frame prediction mode based on prediction mode parameters of the current block, and determining a search area based on the initial vector parameters in the current image.

[0759] In one possible implementation, the intra-frame prediction mode is determined according to the prediction mode parameters of the current block, and the search area includes at least one of the following: a partial area of ​​the reconstructed coding tree block of the current image, the entire area of ​​the reconstructed coding tree block of the current image, the entire reconstructed area of ​​the current coding tree block, and a reconstructed partial area of ​​the current coding tree block where the current block is located.

[0760] In one possible implementation, searching within a search area based on template matching to determine target vector parameters includes: searching within the search area to determine a reference template, calculating a matching cost between the reference template and a first template, and determining the vector parameter of the reference template corresponding to the minimum matching cost as the target vector parameter. Exemplarily, searching within the search area to determine an available reference template.

[0761] In a possible implementation, a condition for determining the availability of a reference template includes at least one of the following: a first sampling point in the template does not exceed a boundary of an image in which it is located; a second sampling point in a reference block corresponding to the template does not exceed a boundary of an image in which it is located; the first sampling point in the template does not exceed a search area; the second sampling point in the reference block corresponding to the template does not exceed a search area; all first sampling points in the template have been reconstructed; and all second sampling points in the reference block corresponding to the template have been reconstructed.

[0762] In one possible implementation, the reference template availability determination condition includes at least one of the following: a first sampling point within the template and the current block are within the same sub-image; a second sampling point within the reference block corresponding to the template and the current block are within the same sub-image; or the second sampling point within the reference block corresponding to the template is not within the current block. Exemplarily, a sub-image may include multiple coding tree units. Exemplarily, a sub-image may be a tile.

[0763] In a possible implementation, the first sampling points are sampling points in the template, or first identification sampling points are preset. The first identification sampling points include sampling points at at least one corner position in the template.

[0764] In one possible implementation, the second sampling points are sampling points within a reference block corresponding to the template, or preset second identification sampling points. The second identification sampling points include sampling points at at least one corner position within the reference block corresponding to the template. Specifically, whether the sampling point is located within the preset image can be determined by determining whether its coordinates are within a valid coordinate range of the preset image area.

[0765] It should be noted that the sampling points can be individual sampling points within the template or the reconstructed block corresponding to the template, or sampling points at preset specific locations. In some embodiments, the identified sampling points within the template refer to one or more sampling points located at the corners of the template area. For example, when only the upper template is present, the upper left and lower right sampling points of the upper template area; or only the lower right sampling point. The identified sampling points within the reconstructed block corresponding to the template refer to one or more sampling points located at the corners of the reconstructed block area. For example, the upper left and lower right sampling points of the reconstructed block area; or only the lower right sampling point of the reconstructed block area.

[0766] That is to say, a search can be performed in a preset search area based on the first template, and a matching template with the minimum cost can be searched according to a preset cost function. Among them, by traversing all search points in the preset search area, one or more candidate vector parameters can be obtained, and these one or more candidate vector parameters can indicate one or more candidate matching templates; the cost is calculated with the first template of the current block respectively, and the search point with the minimum cost is obtained by comparison, and its corresponding candidate vector parameter is the best vector parameter (i.e., the target vector parameter, BV_BEST); its corresponding candidate matching template is the best matching template (i.e., the matching template of this embodiment, T_BEST); and the reference block can be determined based on the best matching template. In the embodiment of the present application, the target vector parameter can be understood as the best vector parameter or the matching vector parameter. Exemplarily, the vector parameter for the inter-frame prediction mode can be MV, and the vector parameter for the intra-frame prediction mode can be BV.

[0767] 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.

[0768] 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:

[0769] In one possible implementation, searching within a search area based on template matching to determine target vector parameters may include: performing a first search within the search area to determine the target vector parameters; or performing a second search within the search area to determine the target vector parameters; wherein a search step size corresponding to the first search is greater than a search step size corresponding to the second search.

[0770] In another possible implementation, a search is performed within a search area based on template matching to determine target vector parameters, including: performing a first search within the search area to determine the first vector parameters and determining an initial matching template based on the first vector parameters; 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 vector parameters; wherein a search step size corresponding to the first search is larger than a search step size corresponding to the second search, and the first search area is smaller than a preset search area.

[0771] 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.

[0772] 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 matching template) can be determined within the vicinity of the best coarse matching template with a step size of 1.

[0773] In another possible implementation, the preset search area may include at least one sub-search area; the search area includes at least one sub-search area; searching within the search area based on template matching to determine the target vector parameter includes: searching within the at least one sub-search area separately to determine the optimal vector parameter and the corresponding matching cost value of each sub-search area; determining the optimal vector parameter corresponding to the minimum matching cost value based on the optimal vector parameter and the corresponding matching cost value of each sub-search area; and using the optimal vector parameter corresponding to the minimum matching cost value as the target vector parameter.

[0774] In one possible implementation, searching within a search area based on template matching to determine a target vector parameter includes: performing a first search within at least one sub-search area to determine the optimal vector parameter of each sub-search area and the corresponding second search area; performing area judgment based on the optimal vector parameter 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; performing a second search within at least two target sub-search areas to determine the optimal vector parameters corresponding to the at least two target sub-search areas; and using the optimal vector parameters corresponding to the at least two target sub-search areas as the target vector parameters.

[0775] It should be noted that in the embodiments of this application, for intra-frame prediction techniques, the search area for the current block template can be the reconstructed portion of the CTB containing the current block, 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.

[0776] 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) in 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, then 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 matching template. This allows the matching cost between the first template of the current block and the matching template to be calculated, denoted as pDiff.

[0777] 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 of this embodiment; its corresponding best matching template T_BEST is the final required matching template.

[0778] In a possible implementation, determining the reference block includes: determining the reference block according to a target vector parameter. Exemplarily, determining the reference block according to the current block and the target vector parameter.

[0779] In another possible implementation, the method further includes: determining a value of first syntax element identification information; wherein the first syntax element identification information is used to indicate whether template matching is applied to the current block; encoding the value of the first syntax element identification information, and writing the obtained encoded bits into the bitstream.

[0780] In another possible implementation, the method further includes: determining a value of third syntax element identification information; wherein the third syntax element identification information is used to indicate a reference block of the current block; encoding the value of the third syntax element identification information, and writing the obtained coded bits into the bitstream.

[0781] In another possible implementation, the method further includes: the first syntax element identification information is used to indicate that template matching is applied to the current block (or determine that template matching is applied to the current block), and determine the value of the third syntax element identification information; and determine the reference block of the current block according to the value of the third syntax element identification information.

[0782] It should be noted that the encoder transmits a flag indicating which filtered reference block is used as the final prediction block. tmpFlag indicates whether template matching is applied to the current coding block, and filterIdx indicates which reference block within the current search range is applied to the filter model. When tmpFlag is 1, the encoder compares the distortion (SAD, MSE, SATD, or SSE) between the reference blocks with applied filter coefficients within the search range and the current original block, selects the optimal reference block, and transmits the corresponding index to the decoder.

[0783] In another possible implementation, determining a value of the third syntax element identification information includes: determining that when template matching is applied to the current block, traversing a search area to search for multiple reference blocks, filtering the reference blocks according to model parameters, and determining a filtered reference block; calculating distortion parameters of the filtered reference block and the current original block; determining a reference block corresponding to a minimum distortion parameter; and determining a value of the third syntax element identification information based on the reference block corresponding to the minimum distortion parameter.

[0784] It should be noted that the filter coefficients are solved and filtered for the templates within the search range, and the Cost is calculated with the current template to decide which template to use, that is, the filter coefficients are calculated for part or all of the templates to be searched in the search range, and then the filter coefficients are applied to the template to be searched, and the Cost thereof and the current template are calculated. The best matching template after filtering is selected according to the Cost, and the reference block corresponding to the best matching template is filtered and used as the final prediction value.

[0785] In another possible implementation, determining a reference block includes: traversing a search area to search for multiple reference templates, and determining model parameters based on a first template and a reference template; filtering the reference template based on the model parameters to obtain a filtered reference template; calculating a matching cost between the filtered reference template and the first template; and determining a reference block of the reference template corresponding to a minimum matching cost as a reference block of the current block.

[0786] S2002: Determine model parameters according to the first template and the matching template.

[0787] 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.

[0788] 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.

[0789] 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.

[0790] 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.

[0791] 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:

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

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

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

[0795] 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.

[0796] 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.

[0797] 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).

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

[0799] First, for c k,l Find the partial derivative and set it 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.

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

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

[0802] 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.

[0803] 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.

[0804] 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.

[0805] 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.

[0806] 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.

[0807] 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.

[0808] 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.

[0809] 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.

[0810] 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.

[0811] 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.

[0812] 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.

[0813] 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.

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

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

[0816] 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.

[0817] 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.

[0818] 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.

[0819] In one possible implementation, determining model parameters based on the first template and the matching template may include: calculating the product of the pixel reconstruction value of the reference block and the coefficient of the corresponding target filter; setting 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; and determining the filtered reference block based on the first output value of the target filter.

[0820] In one possible implementation, determining model parameters based on the first template and the matching template may also include: calculating the product of the pixel reference value of the second boundary filling area corresponding to the reference block and the coefficient of the corresponding target filter; and / or calculating the product of the pixel reference value of the reference template corresponding to the reference block and the coefficient of the corresponding target filter. Filling boundary pixels requires filling boundary pixels, considering that the filter may use reconstructed pixels outside the reference template and reference block. Depending on the filter shape, the area of ​​the boundary that needs to be filled varies. The filled boundary pixels can be used to determine model parameters and / or predict the current block.

[0821] 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).

[0822] 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:

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

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

[0825] 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.

[0826] 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).

[0827] 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.

[0828] 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.

[0829] 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.

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

[0831] 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.

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

[0833] It should be noted that in an embodiment 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 an embodiment 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 position (i, j) in the filtered reference block is calculated as shown in the aforementioned formulas (14) and (15).

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

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

[0836] Here, for the clip operation, the preset value range here may be: between 0 and (1 << BitDepth) - 1, where BitDepth represents the bit depth. If the value of the filtered reference block exceeds the value range of this preset value, 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:

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

[0838] 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];

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

[0840] In this way, after performing a 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.

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

[0842] Determining multiple sets of model parameters according to the first template and the matching template;

[0843] Constructing multiple filter models according to the multiple sets of model parameters, respectively filtering the reference block according to the multiple filter models, and determining multiple filtered reference blocks;

[0844] Determining the predicted value of the current block according to the multiple filtered reference blocks.

[0845] 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 according to a preset method to obtain multiple sets of sub - templates and multiple sets of sub - matching templates; determining multiple sets of model parameters according to the multiple sets of sub - templates and multiple sets of sub - matching templates.

[0846] It should be noted that in the embodiments of the present application, the preset method 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 according to the preset method, 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.

[0847] In a possible implementation manner, the method may further include: determining a target filter from the multiple filter models; filtering the reference block according to the target filter to determine the predicted value of the current block.

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

[0849] 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.

[0850] 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.

[0851] 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.

[0852] 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. Another feasible solution is to determine which filter to use by calculating the cost using the filtered template and the current template.

[0853] For solutions that extend multiple models and multiple filter shapes, the decoding end can sort the solutions by template prediction distortion and select the solution with the smallest template prediction distortion as the final selection.

[0854] Alternatively, both the codec and the decoder may sort the various schemes by template prediction distortion, and specify the prediction scheme to be finally used by transmitting index information in the ordered list in the bitstream.

[0855] In some embodiments, border pixels also need to be filled. This is because the filter may use reconstructed pixels outside the reference template and reference block. Depending on the filter shape, the area of ​​border that needs to be filled varies. This process primarily involves two steps: determining the border filling area between the reference block and the corresponding reference template; and filling the border pixels within the border filling area.

[0856] In some embodiments, the boundary filling area includes at least one of the following: an edge-adjacent area of ​​the matching template, a point-adjacent area of ​​the matching template, an edge-adjacent area of ​​the reference block, and a point-adjacent area of ​​the reference block.

[0857] In some embodiments, boundary pixel filling is performed on the boundary filling area, including: using adjacent pixel reconstruction values ​​within the matching template to fill the boundary pixels of the first boundary filling area corresponding to the matching template; and / or using adjacent pixel reconstruction values ​​within the reference block to fill the boundary pixels of the second boundary filling area corresponding to the reference template.

[0858] In some embodiments, it is determined that a sampling point at a first position within the boundary filling region is unavailable, and boundary pixel filling is performed on the first position within the boundary filling region.

[0859] In some embodiments, the sampling point availability judgment conditions include at least one of the following: the first position sampling point has been reconstructed; the first position is located in the search area; the first position is located in the image where the reference block is located; the first position is located in the sub-image where the reference block is located.

[0860] In some embodiments, filling the boundary pixels of the boundary filling area includes filling the boundary pixels of the boundary filling area with a preset pixel value. For example, the preset pixel value is 0, or a pixel value determined by the encoder.

[0861] In some embodiments, the boundary filling area is determined according to the filter shape, as shown in FIG16A , FIG16B and FIG17 .

[0862] It should be noted that the width of the outer boundary area is a preset width. Exemplarily, the width of the outer boundary area is measured in pixels or sub-pixels and can be any number from 1 to N.

[0863] There are also different ways to fill:

[0864] One filling method is to determine whether the sampling points in the outer boundary filling area are available. If available, the reconstructed pixels are directly used. If not available, the reconstructed pixels of the adjacent reference template or reference block are copied to fill the corresponding positions.

[0865] Another filling method is to directly copy the reconstructed pixels of the adjacent reference template or reference block to fill the blue area.

[0866] Alternatively, you can choose not to fill in the data and instead abandon the corresponding data for computation when encountering a boundary position. The availability of sampling points within the outer boundary filling area may include, but is not limited to, one or more of the following conditions: the sampling point at that location has been reconstructed; the location is within the MV / BV search range; the location is within the image boundary; or the location is within the tile boundary.

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

[0868] 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.

[0869] 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.

[0870] 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.

[0871] 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.

[0872] In some embodiments, the method may further include: determining 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; encoding the value of the second syntax element identification information, and writing the obtained coded bits into the bitstream.

[0873] In some embodiments, when the first syntax element identification information is used to indicate that intra template matching is applied to the current block, the method may further include: determining a value of the 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; encoding the value of the second syntax element identification information, and writing the obtained coded bits into the bitstream.

[0874] 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.

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

[0876] 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;

[0877] 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.

[0878] 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.

[0879] 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:

[0880] 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;

[0881] 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.

[0882] Method three: The encoding end 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 encoding end 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, MSE, 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.

[0883] It should be noted that in addition to calculating the filter coefficients for the best matching template after the search, and applying the filter coefficients to the best matching reference block, it is also possible to apply the filter coefficients to all or part of the reference blocks in the search area, and determine which filtered reference block to use as the final prediction block based on certain conditions. For example, there are the following methods:

[0884] Method 1: Calculate the filter coefficients for the templates within the search range and filter them, and then calculate the cost with the current template to decide which template to use. That is, calculate the filter coefficients for part or all of the templates to be searched in the search range, then apply the filter coefficients to the template to be searched, calculate the cost of the template and the current template, and select the best matching template after filtering based on the cost. Filter the reference block corresponding to the best matching template and use it as the final prediction value.

[0885] Method 2: The encoder transmits a flag indicating which filtered reference block is used as the final prediction block. tmpFlag indicates whether template matching is applied to the current coding block, and filterIdx indicates which reference block within the current search range is applied to the filter model. When tmpFlag is 1, the encoder compares the distortion (SAD, MSE, SATD, or SSE) between the reference blocks within the search range with the applied filter coefficients and the current original block, selects the optimal reference block, and transmits the corresponding index to the decoder.

[0886] 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, the value of the second syntax element identification information, and the value of the third syntax element identification information.

[0887] 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.

[0888] 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.

[0889] 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,

[0890] A first determining unit 2101 is configured to determine a first template of a current block, and to determine a matching template and a reference block; and further configured to determine model parameters based on the first template and the matching template;

[0891] 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;

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

[0893] 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.

[0894] 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.

[0895] 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 of this embodiment. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0896] 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 of any one of the aforementioned embodiments.

[0897] 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,

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

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

[0900] The first processor 2203 is configured to execute, when running the computer program, any one of the encoding methods provided in the embodiments of the present application.

[0901] 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.

[0902] 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.

[0903] 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.

[0904] 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.

[0905] 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 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.

[0906] 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,

[0907] The second determining unit 2301 is configured to determine a first template of the current block, and determine a matching template and a reference block; and further configured to determine a model parameter based on the first template and the matching template;

[0908] 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;

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

[0910] 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.

[0911] 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.

[0912] 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.

[0913] 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,

[0914] 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;

[0915] The second memory 2402 is used to store computer programs that can be run on the second processor 2403;

[0916] The second processor 2403 is configured to execute, when running the computer program, any one of the decoding methods provided in the embodiments of the present application.

[0917] 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.

[0918] 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.

[0919] 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. The predicted value of the 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.

[0920] 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 .

[0921] 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.

[0922] 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.

[0923] 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.

[0924] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0925] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.

[0926] 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.

[0927] 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

[0928] In the embodiment of the present application, whether it is the encoding end or the decoding end, the first template of the current block is determined, as well as the matching template and the reference block; the model parameters are determined based on the first template and the matching template; the reference block is filtered according to the model parameters to determine the filtered reference block; and 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 at 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 used as the predicted pixels of the current block, thereby improving the prediction accuracy, saving the bit rate, and improving the encoding and decoding efficiency, thereby improving the 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 matching template and a reference block; Determining model parameters 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 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.

3. The method according to claim 2, 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; 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; Alternatively, decoding a bitstream to determine a template type of the current block; Alternatively, the template type of the current block is determined according to the size of the current block.

4. The method according to claim 3, 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.

5. The method according to claim 1, wherein: The determining of the matching template comprises: Determine initial vector parameters of the current block; Determine a search area according to the initial vector parameters; Searching within the search area based on template matching to determine target vector parameters; The matching template is determined according to the target vector parameter and the first template.

6. The method according to claim 5, wherein: The determining of the initial vector parameters of the current block includes: Determine, according to the prediction mode parameters of the current block, a candidate list of vector parameters for constructing the current block; The initial vector parameter is determined according to the vector parameter candidate list.

7. The method according to claim 6, wherein: The step of determining, according to the prediction mode parameters of the current block, a candidate list of vector parameters for constructing the current block comprises: Determine, according to the prediction mode parameters of the current block, a candidate list of merge vector parameters for constructing the current block; or, According to the prediction mode parameters of the current block, determine and construct an AMVP vector parameter candidate list for the current block.

8. The method according to claim 5, wherein: The determining of the initial vector parameters of the current block includes: According to the prediction mode parameters of the current block, the initial vector parameters of the current block are determined to be preset vector parameters.

9. The method according to claim 8, wherein: The preset vector parameter is 0.

10. The method according to claim 5, wherein: The step of determining a search area according to the initial vector parameter comprises: The search area is determined according to the initial vector parameter and a preset search range.

11. The method according to claim 10, wherein: The method for determining the search range includes at least one of the following: Using a preset horizontal component search range as the horizontal component search range of the preset search range; Using a preset vertical component search range as the vertical component search range of the preset search range; Decoding the bitstream, and determining a horizontal component search range and / or a vertical component search range of the preset search range; According to the size of the current block, a horizontal component search range and / or a vertical component search range of the preset search range is determined.

12. The method according to claim 5, wherein: The step of determining a search area according to the initial vector parameter comprises: Determining the inter-frame prediction mode according to the prediction mode parameters of the current block, and determining the search area in the reference image according to the initial vector parameters; The intra-frame prediction mode is determined according to the prediction mode parameters of the current block, and the search area is determined in the current image according to the initial vector parameters.

13. The method according to claim 5, wherein: The intra-frame prediction mode is determined according to the prediction mode parameters of the current block, and the search area includes at least one of the following: a partial area of ​​the reconstructed coding tree block of the current image, the entire area of ​​the reconstructed coding tree block of the current image, the entire reconstructed area of ​​the current coding tree block, and the reconstructed partial area of ​​the current coding tree block where the current block is located.

14. The method according to claim 5, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Searching and determining a reference template in the search area, and calculating a matching cost value between the reference template and the first template; The vector parameter of the reference template corresponding to the minimum matching cost value is determined as the target vector parameter.

15. The method according to claim 14, wherein: The step of searching in the search area to determine a reference template comprises: The search area is searched to determine available reference templates.

16. The method according to claim 15, wherein: The reference template availability judgment condition includes at least one of the following: The first sampling point in the template does not exceed the boundary of the image; The second sampling point in the reference block corresponding to the template does not exceed the boundary of the image; The first sampling point in the template does not exceed the search area; The second sampling point in the reference block corresponding to the template does not exceed the search area; The first sampling points in the template have been reconstructed; The second sampling points in the reference block corresponding to the template have been reconstructed.

17. The method according to claim 15 or 16, wherein: The reference template availability judgment condition includes at least one of the following: The first sampling point in the template and the current block are in the same sub-image; The second sampling point in the reference block corresponding to the template and the current block are in the same sub-image; The second sampling point in the template corresponding reference block is not in the current block.

18. The method according to claim 16, wherein: The first sampling points are sampling points in the template, or preset first identification sampling points.

19. The method according to claim 18, wherein: The first identified sampling points include sampling points at at least one corner position in the template.

20. The method according to claim 16, wherein: The second sampling points are sampling points in a reference block corresponding to the template, or preset second identification sampling points.

21. The method according to claim 20, wherein: The second identified sampling points include sampling points at at least one corner position in the reference block corresponding to the template.

22. The method according to claim 5, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Perform a first search in the search area to determine the target vector parameter; or, Perform a second search in the search area to determine the target vector parameter; The search step length corresponding to the first search is greater than the search step length corresponding to the second search.

23. The method according to claim 5, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Perform a first search in the search area, determine a first vector parameter, and determine an initial matching template according to the first vector parameter; 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 vector parameter; 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.

24. The method according to claim 5, wherein: The search area includes at least one sub-search area; searching in the search area based on template matching to determine the target vector parameter includes: Searching in the at least one sub-search area respectively to determine the best vector parameter and the corresponding matching cost value of each sub-search area; According to the optimal vector parameters and the corresponding matching cost values ​​of each sub-search area, the minimum matching cost value corresponding to the Optimal vector parameters; The optimal vector parameter corresponding to the minimum matching cost value is used as the target vector parameter.

25. The method according to claim 24, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Perform a first search in the at least one sub-search area to determine the best vector parameter of each sub-search area and the corresponding second search area; Performing region judgment according to the best vector parameter of each sub-search region and the corresponding second search region, and determining 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 optimal vector parameters corresponding to the at least two target sub-search areas; The best vector parameters corresponding to the at least two target sub-search areas are used as the target vector parameters.

26. The method according to claim 5, wherein: The determining of the reference block comprises: The reference block is determined according to the target vector parameter.

27. The method of claim 1, wherein: The method further comprises: Decode the code stream and determine the value of first syntax element identification information; wherein the first syntax element identification information is used to indicate whether template matching is applied to the current block.

28. The method of claim 1, wherein: The determining of the reference block comprises: Decoding the bitstream and determining a value of the third syntax element identification information; A reference block of the current block is determined according to the value of the third syntax element identification information.

29. The method of claim 1, wherein: The method further comprises: Traversing the search area to search for multiple reference templates, and determining model parameters according to the first template and the reference template; Performing filtering on the reference template according to the model parameters to obtain a filtered reference template; Calculating a matching cost value between the filtered reference template and the first template; The reference block of the reference template corresponding to the minimum matching cost value is determined as the reference block of the current block.

30. The method of claim 1, wherein: The model parameters include coefficients of the target filter.

31. The method according to claim 30, wherein: The determining of model parameters according to the first template and the matching template includes: Calculating the product of the pixel reconstruction value of the reference block and the corresponding coefficient of the target filter; Setting 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; The filtered reference block is determined based on a first output value of the target filter.

32. The method according to claim 31, wherein: The determining of model parameters according to the first template and the matching template further includes: Calculate the product of the pixel reference value of the second boundary filling area corresponding to the reference block and the corresponding coefficient of the target filter; And / or, calculating the product of the pixel reference value of the reference template corresponding to the reference block and the corresponding coefficient of the target filter.

33. The method of claim 1, wherein: The method further comprises: Determining a boundary filling area between the reference block and a corresponding reference template; The boundary filling area is filled with boundary pixels.

34. The method of claim 33, wherein: The boundary filling area includes at least one of the following: an edge adjacent area of ​​the matching template, a point adjacent area of ​​the matching template, an edge adjacent area of ​​the reference block, and a point adjacent area of ​​the reference block.

35. The method of claim 33, wherein: The step of filling the boundary pixels of the boundary filling area comprises: Filling the first boundary filling area corresponding to the matching template with boundary pixels using the adjacent pixel reconstruction values ​​in the matching template; The boundary pixels of the second boundary filling area corresponding to the reference template are filled using the adjacent pixel reconstruction values ​​in the reference block.

36. The method of claim 33, wherein: The step of filling the boundary pixels of the boundary filling area comprises: The boundary pixel filling of the boundary filling area is performed using a preset pixel value.

37. The method of claim 33, wherein: The method comprises: It is determined that a sampling point at a first position in the boundary filling area is unavailable, and boundary pixel filling is performed on the first position in the boundary filling area.

38. The method of claim 37, wherein: The sampling point available judgment conditions include at least one of the following: The first position sampling point has been reconstructed; The first position is within the search area; The first position is located in the image where the reference block is located; The first position is located in the sub-image where the reference block is located.

39. The method according to any one of claims 1, 27 or 28, wherein: The method further comprises: 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.

40. The method of claim 39, 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.

41. A coding method, applied to an encoder, the method comprising: Determine a first template of the current block, and determine a matching template and a reference block; Determining model parameters 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.

42. The method according to claim 41, 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.

43. The method of claim 42, 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; 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; Alternatively, decoding a bitstream to determine a template type of the current block; Alternatively, the template type of the current block is determined according to the size of the current block.

44. The method of claim 43, 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.

45. The method of claim 41, wherein: The determining of the matching template comprises: Determine initial vector parameters of the current block; Determine a search area according to the initial vector parameters; Searching within the search area based on template matching to determine target vector parameters; The matching template is determined according to the target vector parameter and the first template.

46. ​​The method of claim 45, wherein: The determining of the initial vector parameters of the current block includes: Determine, according to the prediction mode parameters of the current block, a candidate list of vector parameters for constructing the current block; The initial vector parameter is determined according to the vector parameter candidate list.

47. The method of claim 46, wherein: The step of determining, according to the prediction mode parameters of the current block, a candidate list of vector parameters for constructing the current block comprises: Determine, according to the prediction mode parameters of the current block, a candidate list of merge vector parameters for constructing the current block; or, According to the prediction mode parameters of the current block, determine and construct an AMVP vector parameter candidate list for the current block.

48. The method of claim 45, wherein: The determining of the initial vector parameters of the current block includes: According to the prediction mode parameters of the current block, the initial vector parameters of the current block are determined to be preset vector parameters.

49. The method of claim 48, wherein: The preset vector parameter is 0.

50. The method of claim 45, wherein: The step of determining a search area according to the initial vector parameter comprises: The search area is determined according to the initial vector parameter and a preset search range.

51. The method of claim 50, wherein: The method for determining the preset search range includes at least one of the following: Using a preset horizontal component search range as the horizontal component search range of the preset search range; Using a preset vertical component search range as the vertical component search range of the preset search range; Decoding the bitstream, and determining a horizontal component search range and / or a vertical component search range of the preset search range; According to the size of the current block, a horizontal component search range and / or a vertical component search range of the preset search range is determined.

52. The method of claim 45, wherein: The step of determining a search area according to the initial vector parameter comprises: Determining the inter-frame prediction mode according to the prediction mode parameters of the current block, and determining the search area in the reference image according to the initial vector parameters; The intra-frame prediction mode is determined according to the prediction mode parameters of the current block, and the search area is determined in the current image according to the initial vector parameters.

53. The method of claim 45, wherein: The intra-frame prediction mode is determined according to the prediction mode parameters of the current block, and the search area includes at least one of the following: a partial area of ​​the reconstructed coding tree block of the current image, the entire area of ​​the reconstructed coding tree block of the current image, the entire reconstructed area of ​​the current coding tree block, and the reconstructed partial area of ​​the current coding tree block where the current block is located.

54. The method of claim 45, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Searching and determining a reference template in the search area, and calculating a matching cost value between the reference template and the first template; The vector parameter of the reference template corresponding to the minimum matching cost value is determined as the target vector parameter.

55. The method of claim 54, wherein: The step of searching in the search area to determine a reference template comprises: The search area is searched to determine available reference templates.

56. The method of claim 55, wherein: The reference template availability judgment condition includes at least one of the following: The first sampling point in the template does not exceed the boundary of the image; The second sampling point in the reference block corresponding to the template does not exceed the boundary of the image; The first sampling point in the template does not exceed the search area; The second sampling point in the reference block corresponding to the template does not exceed the search area; The first sampling points in the template have been reconstructed; The second sampling points in the reference block corresponding to the template have been reconstructed.

57. The method of claim 55 or 56, wherein: The reference template availability judgment condition includes at least one of the following: The first sampling point in the template and the current block are in the same sub-image; The second sampling point in the reference block corresponding to the template and the current block are in the same sub-image; The second sampling point in the template corresponding reference block is not in the current block.

58. The method of claim 56, wherein: The first sampling points are sampling points in the template, or preset first identification sampling points.

59. The method of claim 58, wherein: The first identified sampling points include sampling points at at least one corner position in the template.

60. The method of claim 56, wherein: The second sampling points are sampling points in a reference block corresponding to the template, or preset second identification sampling points.

61. The method of claim 60, wherein: The second identified sampling points include sampling points at at least one corner position in the reference block corresponding to the template.

62. The method of claim 45, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Perform a first search in the search area to determine the target vector parameter; or, Perform a second search in the search area to determine the target vector parameter; The search step length corresponding to the first search is greater than the search step length corresponding to the second search.

63. The method of claim 45, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Perform a first search in the search area, determine a first vector parameter, and determine an initial matching template according to the first vector parameter; 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 vector parameter; 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.

64. The method of claim 45, wherein: The search area includes at least one sub-search area; searching in the search area based on template matching to determine the target vector parameter includes: Searching in the at least one sub-search area respectively to determine the best vector parameter and the corresponding matching cost value of each sub-search area; Determine the optimal vector parameter corresponding to the minimum matching cost value according to the optimal vector parameter and the corresponding matching cost value of each sub-search area; The optimal vector parameter corresponding to the minimum matching cost value is used as the target vector parameter.

65. The method of claim 64, wherein: The searching within the search area based on template matching to determine the target vector parameters includes: Perform a first search in the at least one sub-search area to determine the best vector parameter of each sub-search area and the corresponding second search area; Performing region judgment according to the best vector parameter of each sub-search region and the corresponding second search region, and determining 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 optimal vector parameters corresponding to the at least two target sub-search areas; The best vector parameters corresponding to the at least two target sub-search areas are used as the target vector parameters.

66. The method of claim 45, wherein: The determining of the reference block comprises: The reference block is determined according to the target vector parameter.

67. The method of claim 41, 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 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.

68. The method of claim 41, wherein: The method further comprises: Determine a value of third syntax element identification information; wherein the third syntax element identification information is used to indicate a reference block of the current block; The value of the third syntax element identification information is encoded, and the obtained encoding bits are written into a bitstream.

69. The method of claim 41 or 68, wherein: The determining of the reference block comprises: When determining that the current block is to be template matched, traverse the search area to search for multiple reference blocks, filter the reference blocks according to the model parameters, and determine the filtered reference blocks; Calculating distortion parameters of the filtered reference block and the current original block; Determine the reference block corresponding to the minimum distortion parameter.

70. The method of claim 41 or 68, wherein: The determining of the reference block comprises: Traversing the search area to search for multiple reference templates, and determining model parameters according to the first template and the reference template; Performing filtering on the reference template according to the model parameters to obtain a filtered reference template; Calculating a matching cost value between the filtered reference template and the first template; The reference block of the reference template corresponding to the minimum matching cost value is determined as the reference block of the current block.

71. The method of claim 41, wherein: The model parameters include coefficients of the target filter.

72. The method of claim 71, wherein: The determining of model parameters according to the first template and the matching template further includes: Calculating the product of the pixel reconstruction value of the reference block and the corresponding coefficient of the target filter; Setting 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; The filtered reference block is determined based on a first output value of the target filter.

73. The method of claim 72, wherein: The determining of model parameters according to the first template and the matching template further includes: Calculate the product of the pixel reference value of the second boundary filling area corresponding to the reference block and the corresponding coefficient of the target filter; And / or, calculating the product of the pixel reference value of the reference template corresponding to the reference block and the corresponding coefficient of the target filter.

74. The method of claim 41, wherein: The method further comprises: Determining a boundary filling area between the reference block and a corresponding reference template; The boundary filling area is filled with boundary pixels.

75. The method of claim 74, wherein: The border filling area includes at least one of the following: an edge adjacent area of ​​the matching template, a point adjacent area of ​​the matching template, The edge adjacent area of ​​the reference block, the point adjacent area of ​​the reference block.

76. The method of claim 74, wherein: The step of filling the boundary pixels of the boundary filling area comprises: Filling the first boundary filling area corresponding to the matching template with boundary pixels using the adjacent pixel reconstruction values ​​in the matching template; The boundary pixels of the second boundary filling area corresponding to the reference template are filled using the adjacent pixel reconstruction values ​​in the reference block.

77. The method of claim 74, wherein: The step of filling the boundary pixels of the boundary filling area comprises: The boundary pixel filling of the boundary filling area is performed using a preset pixel value.

78. The method of claim 74, wherein: The method comprises: It is determined that a sampling point at a first position in the boundary filling area is unavailable, and boundary pixel filling is performed on the first position in the boundary filling area.

79. The method of claim 78, wherein: The sampling point available judgment conditions include at least one of the following: The first position sampling point has been reconstructed; The first position is within the search area; The first position is located in the image where the reference block is located; The first position is located in the sub-image where the reference block is located.

80. The method of any one of claims 41, 67 or 68, wherein: The method further comprises: 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.

81. The method of claim 80, wherein: The method further comprises: 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.

82. 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, the value of the second syntax element identification information, and the value of the third syntax element identification information; wherein the first syntax element identification information is used to indicate whether the current block applies intra template matching, the second syntax element identification information is used to indicate whether the current block applies a filter model, and the third syntax element identification information is used to indicate a reference block of the current block.

83. 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 matching template and a reference block; and is further configured to determine a model parameter according to 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.

84. 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 41 to 81 when running the computer program.

85. A decoder comprising a second determination unit, a second filtering unit and a second prediction unit; wherein: The second determining unit is configured to determine a first template of the current block, and determine a matching template and a reference block; and is further configured to determine model parameters according to 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.

86. 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 40 when running the computer program.

87. A computer-readable storage medium, wherein: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 40 is implemented, or the method according to any one of claims 41 to 81 is implemented.