# This is a combination of 7 commits.

# The first commit's message is:
Add a known_warning decorator and suppress warnings in color pkg

# This is the 2nd commit message:

Use the existing all_warnings context manager

# This is the 3rd commit message:

Raise warnings in data

# This is the 4th commit message:

Raise warnings in draw

# This is the 5th commit message:

Raise warnings in exposure

# This is the 6th commit message:

Suppress warnings in exposure tests

# This is the 7th commit message:

Add comments about warning suppressions
This commit is contained in:
Steven Silvester
2014-12-23 16:46:24 -06:00
parent 8955bbf807
commit 874d68ba3f
9 changed files with 40 additions and 20 deletions
+1
View File
@@ -163,3 +163,4 @@ def assert_nD(array, ndim, arg_name='image'):
ndim = [ndim]
if not array.ndim in ndim:
raise ValueError(msg % (arg_name, '-or-'.join([str(n) for n in ndim])))
+2
View File
@@ -0,0 +1,2 @@
import warnings
warnings.simplefilter('error')
+13 -12
View File
@@ -3,54 +3,55 @@ from functools import partial
import numpy as np
from skimage import img_as_float, img_as_uint
from skimage import color, data, filter
from skimage import color, data, filters
from skimage.color.adapt_rgb import adapt_rgb, each_channel, hsv_value
from skimage._shared.utils import all_warnings
# Down-sample image for quicker testing.
COLOR_IMAGE = data.astronaut()[::5, ::5]
GRAY_IMAGE = data.camera()[::5, ::5]
SIGMA = 3
smooth = partial(filter.gaussian_filter, sigma=SIGMA)
smooth = partial(filters.gaussian_filter, sigma=SIGMA)
assert_allclose = partial(np.testing.assert_allclose, atol=1e-8)
@adapt_rgb(each_channel)
def edges_each(image):
return filter.sobel(image)
return filters.sobel(image)
@adapt_rgb(each_channel)
def smooth_each(image, sigma):
return filter.gaussian_filter(image, sigma)
return filters.gaussian_filter(image, sigma)
@adapt_rgb(hsv_value)
def edges_hsv(image):
return filter.sobel(image)
return filters.sobel(image)
@adapt_rgb(hsv_value)
def smooth_hsv(image, sigma):
return filter.gaussian_filter(image, sigma)
return filters.gaussian_filter(image, sigma)
@adapt_rgb(hsv_value)
def edges_hsv_uint(image):
return img_as_uint(filter.sobel(image))
with all_warnings(): # precision loss
return img_as_uint(filters.sobel(image))
def test_gray_scale_image():
# We don't need to test both `hsv_value` and `each_channel` since
# `adapt_rgb` is handling gray-scale inputs.
assert_allclose(edges_each(GRAY_IMAGE), filter.sobel(GRAY_IMAGE))
assert_allclose(edges_each(GRAY_IMAGE), filters.sobel(GRAY_IMAGE))
def test_each_channel():
filtered = edges_each(COLOR_IMAGE)
for i, channel in enumerate(np.rollaxis(filtered, axis=-1)):
expected = img_as_float(filter.sobel(COLOR_IMAGE[:, :, i]))
expected = img_as_float(filters.sobel(COLOR_IMAGE[:, :, i]))
assert_allclose(channel, expected)
@@ -63,7 +64,7 @@ def test_each_channel_with_filter_argument():
def test_hsv_value():
filtered = edges_hsv(COLOR_IMAGE)
value = color.rgb2hsv(COLOR_IMAGE)[:, :, 2]
assert_allclose(color.rgb2hsv(filtered)[:, :, 2], filter.sobel(value))
assert_allclose(color.rgb2hsv(filtered)[:, :, 2], filters.sobel(value))
def test_hsv_value_with_filter_argument():
@@ -80,4 +81,4 @@ def test_hsv_value_with_non_float_output():
filtered_value = color.rgb2hsv(filtered)[:, :, 2]
value = color.rgb2hsv(COLOR_IMAGE)[:, :, 2]
# Reduce tolerance because dtype conversion.
assert_allclose(filtered_value, filter.sobel(value), rtol=1e-5, atol=1e-5)
assert_allclose(filtered_value, filters.sobel(value), rtol=1e-5, atol=1e-5)
+5 -2
View File
@@ -39,7 +39,8 @@ from skimage.color import (rgb2hsv, hsv2rgb,
guess_spatial_dimensions
)
from skimage import data_dir, data
from skimage import data_dir
from skimage._shared.utils import all_warnings
import colorsys
@@ -156,7 +157,9 @@ class TestColorconv(TestCase):
# RGB<->HED roundtrip with ubyte image
def test_hed_rgb_roundtrip(self):
img_rgb = img_as_ubyte(self.img_rgb)
assert_equal(img_as_ubyte(hed2rgb(rgb2hed(img_rgb))), img_rgb)
with all_warnings(): # precision loss
new = img_as_ubyte(hed2rgb(rgb2hed(img_rgb)))
assert_equal(new, img_rgb)
# RGB<->HED roundtrip with float image
def test_hed_rgb_float_roundtrip(self):
+2
View File
@@ -0,0 +1,2 @@
import warnings
warnings.simplefilter('error')
+2
View File
@@ -0,0 +1,2 @@
import warnings
warnings.simplefilter('error')
+2
View File
@@ -0,0 +1,2 @@
import warnings
warnings.simplefilter('error')
+10 -5
View File
@@ -11,6 +11,7 @@ from skimage import exposure
from skimage.exposure.exposure import intensity_range
from skimage.color import rgb2gray
from skimage.util.dtype import dtype_range
from skimage._shared.utils import all_warnings
# Test integer histograms
@@ -52,7 +53,8 @@ def test_equalize_uint8_approx():
def test_equalize_ubyte():
img = skimage.img_as_ubyte(test_img)
with all_warnings(): # precision loss
img = skimage.img_as_ubyte(test_img)
img_eq = exposure.equalize_hist(img)
cdf, bin_edges = exposure.cumulative_distribution(img_eq)
@@ -209,8 +211,9 @@ def test_adapthist_grayscale():
img = skimage.img_as_float(data.astronaut())
img = rgb2gray(img)
img = np.dstack((img, img, img))
adapted = exposure.equalize_adapthist(img, 10, 9, clip_limit=0.01,
nbins=128)
with all_warnings(): # precision loss
adapted = exposure.equalize_adapthist(img, 10, 9, clip_limit=0.01,
nbins=128)
assert_almost_equal = np.testing.assert_almost_equal
assert img.shape == adapted.shape
assert_almost_equal(peak_snr(img, adapted), 97.6876, 3)
@@ -226,7 +229,8 @@ def test_adapthist_color():
warnings.simplefilter('always')
hist, bin_centers = exposure.histogram(img)
assert len(w) > 0
adapted = exposure.equalize_adapthist(img, clip_limit=0.01)
with all_warnings(): # precision loss
adapted = exposure.equalize_adapthist(img, clip_limit=0.01)
assert_almost_equal = np.testing.assert_almost_equal
assert adapted.min() == 0
@@ -244,7 +248,8 @@ def test_adapthist_alpha():
img = skimage.img_as_float(data.astronaut())
alpha = np.ones((img.shape[0], img.shape[1]), dtype=float)
img = np.dstack((img, alpha))
adapted = exposure.equalize_adapthist(img)
with all_warnings(): # precision loss
adapted = exposure.equalize_adapthist(img)
assert adapted.shape != img.shape
img = img[:, :, :3]
full_scale = skimage.exposure.rescale_intensity(img)
+3 -1
View File
@@ -39,6 +39,7 @@ def imread(fname, dtype=None, img_num=None, **kwargs):
.. [2] http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
"""
print('imread', fname)
if hasattr(fname, 'lower') and dtype is None:
kwargs.setdefault('key', img_num)
if fname.lower().endswith(('.tiff', '.tif')):
@@ -47,7 +48,8 @@ def imread(fname, dtype=None, img_num=None, **kwargs):
im = Image.open(fname)
try:
# this will raise an IOError if the file is not readable
im.getdata()[0]
#im.getdata()[0]
pass
except IOError:
site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries"
raise ValueError('Could not load "%s"\nPlease see documentation at: %s' % (fname, site))