Skip to content

ENH: routine to estimate the noise standard deviation from an image - #1837

Merged
soupault merged 16 commits into
scikit-image:masterfrom
grlee77:noise_estimation
Aug 24, 2016
Merged

soupault merged 16 commits into
scikit-image:masterfrom
grlee77:noise_estimation

Conversation

@grlee77

@grlee77 grlee77 commented Dec 21, 2015

Copy link
Copy Markdown
Contributor

This PR adds a routine for estimating the (Gaussian) noise standard deviation from an image. This should be of use with the various denoising routines in the usual case when the underlying noise standard deviation is unknown.

The algorithm implemented is based on the median absolute deviation of wavelet detail coefficients, so it requires PyWavelets to run.

For example, this could be used by the method of #1833 to automate the threshold estimation.

A minimal example:

import skimage.data
from skimage import img_as_float
from skimage.restoration import estimate_sigma
img = img_as_float(skimage.data.camera())
sigma = 0.1
img = img + sigma * np.random.standard_normal(img.shape)
sigma_hat = estimate_sigma(img, multichannel=False)
print("True sigma = {}".format(sigma))
print("Estimated sigma = {}".format(sigma_hat))
True sigma = 0.1
Estimated sigma = 0.09989763880477982

@grlee77

grlee77 commented Dec 21, 2015

Copy link
Copy Markdown
Contributor Author

I left multichannel a required argument, because I thought defaulting to False was a bit dangerous. If a color image is input, but multichannel False, this will cause a substantial error in the estimation of sigma. (This is because the DWT is then improperly performed along the channels dimension as well).

@stefanv

stefanv commented Dec 21, 2015

Copy link
Copy Markdown
Member

Perhaps @arokem would be willing to help us review this one. He has dived deep into the landscape of noise estimation for neuroimaging in the past.

@arokem

arokem commented Dec 21, 2015

Copy link
Copy Markdown
Contributor

Yeah, I can take a look.

@grlee77

grlee77 commented Dec 21, 2015

Copy link
Copy Markdown
Contributor Author

The error on Travis is due to the presence of the docstring example, but lack of PyWavelets so the doctest fails. Is there a simple way to tell the testing to skip it?

@grlee77

grlee77 commented Dec 22, 2015

Copy link
Copy Markdown
Contributor Author

The neuroimaging use case (at least for MRI) is a bit more complicated and would benefit from a more specialized solution.

Often, one only has magnitude images which have Rician rather than Gaussian noise. Gaussian is a reasonable approximation when SNR is not too low, though. Also, for MRI, the noise standard deviation is often not spatially uniform so it is better to have localized estimates of sigma rather than a single value for the whole image/volume.

@stefanv

stefanv commented Dec 22, 2015

Copy link
Copy Markdown
Member

Try # doctest: +SKIP

@soupault soupault added the ⏩ type: Enhancement Improve existing features label Dec 22, 2015
@grlee77

grlee77 commented Dec 22, 2015

Copy link
Copy Markdown
Contributor Author

Okay, the doctest is skipped now. It fails now because I listed PyWavelets in the optional_dependencies.rst file, but it is not available.

Comment thread skimage/restoration/_denoise.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No references in first line of docstring.

@stefanv

stefanv commented Dec 22, 2015

Copy link
Copy Markdown
Member

Failing because of docstring formatting.

@JDWarner

Copy link
Copy Markdown
Contributor

Once we officially tag and release 0.12, we should seriously discuss adding PyWavelets as a required dependency for 0.13+. Then the docstring will pass, instead of needing to be skipped.

@stefanv

stefanv commented Dec 22, 2015 via email

Copy link
Copy Markdown
Member

@grlee77

grlee77 commented Dec 22, 2015

Copy link
Copy Markdown
Contributor Author

The remaining failure (segfault!) on Python 2.6 does not seem related to this PR:

skimage.feature.tests.test_util.test_plot_matches ... tools/travis_script.sh: line 111: 10304 Segmentation fault      (core dumped) nosetests $TEST_ARGS

The command "tools/travis_script.sh" exited with 139.

Comment thread skimage/restoration/_denoise.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.

Is the call to asarray a standard thing in skimage, even when input is defined to be an array in the docstring?

@arokem

arokem commented Dec 22, 2015

Copy link
Copy Markdown
Contributor

