A video decoding apparatus for decoding an encoded image, the video decoding apparatus comprising: a matrix reference pixel derivation unit configured to derive reference samples by using top neighboring samples and left neighboring samples of a current block, wherein each of the top neighboring samples and the left neighboring samples are derived by performing a down-sampling process for matrix-based intra sample prediction; a weight matrix derivation unit configured to derive a weight matrix, which is defined by using a prediction size, based on an intra prediction mode and a size index; a matrix prediction image derivation unit configured to derive a prediction image, which is defined by using the prediction size, by using a product-sum operation, which is performed by using (i) sample values in the reference samples and (ii) elements in the weight matrix; and a matrix prediction image interpolation unit configured to derive a predicted image by using the prediction image, wherein: the size index is derived according to a value of a transform block width and a value of a transform block height, the prediction size is derived by using the size index, in a case that a first condition, that both the value of the transform block width and the value of the transform block height are equal to 4, is true, the size index is set equal to 0 and the prediction size is set equal to 4, in a case that the first condition is false and a second condition, that (i) either the value of the transform block width or the value of the transform block height is equal to 4 or (ii) both the value of the transform block width and the value of the transform block height are equal to 8, is true, the size index is set equal to 1 and the prediction size is set equal to 4, and in a case that the first condition is false and the second condition is false, the size index is set equal to 2 and the prediction size is set equal to 8. a matrix reference pixel derivation unit configured to derive reference samples by using top neighboring samples and left neighboring samples of a current block, wherein each of the top neighboring samples and the left neighboring samples are derived by performing a down-sampling process for matrix-based intra sample prediction; a weight matrix derivation unit configured to derive a weight matrix, which is defined by using a prediction size, based on an intra prediction mode and a size index; a matrix prediction image derivation unit configured to derive a prediction image, which is defined by using the prediction size, by using a product-sum operation, which is performed by using (i) sample values in the reference samples and (ii) elements in the weight matrix; and a matrix prediction image interpolation unit configured to derive a predicted image by using the prediction image, wherein: the size index is derived according to a value of a transform block width and a value of a transform block height, the prediction size is derived by using the size index, in a case that a first condition, that both the value of the transform block width and the value of the transform block height are equal to 4, is true, the size index is set equal to 0 and the prediction size is set equal to 4, in a case that the first condition is false and a second condition, that (i) either the value of the transform block width or the value of the transform block height is equal to 4 or (ii) both the value of the transform block width and the value of the transform block height are equal to 8, is true, the size index is set equal to 1 and the prediction size is set equal to 4, and in a case that the first condition is false and the second condition is false, the size index is set equal to 2 and the prediction size is set equal to 8. the size index is derived according to a value of a transform block width and a value of a transform block height, the prediction size is derived by using the size index, in a case that a first condition, that both the value of the transform block width and the value of the transform block height are equal to 4, is true, the size index is set equal to 0 and the prediction size is set equal to 4, in a case that the first condition is false and a second condition, that (i) either the value of the transform block width or the value of the transform block height is equal to 4 or (ii) both the value of the transform block width and the value of the transform block height are equal to 8, is true, the size index is set equal to 1 and the prediction size is set equal to 4, and in a case that the first condition is false and the second condition is false, the size index is set equal to 2 and the prediction size is set equal to 8.