I am trying to implement image compression using fft. I follow these steps:
- Pad the height and weight of the input image to be powers of two (for easier DFT application)
- For each of the red, green and blue channels:
- Transform each row to its DFT
- Transform each column to its DFT
- Turn the bottom CR% (compression rate) of the elements into zero (according to the size of the absolute value)
- Inverse transform each column
- Inverse transform each row
- Unpad the image to it's original dimensions
I tried this experiment on the image below with compression rates 10, 50, and 90, and here are the results
As you can see, it mostly works fine, except there some patchy areas in certain dark regions of the image.
My question is, is this an expected behavior assuming the steps above are followed? If yes, what kind of mitigation techniques exist to avoid this? Also, could this be caused by numerical errors and why exactly does this happen mostly on dark areas?
I tried adjusting the compression rate, but the patchy areas appear as low as at 20% compression rate, which means I am not able to get a reasonable compression.
EDIT: I also get interesting results with this picture:
Looks like thing break when there are areas that are too dark or too light
SOLUTION: As was mentioned in the comments, I was converting to uint8 which cased small negatives to turn into large values and vice versa. Clipping at 0 and 255 after applying the inverse transform fixed the issue.