Hi im trying to do mammogram image enhancement in wavelet domain based on this paper A Direct Image Contrast Enhancement Algorithm in the Wavelet Domain for Screening Mammograms. Where its used 4 level decomposition with 'db16' wavelet. The main enhancement algorithm is presented in this image for easier and faster reading: image.And here is my code implementation:
LAMBDA = 1.80
#based on eq.10 in the image
#coefficient computation
def compute(L,a,b,c):
a_b = np.divide(a,b,out=np.zeros_like(a),where = b!=0)
result = L * a_b * c
print('max',np.max(result))
return result
# For 4-level decomposition,
C = pywt.wavedec2(img, 'db16', mode='periodization', level=4)
# C = [cA4,(cH4,cV4,cD4), (cH3,cV3,cD3),(cH2,cV2,cD2),(cH1,cV1,cD1)]
# C = (C[0], (C[-4]), (C[-3]), (C[-2]), (C[-1]))
cA4 = C[0]
lcA4 = cA4
# for cA3,
C3=(cA4,(C[-4]))
cA3=pywt.waverec2(C3, 'db16', mode='periodization')
#the computation
print(1)
lcD4 = tuple([LAMBDA * v for v in C[-4]])
LC3 = (lcA4,lcD4)
lcA3 = pywt.waverec2(LC3,'db16',mode='periodization')
# for cA2,
C2 = (cA3,(C[-3]))
cA2 = pywt.waverec2(C2,'db16',mode='periodization')
#the computation
print(2)
lcD3 = tuple([compute(LAMBDA,v,cA3,lcA3) for v in C[-3]])
LC2 = (lcA3,lcD3)
lcA2 = pywt.waverec2(LC2,'db16',mode='periodization')
#for cA1,
C1 = (cA2,(C[-2]))
cA1 = pywt.waverec2(C1,'db16',mode='periodization')
#the computation
print(3)
lcD2 = tuple([compute(LAMBDA,v,cA2,lcA2) for v in C[-2]])
LC1 = (lcA2,lcD2)
lcA1 = pywt.waverec2(LC1,'db16',mode='periodization')
#for cA0
C0 = (cA1,(C[-1]))
cA0 = pywt.waverec2(C0,'db16',mode='periodization')
# the computation
print(4)
lcD1 = tuple([compute(LAMBDA,v,cA1,lcA1) for v in C[-1]])
LC0 = (lcA1,lcD1)
lcA0 = pywt.waverec2(LC0,'db16',mode='periodization')
enhanced_img = lcA0.astype(np.uint8)
The original image im working with: original-image where it has 1024x1024 resolution with max value of 242 and min value of 0.
The result of enhanced image is here: enhanced-img which has same resolution, but as you can see there is alot distortion in areas that supposed to be black while (i think) there is enhancement in breast region.
My hypothesis for the cause of this is due to the computation that i did in those wavelet coefficient as the max value of the resulted computation is so big like 1e+16 and more. But I dont know if its correct or not to point this as the cause. For the zero division in computation i handled it by the first line in compute()
and im not sure too if its the right thing to do (by setting the result to 0 for division by zero).
Im asking this because there are no many example of wavelet coefficient manipulation/computation and the value of the coefficient itself is kinda arbitary for me.
I hope anybody can help me to implementing this enhancement techniques.
Thank you,and sorry for my bad english .