I have learned that an image is to be divided by 8*8 blocks, and the 2D DCT is then applied to these blocks. My question is, what if the image is not divisible by 8? What should I do in this case?
Then it's size is extended by padding zeros or repeating at the end, such that the new size is divisible by 8. Note that reverse repetition at the end reduces the DCT compression size on that block compared to a zero pad approach.
For example if the image was 29 x 27 , then you should add 3 pixels at the right end and 5 lines at the bottom so that it becomes 32 x 32.
Note that you should include the pixel size of the image in the header part so that during decoding process you create the true sized image as 29 x 32