Python 中图像的二维小波滤波

问题描述 投票:0回答:2

我正在尝试在 python 中进行 2d 小波滤波。我发现了 PyWavelets,并且已经研究它有一段时间了。我正在尝试进行 4 个级别的转换。当我打印出来时,它给出了奇怪的输出,我不确定到底发生了什么。我尝试了一些方法,但这是最新的例子:

test = pywt.dwt2(picture,'db1')

任何有关使用 PyWavelet 或一般情况在图像上执行 2d 小波的帮助将不胜感激。谢谢你。

编辑:小波变换的类型并不重要

python image filtering wavelet-transform pywavelets
2个回答
2
投票

你能解释一下奇怪的输出到底是什么吗? 你应该得到带有 cA、cL、cH 和 cD 系数的输出向量。 如果要查看变换域图像,请按如下方式排列系数: cA, (cH, cV, cD)

输出向量的长度=输入图像的行x列 (前提是您有方形图像)

如果要查看较低分辨率的图像,请以正方形格式排列输出向量中的前 1/4 个元素 (cA)。目前,他们会像 [第 1 行、第 2 行、第 3 行...] 另外,您是否在 pywt.dwt2 命令中给出 level 参数(可选)?

参考这个http://www.pybytes.com/pywavelets/ref/2d-dwt-and-idwt.html


0
投票

图像小波变换背后的整个思想是根据频率和时间对信号进行域分析,这是离散傅里叶变换无法提供的。该函数的 4 个输出,即 [cA cV; cH cD] 提供图像多分辨率视图的 4 个近似子带:

cA(近似子带):通过低通滤波器获得的低频分量,提供较低分辨率的图像近似。

cV(垂直细节子带):捕获高频垂直分量,对于检测垂直边缘和精细细节很有用。

cH(水平细节子带):与 cV 类似,但针对水平分量,有助于识别水平边缘和特征。

cD(Diagonal Detail Subband):表示高频对角分量,通过高通滤波器获得,突出对角边缘和特征。

下面是一个 Python 代码,可以让您了解其功能,但它并不完全是小波。

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

image = cv.imread('/content/diamond.png', cv.IMREAD_GRAYSCALE)

def conv(image, filter):
  dimx = image.shape[0]-filter.shape[0]+1
  dimy = image.shape[1]-filter.shape[1]+1
  ans = np.zeros((dimx,dimy))
  for i in range(dimx):
    for j in range(dimy):
      ans[i,j] = np.sum(image[i:i+filter.shape[0],j:j+filter.shape[1]]*filter)
  return ans


def dwt(image):
  lowpass = np.ones((3,3))*(1/9)
  highpass_x = np.array([[1,0,-1],[2,0,-2],[1,0,-1]])#sobel filter
  highpass_y = np.array([[1,2,1],[0,0,0],[-1,-2,-1]])#sobel filter
  l = conv(image, lowpass)
  h = conv(image,highpass_x)
  ll = conv(l,lowpass)#approximate subband
  lh = conv(l,highpass_x)#horizontal subband
  hl = conv(l,highpass_y)#vertical subband
  hh = conv(h,highpass_y)#diagonal subband
  return ll, lh, hl, hh

ll0, lh0, hl0 ,hh0 = dwt(image)

plt.figure(figsize=(5,4))
plt.subplot(2,2,1), plt.imshow(ll0, cmap='gray')
plt.subplot(2,2,2), plt.imshow(lh0, cmap='gray')
plt.subplot(2,2,3), plt.imshow(hl0, cmap='gray')
plt.subplot(2,2,4), plt.imshow(hh0, cmap='gray')

它将给出如下输出:

this shows the cA,cV,cH,cD subbands of the initial image.

© www.soinside.com 2019 - 2024. All rights reserved.