Skip to content

Implemented wavelet filter - #760

Closed
thearn wants to merge 18 commits into
scikit-image:masterfrom
thearn:wavelets
Closed

thearn wants to merge 18 commits into
scikit-image:masterfrom
thearn:wavelets

Conversation

@thearn

@thearn thearn commented Oct 6, 2013

Copy link
Copy Markdown

Relevant to #602: I've implemented a basic discrete wavelet transform filter for scikit-image.
At the moment, it's importing pywavelets directly, but it sounds like there will be a closer integration of source to come.

The basics:

An n-level discrete wavelet transform decomposes a digital image into 1 + 3_n coefficient matrices. The first is called the *approximation subband_, which captures the mean (and other low-frequency information) of the original image, and is essentially a down-sampled representation of it.

The remaining coefficient matrices are called the detail subbands. Thresholding functions are applied to these matrices. The wavelet transform is then reversed, to give the denoised result. Thresholding can either be soft or hard.

The main variation between the wavelet denoising methods that are out there in the literature are in how the thresholding values for each detail subband is determined (whether it is uniform across all detail subbands, or individual for each, etc).

The function implemented here allows a user to specify the detail thresholds either uniformly, or by level, or by individual subband. This way, this function can be used to implement the majority of wavelet denoising methods out there (BayesShrink. SureShrink. etc) by writing short wrapping functions which pre-compute the thresholds accordingly.

I'll work on more thorough documentation / examples before moving to implement BayesShrink/VisuShrink/SureShrink. Couldn't hurt to have more tests either. If it desirable to have these things done before issuing a pull request, no problem. I will wait until I have it all together, if desired.

I also have some methods of my own that are pre-publication, but would be happy to include.

Usage is pretty simple. Arguments to wavelet_filter are the image to be denoised, threshold value(s), and all arguments which could be passed to pywt.wavedec2. Note that in wavelet_filter, the wavelet function to use is an optional arguement, and defaults to haar.

from skimage.filters import wavelet_filter
from scipy.misc import lena
A = lena()
#1-level db4 transform, soft threshold all detail subbands at t=10.
B = wavelet_filter(A, 10.,  wavelet="db4")
#3-level Haar transform, hard threshold each level with its own value
t = [10., 8., 3.]
B = wavelet_filter(A, t, thresh_type="hard", level=3)
#2-level sym14 transform, with each subband getting its own threshold
t = [[10., 80., 30.], [80., 17., 19.]]
B = wavelet_filter(A, t, wavelet="sym14", level=2)

Here are results for

wavelet_filter(A, 25., wavelet="sym14", level=10)

Artifacts can be reduced by finer tuning of the thresholds, and careful selection of the wavelet function.

Comment thread skimage/filter/_wavelet.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the public face of wavelet filtering in skimage, we should probably list the available wavelets. That way users don't have to go hunting through pywavelets documentation. Same applies to mode.

@JDWarner

JDWarner commented Oct 6, 2013

Copy link
Copy Markdown
Contributor

Thanks for your contribution! I'm really glad to see wavelets arriving in skimage (and hopefully scipy 1.0)!

Some minor tweaks will be needed for Python 3 compatibility, and to get Travis happy you'll need to edit .travis.yml in the package root to install pywavelets. That should get the 2.x branch passing, but 3.x will probably still fail until nigma/pywt#7 gets merged in.

I think there are a couple tweaks to be made in the docstring as well, but I'll let someone with better reStructuredTest-fu chime in there.

@thearn

thearn commented Oct 6, 2013

Copy link
Copy Markdown
Author

Sounds good - I appreciate the quick feedback! I'll make the changes and continue with documentation.

thearn added 2 commits August 22, 2014 10:31
… into wavelets

Conflicts:
	.travis.yml
	CONTRIBUTORS.txt
	skimage/filter/__init__.py
…o wavelets

Conflicts:
	skimage/filter/_wavelet.py
	skimage/filter/tests/test_wavelet.py
@soupault soupault mentioned this pull request Mar 8, 2016
8 of 9 tasks
@soupault soupault added this to the 0.13 milestone Mar 15, 2016
@JDWarner

JDWarner commented Aug 5, 2016

Copy link
Copy Markdown
Contributor

@thearn I know this is a blast from the past, but we now have PyWavelets in scikit-image. If you have any other wavelet-based algorithms to contribute, this would be a great time to dust things off and take another look!

@ahojnnes

ahojnnes commented Aug 5, 2016

Copy link
Copy Markdown
Member

+1!

@stefanv

stefanv commented Aug 5, 2016

Copy link
Copy Markdown
Member

To be precise: we now have PyWavelets as a scikit-image dependency, so it is available for implementing wavelet-based algorithms.

@thearn

thearn commented Aug 5, 2016

Copy link
Copy Markdown
Author

Wow, it has been awhile! Might take me a bit to get it back up to speed and correct the tests, but I'll make a point to get back on this.

@thearn

thearn commented Aug 5, 2016 •

Copy link
Copy Markdown
Author

Looks like the features from my PR have since been provided:

https://github.com/scikit-image/scikit-image/blob/master/skimage/restoration/_denoise.py#L338-L377
So I'll close this PR. I do have some additional methods, but those would be best be presented as a new PR.

@thearn thearn closed this Aug 5, 2016
@thearn
thearn deleted the wavelets branch August 5, 2016 19:05
@stefanv

stefanv commented Aug 5, 2016

Copy link
Copy Markdown
Member

@thearn We're playing the long game here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants