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

问题描述 投票:1回答:1

我有两张图片:

原始图像

enter image description here

二值化图像

enter image description here

我已通过将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系数分布,如下图所示:

enter image description here

事情是我不知道如何绘制它。以下是我所做的:

    #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

我的问题是:

  1. [图中的XY-axis代表什么?
  2. [DCT系数是否存储在noise_dct_dataground_truth_dct_data中?
  3. Y-axis代表其对应的DCT系数的频率吗?
  4. 直方图是否适合表示DCT系数分布。
  5. DCT系数通常根据其频率分为三个子带,即低,中和高频带。在低,中或高频段中,我们可以用来对DCT系数进行分类的阈值是多少?换句话说,如何对DCT系数频带进行径向分类?以下是DCT系数频段的径向分类示例。

enter image description here

这个想法是基于论文:Noise Characterization in Ancient Document Images Based on DCT Coefficient Distribution

python image-processing signal-processing dft dct
1个回答
0
投票

在我看来,您共享的绘图示例看起来像是内核密度绘图。密度图“直方图的一种变化,它使用内核平滑来绘制值,从而通过平滑噪声来实现更平滑的分布。” (请参见https://datavizcatalogue.com/methods/density_plot.html

这个基于matplotlib构建的seaborn库具有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")

kdeplot example

请注意,重新运行此代码会产生稍有不同的图像,因为我使用的是随机生成的数据。

© www.soinside.com 2019 - 2024. All rights reserved.