An image decoding method performed by a decoding apparatus, the method comprising: obtaining residual information and a low-frequency non-separable transform (LFNST) index from a bitstream; deriving transform coefficients for a current block from the residual information; deriving residual samples for the current block by performing an inverse primary transform on the transform coefficients using transform kernels for vertical and horizontal directions; and generating a reconstructed picture by adding prediction samples for the current block and the residual samples, characterized in that in response to the current block being divided into sub-partition blocks as an intra sub-partition, ISP, is applied and the LFNST index being equal to 0, the transform kernel for the vertical direction is determined by checking a vertical length of a sub-partition block divided from the current block, and the transform kernel for the horizontal direction is determined by checking a horizontal length of the sub-partition block, wherein the transform kernel for the vertical direction is determined as DST-7 for the sub-partition block whose vertical length is checked to be equal to or greater than 4 and less than or equal to 16, and the transform kernel for the vertical direction is determined as DCT-2 for the sub-partition block whose vertical length is checked not to be equal to or greater than 4 and less than or equal to 16, wherein the transform kernel for the horizontal direction is determined as DST-7 for the sub-partition block whose horizontal length is checked to be equal to or greater than 4 and less than or equal to 16, and the transform kernel for the horizontal direction is determined as DCT-2 for the sub-partition block whose horizontal length is checked not to be equal to or greater than 4 and less than or equal to 16, and wherein in response to the current block being divided into the sub-partition blocks as the ISP is applied and the LFNST index being greater than 0, the transform kernels for the vertical and horizontal directions are respectively determined as DCT-2. obtaining residual information and a low-frequency non-separable transform (LFNST) index from a bitstream; deriving transform coefficients for a current block from the residual information; deriving residual samples for the current block by performing an inverse primary transform on the transform coefficients using transform kernels for vertical and horizontal directions; and generating a reconstructed picture by adding prediction samples for the current block and the residual samples, characterized in that in response to the current block being divided into sub-partition blocks as an intra sub-partition, ISP, is applied and the LFNST index being equal to 0, the transform kernel for the vertical direction is determined by checking a vertical length of a sub-partition block divided from the current block, and the transform kernel for the horizontal direction is determined by checking a horizontal length of the sub-partition block, wherein the transform kernel for the vertical direction is determined as DST-7 for the sub-partition block whose vertical length is checked to be equal to or greater than 4 and less than or equal to 16, and the transform kernel for the vertical direction is determined as DCT-2 for the sub-partition block whose vertical length is checked not to be equal to or greater than 4 and less than or equal to 16, wherein the transform kernel for the horizontal direction is determined as DST-7 for the sub-partition block whose horizontal length is checked to be equal to or greater than 4 and less than or equal to 16, and the transform kernel for the horizontal direction is determined as DCT-2 for the sub-partition block whose horizontal length is checked not to be equal to or greater than 4 and less than or equal to 16, and wherein in response to the current block being divided into the sub-partition blocks as the ISP is applied and the LFNST index being greater than 0, the transform kernels for the vertical and horizontal directions are respectively determined as DCT-2.