import cv2
import numpy as np
from PIL import Image
from scipy import fftpack
import matplotlib.pyplot as plt
from torchvision import transforms
def dct2(array):
array = fftpack.dct(array, type=2, norm="ortho", axis=0)
array = fftpack.dct(array, type=2, norm="ortho", axis=1)
array = np.abs(array)
epsilon=1e-12
array += epsilon
array = np.log(array)
return array
if __name__ == '__main__':
name = r'./images/010001.jpg'
# img_u8 = Image.open(name)
#
# trans_resize = transforms.Resize((1024, 1024))
# img_resize = trans_resize(img_u8)
img_resize = cv2.imread(name,1)
dct_img = dct2(img_resize)
print(dct_img.shape)
plt.figure("Image") # 图像窗口名称
plt.imshow(dct_img.astype(np.uint8))
plt.axis('on') # 关掉坐标轴为 off
plt.title('image') # 图像题目
plt.show()
__image_transform = transforms.Compose([
transforms.ToTensor()])
img_data = __image_transform(dct_img)
print(img_data.size())
图片DCT
最新推荐文章于 2022-04-25 20:36:46 发布