Image encoding/decoding method and device for performing BDOF, and method for transmitting bitstream
An image encoding/decoding method and apparatus are provided. An image decoding method according to the present disclosure is performed by an image decoding apparatus. The image decoding method may comprise deriving a prediction sample of a current block based on motion information of the current block, determining whether bi-directional optical flow (BDOF) applies to the current block, based on that the BDOF applies to the current block, deriving a gradient for a current subblock in the current block, deriving motion refinement (v x , v y ) for the current subblock based on the gradient, deriving a BDOF offset based on the gradient and the motion refinement, and deriving a refined prediction sample for the current block based on the prediction sample of the current block and the BDOF offset.
1 . An image decoding method performed by an image decoding apparatus, the image decoding method comprising:
deriving a L0 prediction sample and a L1 prediction sample of a current block based on motion information of the current block;
deriving a gradient for a predetermined area including a current subblock in the current block;
deriving motion offset (vx, vy) for the current subblock based on the gradient;
deriving a BDOF (Bi-directional Optical Flow) offset based on the gradient and the motion offset; and
deriving a prediction sample for the current block based on the L0 prediction sample, the L1 prediction sample of the current block, the BDOF offset and a fourth shift,
wherein a value of the fourth shift is derived based on a bit depth of the current block,
wherein the gradient is derived by right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a first shift,
wherein the deriving the motion offset (vx, vy) comprises:
deriving a first intermediate parameter diff by subtracting the L1 prediction sample of the current block from the L0 prediction sample of the current block; and
deriving second intermediate parameters tempH and tempV by right-shifting the gradient by a third shift,
wherein the deriving the first intermediate parameter diff comprises right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a second shift,
wherein the first shift, the second shift and the third shift are set to a fixed value regardless of a bit depth of the current block,
wherein a value of the first shift is different from a value of the second shift and a value of the third shift, and
wherein a value of the second shift is different from a value of the third shift.
2 . The image decoding method of claim 1 , wherein the first shift is 6.
3 . The image decoding method of claim 1 , wherein the second shift is 4.
4 . The image decoding method of claim 1 , wherein the third shift is 1.
5 . The image decoding method of claim 1 , wherein the motion offset (vx, vy) is clipped in a predetermined range.
6 . The image decoding method of claim 5 , wherein the predetermined range in which the motion offset (vx, vy) is clipped is set to a fixed range regardless of a bit depth of the current block.
7 . The image decoding method of claim 1 ,
wherein the deriving the BDOF offset comprises right-shifting, by a predetermined shift, a value derived based on the gradient and the motion offset, and
wherein the predetermined shift is set to a fixed range regardless of a bit depth of the current block.
8 . The image decoding method of claim 1 ,
wherein the deriving the prediction sample for the current block comprises clipping the BDOF offset in a predetermined range, and
wherein the predetermined range is set based on a bit depth of the current block.
9 . An image encoding method performed by an image encoding apparatus, the image encoding method comprising:
deriving a L0 prediction sample and a L1 prediction sample of a current block based on motion information of the current block;
deriving a gradient for a predetermined area including a current subblock in the current block;
deriving motion offset (vx, vy) for the current subblock based on the gradient;
deriving a BDOF (Bi-directional Optical Flow) offset based on the gradient and the motion offset; and
deriving a prediction sample for the current block based on the L0 prediction sample, the L1 prediction sample of the current block, the BDOF offset and a fourth shift,
wherein a value of the fourth shift is derived based on a bit depth of the current block,
wherein the gradient is derived by right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a first shift,
wherein the deriving the motion offset (vx, vy) comprises:
deriving a first intermediate parameter diff by subtracting the L1 prediction sample of the current block from the L0 prediction sample of the current block; and
deriving second intermediate parameters tempH and tempV by right-shifting the gradient by a third shift,
wherein the deriving the first intermediate parameter diff comprises right-shifting the LO prediction sample and the L1 prediction sample of the current block by a second shift,
wherein the first shift, the second shift and the third shift are set to a fixed value regardless of a bit depth of the current block,
wherein a value of the first shift is different from a value of the second shift and a value of the third shift, and
wherein a value of the second shift is different from a value of the third shift.
10 . A method of transmitting a bitstream comprising:
deriving a L0 prediction sample and a L1 prediction sample of a current block based on motion information of the current block;
deriving a gradient for a predetermined area including a current subblock in the current block;
deriving motion offset (vx, vy) for the current subblock based on the gradient;
deriving a BDOF (Bi-directional Optical Flow) offset based on the gradient and the motion offset;
deriving a prediction sample for the current block based on the L0 prediction sample, the L1 prediction sample of the current block, the BDOF offset and a fourth shift;
encoding the current block based on the prediction sample to generate the bitstream; and
transmitting the bitstream,
wherein a value of the fourth shift is derived based on a bit depth of the current block,
wherein the gradient is derived by right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a first shift,
wherein the deriving the motion offset (vx, vy) comprises:
deriving a first intermediate parameter diff by subtracting the L1 prediction sample of the current block from the L0 prediction sample of the current block; and
deriving second intermediate parameters tempH and tempV by right-shifting the gradient by a third shift,
wherein the deriving the first intermediate parameter diff comprises right-shifting the L0 prediction sample and the L1 prediction sample of the current block by a second shift,
wherein the first shift, the second shift and the third shift are set to a fixed value regardless of a bit depth of the current block,
wherein a value of the first shift is different from a value of the second shift and a value of the third shift, and
wherein a value of the second shift is different from a value of the third shift.