【问题标题】:How to reconstruct image using HH,HL,LH and LL band of DWT in Python?如何在 Python 中使用 DWT 的 HH、HL、LH 和 LL 波段重建图像?
【发布时间】:2020-07-02 10:09:31
【问题描述】:

我找到了一张图片的 DWT,代码如下

import numpy as np
import matplotlib.pyplot as plt
import cv2
import pywt
import pywt.data


# Load image
original = cv2.imread('/content/drive/My Drive/Colab Notebooks/Asplab/fgsm/watermark1.JPEG')
original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
# Wavelet transform of image, and plot approximation and details
titles = ['Approximation', ' Horizontal detail',
      'Vertical detail', 'Diagonal detail']
coeffs2 = pywt.dwt2(original, 'bior1.3')
LL, (LH, HL, HH) = coeffs2
fig = plt.figure(figsize=(12, 3))
for i, a in enumerate([LL, LH, HL, HH]):
  ax = fig.add_subplot(1, 4, i + 1)
  ax.imshow(a, interpolation="nearest", cmap=plt.cm.gray)
  ax.set_title(titles[i], fontsize=10)
  ax.set_xticks([])
  ax.set_yticks([])

fig.tight_layout()
plt.show()

这段代码给了我近似、水平、垂直和对角线。如何使用这四个波段重建原始图像?

【问题讨论】:

    标签: python dwt


    【解决方案1】:

    试试这个代码。只是您必须使用小波变换(如“haar”或“db2”或“db3”或“bior”)将获得的系数传递给 idwt2 函数

    imgr=pywt.idwt2(coeffs2,'db3')
    imgr=np.uint8(imgr)
    
    plt.figure(figsize=(30,30))
    plt.show()
    
    plt.imshow(imgr,interpolation="nearest",cmap=plt.cm.gray)
    plt.title('reconstruction image',fontsize=40)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-02
      • 2021-01-30
      • 2016-01-24
      • 2021-08-26
      • 2018-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多