How to discard coefficients in the frequency domain without losing too much quality? I was reading a text that shows that one can throw away 66% of the coefficients and gets an image that is still acceptable.

I tried to replicate it using python (last example) and selectively throwing away some of the coefficients but I couldn't get a great image, mine is looking like a ghost.

How can I discard that not so important to the image?



import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from scipy import signal

# loading the image
img = mpimg.imread('i/super_mario_head.png')

# image in frequency domain
fft_original = np.fft.rfft2(img)

# discarding some coefficients (except initial square 80x80)
for x in range(300):
    for y in range(300):
        discard_x = x &gt; 80
        discard_y = y &gt; 80

        if discard_x and discard_y:
            fft_original[x,y] = 0

# reverse from frequency to spatial
i_fft_original = np.fft.irfft2(fft_original)

f, (plt1, plt2) = plt.subplots(1, 2, figsize=(15,15))

plt1.axis('off');plt1.set_title('Original');plt1.imshow(img[:,:,0], cmap='gray');
plt2.axis('off');plt2.set_title('Reversed');plt2.imshow(i_fft_original[:,:,0], cmap='gray');
You are throwing away coefficients before checking to see if their current magnitudes are small (smaller than typically visible).

(You might also want to rescale what's left to preserve total energy.)