I am trying to apply haar wavelet on an image in python. Here is the code
from pywt import dwt2, idwt2
img = cv2.imread('xyz.png')
cA, (cH, cV, cD) = dwt2(img, 'haar')
Then I modify coefficients embedding some data like given below
cH1=cH+k*pn_sequence_h
cV1=cV+k*pn_sequence_v
After that, I apply idwt with below code
idwt2(cA,(cH1,cV1,cD),'haar')[:Mc,:Nc]
where Mc and Nc are height and width of decomposed image.
But, I get an error with this code. Below is an error.
Traceback (most recent call last):
File "dwt.py", line 15, in <module>
idwt2(cA,(cH1,cV1,cD),'haar')[:Mc,:Nc]
File "C:\Python27\lib\site-packages\pywt\_multidim.py", line 104, in idwt2
LL, (HL, LH, HH) = coeffs
ValueError: too many values to unpack
What should I do in order to fix this error? I am new to python. Any help will be greatly appreciated.
I have also tried like this in below code. But here I don't get coefficients like CA, CH, CV, CD. what I get is all coefficients together.
import numpy as np
import pywt
import numpy
import PIL
from PIL import Image
img = PIL.Image.open("rot.png").convert("L")
imgarr = numpy.array(img)
coeffs = pywt.dwt2(imgarr, 'haar')
pywt.idwt2(coeffs, 'haar')