Overall - looks good to me. Once the small comments are addressed, I think this is good to go.

Comment thread skimage/restoration/_denoise.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.

Typo "Jain" should be "Iain".

@grlee77

grlee77 commented Dec 22, 2015

Copy link
Copy Markdown
Contributor Author

Should PyWavelets be listed in optional_dependencies.rst? It seemed like doing so caused Travis to try and find wheels for PyWavelets at http://travis-wheels.scikit-image.org/. There is support for bdist_wheel in PyWavelets, so I think it should be possible to generate the necessary wheels fairly easily.

I have tested with PyWavelets v0.3.0 and from current master. For a 512x512 grayscale image, estimate_sigma requires ~100 ms on v0.3.0 and ~10 ms for master.

@grlee77

grlee77 commented Dec 22, 2015

Copy link
Copy Markdown
Contributor Author

Also, should I add a conversion via img_as_float for the input to estimate_sigma? The estimate_sigma function will work fine for integer images (PyWavelets will convert to double precision internally in that case), but it appears the other denoising functions convert their inputs to float, which could potentially lead to users calling estimate_sigma on the integer image and then passing that sigma on to another function where it would be much too large once the image gets rescaled to [0, 1].

@JDWarner

Copy link
Copy Markdown
Contributor

@grlee77 Realistically, we aren't merging this before 0.12 is released. My thought process moving forward is to make PyWavelets a required dependency and open the floodgates to wavelet-based algorithms as major new features in 0.13. Further discussion on this in #1838. We're not talking a long time, here - work on 0.13dev should begin soon.

For now, it would probably be cleanest (but not entirely satisfying) to continue with this PR assuming PyWavelets will be made a dependency in a separate PR. Ergo, drop the optional checks or raised errors/warnings in favor of assuming it'll be there. Yes, the tests will fail until after 0.12 is tagged and released. After that, a PR making PyWavelets a dependency can be merged and a simple rebase will bring this into the green. You can move forward with development/testing locally in virtualenvs.

@emmanuelle

Copy link
Copy Markdown
Member

@blink1073 any idea about the segmentation fault of Travis?

@blink1073

Copy link
Copy Markdown
Contributor

@emmanuelle, no idea, but it looks like it was unrelated to this PR and caused by matplotlib. I restarted the build to see if it is reproducible.

@blink1073

Copy link
Copy Markdown
Contributor

@emmanuelle

Copy link
Copy Markdown
Member

@blink1073 do we need matplotlib 1.5 for the build? python 2.6 should be deprecated only after 0.12.

@blink1073

Copy link
Copy Markdown
Contributor

We could pin to a lower version of matplotlib on our Travis build, and just rely on the fact that the user shouldn't be installing a newer version in they are on Py26.

@emmanuelle

Copy link
Copy Markdown
Member

sounds good

@blink1073

Copy link
Copy Markdown
Contributor

See #1841

@grlee77

grlee77 commented Dec 23, 2015

Copy link
Copy Markdown
Contributor Author

@JDWarner: That all sounds good to me. I did not expect it to go in for 0.12. I can eventually rebase this to remove some of the unecessary commits adding and removing the optional dependency, etc.

References
----------
.. [1] D. L. Donoho and I. M. Johnstone. "Ideal spatial adaptation
by wavelet shrinkage." Biometrika 81.3 (1994): 425-455.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add DOI:10.1093/biomet/81.3.425 please?

@sciunto

sciunto commented Aug 21, 2016

Copy link
Copy Markdown
Member

@grlee77 Thanks for pushing this :) very appreciated. I looked more carefully to your code. I think I found a possible bug and I raise few minor stuffs. Otherwise, it looks good. I'll look at it again once you fixed these little things.

Thanks.

@sciunto

sciunto commented Aug 21, 2016 •

Copy link
Copy Markdown
Member

Also, if you can incorporate this in the examples, that would be great! ;)

@jni

jni commented Aug 24, 2016

Copy link
Copy Markdown
Member

LGTM, thanks @grlee77!

@soupault

Copy link
Copy Markdown
Member

Awesome! Thanks a lot @grlee77!

@soupault
soupault merged commit 90422ae into scikit-image:master Aug 24, 2016
@grlee77
grlee77 deleted the noise_estimation branch May 11, 2017 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⏩ type: Enhancement Improve existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.