Decoding method and encoding method involving weight determination for predictors, and apparatus incorporating the same
The proposed decoding method addresses low adaptivity and accuracy issues in intra prediction fusion by determining multiple reference areas for HoG and TM cost estimation, resulting in enhanced predictor accuracy and compression efficiency.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- SHENZHEN TCL NEW-TECH CO LTD
- Filing Date
- 2024-12-26
- Publication Date
- 2026-07-02
AI Technical Summary
Existing video coding methods face issues of low adaptivity, inaccurate predictors, and low compression efficiency due to the use of histogram of gradients (HoG) and template matching (TM) based weighting in intra prediction fusion processes.
A decoding method that determines multiple reference areas for histogram of gradients (HoG) and template matching (TM) cost estimation, calculates directional and non-directional prediction modes, and applies weighted fusion to generate predicted samples, improving prediction accuracy and efficiency.
Enhances the adaptivity and accuracy of predictors, leading to improved compression efficiency by optimizing the weighting process in intra prediction fusion.
Smart Images

Figure CN2024142917_02072026_PF_FP_ABST
Abstract
Description
DECODING METHOD AND ENCODING METHOD INVOLVING WEIGHT DETERMINATION FOR PREDICTORS, AND APPARATUS INCORPORATING THE SAMETECHNICAL FIELD
[0001] The present disclosure generally relates to encoding and decoding technology, and in particular to a decoding method, an encoding method, an apparatus for decoding or encoding, and a computer readable non-transitory medium.BACKGROUND
[0002] In video coding, methods to generate a predictor for a block from previously reconstructed samples are generally referred to as a block prediction methods. These previously reconstructed samples are called “reference samples” , and their spatial location within a picture is referred to as “reference area” .
[0003] When reference area and a predicted block belong to different pictures, a block prediction method is called a block inter-prediction method. When reference area and a predicted block belong to the same picture, a block prediction method is called as a block intra-prediction.
[0004] Intra prediction methods involve defining one or more reference lines within a reference area, from which samples of a predicted block are derived through specific processing steps. Initially, this involves determining a reference area, such as selecting the distance to the predicted block, exemplified by methods like MRL / TMRL. For instance, TMRL outlines reference lines and a template area, as illustrated in FIG. 1, and prepares a sorted list of candidates as shown in FIG. 2. Each candidate in this list pairs an intra prediction mode with a reference line index, indicating a distance to the predicted block. The prediction for a template area then proceeds using parameters from each candidate in the sorted list, with candidates organized based on the cost metrics calculated concerning the reconstructed samples of the reference area. Furthermore, the selection of samples from a reference line is contingent on the predicted sample's position within the block. Finally, a Finite Impulse Response (FIR) filter is applied to the chosen samples within a reference line to determine the predicted sample's value. Notably, the FIR can vary for different positions within the predicted block, potentially serving as an interpolation filter determined for each row or column based on the fractional displacement of the predicted row or column relative to the reference line.
[0005] Directional intra prediction is performed by propagating a reference line inside a block to be predicted in some spatial direction. In VVC, 92 intra prediction directions are defined (see FIG. 3) . These prediction directions correspond to intra prediction modes, each of these modes is assigned a number called an intra prediction index.
[0006] Proposal JVET-AB0157 ( “EE2-1.12: Combination of EE2-1.10 and EE2-1.11” ) and JVET-AB0148 ( “EE2-1.11: Intra prediction fusion” ) includes description of an intra prediction method that uses a linear combination of two intra predictors that were obtained for the same intra prediction mode but for different reference lines.
[0007] Particularly, for angular intra prediction modes including the single mode case of TIMD and DIMD, the proposed method derives intra prediction by weighting intra predictions obtained from multiple reference lines represented as pfusion=w0pline+w1pline+1 , where pline is the intra prediction from the default reference line and pline+1 is the prediction from the line above the default reference line as FIG. 4 illustrates. The weights are set as w0=3 / 4 and w1=1 / 4 [JVET-AB0157] .
[0008] This technique referred to as intra prediction fusion derives predicted samples as a weighted combination of multiple predictors generated from different reference lines. In this process multiple intra predictors are generated and then fused by weighted averaging. The process of deriving the predictors to be used in the fusion process is described as follows:
[0009] 1) For angular intra prediction modes including the single mode case of TIMD and DIMD, the proposed method derives intra prediction by weighting intra predictions obtained from multiple reference lines represented as pfusion=w0pline+w1pline+1, where pline is the intra prediction from the default reference line and pline+1 is the prediction from the line above the default reference line. The weights are set as w0=3 / 4 and w1=1 / 4.
[0010] 2) For TIMD mode with blending, pline is used for the first mode (w0=1, w1=0) and pline+1 is used for the second mode (w0=0, w1=1) .
[0011] 3) For DIMD mode with blending, the number of predictors selected for a weighted average is increased from 3 to 6.
[0012] The angular intra prediction fusion method is applied to luma blocks when angular intra mode has non-integer slope (required reference samples interpolation) and the block size is greater than 16, it is used with MRL (see FIG. 5) and not applied for ISP coded blocks. In the method studied in the sub-test a, PDPC is applied for the intra prediction mode using the closest to the current block reference line.
[0013] In current design, fusion-based prediction uses either histogram of gradients (HoG) based weighting (as in DIMD) or Template matching (TM) based weighting (as in TIMD) . This separated approach may lead to the following issues: low adaptivity, inaccurate predictors, and low compression efficiency.SUMMARY
[0014] Accordingly, the present disclosure aims to provide a decoding method, an encoding method, an apparatus for decoding or encoding, and a computer readable non-transitory medium.
[0015] A technical scheme adopted by the present disclosure is to provide a decoding method. The method includes: determining a first reference area of a current block for estimation of histogram of gradients (HoG) ; determining a second reference area of the current block for estimation of template matching (TM) cost; acquiring one or more directional prediction modes based on the estimation of HoG; determining one or more TM cost-based weights of the one or more directional prediction modes based on the estimation of TM cost; determining one or more final weights of the one or more directional prediction modes based on the one or more TM cost-based weights; and applying the one or more directional prediction modes with the one or more final weights for generating predicted samples of the current block.
[0016] Another technical scheme adopted by the present disclosure is to provide a decoding method. The method includes: determining a reference area of a current block for estimation of histogram of gradients (HoG) ; acquiring one or more directional prediction modes and their original weights; acquiring one or more non-directional prediction modes and their corresponding weights; determining a first weight sum by summing the original weights of the one or more directional prediction modes; determining a second weight sum by summing the original weights of the one or more directional prediction modes and the weights of the one or more non-directional prediction modes, wherein the second weight sum is equal to a norm number; acquiring a weight scale which is equal to the second weight sum divided by the first weight sum; and normalizing weights of the one or more directional prediction modes based on the weight scale and the norm number.
[0017] Another technical scheme adopted by the present disclosure is to provide a decoding method. The method includes: determining a first reference area of a current block; determining a second reference area of the current block; determining a prediction mode; acquiring a first template matching (TM) cost within a template area of the current block based on the first reference area and the prediction mode; acquiring a second TM cost within the template area based on the second reference area and the prediction mode; determining a first weight for the first reference area and a second weight for the second reference area based on the first TM cost and the second TM cost; and generating predicted samples of the current block based on reference samples within the first reference area scaled by the first weight and / or reference samples within the second reference area scaled by the second weight.
[0018] Another technical scheme adopted by the present disclosure is to provide an encoding method. The method includes: determining a first reference area of a current block for estimation of histogram of gradients (HoG) ; determining a second reference area of the current block for estimation of template matching (TM) cost; acquiring one or more directional prediction modes based on the estimation of HoG; determining one or more TM cost-based weights of the one or more directional prediction modes based on the estimation of TM cost; determining one or more final weights of the one or more directional prediction modes based on the one or more TM cost-based weights; and applying the one or more directional prediction modes with the one or more final weights for generating predicted samples of the current block.
[0019] Another technical scheme adopted by the present disclosure is to provide an apparatus for video decoding or encoding. The apparatus includes a processor and a memory. The memory is configured to store executable instructions that, when executed by the processor, cause the processor to perform any of the foregoing methods.
[0020] Another technical scheme adopted by the present disclosure is to provide a computer readable medium. The computer readable medium is configured to store executable instructions that, when executed by the processor, cause the processor to perform any of the foregoing methods.BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to clearly explain the technical solutions in the embodiments of the present disclosure, the drawings used in the description of the embodiments will be briefly described below. Obviously, the drawings in the following description are merely some embodiments of the present disclosure. For those of ordinary skill in the art, other drawings may also be obtained based on these drawings without any creative work.
[0022] FIG. 1 shows reference lines and template areas as defined in TMRL.
[0023] FIG. 2 shows an exemplary sorted list of candidates used in TMRL.
[0024] FIG. 3 shows directions for angular intra prediction modes in VVC.
[0025] FIG. 4 illustrates the process of using two adjacent reference lines to predict a block.
[0026] FIG. 5 illustrates the process of using two non-adjacent reference lines to predict a block.
[0027] FIG. 6 shows an example of grouped angular modes for prediction of a luminance block.
[0028] FIG. 7 illustrates dependency of the bin parsing step on the sample reconstruction (decoding) process.
[0029] FIG. 8 shows reference lines and template areas used in TMRL.
[0030] FIG. 9 illustrates a prediction process of the proposed BVG-DIMD method.
[0031] FIG. 10 is a flowchart of a decoding method according to an embodiment of the present disclosure.
[0032] FIG. 11 shows samples used in DIMD template-cost-based fusion for a 16x8 block.
[0033] FIG. 12 shows samples used in DIMD template-cost-based fusion for a 16x16 block.
[0034] FIG. 13 shows samples used in DIMD template-cost-based fusion for a 8x4 block.
[0035] FIG. 14 shows samples used in non-adjacent decoder-side intra mode derivation (NADIMD) with template-cost-based fusion.
[0036] FIG. 15 shows a Block-vector guided decoder-side intra mode derivation (BVG-DIMD) process
[0037] FIG. 16 shows samples used in BVG-DIMD template-cost-fusion for a 16x8 block.
[0038] FIG. 17 shows a process for obtaining the candidate fusion mode list for the fusion process with an additional condition on the template matching costs.
[0039] FIG. 18 illustrates a process for obtaining a set of fusion intra prediction for a reference line with elimination of modes that belong to adjacent DIMD.
[0040] FIG. 19 is a flowchart of a decoding method according to another embodiment of the present disclosure.
[0041] FIG. 20 illustrates a process for redistribution of HoG-derived weights for non-adjacent DIMD.
[0042] FIG. 21 is a flowchart of a decoding method according to yet another embodiment of the present disclosure.
[0043] FIG. 22 shows reference samples of the main reference line that are used to obtain predictors for the template.
[0044] FIG. 23 shows reference samples of the adjacent reference line that are used to obtain predictors for the template.
[0045] FIG. 24 illustrates a process for conditionally enabling intra fusion based on the TM cost value.
[0046] FIG. 25 is a flowchart of an encoding method according to an embodiment of the present disclosure.
[0047] FIG. 26 illustrates a process for selecting an alternative interpolation filter based on the size of the current block.
[0048] FIG. 27 is a schematic diagram of an apparats for decoding or encoding according to an embodiment of the present disclosure.DETAILED DESCRIPTION
[0049] The disclosure will now be described in detail with reference to the accompanying drawings and examples. Apparently, the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0050] Introduction for several related technologies of the present disclosure will be given below, including: 1) Predictors elimination technique for HEVC; 2) Template-based multiple reference line intra prediction; 3) Block Vector guided DIMD. ● Predictors Elimination Technique for HEVC
[0051] In document JVET-C0023, an orientation-aware prediction modes elimination technique as well as improvements to MPM selection algorithm are proposed. An example of mode grouping is shown in FIG. 6. The main idea behind the proposed technique is to group together close angular modes, and to reconsider mode signaling mechanism as to utilize the elimination of some of the directional intra prediction. Maximal difference between predictor pixels below the threshold depending on quantization parameter (QP) is used as the similarity criterion.
[0052] As summarized in the JVET meeting notes (JVET-C1000, page 39) on contribution JVET-C0023, “this contribution proposes a QP dependent similarity criteria for predictor blocks as well as modifications to existent intra modes coding that allow content-dependent grouping of equal (or similar) predictors (aka a predictors elimination technique) for the price of computational complexity in the order of the prediction modes number. A modified MPM selection algorithm enabling orientation-aware operation on group numbers in place of mode indexes is also proposed.
[0053] Parsing of content-dependent group indexes can only be performed by the decoder when all the pixels required for predictors construction are available, thus the contribution proposes CU bitstream reordering.
[0054] The predictor elimination technique for HEVC has been described, and a mechanism to indicate intra prediction modes have been proposed. The drawback of the proposed technique is the dependency of the parsing process on the process of sample reconstruction. FIG. 7 illustrates this parsing dependency.
[0055] This dependency makes the technique proposed in JVET-C0023 to be impractical, because Context-Adaptive Binary Arithmetic Coding (CABAC) is an essentially serial process, which is hardly parallelized. Such a dependency slows down the overall decoding pipeline, which comprises parsing, derivation, and decoding processes, since the parsing process may not continue before the reconstructed samples needed to estimate the similarity of candidate predictors are completely decoded, i.e. the parsing process interrupts to alternate with the derivation and decoding process instead of keeping bins parsed with no delay. ● Template-based multiple reference line intra prediction
[0056] Template-based multiple reference line intra prediction (TMRL) mode combines reference line and prediction mode together and uses a template matching method to construct a list of candidate combinations. An index to the candidate combination list is coded to indicate which reference line and prediction mode is used in coding the current block. The regular multiple reference line (MRL) for the non-TIMD part is replaced with TMRL mode.
[0057] The TMRL mode extends reference line candidate list and the intra-prediction-mode candidate list. The extended reference line candidate list is {1, 3, 5, 7, 12} . The size of the intra-prediction-mode candidate list is 10. The construction of the intra-prediction-mode candidate list is similar to MPM except the planar mode is excluded from the intra-prediction-mode candidate list, DC mode is added after 5 neighboring PUs’ modes and DIMD modes if its not included and the angular modes with delta angles from ±1 to ±4 (compared the existing angular modes in the intra-prediction-mode candidate list) are added. The precision of angular prediction is extended from 65 to 129. Additionally non-adjacent positions are added as candidates in constructing the intra candidate list. If the neighboring or non-adjacent blocks are coded with SGPM or GPM modes, the intra modes of the blocks are replaced by the partitioning angles.
[0058] The TMRL candidate is constructed as follows. There are 5x10=50 combinations of the extended reference line and the allowed intra-prediction modes for a block. Since the extended reference line starts from reference line 1, the area covered by reference line 0 is used for template matching. The SAD costs over the template area (see FIG. 8) are calculated between the predictions (generated by 50 combinations) and the reconstructions. The 20 combinations with the least SAD cost are selected in an ascending order to form the TMRL candidate list.
[0059] For TMRL signaling instead of coding the reference line and the intra mode directly, an index to the TMRL candidate list is coded to indicate which combination of reference line and prediction mode is used for coding the current block. ● Block Vector guided DIMD
[0060] In [JVET-AJ0087] , it was proposed to use the reference samples pointed at by the block vectors, instead of the neighboring samples shown in FIG. 9, to build HoG and derive intra modes. Up to 5 block vectors are obtained by a searching process like in IntraTMP. With each block vector, a reference area in the current picture is determined and its samples are used to derive the intra modes and corresponding amplitudes. All results are counted in constructing the HoG. Similar to the DIMD and OBIC modes, five intra modes with the highest amplitudes are selected and the prediction of the current block is the blending of those five predictors and a non-directional predictor. The non-directional predictor is the blending of up to 5 BV-based predictors obtained using the block vectors.
[0061] The conventional fusion-based prediction uses either HoG-based weighting (as in DIMD) or TM-based weighting (as in TIMD) , which may lead to several issues including low adaptivity, inaccurate predictors, and low compression efficiency.
[0062] In terms of adaptivity, the weight of the non-directional component is usually fixed to a pre-determined value in the existing design. Although the non-directional component's part in the predicted block could potentially be estimated from the template, this opportunity is currently not utilized in the design, leading to lower adaptivity.
[0063] When it comes to the accuracy of predictors, determining a list of modes for the fusion process and the weights used in this process, based solely on the edge strength (as in DIMD) or template prediction error (as in TIMD) , introduces inaccuracies to the fused predictors. If only the edge strength is considered in the fusion process, the predictor constructed with the corresponding edge may overshadow other relevant predictors. Furthermore, selecting intra prediction modes based on the template prediction error may result in overlooking intra prediction modes relevant to the current block. This happens because the area occupied by an edge in the template may not be significant, leading to a minimal contribution to the template prediction error.
[0064] Lastly, the issue of low compression efficiency arises as a consequence of prediction inaccuracy. This inaccuracy either increases distortion or necessitates additional bits in the bitstream to code the residual signal to compensate for the inaccuracy, leading to an increase in bitrate.
[0065] The present disclosure provides a decoding method involving weight determination for predictors. The method may solve one or more above-mentioned issues. The decoding method involves a fusion prediction process. FIG. 10 is a flowchart of a decoding method according to an embodiment of the present disclosure. As shown in FIG. 10, the method includes operations described in blocks S101 to S106.
[0066] In S101, a first reference area of a current block for estimation of histogram of gradients (HoG) is determined.
[0067] Samples that are used in derivation of histogram of gradients (HoG) are defined. For example, they can be the samples to the left and above of the current block.
[0068] In S102, a second reference area of the current block for estimation of template matching (TM) cost is determined.
[0069] An area that is used for TM cost estimation is determined. This area may be defined by the size and position of the current block. For example, the area may include two region, one of which is adjacent to the left side of the current block, and the other is adjacent to the top side of the current block.
[0070] In one embodiment, the first reference area may include an above template area and a left template area of the current block. The second reference area may be substantially the same of the first reference area, or the second reference area may overlap with the first reference area.
[0071] For example, FIG. 11 depicts the samples that are used in this process for a predicted block of size 16 by 8. Some of the samples are used just for HoG estimation and will not be used in template matching cost estimation. These samples are denoted as “Template samples used by the edge operator only” . The first reference area may cover these samples and other samples located in the area denoted as “Templates” , while the second reference area may cover samples located in the area denoted as “Templates” but not “template samples used by the edge operator only” . FIG. 12 and FIG. 13 show the samples that are used in the process for predicted blocks of size 16 by 16 and 8 by 4 respectively. It could be observed that the number of lines in the template (i.e., the second reference area) can be determined by the block size.
[0072] In another embodiment, the first reference area may include a primary reference line and a secondary reference line which are non-adjacent to the current block. The second reference area may be different from the first reference area. For example, the second reference area may include an above template area and a left template area of the current block. Alternatively or additionally, the second reference area may include an adjacent reference line of the current block.
[0073] For example, FIG. 14 depicts the samples that are used in this process. HoG can be obtained by applying edge operator to the areas of the primary and secondary reference lines, which constitute the first reference area. The second reference area may be determined in the same manner as shown in FIGs. 11 to 13, that is, one part adjacent to the left side of the current block (predicted block) and another part adjacent to the above side of the current block. Alternatively, the second reference area may be the area of the adjacent reference line, i.e., the 0-th reference line.
[0074] In another embodiment, the first reference area may include an above template area, a left template area and a reference area of a non-directional prediction mode. The second reference area may include the above template area and the left template area.
[0075] For example, FIG. 15 shows a Block-vector guided decoder-side intra mode derivation (BVG-DIMD) process, and FIG. 16 shows samples used in BVG-DIMD template-cost-fusion for a 16x8 block. As shown in FIG. 15 and FIG. 16, determination for a HoG may be calculated within the first reference area of the current block. The first reference area includes the above template area, a left template area and the areas referenced by BV (one or such areas is denoted as “BV-referenced area” . In subsequent steps of obtaining predictors for templates, for the directional intra prediction modes, the predictors of templates are constructed by propagating samples of reference line inside the template. For BV-predictors, the template predictor is obtained by taking reconstructed samples from the templates of the BV-referenced areas.
[0076] In S103, one or more directional prediction modes are acquired based on the estimation of HoG.
[0077] The HoG can be obtained by applying an edge operator within the first reference area determined in S101. For each position of the edge operator, gradient values are estimated by convolving horizontal and vertical filters of the edge operator with the samples of the first reference area. A bin of histogram is updated by adding magnitude of the gradient, and the bin position within a histogram is determined by estimating a gradient angle (which could be obtained as, e.g., an acrtan of a ration of output of the horizontal filter to the output of the vertical filter) . Magnitude of the gradient could be estimated as a sum of absolute values of outputs of the horizontal and vertical filters.
[0078] The HoG results can be used to determine a list of candidate intra-prediction modes. For example, a set of bins with the highest magnitude values are selected, and the list of candidate intra prediction modes is obtained from the positions of the bins having the highest magnitude in the HoG.
[0079] In some embodiments, the one or more directional prediction modes are selected from results of the estimation of HoG based on their results of the estimation of TM cost, and TM costs of the one or more directional prediction modes are less than a TM cost threshold. The TM cost threshold may be pre-defined; alternatively, the TM cost threshold may be equal to a product of a number of samples in the current block and a pre-set factor; alternatively, the TM cost threshold may be determined based on a TM cost of a first prediction mode sorted based on the results of the estimation of HoG.
[0080] FIG. 17 shows a process for obtaining the candidate fusion mode list for the fusion process with an additional condition on the template matching costs. The steps of this process are explained below.
[0081] In step 1, HoG is constructed. This step is performed in the same way as in the prior art.
[0082] In step 2, modes of HoG are sorted in descending order, so as the modes that have higher magnitudes in HoG precede the ones that have lower magnitudes. Modes that correspond to zero magnitude values are not included into the sorted list of intra prediction modes. Result of this step is the list of Nmodes intra prediction modes sorted in accordance with HoG magnitudes.
[0083] In the next steps, n denotes the number of modes in the output fusion list, Mmax denotes the maximum number of modes in the fusion list. The following steps are performed for selecting the intra prediction modes from the sorted list, starting from the head element of this list.
[0084] In step 1, condition “n< Mmax” guarantees that the output list will contain no more that Mmax maximum number of modes. If at some iteration n becomes equal to Mmax, the steps are complete and the output list of fusion modes having Mmax candidates is ready.
[0085] In step 2, template matching cost is calculated for an intra prediction mode i to determine template matching cost Ci.
[0086] In Step 3, this cost is compared with a threshold CTHR in order to determine whether this mode provides a sufficiently low prediction error for the template area. When this condition is not satisfied, the mode is skipped from consideration and is not included into the output list.
[0087] Threshold CTHR could be defined as follows.
[0088] It can be defined as a predetermined value. For example, CTHR = S·k, where S is the number of samples in the current block and k is a factor; factor k could be set equal to 0.5, 1, 1.5, 2, or some other value. For example, CTHR may be equal to 1.
[0089] Alternatively, it can be defined in relation with the template cost of the first intra prediction mode in the sorted list of intra prediction modes. For example, it can be set equal to this cost. For example, it can be set equal to this cost multiplied by a factor k, wherein k could be set equal to 2, 1.5 or 1.1, or some other predetermined value.
[0090] Alternatively, it can be determined with combination of the above two methods.
[0091] When condition of Step 3 is satisfied, the mode is added to the list of fused modes and the counter of fusion modes n is increased by one.
[0092] In the last step when the iteration of the sorted list is complete, the number of elements in the output list of modes is defined, e.g., by assigning to the last value of fusion modes counter n to 1.
[0093] If the first reference area includes the non-adjacent reference lines, the set of directional prediction modes determined by HoG estimation in the first reference area can be further estimated with consideration of the set of modes that are obtained for the DIMD process of the adjacent reference line (conventional adjacent DIMD) . In particular, the modes, which are included in a set of adjacent DIMD mode, are excluded from consideration when obtaining a set of fusion intra prediction for a reference line.
[0094] An exemplary flowchart of obtaining a set of fusion intra prediction for a reference line with index r is shown in FIG. 18. In this algorithm, a mode i is not added to the list of fusion modes for reference line r when this mode is also used present in one of the fusion modes obtained by DIMD process for the adjacent reference line.
[0095] In an alternative embodiment, instead of “i∈LDIMD” condition, a check of whether the mode i is close to any of the fusion modes of the DIMD set. When the absolute value of the difference between mode i and any of the mode of the DIMD set is greater than some threshold α, a mode i is not added to the list of fusion modes for reference line r. Practical value of threshold α could be defined as 2, 3, or 4. Existing predictor similarity check methods can be applied in this process, such as the similarity check method disclosed in the patent application PCT / CN2024 / 103922 and PCT / CN2024 / 104034.
[0096] In an embodiment, the algorithm is applied when reference line with index r is greater than 1. In another embodiment, the algorithm is applied when reference line with index r is greater than 3.
[0097] In S104, one or more TM cost-based weights of the one or more directional prediction modes are determined based on the estimation of TM cost.
[0098] Predictors may be constructed for each of the candidate prediction modes determined in S103 within the second reference area. The value of TM cost may be calculated as some metric between a predictor and reconstructed samples of the second reference area for estimating the TM cost. The metric may be, for example, SAD, SSD, HAD or a combination metric.
[0099] The weights for each directional prediction modes may be determined from the obtained costs by taking the inverse proportion of the costs values. In other words, the lower template cost is provided by a mode, the higher value of the weight to the predictor of a block for this mode is specified in the fusion process.
[0100] In some embodiments, the operation of determining the one or more TM cost-based weights of the one or more directional prediction modes may include: determining a plurality of candidate prediction modes, wherein the plurality of candidate prediction modes comprise the one or more directional prediction modes; determining TM cost-based weights of the plurality of candidate prediction modes based on their TM costs, wherein a candidate prediction mode having a larger TM cost is determined to have a smaller TM cost-based weight.
[0101] This could be performed using the following formula to determine a weight wi for a predictor with a template matching cost Ci within a set of N predictors:
[0102] Another formula to determine a weight wi for a predictor with a template matching cost Ci within a set of N predictors can be:
[0103] Another formula to determine a weight wi for a predictor with a template matching cost Ci within a set of N predictors can be:
[0104] When performing calculation in fixed-pointer arithmetic, the following steps could be performed.
[0105] In Step 1, for a set of M directional modes, i=0.. M-1 , calculate the weights as follows:
[0106] In the formula, Z is a predetermined normalized sum of weights, is the normalized TM cost of the predictor for the i-th prediction mode. For example, Z could be defined as a power-of-2 value: Z=2k.
[0107] In this example, a practical value of k is selected from [2.. 8] . The value of Z is determined by the bit-depth of the hardware and the maximum number of predictors which are fused.
[0108] Costs in this example are also normalized in the following way:
[0109] In Step 2, for a set of K non-directional modes, i=0.. K-2 , calculate the weights as follows:
[0110] The weight for the last non-directional mode is obtained by subtracting the sum of weights of all the modes from the norm:
[0111] The motivation for this process is in the inaccuracy of integer division operation that is used to obtain normalized costs.
[0112] In some embodiments, the plurality of candidate prediction modes may further include one or more non-directional prediction modes. That is, the fusion process may involve not only the directional prediction modes derived based on HoG, but also some other non-directional prediction modes. TM cost-based weights of the non-directional prediction modes may be determined in a similar way as explained above.
[0113] The non-directional prediction mode may be any of the following: Block-vector (BV) mode, Planar mode, or other non-directional prediction modes (e.g., MIP, PDP, NN-based intra-prediction modes) .
[0114] If non-directional prediction modes are involved in the fusion process, the total TM cost-based weights of the directional prediction modes will be reduced, but the determination method of TM cost-based weight for each mode can remain the same.
[0115] In S105, one or more final weights of the one or more directional prediction modes are determined based on the one or more TM cost-based weights.
[0116] In one embodiment, the final weights of the directional prediction modes may be equal to the corresponding TM cost-based weights of the directional prediction modes. That is, the selection of the directional prediction modes is based on HoG estimation while the final weights of the directional prediction modes may be fully determined by their TM costs.
[0117] In another embodiment, HoG-based weights of the directional prediction modes may be acquired based on the estimation of HoG. Specifically, a directional prediction mode having a larger magnitude in the HoG may be determined to have a larger HoG-based weight. The method for determining the HoG-based weights for the directional prediction modes may use any of existing technologies and will not be elaborated herein. The final weights of the directional prediction modes may be determined based on both the corresponding TM cost-based weights and the corresponding HoG-based weights of the directional prediction modes.
[0118] Specifically, a linear combination of inverse TM cost and HoG magnitude could be used to determine the final weights of the directional prediction modes. The final weights could be obtained as follows:
[0119] In the formula, wHoG (i) is the HoG-based weight of the i-th prediction mode, wTPL (i) is the TM cost-based weight of the i-th prediction mode. and N is the number of intra prediction modes involved in the fusion process, and are renormalization factors.
[0120] It should be noticed, non-directional prediction modes can be involved in the fusion process. In this case, the final weight for a non-directional prediction mode may depend on its TM cost-based weight only. That is, the HoG-based weight for a non-directional prediction mode may be deemed as some constant value, In particular, this constant value could be equal to zero. In another example, the HoG-based weight for a non-directional prediction mode may be assigned to a value which is proportional to an average value of HoG-based weights of all the directional prediction modes involved in the fusion process.
[0121] Optionally, weights determined by template matching costs may be determined to have more impact on the resulting weights. In this case, a scaling factor for the Tm cost-based weights may be acquired, and the one or more final weights of the one or more directional prediction modes are calculated based on the one or more TM cost-based weights scaled with the scaling factor and the one or more HoG-based weights: where γ is the scaling factor (or called template matching cost prioritization factor) .
[0122] Practical values of γ could be defined, e.g., as So as the weights determined by template matching cost will have more impact on the resulting weight than the weights determined by HoG.
[0123] In another embodiment, renormalization could be performed base on weights multiplication, so as to prioritize modes that have high weights for both determination methods: based on HoG and based on template cost. For a given norm Z (that determines precision of weighting in the fusion process) , the following steps are performed: w* (i) =wHoG (i) ·wTPL (i) w (i) =k·w* (i) , where
[0124] The target fusion weight norm Z could be predetermined to such values as 8, 16, 32, 64, 128, or 256.
[0125] For weight w* (i) that have the smallest value, the resulting weight w (i) could be obtained as so as to handle the rounding effect of fixed-point division operation when calculating the value of k.
[0126] In S106, the one or more directional prediction modes are applied with the one or more final weights for generating predicted samples of the current block.
[0127] With the final weights, a fused predictor generated from predictors of the directional prediction modes can be obtained for prediction of the current block.
[0128] In the above method shown in FIG. 10, template matching costs of the directional prediction modes are utilized in determining weights of these directional prediction modes in the fusion prediction process. Impact of an intra prediction mode on the overall predictor is estimated by how well this intra mode can predict the template of the current block. Therefore, the prediction accuracy of the fusion prediction process may be improved.
[0129] The present disclosure further provides a method for redistribution of HoG-derived weights for non-adjacent DIMD. FIG. 19 is a flowchart of a decoding method according to another embodiment of the present disclosure. As shown in FIG. 19, the method includes operations described in blocks S201 to S207.
[0130] In S201, a reference area of a current block for estimation of HoG is determined.
[0131] In S202, one or more directional prediction modes and their original weights are acquired.
[0132] In S203, one or more non-directional prediction modes and their corresponding weights are acquired.
[0133] In S204, a first weight sum is determined by summing the original weights of the one or more directional prediction modes.
[0134] In S205, a second weight sum is determined by summing the original weights of the one or more directional prediction modes and the weights of the one or more non-directional prediction modes.
[0135] In S206, a weight scale is acquired which is equal to the second weight sum divided by the first weight sum.
[0136] In S207, weights of the one or more directional prediction modes are normalized based on the weight scale and the norm number.
[0137] The operation of normalizing weights of the one or more directional prediction modes based on the weight scale and the norm number may include: for each of the one or more directional prediction modes except for a last mode, determining its weight to be substantially equal to its original weight times the weight scale; and for the last mode, determining its weight to be equal to a difference between the norm number and a sum of normalized weights of other of the one or more directional prediction modes.
[0138] A detailed explanation of the process is given below with reference to FIG. 20.
[0139] In the fusion process of non-adjacent DIMD, planar component are not engaged. The set of weights could be obtained by reusing of the weight calculation module of casual DIMD, taking only a subset of derived intra prediction modes (e.g., without non-directional component) and recalculate the values of weight for this selected subset of intra prediction modes.
[0140] The initial steps of this embodiment could be performed as in the prior art, or as described in foregoing sections of the present disclosure.
[0141] The step “Select subset of modes” (step 1) may be performed by selecting only the directional modes from the overall set of modes. In another embodiment, the subset could be determined with consideration of template costs for these modes.
[0142] The step “Get weight scale” (step 2) may be performed by performed as follows:
[0143] In the formula, s is the sum of all the non-normalized weights w* (i) in the subset of modes; ssub is the sum of weights for the modes of the subset of modes that we want after normalization, e.g., ssub may be equal to a required norm number; and p is a precision parameter for the redistribution operation. A practical value of parameter p could be set equal to 10.
[0144] In step 3, the output weight for the last intra prediction mode in the subset of modes is initialized to ssub, and in the following steps this output weight is decreased by the values of determined weights for the other modes.
[0145] For each of the modes of the output subset except the last one, the following scaling step (step 4) is performed. In this step the output value of weight w (i) is obtained from the input weight w* (i) by scaling: w (i) = (fs·w* (i) +ro ) >>p where ro= (1<<p) >>1 is the rounding offset depending on the precision parameter p.
[0146] In this method, the input weights are determined with the understanding that non-directional prediction modes and non-directional weights are also present. However, only the directional modes and their corresponding weights are being considered for this particular process.
[0147]
[0148] The present disclosure further provides a decoding method involving weight determination for reference samples that are constructed from different reference areas. FIG. 21 is a flowchart of a decoding method according to yet another embodiment of the present disclosure. As shown in FIG. 21, the method includes operations described in blocks S301 to S307.
[0149] In S301, a first reference area of a current block is determined.
[0150] In S302, a second reference area of the current block is determined.
[0151] In S303, a prediction mode is determined.
[0152] In S304, a first TM cost within a template area of the current block is acquired based on the first reference area and the prediction mode.
[0153] In S305, a second TM cost within the template area is acquired based on the second reference area and the prediction mode.
[0154] In S306, a first weight for the first reference area and a second weight for the second reference area are determined based on the first TM cost and the second TM cost.
[0155] In S307, predicted samples of the current block are generated based on reference samples within the first reference area scaled by the first weight and / or reference samples within the second reference area scaled by the second weight.
[0156] In one embodiment, the operation of determining the first weight for the first reference area and the second weight for the second reference area based on the first TM cost and the second TM cost may include: acquiring a first factor; when the first TM cost is less than the second TM cost, and a product of the first TM cost and the first factor is less than the second TM cost, determining the second weight to be zero and determining the first weight to be a norm number. Alternatively or additionally, the operation of determining the first weight for the first reference area and the second weight for the second reference area based on the first TM cost and the second TM cost may further include: acquiring a second factor; when the second TM cost is less than the first TM cost, and a product of the second TM cost and the second factor is less than the first TM cost, determining the first weight to be zero and determining the second weight to be the norm number.
[0157] In one embodiment, the first weight is substantially equal to a norm number multiplied by a ratio of the second TM cost to a sum of the first TM cost and the second TM cost. The second weight is substantially equal to the norm number multiplied by a ratio of the first TM cost to a sum of the first TM cost and the second TM cost.
[0158] A detailed explanation of the process is given below with reference to FIGs. 22 to 24.
[0159] In this embodiment parameters of intra fusion are determined using template matching costs obtained for predictors that are constructed from reference samples of the main reference line (see FIG. 22) and reference samples of the adjacent reference line (see FIG. 23) .
[0160] In the first two steps, template costs Cmain and Cadj are calculated for main and adjacent reference lines, respectively. In the next step, costs are compared with each other, in the next two checks.
[0161] If Cadj < Cmain and Cmain is greater that Cadj at least k1 times, intra prediction for the block is defined to be performed from the main reference line.
[0162] If Cmain < Cadj and Cadj is greater that Cmain at least k2 times, intra prediction for the block is defined to be performed from the adjacent reference line.
[0163] The practical value of k1 and k2 could be set equal to 1.1, 1.5, 2, or some other integer value. These values could be obtained, e.g., by training over some dataset.
[0164] In a particular embodiment, k1 = k2=k.
[0165] In another embodiment, k could be determined based on the block size (see Table 1 below) . Table 1
[0166] In yet another embodiment, k could be determined based on the block size (see Table 2 below) . Table 2
[0167] It could be noticed, that selection of the reference line for prediction could be performed by allocating fusion weights for the predictors obtained for the main and adjacent reference lines to the maximum value Z and minimum value 0.
[0168] When neither of the conditions shown in FIG. 24 are fulfilled, the weights for the predictors obtained for the main and adjacent reference lines are set based on template costs Cmain and Cadj, e.g., as follows: wmain= (Z·Cadj+ro) / s wadj=Z-wmain s=Cadj+Cmain ro=s>>1
[0169] Alternatively, when neither of the conditions shown in FIG. 24 are fulfilled, the weights for the predictors are defined to some default values. For example, when the weighting norm value of Z is equal to 64, wmain may be equal to 48 while wadj may be equal to 16.
[0170] In this process, the TM cost-based weighting may be related to reference lines instead of prediction modes. The result of the process may also be utilized in fusion prediction process to improve prediction accuracy.
[0171] The present disclosure further provides an encoding method involving weight determination for predictors. FIG. 25 is a flowchart of an encoding method according to an embodiment of the present disclosure. As shown in FIG. 25, the method includes operations described in blocks S401 to S406.
[0172] In S401, a first reference area of a current block for estimation of histogram of gradients (HoG) is determined.
[0173] In S402, a second reference area of the current block for estimation of template matching (TM) cost is determined.
[0174] In S403, one or more directional prediction modes are acquired based on the estimation of HoG.
[0175] In S404, one or more TM cost-based weights of the one or more directional prediction modes are determined based on the estimation of TM cost.
[0176] In S405, one or more final weights of the one or more directional prediction modes are determined based on the one or more TM cost-based weights.
[0177] In S406, the one or more directional prediction modes are applied with the one or more final weights for generating predicted samples of the current block.
[0178] The method described with regard to FIG. 25 may be similar to the method described with regard to FIG. 10, details of which will not be repeated for simplicity and clarity.
[0179] Optionally, after performing the predictor weight determination process, the encoding device may transmit information relative to the weight determination process to a corresponding decoder via a bitstream. For example, the information may include: indication of the criteria for selecting the directional prediction modes, indication for the first reference area and / or the second reference area, any scaling factor used in the process, etc.
[0180] According to some embodiments of the present disclosure, a set of modes that are used to perform intra prediction are based on gradients within a template area. Thus, implementation of the present disclosure may improve prediction accuracy. The benefits of TIMD and DIMD mechanisms are combined within this method.
[0181] On one hand, an intra prediction mode that is selected as one of the fusion modes for predicting a current block is determined with consideration of the directionality of edges in the template area, i.e., direction of edges in the template. On the other hand, the impact of an intra prediction mode on the overall predictor is estimated by how well this intra mode can predict the template of the current block: not necessarily intra prediction modes that corresponds to higher gradient magnitude values in HoG provide more accurate prediction of a template.
[0182] The present disclosure further provides a method for enabling alternative interpolation filter for the intra prediction mechanisms that engage intra prediction fusion.
[0183] When several intra predictors are combined in a fusion process, the resulting predictor is blurred as compared to an input intra predictor of the fusion process. This blurring occurs because: 1) different intra prediction modes propagate reference samples with different angles, and the position of the edges in a predicted block is different; and 2) different reference lines used in intra prediction have different samples that are propagated inside the block.
[0184] For this reason, a less smoothing interpolation filter for obtaining an input intra predictor may be more beneficial, since the resulting fused predictor will be less blurry in this case.
[0185] In this embodiment, an alternative set of interpolation filter coefficients is used, when the process of intra prediction comprises a fusion process.
[0186] In an embodiment, when TMRL flag is indicated for a block, the alternative interpolation filter is used when obtaining angular prediction (e.g., in the intra fusion process) .
[0187] In an embodiment, when no-adjacent DIMD fusion flag is indicated for a block, the alternative interpolation filter is used when obtaining input predictors for the fusion process.
[0188] In an embodiment, when TIMD flag is enabled, the alternative interpolation filter is used when obtaining input predictors for the fusion process.
[0189] In an embodiment, when DIMD flag is enabled, the alternative interpolation filter is used when obtaining input predictors for the fusion process.
[0190] In an embodiment, the alternative interpolation filter is set as follows (see Table 3) : Table 3
[0191] In an embodiment, the alternative interpolation filter is set as follows (see Table 4) : Table 4
[0192] In an embodiment, alternative interpolation filter is used when the size of the block S is less than a threshold TS. The process is illustrated in FIG. 26. The size of the block S is the number of samples that the block comprises.
[0193] The practical values of the threshold TS may be set equal to 256, or 512 samples.
[0194] In an embodiment, condition “is fusion enabled” is true, when a TMRL flag is enabled for this block.
[0195] In an embodiment, condition “is fusion enabled” is true, when a TIMD flag is enabled for this block.
[0196] In an embodiment, condition “is fusion enabled” is true, when a DIMD flag is enabled for this block.
[0197] In an embodiment, condition “is fusion enabled” is true when a single intra prediction mode is used to obtain a block predictor, e.g., in an intra fusion process.
[0198] In an embodiment, condition “is fusion enabled” is true when the number of fusion modes (e.g., in DIMD) is less than a threshold. Particular threshold values could be set equal to 2, 3, or 4 modes.
[0199] In an embodiment, condition “is fusion enabled” is true when BV predictor is selected as non-directional component of DIMD.
[0200] In an embodiment, condition “is fusion enabled” is true when DIMD is performed for the current block and the HoG magnitude for the first DIMD intra prediction mode is greater than the HoG magnitude for the second DIMD mode by a factor of k in the list of fusion DIMD mode. In practice, the factor k may be set equal to 1.1, 1.5 or 2.
[0201] In an embodiment, wherein instead of ” S<TS” condition, the following condition is used: max (W, H) < 8 where W is block width and H is block height.
[0202] In an embodiment, wherein instead of ” S<TS” condition, the following condition is used: max (W, H) < 16 where W is block width and H is block height.
[0203] FIG. 27 conceptually illustrates an apparatus 500 with which some embodiments of the invention are implemented. The apparatus 500 may be a decoder or an encoder. The apparatus 500 may be a computer (e.g., a desktop computer, personal computer, tablet computer, etc. ) , phone, PDA, or any other sort of electronic device. Such an apparatus includes various types of computer readable media and interfaces for various other types of computer readable media. The apparatus 500 includes a processor 502 and a memory 504. The memory 504 is configured to store executable instructions that, when executed by the processor, cause the processor to perform any one of the foregoing decoding or encoding methods.
[0204] The processor 502 may be a single processor or a multi-core processor in different embodiments. In some embodiments, the processor may include a GPU, NPU or DSP which may offload various computations or complement the image processing provided by the processor 502.
[0205] Some embodiments include electronic components, such as microprocessors, storage and memory that store computer program instructions in a machine-readable or computer-readable medium (alternatively referred to as computer-readable storage media, machine-readable media, or machine-readable storage media) . Some examples of such computer-readable media include RAM, ROM, read-only compact discs (CD-ROM) , recordable compact discs (CD-R) , rewritable compact discs (CD-RW) , read-only digital versatile discs (e.g., DVD-ROM, dual-layer DVD-ROM) , a variety of recordable / rewritable DVDs (e.g., DVD-RAM, DVD-RW, DVD+RW, etc. ) , flash memory (e.g., SD cards, mini-SD cards, micro-SD cards, etc. ) , magnetic and / or solid state hard drives, read-only and recordable discs, ultra density optical discs, any other optical or magnetic media, and floppy disks. The computer-readable media may store a computer program that is executable by at least one processing unit and includes sets of instructions for performing various operations. Examples of computer programs or computer code include machine code, such as is produced by a compiler, and files including higher-level code that are executed by a computer, an electronic component, or a microprocessor using an interpreter.
[0206] While the above discussion primarily refers to microprocessor or multi-core processors that execute software, some embodiments are performed by one or more integrated circuits, such as application specific integrated circuits (ASICs) or field programmable gate arrays (FPGAs) . In some embodiments, such integrated circuits execute instructions that are stored on the circuit itself. In addition, some embodiments execute software stored in programmable logic devices (PLDs) , ROM, or RAM devices.
[0207] As used in this specification and any claims of this application, the terms “computer” , “server” , “processor” , and “memory” all refer to electronic or other technological devices. These terms exclude people or groups of people. As used in this specification and any claims of this application, the terms “computer readable medium, ” “computer readable media, ” and “machine readable medium” are entirely restricted to tangible, physical objects that store information in a form that is readable by a computer. These terms exclude any wireless signals, wired download signals, and any other ephemeral signals.
[0208] The present disclosure further provides a computer readable media which is configured to store executable instructions. When the instructions are executed by a processor, the processor may perform any one of the foregoing methods and processes. Many of the above-described features and applications are implemented as software processes that are specified as a set of instructions recorded on a computer readable storage medium (also referred to as computer readable medium) . When these instructions are executed by one or more computational or processing unit (s) (e.g., one or more processors, cores of processors, or other processing units) , they cause the processing unit (s) to perform the actions indicated in the instructions. Examples of computer readable media include, but are not limited to, CD-ROMs, flash drives, random access memory (RAM) chips, hard drives, erasable programmable read only memories (EPROMs) , electrically erasable programmable read-only memories (EEPROMs) , etc. The computer readable media does not include carrier waves and electronic signals passing wirelessly or over wired connections.
[0209] In this specification, the term “software” is meant to include firmware residing in read-only memory or applications stored in magnetic storage which can be read into memory for processing by a processor. Also, in some embodiments, multiple software inventions can be implemented as sub-parts of a larger program while remaining distinct software inventions. In some embodiments, multiple software inventions can also be implemented as separate programs. Finally, any combination of separate programs that together implement a software invention described here is within the scope of the invention. In some embodiments, the software programs, when installed to operate on one or more electronic systems, define one or more specific machine implementations that execute and perform the operations of the software programs.
[0210] While the disclosure has been described with reference to numerous specific details, one of ordinary skill in the art will recognize that the invention can be embodied in other specific forms without departing from the spirit of the invention. In addition, a number of the figures conceptually illustrate processes and methods. The specific operations of these processes may not be performed in the exact order shown and described. The specific operations may not be performed in one continuous series of operations, and different specific operations may be performed in different embodiments. Furthermore, the process could be implemented using several sub-processes, or as part of a larger macro process.
[0211] The foregoing is merely embodiments of the present disclosure, and is not intended to limit the scope of the disclosure. Any transformation of equivalent structure or equivalent process which uses the specification and the accompanying drawings of the present disclosure, or directly or indirectly application in other related technical fields, are likewise included within the scope of the protection of the present disclosure.
Claims
1.A decoding method, comprising:determining a first reference area of a current block for estimation of histogram of gradients (HoG) ;determining a second reference area of the current block for estimation of template matching (TM) cost;acquiring one or more directional prediction modes based on the estimation of HoG;determining one or more TM cost-based weights of the one or more directional prediction modes based on the estimation of TM cost;determining one or more final weights of the one or more directional prediction modes based on the one or more TM cost-based weights; andapplying the one or more directional prediction modes with the one or more final weights for generating predicted samples of the current block.2.The method of claim 1, whereinthe first reference area comprises an above template area and a left template area of the current block.3.The method of claim 1, whereinthe first reference area comprises a primary reference line and a secondary reference line which are non-adjacent to the current block;the second reference area comprises an above template area and a left template area of the current block, or the second reference area comprises an adjacent reference line of the current block.4.The method of claim 1, whereinthe first reference area comprises an above template area, a left template area and a reference area of a non-directional prediction mode;the second reference area comprises the above template area and the left template area.5.The method of claim 1, wherein the determining the one or more TM cost-based weights of the one or more directional prediction modes comprises:determining a plurality of candidate prediction modes, wherein the plurality of candidate prediction modes comprise the one or more directional prediction modes;determining TM cost-based weights of the plurality of candidate prediction modes based on their TM costs, wherein a candidate prediction mode having a larger TM cost is determined to have a smaller TM cost-based weight.6.The method of claim 5,wherein the plurality of candidate prediction modes further comprise one or more non-directional prediction modes.7.The method of claim 5, wherein the one or more final weights of the one or more directional prediction modes are equal to the TM cost-based weights of the one or more directional prediction modes.8.The method of claim 5, further comprising:acquiring one or more HoG-based weights of the one or more directional prediction modes based on the estimation of HoG, wherein a directional prediction mode having a larger magnitude in the HoG is determined to have a larger HoG-based weight;wherein the determining the one or more final weights of the one or more directional prediction modes based on the one or more TM cost-based weights comprises:determining the one or more final weights of the one or more directional prediction modes based on the one or more TM cost-based weights and the one or more HoG-based weights.9.The method of claim 8, further comprising:acquiring a scaling factor for the one or more TM cost-based weights;wherein the one or more final weights of the one or more directional prediction modes are calculated based on the one or more TM cost-based weights scaled with the scaling factor and the one or more HoG-based weights.10.The method of claim 1,wherein the one or more directional prediction modes are selected from results of the estimation of HoG based on their results of the estimation of TM cost, wherein a TM costs of the one or more directional prediction modes are less than a TM cost threshold.11.The method of claim 10, whereinthe TM cost threshold is pre-defined; orthe TM cost threshold is equal to a product of a number of samples in the current block and a pre-set factor; orthe TM cost threshold is determined based on a TM cost of a first prediction mode sorted based on the results of the estimation of HoG.12.A decoding method, comprising:determining a reference area of a current block for estimation of histogram of gradients (HoG) ;acquiring one or more directional prediction modes and their original weights;acquiring one or more non-directional prediction modes and their corresponding weights;determining a first weight sum by summing the original weights of the one or more directional prediction modes;determining a second weight sum by summing the original weights of the one or more directional prediction modes and the weights of the one or more non-directional prediction modes, wherein the second weight sum is equal to a norm number;acquiring a weight scale which is equal to the second weight sum divided by the first weight sum; andnormalizing weights of the one or more directional prediction modes based on the weight scale and the norm number.13.The method of claim 12, wherein the normalizing weights of the one or more directional prediction modes based on the weight scale and the norm number comprises:for each of the one or more directional prediction modes except for a last mode, determining its weight to be substantially equal to its original weight times the weight scale; andfor the last mode, determining its weight to be equal to a difference between the norm number and a sum of normalized weights of other of the one or more directional prediction modes.14.A decoding method, comprising:determining a first reference area of a current block;determining a second reference area of the current block;determining a prediction mode;acquiring a first template matching (TM) cost within a template area of the current block based on the first reference area and the prediction mode;acquiring a second TM cost within the template area based on the second reference area and the prediction mode;determining a first weight for the first reference area and a second weight for the second reference area based on the first TM cost and the second TM cost; andgenerating predicted samples of the current block based on reference samples within the first reference area scaled by the first weight and / or reference samples within the second reference area scaled by the second weight.15.The method of claim 14, wherein the determining the first weight for the first reference area and the second weight for the second reference area based on the first TM cost and the second TM cost comprises:acquiring a first factor;when the first TM cost is less than the second TM cost, and a product of the first TM cost and the first factor is less than the second TM cost, determining the second weight to be zero and determining the first weight to be a norm number.16.The method of claim 15, wherein the determining the first weight for the first reference area and the second weight for the second reference area based on the first TM cost and the second TM cost comprises:acquiring a second factor;when the second TM cost is less than the first TM cost, and a product of the second TM cost and the second factor is less than the first TM cost, determining the first weight to be zero and determining the second weight to be the norm number.17.The method of claim 14,wherein the first weight is substantially equal to a norm number multiplied by a ratio of the second TM cost to a sum of the first TM cost and the second TM cost;wherein the second weight is substantially equal to the norm number multiplied by a ratio of the first TM cost to a sum of the first TM cost and the second TM cost.18.An encoding method, comprising:determining a first reference area of a current block for estimation of histogram of gradients (HoG) ;determining a second reference area of the current block for estimation of template matching (TM) cost;acquiring one or more directional prediction modes based on the estimation of HoG;determining one or more TM cost-based weights of the one or more directional prediction modes based on the estimation of TM cost;determining one or more final weights of the one or more directional prediction modes based on the one or more TM cost-based weights; andapplying the one or more directional prediction modes with the one or more final weights for generating predicted samples of the current block.19.An apparatus for video decoding or encoding, comprising a processor and a memory, wherein the memory is configured to store executable instructions that, when executed by the processor, cause the processor to perform the method of any of claims 1 to 18.20.A computer readable non-transitory medium storing executable instructions that, when executed by a processor, cause the processor to perform the method of any of claims 1 to 18.