dct.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:website-4mb 作者: dettoman 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号