Discrete Cosine Transform (DCT) Coefficient Distribution

I have two images :

Original Image

Binarize Image

I have applied Discrete Cosine Transform to the two images by dividing the 256x256 image into 8x8 blocks. After, I want to compare their DCT Coefficient Distributions.

import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
import numpy as np
import os.path
import scipy
import statistics

from numpy import pi
from numpy import sin
from numpy import zeros
from numpy import r_
from PIL import Image
from scipy.fftpack import fft, dct
from scipy import signal
from scipy import misc

if __name__ == '__main__':
image_counter = 1

# Opens the noisy image.
noise_image_path = 'noise_images/' + str(image_counter) + '.png'
noise_image = Image.open(noise_image_path)

# Opens the binarize image
ground_truth_image_path = 'ground_truth_noise_patches/' + str(image_counter) + '.png'
ground_truth_image = Image.open( ground_truth_image_path)

#Converts the images into Ndarray
noise_image = np.array(noise_image)
ground_truth_image = np.array(ground_truth_image)

#Create variables noise_dct_data and ground_truth_dct_data where the DCT coefficients of the two images will be stored.
noise_image_size = noise_image.shape
noise_dct_data = np.zeros(noise_image_size)
ground_truth_image_size = ground_truth_image.shape
ground_truth_dct_data = np.zeros(ground_truth_image_size)

for i in r_[:noise_image_size[0]:8]:
for j in r_[:noise_image_size[1]:8]:
# Apply DCT to the two images every 8x8 block of it.
noise_dct_data[i:(i+8),j:(j+8)] = dct(noise_image[i:(i+8),j:(j+8)])
# Apply DCT to the binarize image every 8x8 block of it.
ground_truth_dct_data[i:(i+8),j:(j+8)] = dct(ground_truth_image[i:(i+8),j:(j+8)])


The above code gets the DCT of the two images. I want to create their DCT Coefficient Distribution just like the image below:

The thing is I dont know how to plot it. Below is what I did:

#Convert 2D array to 1D array
noise_dct_data = noise_dct_data.ravel()
ground_truth_dct_data = ground_truth_dct_data.ravel()

#I just used a Histogram!
n, bins, patches = plt.hist(ground_truth_dct_data, 2000, facecolor='blue', alpha=0.5)
plt.show()

n, bins, patches = plt.hist(noise_dct_data, 2000, facecolor='blue', alpha=0.5)
plt.show()

image_counter = image_counter + 1


My questions are :

1. What does the X and Y-axis in the figure represents?
2. Are the value stored in noise_dct_data and ground_truth_dct_data, the DCT coefficients?
3. Does the Y-axis represents the frequency of its corresponding DCT coefficients?
4. Is the histogram appropriate to represent the DCT coefficient distribution?
5. The DCT coefficients are normally classified into three sub-bands based on their frequencies, namely low, middle and high frequency-bands. What is the threshold value we can use to classify a DCT Coefficient in low, middle or high frequency band? In other words, how can we classify the DCT coefficient frequency bands radially? Below is an example of the radial classification of the DCT coefficient frequency bands.

The idea is based from the paper : Noise Characterization in Ancient Document Images Based on DCT Coefficient Distribution

• What about MATLAB code, is that OK? – Royi Feb 6 at 13:05
• Puts most of the co-efficients in the zero the bin. So I guess how the co-efficients are distributed which is shown in your graph. – jomegaA Feb 6 at 13:36
• @Royi --> It's okay, as long as I can analyze how DCT works and answer my questions above. That would be great. – alyssaeliyah Feb 7 at 0:41

1. Probably the value of the DCT coefficient and its frequency (i.e., a histogram plot). However, it's impossible to say that with certainty given the information you have provided. If you found that plot in the linked paper, then the definitions of the x- and y-axes are in all likelihood given therein. The paper is behind a paywall, so it's not helpful to anyone without an IEEE account.

2. Yes. Check the scipy documentation for the dct() function.

3. See 1.

4. This is impossible to answer. What does appropriate mean in this context?

5. To classify a coefficient as either low, middle, or high frequency, compute its distance from the DC bin. For bin (m,n), its distance will be r = sqrt( (m-1)^2 + (n-1)^2 ). Judging by the picture you included, it looks like low frequencies are those with r < M/2, middle frequencies are those with M/2 <= r < M, and high frequencies are those with r >= M.

EDIT: