mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-23 13:10:18 +08:00
Fix test: clip image that exceeded float range.
This commit is contained in:
committed by
Stefan van der Walt
parent
0dcd5dc38e
commit
5ed5c070c7
@@ -15,6 +15,8 @@ class TestTvDenoise():
|
||||
lena = color.rgb2gray(data.lena())[:256, :256]
|
||||
# add noise to lena
|
||||
lena += 0.5 * lena.std()*np.random.randn(*lena.shape)
|
||||
# clip noise so that it does not exceed allowed range for float images.
|
||||
lena = np.clip(lena, 0, 1)
|
||||
# denoise
|
||||
denoised_lena = filter.tv_denoise(lena, weight=60.0)
|
||||
# which dtype?
|
||||
|
||||
@@ -20,7 +20,7 @@ _supported_types = (np.uint8, np.uint16, np.uint32,
|
||||
np.float16, np.float32, np.float64)
|
||||
|
||||
|
||||
def _convert(image, dtype):
|
||||
def convert(image, dtype):
|
||||
"""
|
||||
Convert an image to the requested data-type.
|
||||
|
||||
@@ -167,7 +167,7 @@ def img_as_float(image):
|
||||
Negative input values will be shifted to the positive domain.
|
||||
|
||||
"""
|
||||
return _convert(image, np.float64)
|
||||
return convert(image, np.float64)
|
||||
|
||||
|
||||
def img_as_uint(image):
|
||||
@@ -188,7 +188,7 @@ def img_as_uint(image):
|
||||
Negative input values will be shifted to the positive domain.
|
||||
|
||||
"""
|
||||
return _convert(image, np.uint16)
|
||||
return convert(image, np.uint16)
|
||||
|
||||
|
||||
def img_as_int(image):
|
||||
@@ -210,7 +210,7 @@ def img_as_int(image):
|
||||
the output image will still only have positive values.
|
||||
|
||||
"""
|
||||
return _convert(image, np.int16)
|
||||
return convert(image, np.int16)
|
||||
|
||||
|
||||
def img_as_ubyte(image):
|
||||
@@ -232,4 +232,4 @@ def img_as_ubyte(image):
|
||||
the output image will still only have positive values.
|
||||
|
||||
"""
|
||||
return _convert(image, np.uint8)
|
||||
return convert(image, np.uint8)
|
||||
|
||||
@@ -2,7 +2,7 @@ import numpy as np
|
||||
from numpy.testing import assert_equal, assert_raises
|
||||
from skimage import img_as_int, img_as_float, \
|
||||
img_as_uint, img_as_ubyte
|
||||
from skimage.util.dtype import _convert
|
||||
from skimage.util.dtype import convert
|
||||
|
||||
|
||||
dtype_range = {np.uint8: (0, 255),
|
||||
@@ -40,7 +40,7 @@ def test_range():
|
||||
def test_range_extra_dtypes():
|
||||
"""Test code paths that are not skipped by `test_range`"""
|
||||
|
||||
# Add non-standard data types that are allowed by the `_convert` function.
|
||||
# Add non-standard data types that are allowed by the `convert` function.
|
||||
dtype_range_extra = dtype_range.copy()
|
||||
dtype_range_extra.update({np.int32: (-2147483648, 2147483647),
|
||||
np.uint32: (0, 4294967295)})
|
||||
@@ -55,7 +55,7 @@ def test_range_extra_dtypes():
|
||||
for dtype_in, dt in dtype_pairs:
|
||||
imin, imax = dtype_range_extra[dtype_in]
|
||||
x = np.linspace(imin, imax, 10).astype(dtype_in)
|
||||
y = _convert(x, dt)
|
||||
y = convert(x, dt)
|
||||
omin, omax = dtype_range_extra[dt]
|
||||
yield _verify_range, \
|
||||
"From %s to %s" % (np.dtype(dtype_in), np.dtype(dt)), \
|
||||
|
||||
Reference in New Issue
Block a user