def dct_gen(frame):
# read Frame
[r, c, d] = frame.shape
framebw = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
########## DCT ##########
# Reshape in 8x8 type array
framedct = np.reshape(framebw / 255.0, (-1, 8), order='C')
# Apply DCT line and column wise
X = sft.dct(framedct, axis=1, norm='ortho')
X = np.reshape(X, (-1, c), order='C')
X = np.reshape(X.T, (-1, 8), order='C')
X = sft.dct(X, axis=1, norm='ortho')
# shape back to original shape
X = (np.reshape(X, (-1, r), order='C')).T
# Zeroing DC-Coefficients
X[::8,::8] = 0
########## IDCT ##########
# Reshape in 8x8 type array
X = np.reshape(X, (-1, 8), order='C')
# Apply IDCT line and column wise
X = sft.idct(X, axis=1, norm='ortho')
X = np.reshape(X, (-1, c), order='C')
X = np.reshape(X.T, (-1, 8), order='C')
x = sft.idct(X, axis=1, norm='ortho')
# shape back to original shape
x = (np.reshape(x, (-1, r), order='C')).T
# cast into output image
x = x*255
frameout = np.zeros_like(frame)
frameout[:, :, 0] = x
frameout[:, :, 1] = x
frameout[:, :, 2] = x
return frameout
评论列表
文章目录