Skip to content

Commit

Permalink
Rename nl_means_denoising to denoise_nl_means
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanv committed Aug 27, 2015
1 parent 9fa408a commit e084c5f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
3 changes: 3 additions & 0 deletions TODO.txt
@@ -1,8 +1,11 @@
Remember to list any API changes below in `doc/source/api_changes.txt`.



Version 0.14
------------
* Remove deprecated ``ntiles_*` kwargs in ``equalize_adapthist``.
* Remove deprecated ``skimage.restoration.nl_means_denoising``.


Version 0.13
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/plot_nonlocal_means.py
Expand Up @@ -15,7 +15,7 @@
import matplotlib.pyplot as plt

from skimage import data, img_as_float
from skimage.restoration import nl_means_denoising
from skimage.restoration import denoise_nl_means


astro = img_as_float(data.astronaut())
Expand All @@ -24,7 +24,7 @@
noisy = astro + 0.3 * np.random.random(astro.shape)
noisy = np.clip(noisy, 0, 1)

denoise = nl_means_denoising(noisy, 7, 9, 0.08)
denoise = denoise_nl_means(noisy, 7, 9, 0.08)

fig, ax = plt.subplots(ncols=2, figsize=(8, 4))

Expand Down
10 changes: 9 additions & 1 deletion skimage/restoration/__init__.py
Expand Up @@ -22,7 +22,12 @@
from .unwrap import unwrap_phase
from ._denoise import denoise_tv_chambolle, denoise_tv_bregman, \
denoise_bilateral
from .non_local_means import nl_means_denoising
from .non_local_means import denoise_nl_means
from .._shared.utils import copy_func, deprecated

nl_means_denoising = copy_func(denoise_nl_means, name='nl_means_denoising')
nl_means_denoising = deprecated('skimage.restoration.denoise_nl_means')(nl_means_denoising)


__all__ = ['wiener',
'unsupervised_wiener',
Expand All @@ -31,4 +36,7 @@
'denoise_tv_bregman',
'denoise_tv_chambolle',
'denoise_bilateral',
'denoise_nl_means',
'nl_means_denoising']

del copy_func, deprecated
36 changes: 16 additions & 20 deletions skimage/restoration/non_local_means.py
Expand Up @@ -6,8 +6,8 @@
_fast_nl_means_denoising_3d)


def nl_means_denoising(image, patch_size=7, patch_distance=11, h=0.1,
multichannel=True, fast_mode=True):
def denoise_nl_means(image, patch_size=7, patch_distance=11, h=0.1,
multichannel=True, fast_mode=True):
"""
Perform non-local means denoising on 2-D or 3-D grayscale images, and
2-D RGB images.
Expand Down Expand Up @@ -41,10 +41,6 @@ def nl_means_denoising(image, patch_size=7, patch_distance=11, h=0.1,
result : ndarray
Denoised image, of same shape as `image`.
See Also
--------
fast_nl_means_denoising
Notes
-----
Expand All @@ -68,19 +64,19 @@ def nl_means_denoising(image, patch_size=7, patch_distance=11, h=0.1,
image.size * patch_distance ** image.ndim
The computing time depends only weakly on the patch size, thanks to the
computation of the integral of patches distances for a given shift, that
reduces the number of operations [1]_. Therefore, this algorithm executes
faster than `nl_means_denoising`, at the expense of using twice as much
memory.
The computing time depends only weakly on the patch size, thanks to
the computation of the integral of patches distances for a given
shift, that reduces the number of operations [1]_. Therefore, this
algorithm executes faster than the classic algorith
(``fast_mode=False``), at the expense of using twice as much memory.
Compared to the classic non-local means algorithm implemented in
`nl_means_denoising`, all pixels of a patch contribute to the distance to
another patch with the same weight, no matter their distance to the center
of the patch. This coarser computation of the distance can result in a
slightly poorer denoising performance. Moreover, for small images (images
with a linear size that is only a few times the patch size), the classic
algorithm can be faster due to boundary effects.
Compared to the classic algorithm, all pixels of a patch contribute
to the distance to another patch with the same weight, no matter
their distance to the center of the patch. This coarser computation
of the distance can result in a slightly poorer denoising
performance. Moreover, for small images (images with a linear size
that is only a few times the patch size), the classic algorithm can
be faster due to boundary effects.
The image is padded using the `reflect` mode of `skimage.util.pad`
before denoising.
Expand All @@ -97,8 +93,8 @@ def nl_means_denoising(image, patch_size=7, patch_distance=11, h=0.1,
--------
>>> a = np.zeros((40, 40))
>>> a[10:-10, 10:-10] = 1.
>>> a += 0.3*np.random.randn(*a.shape)
>>> denoised_a = nl_means_denoising(a, 7, 5, 0.1)
>>> a += 0.3 * np.random.randn(*a.shape)
>>> denoised_a = denoise_nl_means(a, 7, 5, 0.1)
"""
if image.ndim == 2:
image = image[..., np.newaxis]
Expand Down
30 changes: 15 additions & 15 deletions skimage/restoration/tests/test_denoise.py
Expand Up @@ -153,49 +153,49 @@ def test_nl_means_denoising_2d():
img = np.zeros((40, 40))
img[10:-10, 10:-10] = 1.
img += 0.3*np.random.randn(*img.shape)
denoised = restoration.nl_means_denoising(img, 7, 5, 0.2, fast_mode=True)
denoised = restoration.denoise_nl_means(img, 7, 5, 0.2, fast_mode=True)
# make sure noise is reduced
assert img.std() > denoised.std()
denoised = restoration.nl_means_denoising(img, 7, 5, 0.2, fast_mode=False)
denoised = restoration.denoise_nl_means(img, 7, 5, 0.2, fast_mode=False)
# make sure noise is reduced
assert img.std() > denoised.std()


def test_nl_means_denoising_2drgb():
def test_denoise_nl_means_2drgb():
# reduce image size because nl means is very slow
img = np.copy(astro[:50, :50])
# add some random noise
img += 0.5 * img.std() * np.random.random(img.shape)
img = np.clip(img, 0, 1)
denoised = restoration.nl_means_denoising(img, 7, 9, 0.3, fast_mode=True)
denoised = restoration.denoise_nl_means(img, 7, 9, 0.3, fast_mode=True)
# make sure noise is reduced
assert img.std() > denoised.std()
denoised = restoration.nl_means_denoising(img, 7, 9, 0.3, fast_mode=False)
denoised = restoration.denoise_nl_means(img, 7, 9, 0.3, fast_mode=False)
# make sure noise is reduced
assert img.std() > denoised.std()


def test_nl_means_denoising_3d():
def test_denoise_nl_means_3d():
img = np.zeros((20, 20, 10))
img[5:-5, 5:-5, 3:-3] = 1.
img += 0.3*np.random.randn(*img.shape)
denoised = restoration.nl_means_denoising(img, 5, 4, 0.2, fast_mode=True,
denoised = restoration.denoise_nl_means(img, 5, 4, 0.2, fast_mode=True,
multichannel=False)
# make sure noise is reduced
assert img.std() > denoised.std()
denoised = restoration.nl_means_denoising(img, 5, 4, 0.2, fast_mode=False,
denoised = restoration.denoise_nl_means(img, 5, 4, 0.2, fast_mode=False,
multichannel=False)
# make sure noise is reduced
assert img.std() > denoised.std()


def test_nl_means_denoising_multichannel():
def test_denoise_nl_means_multichannel():
img = np.zeros((21, 20, 10))
img[10, 9:11, 2:-2] = 1.
img += 0.3*np.random.randn(*img.shape)
denoised_wrong_multichannel = restoration.nl_means_denoising(img,
denoised_wrong_multichannel = restoration.denoise_nl_means(img,
5, 4, 0.1, fast_mode=True, multichannel=True)
denoised_ok_multichannel = restoration.nl_means_denoising(img,
denoised_ok_multichannel = restoration.denoise_nl_means(img,
5, 4, 0.1, fast_mode=True, multichannel=False)
snr_wrong = 10 * np.log10(1. /
((denoised_wrong_multichannel - img)**2).mean())
Expand All @@ -204,19 +204,19 @@ def test_nl_means_denoising_multichannel():
assert snr_ok > snr_wrong


def test_nl_means_denoising_wrong_dimension():
def test_denoise_nl_means_wrong_dimension():
img = np.zeros((5, 5, 5, 5))
assert_raises(NotImplementedError, restoration.nl_means_denoising, img)
assert_raises(NotImplementedError, restoration.denoise_nl_means, img)


def test_no_denoising_for_small_h():
img = np.zeros((40, 40))
img[10:-10, 10:-10] = 1.
img += 0.3*np.random.randn(*img.shape)
# very small h should result in no averaging with other patches
denoised = restoration.nl_means_denoising(img, 7, 5, 0.01, fast_mode=True)
denoised = restoration.denoise_nl_means(img, 7, 5, 0.01, fast_mode=True)
assert np.allclose(denoised, img)
denoised = restoration.nl_means_denoising(img, 7, 5, 0.01, fast_mode=False)
denoised = restoration.denoise_nl_means(img, 7, 5, 0.01, fast_mode=False)
assert np.allclose(denoised, img)


Expand Down

0 comments on commit e084c5f

Please sign in to comment.