Python 离散余弦变换(DCT)系数分布

Python 离散余弦变换(DCT)系数分布,python,image-processing,signal-processing,dft,dct,Python,Image Processing,Signal Processing,Dft,Dct,我有两张照片: 原始图像 二值化图像 通过将256x256图像分割为8x8块,我对两幅图像应用了离散余弦变换。之后,我想比较它们的DCT系数分布 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 im

我有两张照片:

原始图像

二值化图像

通过将256x256图像分割为8x8块,我对两幅图像应用了离散余弦变换。之后,我想比较它们的DCT系数分布

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)])
上面的代码得到两幅图像的DCT。我想创建他们的DCT系数分布,如下图所示:

问题是我不知道怎么画。以下是我所做的:

    #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
我的问题是:

  • 图中的
    X
    Y轴
    代表什么
  • 值是否存储在
    噪声\u dct\u数据
    地面\u真相\u dct\u数据
    中,即dct系数
  • Y轴是否表示其相应DCT系数的频率
  • 直方图是否适合表示DCT系数分布
  • DCT系数通常根据其频率分为三个子带,即低频、中频和高频带。在低频、中频或高频段,我们可以使用什么阈值来分类DCT系数?换言之,我们如何对DCT系数频带进行径向分类?下面是DCT系数频带的径向分类示例

  • 这个想法来源于一篇论文:

    在我看来,你分享的绘图示例就像一个内核密度图。密度图“直方图的一种变化,它使用核平滑来绘制值,通过平滑噪声来实现更平滑的分布。”

    seaborn库构建在matplotlib之上,具有kdeplot函数,可以处理两组数据。下面是一个玩具示例:

    import numpy as np 
    from scipy.fftpack import dct
    import seaborn 
    
    sample1 = dct(np.random.rand(100))
    sample2 = dct(np.random.rand(30))
    seaborn.kdeplot(sample1, color="r")
    seaborn.kdeplot(sample2, color="b")
    

    请注意,由于我使用的是随机生成的数据,因此重新运行此代码将生成一个稍微不同的图像

    要直接回答您的编号问题:

    1。图中的X轴和Y轴代表什么?

    在kdeplot中,X轴表示密度,y轴表示具有这些值的观测数。与直方图不同,它使用平滑方法来尝试估计噪声观测数据背后数据的“真实”分布

    2。值是否存储在噪声\u dct\u数据和地面\u真值\u dct\u数据中,即dct系数?

    根据您设置代码的方式,是的,这些变量存储了您执行的DCT变换的结果

    3。Y轴是否表示其相应DCT系数的频率?

    是的,但是要平滑。类似于直方图,但不完全相同

    4。直方图是否适合表示DCT系数分布?

    这取决于观察的数量,但如果你有足够的数据,直方图应该会给出非常相似的结果

    5。DCT系数通常根据其频率分为三个子带,即低频、中频和高频带。在低频、中频或高频段,我们可以使用什么阈值来分类DCT系数?换句话说,我们如何对DCT系数频带进行径向分类?

    我认为这个问题可能过于复杂,无法在stack上令人满意地回答,但我的建议是尝试找出本文作者是如何完成这项任务的。引用的文章“盲图像质量评估:DCT域中的自然场景统计方法”似乎在谈论径向基函数(RBF),但这看起来像是一种根据频率数据训练监督模型以预测扫描整体质量的方法

    关于数据分区,他们表示,“为了从局部图像块捕获方向信息,DCT块被定向分区……上、中、下分区分别对应于低频、中频和高频DCT子带。”


    我认为,在至少一种情况下,分区是由子带DCT确定的。(参见)关于这类方法,似乎有大量文献

    许多人可能无法访问IEEE,请共享指向公共可用链接的链接。@RavitejaNarra-->我已将论文上载到驱动器中供公众查看。谢谢谢谢你的主意。非常感谢:)