0

i have find the DWT of an image which code is below

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()

This code gives me approximation,horizontal,vertical and diagonal. How can i reconstruct original image using these four band?

1 Answers1

0

Try this code. It is just that you have to pass the coefficients which you got to the idwt2 function with your wavelet transform like 'haar' or 'db2' or 'db3'or 'bior'

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)
David Buck
  • 3,752
  • 35
  • 31
  • 35
R_99
  • 1
  • 1