1. A method of encoding an image, the method comprising: determining a context model to be used to entropy encode a residual value of a current pixel with reference to at least one pixel value that is encoded before the current pixel; determining a residual value group to which the residual value belongs, based on the determined context model; selecting a code table based on the determined context model and the determined residual value group; and entropy encoding the residual value according to the selected code table.