【图像处理】图像离散小波变换(Discrete Wavelet Transform)及python代码实现

Motivation

看到有论文用到了图像的Haar Discrete Wavelet Transform(HDWT),前面也听老师提到过用小波变换做去噪、超分的文章,于是借着这个机会好好学习一下。

直观理解

参考知乎上的这篇文章:https://zhuanlan.zhihu.com/p/22450818 关于傅立叶变换和小波变换的直观概念解释的非常清楚(需要对傅立叶变换有基本的理解)

二维图像离散小波变换(DWT)

先放一张图直观感受一下这个过程(图中是经过两次DWT的)
在这里插入图片描述1. 首先明确什么是HL。H和L其实表示的是高通滤波器(High pass filter)和低通滤波器(Low pass filter)。高通滤波器用于提取边缘特征,低通滤波器用于图像近似(approximation).
2. 两次滤波得到输出结果。如下图所示,先通过低通和高通滤波器(纵向 vertical),再分别通过一次低通和高通滤波器(横向 horizontal)。最后得到LL, HL, LH, HH。分别表示近似图像(也可以理解为压缩了的图像,有损失)、纵向边缘特征(通过了纵向高通滤波器)、横向边缘特征(通过了横向高通滤波器)、对角特征(diagonal 横向纵向都通过高通滤波器)。
在这里插入图片描述
上图看不太清楚的话可以看下面这张图(看看后面的图就好了,中间的过程感觉表示的不太对)
在这里插入图片描述
来源:Wavelet based transition region extraction for image segmentation

关于横向和纵向的边缘特征,可以看下面这张有条纹噪声图片的HDWT(Haar Discrete Wavelet Transform),比较明显。
在这里插入图片描述
来源: Wavelet Deep Neural Network for Stripe Noise Removal

python代码

import numpy as np
from matplotlib import pyplot as plt
import pywt
import PIL

img = PIL.Image.open("xxx.tif")
img = np.array(img)
LLY,(LHY,HLY,HHY) = pywt.dwt2(img, 'haar')
plt.subplot(2, 2, 1)
plt.imshow(LLY, cmap="Greys")
plt.subplot(2, 2, 2)
plt.imshow(LHY, cmap="Greys")
plt.subplot(2, 2, 3)
plt.imshow(HLY, cmap="Greys")
plt.subplot(2, 2, 4)
plt.imshow(HHY, cmap="Greys")
plt.show()

我的结果:
在这里插入图片描述
还是比较明显能看出水平和纵向特征的。

参考文章

  1. https://medium.com/@koushikc2000/2d-discrete-wavelet-transformation-and-its-applications-in-digital-image-processing-using-matlab-1f5c68672de3
  2. https://ataspinar.com/2018/12/21/a-guide-for-using-the-wavelet-transform-in-machine-learning/
  3. https://medium.com/image-vision/2d-dwt-a-brief-intro-89e9ef1698e3

如果对您有帮助,请不要吝啬您的点赞,如需转载请评论告知!

在此谢过各位!

  • 38
    点赞
  • 127
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 10
    评论
以下是一个使用pywt库实现离散小波变换提取突变点所在位置的Python代码: ```python import numpy as np import pywt def detect_change_points(data, wavelet='db4', level=2, threshold=3): # 1. Apply Discrete Wavelet Transform (DWT) to the data coeffs = pywt.wavedec(data, wavelet, level=level) # 2. Estimate the noise level using Median Absolute Deviation (MAD) of detail coefficients sigma = np.median([np.abs(c - np.median(c)) / 0.6745 for c in coeffs[1:]]) # 3. Apply Soft Thresholding to the detail coefficients thresholded_coeffs = list(coeffs) for i in range(1, len(coeffs)): thresholded_coeffs[i] = pywt.threshold(coeffs[i], sigma * threshold, mode='soft') # 4. Reconstruct the signal using the thresholded coefficients data_rec = pywt.waverec(thresholded_coeffs, wavelet) # 5. Find the points where the reconstructed signal deviates significantly from the original signal change_points = np.where(np.abs(data - data_rec) > sigma * threshold)[0] return change_points ``` 使用示例: ```python import matplotlib.pyplot as plt # Generate some example data np.random.seed(0) t = np.linspace(0, 1, 1000) data = np.sin(2 * np.pi * 10 * t) + np.sin(2 * np.pi * 20 * t) + np.random.randn(1000) * 0.5 # Detect change points change_points = detect_change_points(data, wavelet='db4', level=2, threshold=3) # Plot the data and the change points plt.plot(t, data) plt.plot(t[change_points], data[change_points], 'ro') plt.show() ``` 输出结果: ![image](https://user-images.githubusercontent.com/45757851/134370555-ebf85a3c-eb24-4c9e-9f1d-8d7f4a4b4c94.png) 在这个例子中,我们生成了一个由两个正弦波和噪声组成的信号,并使用离散小波变换提取了其中的突变点。可以看到,我们成功地找到了信号中两个正弦波的交界点。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小丫么小阿豪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值