PyWavelets / pywt

PyWavelets - Wavelet Transforms in Python
http://pywavelets.readthedocs.org
MIT License
2.04k stars 470 forks source link

Reconstructing approximation coefficient #562

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi first of all thx you for this great module, it help me so much learning wavelet transform. Currently im doing image enhancement in wavelet domain based on this paper A Direct Image Contrast Enhancement Algorithm in the Wavelet Domain for Screening Mammograms. In this paper there are computation as follow :

Screenshot from 2020-08-15 00-20-35 My problem is when im doing the eq.11 which i believe the meaning is to reconstruct the lower level scale by using the higher level scale. Here im using idwt() function but the shape of A3 and LA3 is not matching. And here is my code that i used :

data = [ ]
coeffs = [ ]
d = img
for i in range(4):
    d,c = pywt.dwt2(d,'db16')
    data.append(d)
     coeffs.append(c)

#level 4 bands
#computation in the paper (eq.10)
#LAMDA is a scalar
coeffs[-1] = tuple([LAMBDA * v for v in coeffs[-1]])
A4 = data[-1]
LA3 = pywt.idwt2((A4,coeffs[-1]),'db16')
A3 = data[-2]
print(A3.shape,LA3.shape) 

list 'data' contain the approximated and list 'coeff; contains the detailed coeff. Result :

(352, 567) (352, 568)

In this happening because interpolation error ? - i read in another issue that i think have similiar problem here, but still not clear for me to tackle this particular problem. I need to do the 'computation' where it doing multiplication and division so it need equal shape. When im using the wavedec() and waverec() functions the same things happen. Please i kindly need your help, thx you so much before. Sorry for my bad english and explanations.

grlee77 commented 4 years ago

I see in #563 that you resolved this by padding size to a multiple of 2**level. You can also just discard the extra coefficient from the end of the reconstructed signal.

A size mismatch by one mismatch can occur for forward transform followed by inverse transform for certain sizes and boundary modes. Discarding the last sample along any axis which is larger by 1 in size should give the expected reconstruction.