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 :


What does the X and Y-axis in the figure represents?
Are the value stored in noise_dct_data and ground_truth_dct_data, the DCT coefficients?
Does the Y-axis represents the frequency of its corresponding DCT coefficients?
Is the histogram appropriate to represent the DCT coefficient distribution?
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
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.
Yes. Check the scipy documentation for the dct() function.
See 1.
This is impossible to answer. What does appropriate mean in this context?
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 &lt; M/2, middle frequencies are those with M/2 &lt;= r &lt; M, and high frequencies are those with r &gt;= M.


EDIT:

From the linked paper:


  Furthermore, it has been explained that noise addition to an image
  changes its DCT coefficient distribution [9], as we confirm in Fig. 2
  for a document image. Part (a) of the figure is an example of
  noiseless document image, part (b) is the noisy version of image (a)
  due to Gaussian blurring and Gaussian noise addition, and part (c)
  shows the higher frequency DCT coefficient distribution of of part(a)
  and (b) respectively. A lower-peaked histogram belongs to the
  ground-truth (GT) image, while a sharp-peaked histogram belongs to the
  noisy document image.


So part (c), which is the image you included, shows the histograms of the "higher frequency" DCT coefficients. Thus, the x-axis is the value of the DCT coefficient for the high frequency band, and the y-axis is its normalized histogram value. (The normalized histogram value is sometimes called "frequency", but that can get confusing in this case since DCT coefficients also represent frequencies. The normalized histogram value is just the number of occurrences of a certain value divided by the total number input samples to the histogram.)