"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "skimage/restoration/tests/test_denoise.py" between
scikit-image-0.19.2.tar.gz and scikit-image-0.19.3.tar.gz

About: scikit-image is a collection of algorithms for image processing in Python.

test_denoise.py  (scikit-image-0.19.2):test_denoise.py  (scikit-image-0.19.3)
skipping to change at line 19 skipping to change at line 19
from skimage import color, data, img_as_float, restoration from skimage import color, data, img_as_float, restoration
from skimage._shared._warnings import expected_warnings from skimage._shared._warnings import expected_warnings
from skimage._shared.utils import _supported_float_type, slice_at_axis from skimage._shared.utils import _supported_float_type, slice_at_axis
from skimage.metrics import peak_signal_noise_ratio, structural_similarity from skimage.metrics import peak_signal_noise_ratio, structural_similarity
from skimage.restoration._denoise import _wavelet_threshold from skimage.restoration._denoise import _wavelet_threshold
try: try:
import dask # noqa import dask # noqa
except ImportError: except ImportError:
DASK_NOT_INSTALLED_WARNING = 'The optional dask dependency is not installed' DASK_NOT_INSTALLED_WARNING = (
'The optional dask dependency is not installed'
)
else: else:
DASK_NOT_INSTALLED_WARNING = None DASK_NOT_INSTALLED_WARNING = None
np.random.seed(1234) np.random.seed(1234)
astro = img_as_float(data.astronaut()[:128, :128]) astro = img_as_float(data.astronaut()[:128, :128])
astro_gray = color.rgb2gray(astro) astro_gray = color.rgb2gray(astro)
checkerboard_gray = img_as_float(data.checkerboard()) checkerboard_gray = img_as_float(data.checkerboard())
checkerboard = color.gray2rgb(checkerboard_gray) checkerboard = color.gray2rgb(checkerboard_gray)
# versions with one odd-sized dimension # versions with one odd-sized dimension
skipping to change at line 1033 skipping to change at line 1035
rescale_sigma=rescale_sigma) rescale_sigma=rescale_sigma)
@pytest.mark.parametrize('rescale_sigma', [True, False]) @pytest.mark.parametrize('rescale_sigma', [True, False])
def test_denoise_wavelet_biorthogonal(rescale_sigma): def test_denoise_wavelet_biorthogonal(rescale_sigma):
"""Biorthogonal wavelets should raise a warning during thresholding.""" """Biorthogonal wavelets should raise a warning during thresholding."""
img = astro_gray img = astro_gray
assert_warns(UserWarning, restoration.denoise_wavelet, img, assert_warns(UserWarning, restoration.denoise_wavelet, img,
wavelet='bior2.2', channel_axis=None, wavelet='bior2.2', channel_axis=None,
rescale_sigma=rescale_sigma) rescale_sigma=rescale_sigma)
@pytest.mark.parametrize('channel_axis', [-1, None])
@pytest.mark.parametrize('rescale_sigma', [True, False]) @pytest.mark.parametrize('rescale_sigma', [True, False])
def test_cycle_spinning_multichannel(rescale_sigma): def test_cycle_spinning_multichannel(rescale_sigma, channel_axis):
sigma = 0.1 sigma = 0.1
rstate = np.random.default_rng(1234) rstate = np.random.default_rng(1234)
for channel_axis in -1, None: if channel_axis is not None:
if channel_axis is not None: img = astro
img = astro # can either omit or be 0 along the channels axis
# can either omit or be 0 along the channels axis valid_shifts = [1, (0, 1), (1, 0), (1, 1), (1, 1, 0)]
valid_shifts = [1, (0, 1), (1, 0), (1, 1), (1, 1, 0)] # can either omit or be 1 on channels axis.
# can either omit or be 1 on channels axis. valid_steps = [1, 2, (1, 2), (1, 2, 1)]
valid_steps = [1, 2, (1, 2), (1, 2, 1)] # too few or too many shifts or non-zero shift on channels
# too few or too many shifts or non-zero shift on channels invalid_shifts = [(1, 1, 2), (1, ), (1, 1, 0, 1)]
invalid_shifts = [(1, 1, 2), (1, ), (1, 1, 0, 1)] # too few or too many shifts or any shifts <= 0
# too few or too many shifts or any shifts <= 0 invalid_steps = [(1, ), (1, 1, 1, 1), (0, 1), (-1, -1)]
invalid_steps = [(1, ), (1, 1, 1, 1), (0, 1), (-1, -1)] else:
else: img = astro_gray
img = astro_gray valid_shifts = [1, (0, 1), (1, 0), (1, 1)]
valid_shifts = [1, (0, 1), (1, 0), (1, 1)] valid_steps = [1, 2, (1, 2)]
valid_steps = [1, 2, (1, 2)] invalid_shifts = [(1, 1, 2), (1, )]
invalid_shifts = [(1, 1, 2), (1, )] invalid_steps = [(1, ), (1, 1, 1), (0, 1), (-1, -1)]
invalid_steps = [(1, ), (1, 1, 1), (0, 1), (-1, -1)]
noisy = img.copy() + 0.1 * rstate.standard_normal(img.shape)
noisy = img.copy() + 0.1 * rstate.standard_normal(img.shape)
denoise_func = restoration.denoise_wavelet
denoise_func = restoration.denoise_wavelet func_kw = dict(sigma=sigma, channel_axis=channel_axis,
func_kw = dict(sigma=sigma, channel_axis=channel_axis, rescale_sigma=rescale_sigma)
rescale_sigma=rescale_sigma)
# max_shifts=0 is equivalent to just calling denoise_func # max_shifts=0 is equivalent to just calling denoise_func
with expected_warnings([DASK_NOT_INSTALLED_WARNING]):
dn_cc = restoration.cycle_spin(noisy, denoise_func, max_shifts=0,
func_kw=func_kw,
channel_axis=channel_axis)
dn = denoise_func(noisy, **func_kw)
assert_array_equal(dn, dn_cc)
# denoising with cycle spinning will give better PSNR than without
for max_shifts in valid_shifts:
with expected_warnings([DASK_NOT_INSTALLED_WARNING]): with expected_warnings([DASK_NOT_INSTALLED_WARNING]):
dn_cc = restoration.cycle_spin(noisy, denoise_func, max_shifts=0, dn_cc = restoration.cycle_spin(noisy, denoise_func,
max_shifts=max_shifts,
func_kw=func_kw, func_kw=func_kw,
channel_axis=channel_axis) channel_axis=channel_axis)
dn = denoise_func(noisy, **func_kw) psnr = peak_signal_noise_ratio(img, dn)
assert_array_equal(dn, dn_cc) psnr_cc = peak_signal_noise_ratio(img, dn_cc)
assert psnr_cc > psnr
# denoising with cycle spinning will give better PSNR than without for shift_steps in valid_steps:
for max_shifts in valid_shifts: with expected_warnings([DASK_NOT_INSTALLED_WARNING]):
with expected_warnings([DASK_NOT_INSTALLED_WARNING]): dn_cc = restoration.cycle_spin(noisy, denoise_func,
dn_cc = restoration.cycle_spin(noisy, denoise_func, max_shifts=2,
max_shifts=max_shifts, shift_steps=shift_steps,
func_kw=func_kw, func_kw=func_kw,
channel_axis=channel_axis) channel_axis=channel_axis)
psnr = peak_signal_noise_ratio(img, dn) psnr = peak_signal_noise_ratio(img, dn)
psnr_cc = peak_signal_noise_ratio(img, dn_cc) psnr_cc = peak_signal_noise_ratio(img, dn_cc)
assert psnr_cc > psnr assert psnr_cc > psnr
for shift_steps in valid_steps: for max_shifts in invalid_shifts:
with expected_warnings([DASK_NOT_INSTALLED_WARNING]): with pytest.raises(ValueError):
dn_cc = restoration.cycle_spin(noisy, denoise_func, dn_cc = restoration.cycle_spin(noisy, denoise_func,
max_shifts=2, max_shifts=max_shifts,
shift_steps=shift_steps, func_kw=func_kw,
func_kw=func_kw, channel_axis=channel_axis)
channel_axis=channel_axis) for shift_steps in invalid_steps:
psnr = peak_signal_noise_ratio(img, dn) with pytest.raises(ValueError):
psnr_cc = peak_signal_noise_ratio(img, dn_cc) dn_cc = restoration.cycle_spin(noisy, denoise_func,
assert psnr_cc > psnr max_shifts=2,
shift_steps=shift_steps,
for max_shifts in invalid_shifts: func_kw=func_kw,
with pytest.raises(ValueError): channel_axis=channel_axis)
dn_cc = restoration.cycle_spin(noisy, denoise_func,
max_shifts=max_shifts,
func_kw=func_kw,
channel_axis=channel_axis)
for shift_steps in invalid_steps:
with pytest.raises(ValueError):
dn_cc = restoration.cycle_spin(noisy, denoise_func,
max_shifts=2,
shift_steps=shift_steps,
func_kw=func_kw,
channel_axis=channel_axis)
def test_cycle_spinning_num_workers(): def test_cycle_spinning_num_workers():
img = astro_gray img = astro_gray
sigma = 0.1 sigma = 0.1
rstate = np.random.default_rng(1234) rstate = np.random.default_rng(1234)
noisy = img.copy() + 0.1 * rstate.standard_normal(img.shape) noisy = img.copy() + 0.1 * rstate.standard_normal(img.shape)
denoise_func = restoration.denoise_wavelet denoise_func = restoration.denoise_wavelet
func_kw = dict(sigma=sigma, channel_axis=-1, rescale_sigma=True) func_kw = dict(sigma=sigma, channel_axis=-1, rescale_sigma=True)
# same results are expected whether using 1 worker or multiple workers # same results are expected whether using 1 worker or multiple workers
dn_cc1 = restoration.cycle_spin(noisy, denoise_func, max_shifts=1, dn_cc1 = restoration.cycle_spin(noisy, denoise_func, max_shifts=1,
func_kw=func_kw, channel_axis=None, func_kw=func_kw, channel_axis=None,
num_workers=1) num_workers=1)
# Repeat dn_cc1 computation, but without channel_axis specified to
# verify that the default behavior is channel_axis=None
dn_cc1_ = restoration.cycle_spin(noisy, denoise_func, max_shifts=1,
func_kw=func_kw, num_workers=1)
assert_array_equal(dn_cc1, dn_cc1_)
with expected_warnings([DASK_NOT_INSTALLED_WARNING]): with expected_warnings([DASK_NOT_INSTALLED_WARNING]):
dn_cc2 = restoration.cycle_spin(noisy, denoise_func, max_shifts=1, dn_cc2 = restoration.cycle_spin(noisy, denoise_func, max_shifts=1,
func_kw=func_kw, channel_axis=None, func_kw=func_kw, channel_axis=None,
num_workers=4) num_workers=4)
dn_cc3 = restoration.cycle_spin(noisy, denoise_func, max_shifts=1, dn_cc3 = restoration.cycle_spin(noisy, denoise_func, max_shifts=1,
func_kw=func_kw, channel_axis=None, func_kw=func_kw, channel_axis=None,
num_workers=None) num_workers=None)
assert_array_almost_equal(dn_cc1, dn_cc2) assert_array_almost_equal(dn_cc1, dn_cc2)
assert_array_almost_equal(dn_cc1, dn_cc3) assert_array_almost_equal(dn_cc1, dn_cc3)
 End of changes. 9 change blocks. 
64 lines changed or deleted 73 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)