我正在通过python进行8by8块dct转换。 出现以下错误消息:
AttributeError: 'Image' object has no attribute 'T'
这是我的代码的一部分:
from scipy.fftpack import dct
from PIL import Image
import glob
def dct_2(img):
#Get 2D Cosine Transform of Image
return dct(dct(img.T, norm='ortho').T, norm='ortho')
images = image_open(path)
for i in range(0, len(images)):
box3 = (1,1,256,256)
a = images[i].crop(box3)
width , height = a.size
(y,cb,cr) = a.split()
for q in range(1, height-32 , 32):
for w in range(1 , width-32 ,32):
box1 =(q,w,q+63,w+63)
block = y.crop(box1)
for j in range(1,64,8):
for n in range(1,64,8):
box2 = (j,n,j+7,n+7)
temp = block.crop(box2)
dct_temp = dct_2(temp)
答案 0 :(得分:1)
在应用转置之前,您需要将图像对象转换为数组。
import numpy as np
def dct_2(img):
#Get 2D Cosine Transform of Image
return dct(dct(np.asarray(img).T, norm='ortho').T, norm='ortho')