def old_idct(x): '''dct type 3 in 2D; transform -> image''' out = np.empty((32, 32, 3), dtype='float32') for ch in range(3): out[:, :, ch] = scidct(scidct(x[:, :, ch], type=3, norm='ortho', axis=0), type=3, norm='ortho', axis=1) return np.clip(out, 0, 255).astype('uint8')
def old_dct(x): '''dct type 2 in 2D; image -> transform''' out = np.empty((32, 32, 3), dtype='float32') for ch in range(3): out[:, :, ch] = scidct(scidct(x[:, :, ch], type=2, norm='ortho', axis=0), type=2, norm='ortho', axis=1) return out
def expand(im, scale_x=2): '''expand takes a 32x32x3 ndarray image and expands it by DCT/iDCT scale contrast to full range does not change colorspace''' newsize = scale_x * 32 tr = dct(im) tr_pad = np.zeros((newsize, newsize, 3), dtype='float32') tr_pad[:32, :32, :] = np.multiply(tr, scale_x) lo = np.amin(tr[:, :, 0]) # print(lo) hi = np.amax(tr[:, :, 0]) # print(hi) tr[:, :, 0] = np.multiply(np.subtract(tr[:, :, 0], lo), 255/(hi - lo)) out = np.empty((newsize, newsize, 3), 'float32') for ch in range(3): out[:, :, ch] = scidct(scidct(tr_pad[:, :, ch], type=3, norm='ortho', axis=0), type=3, norm='ortho', axis=1) return np.clip(out, 0, 255).astype('uint8')
def idct(x): return np.clip(scidct(scidct(x, type=3, norm='ortho', axis=0), type=3, norm='ortho', axis=1), 0, 255).astype('uint8')
def dct(x): return scidct(scidct(x, type=2, norm='ortho', axis=1), type=2, norm='ortho', axis=0)