denose with dwt
来源:互联网 发布:python单引号和双引号 编辑:程序博客网 时间:2024/06/03 16:59
import sysimport cv2import numpy as npimport pywtdef apply_thresh(coef, thresh, mode):if mode == 'hard':tmp = np.abs(coef)tmp = tmp >= threshcoef = coef * tmpelse: #softtmp = np.abs(coef)tmp = tmp >= threshcoef = coef * tmpcoef = np.sign(coef) * (np.abs(coef) - thresh)return coefdef get_thresh_uplimit(coef):c = 13 #noise estimations = coef.shape[0] * coef.shape[1]return c * np.sqrt(2 * np.log(s))def get_thresh_MAD(coef): #mean absolute differencec = 2.0coef = np.abs(coef)return c * np.std(np.reshape(coef, coef.shape[0]*coef.shape[1]))def denoise_dwt(img):if img.ndim != 2:img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)img = np.float32(img)h,w = img.shapeif h < 32 or w < 32:return np.zeros(img.shape,np.uint8)get_thresh = get_thresh_uplimitN = 3coef = pywt.wavedec2(img, 'db1', level = N)for k in range(2,N+1):cH, cV, cD = coef[k]t = get_thresh(cH)cH = apply_thresh(cH, t, 'soft')t = get_thresh(cV)cV = apply_thresh(cV, t, 'soft')t = get_thresh(cD)cD = apply_thresh(cD, t, 'soft')coef[k] = (cH, cV, cD)cleanimg = pywt.waverec2(coef, 'db1')cleanimg = np.uint8(cleanimg)return cleanimgdef imnoise(img):if img.ndim != 2:img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)noiseimg = np.float32(img) + np.random.normal(0, 50, img.shape)m0 = np.zeros(img.shape, float)m1 = np.ones(img.shape,float) * 255noiseimg = np.minimum(noiseimg, m1)noiseimg = np.maximum(noiseimg, m0)noiseimg = np.uint8(noiseimg)return noiseimgif __name__=='__main__':img = cv2.imread(sys.argv[1])cv2.imshow('src', img)cv2.waitKey(-1)noiseimg = imnoise(img)cv2.imshow('noise', noiseimg)cv2.waitKey(-1)cleanimg = denoise_dwt(noiseimg)cv2.imshow('clean', cleanimg)cv2.waitKey(-1)
0 0
- denose with dwt
- DWT
- 小波去噪DWT
- 离散小波-DWT
- haar dwt in python
- Cortex M3 DWT
- dwt和wavedec区别
- EFM32片内外设 -- DWT
- 离散小波变换-DWT
- dwt文件和lbi文件
- 小波变换(dwt)
- ECSHOP index.dwt 首页调用关系
- Matlab中小波变换dwt和wavedec
- ecshop中 dwt, lbi 文件详解
- ecshop中的dwt和lbi文件
- ecshop中 dwt, lbi 文件详解
- Zend Studio easyeclipse 打开*.dwt,*.lbi文件
- ecshop中 dwt, lbi 文件详解
- 事件监听机制——键盘事件
- mac 下 mysql 忘记密码解决方法
- 计算机网络综合实验
- openflow搭建过程和安装过程中可能的问题
- UI基础第十四弹: UITableview控件简单介绍
- denose with dwt
- sql server获取周期性的特定日期
- Kindle 助手上线啦
- IT草根创业者该做什么?
- Yii2 使用一 安装
- linux c++中文处理问题及occi入库中文
- 如何实现“秒杀”系统
- npc
- 17位序列号