设为首页 加入收藏

TOP

在python3下使用OpenCV做离散余弦变换DCT及其反变换IDCT
2018-10-19 16:55:32 】 浏览:31
Tags:python3 使用 OpenCV 离散 余弦 变换 DCT 及其 IDCT

对图像处理经常用到DCT, Python下有很多带有DCT算法包, 这里使用OpenCV的DCT做变换, 并简单置0部分数据, 再查看反变换图像的效果.


import numpy as np
import cv2
# from matplotlib import pyplot as plt

y = cv2.imread('window.bmp', 0)
# print(y.shape)
cv2.imshow("gray",y)
y1 = y.astype(np.float32)
# print(y1.dtype)
Y = cv2.dct(y1)
print(Y.shape)
for i in range(0,240):
     for j in range(0,320):
         if i > 100 or j > 100:
             Y[i,j] = 0
cv2.imshow("Dct",Y)
y2 = cv2.idct(Y)
# print(y2.dtype)
cv2.imshow("iDCT",y2.astype(np.uint8))
cv2.waitKey(0)

对于320x240的图像, 在频域对大于100的行和列都置零(相当于低通滤波)后, 反变换后图像有点模糊, 但还能还原大致效果.


image

cnblogs Tags: python, ,
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇初识python元类(metaclass) 下一篇你好同窗,我们开始吧,这是我们..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目