python의 이미지 배열에 scipy.fftpack.dct 및 scipy.fftpack.idct를 사용하고 있습니다. 그러나 전체 이미지에 적용하는 것이 아니라 이미지의 개별 8x8 블록에 적용하고 싶습니다. 이것은 내가 데 문제는 내가 8 × 8 블록에 DCT를 적용 할 때, 다음 IDCT 바로 이후에 모든 정보가 손실된다는 점이다이Python scipy 이미지의 작은 블록에서 DCT가 작동하지 않습니다.
from PIL import Image
import numpy as np
from scipy.fftpack import dct, idct
class ImageController():
def __init__(self, image_name):
im = np.asarray(Image.open(image_name))
self.origional_size = im.shape
im_x_dim, im_y_dim = self.origional_size
self.image = im
if not self.image.flags.writeable:
self.image.flags.writeable = True
def get(self):
return self.image
def display(self):
Image.fromarray(self.image).show()
return self
def apply_dct(self):
# self.image = dct(self.image, norm='ortho')
self.loop_through_8_x_8(dct)
return self
def apply_idct(self):
# self.image = idct(self.image, norm='ortho')
self.loop_through_8_x_8(idct)
return self
def loop_through_8_x_8(self, appyFunc):
print appyFunc
row = 0
while row < len(self.image):
col = 0
while col < len(self.image[row]):
self.image[row:row+8, self.get_list(col)] = appyFunc(self.image[row:row+8, self.get_list(col)] , norm='ortho')
col += 8
row += 8
print row, col
return self;
def get_list(self, index):
x = []
for i in range(index, index + 8):
x.append(i)
return x
을 테스트에 쓴 간단한 클래스이며, 이미지는 엉망처럼 보인다 . 제가 부르고있는 것은
입니다.이 이미지를 실행하면 이미지가 모두 잡음에 불과합니다. 그러나 apply_dct() 및 apply_idct()에서 보면 8x8 블록 대신 전체 이미지에서 DCT 및 IDCT를 시도한 부분이 주석 처리되어 있습니다. 이 작업을 수행하면 완벽하게 작동하지만 8x8 블록을 사용하려고하면 작동하지 않으며 전체 이미지가 아닌 8x8 블록에만 적용해야합니다.
추가 정보 필요한 경우 이미지는 회색조이므로 채널이 하나뿐입니다.