对图像应用离散余弦变换

Apply Discrete Cosine Transform to an Image

我想对我的图像应用离散余弦变换

import os.path
from PIL import Image

if __name__ == '__main__':
    image_counter = 1  
while True:      
    if not os.path.isfile('noise_images/' + str (image_counter) + '.png'):
        break
    print(image_counter)
    noise_image_path = 'noise_images/' + str(image_counter) + '.png'
    noise_image = Image.open(noise_image_path)  
    # Apply DCT to an image.

    image_counter = image_counter + 1

看看这个scipy.fftpack.dct

下面是使用这个的示例代码:

import cv2
from scipy.fftpack import dct

def dct2(block):
    return dct(dct(block.T, norm='ortho').T, norm='ortho')

img = cv2.imread(filename)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dctImage = dct2(img.astype(float))