Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Apply CLAHE and Bayesian Thresholding to the Coefficients for Reconstruction? #630

Open
sarmientoj24 opened this issue Mar 21, 2022 · 2 comments
Labels

Comments

@sarmientoj24
Copy link

I am trying to follow this image preprocessing block using pywt but I cannot do CLAHE on the coefficients such as LL, and thresholding on the other three.
JMSS-5-59-g001

import pywt
import pywt.data

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

How do you apply CLAHE for LL and thresholding for LH, HL, HH and reconstruct the wavelets?

@grlee77
Copy link
Contributor

grlee77 commented Mar 21, 2022

Hi @sarmientoj24, here are some ideas:

For CLAHE, I would install scikit-image and then use skimage.exposure.equalize_adapthist.

For BayesShrink there is an implementation in skimage.restoration.denoise_wavelet that is based on PyWavelets. The denoise_wavelet source code is likely a good starting point for your implementation. It currently is nD as oppopsed to 2D specific, so you will see pywt.wavedecn and pywt.waverecn used instead of their 2D counterparts.

The default for that function is method='BayesShrink', however it does NOT apply CLAHE to the approximation coefficients (it thresholds the detail coefficients, but also does not apply whatever the "linear enhancement" in the diagram above is). By default it uses a multilevel decomposition (i.e. using pywt.wavedecn instead of pywt.dwt2), but you could set wavelet_levels=1 to force this to be only a single level as in the diagram above.

@sarmientoj24
Copy link
Author

Thank you @grlee77
Yeah I can do CLAHE actually. But then, when I reconstruct it, it's just some garbage image that is remaining. I guess it's because the values are now changed.

My question is more of a pseudocode or instruction how to do the pywt deconstruction -> clahe, then reconstruction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants