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?
1 Answer
Then its 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 the decoding process you create the true sized image as 29 x 27.
-
2$\begingroup$ Good answer, but I would suggest padding the image with something better than zeros. The addition of zeros will introduce a lot more high frequency content to your image and may cause distortion if you're using DCT to compress. One alternative is to repeat the value at the edge of the image, but just see what gives you the best results. $\endgroup$– goldrikNov 13, 2017 at 22:17
-
2$\begingroup$ Different padding options are allowed in the standard, as mentioned in the answer to the previous question on [JPEG DCT padding ](dsp.stackexchange.com/a/35343/15892) $\endgroup$ Nov 14, 2017 at 9:14