# Low-pass filtering with DCT produces blocky, high-frequency results?

I have a grayscale image, available at https://pasteboard.co/IdX7NfA.png. Now I want to low-pass filter this image in the Discrete Cosine Transform (DCT) spectrum.

Specifically, I centered the image so that it has both positive and negative values, DCT'ed that centered image, set to zero the coefficients for components with higher frequency than (5, 5) (DC component being (0, 0)), and finally inverse DCT'ed it back to an image.

Here's how I did it in Python (assuming you download that source image to ~/gs.png):

import cv2
from scipy.fftpack import dct, idct

# Read and zero-mean the image
offset = np.iinfo(im.dtype).max / 2
im = im.astype(float) - offset

# DCT
coeffs = dct(dct(im.T, type=2, norm='ortho').T, type=2, norm='ortho')


To my surprise, the low-pass filtered image recon has many blocky, high-frequency structures. It looks like this: