diff --git a/doc/source/user_guide/transforming_image_data.rst b/doc/source/user_guide/transforming_image_data.rst index 817e8190..883cda41 100644 --- a/doc/source/user_guide/transforming_image_data.rst +++ b/doc/source/user_guide/transforming_image_data.rst @@ -50,7 +50,7 @@ background is realized with :func:`rgba2rgb` :: >>> from skimage.color import rgba2rgb >>> from skimage import data - >>> img_rgba = data.horse() + >>> img_rgba = data.logo() >>> img_rgb = rgba2rgb(img_rgba) Conversion between color and gray values diff --git a/skimage/_shared/_warnings.py b/skimage/_shared/_warnings.py index d397d8e9..e6c43d32 100644 --- a/skimage/_shared/_warnings.py +++ b/skimage/_shared/_warnings.py @@ -82,7 +82,6 @@ def expected_warnings(matching): matching : list of strings or compiled regexes Regexes for the desired warning to catch - Examples -------- >>> from skimage import data, img_as_ubyte, img_as_float @@ -96,14 +95,14 @@ def expected_warnings(matching): pattern(s). Raises a ValueError if any match was not found or an unexpected warning was raised. - Allows for three types of behaviors: "and", "or", and "optional" matches. + Allows for three types of behaviors: `and`, `or`, and `optional` matches. This is done to accomodate different build enviroments or loop conditions that may produce different warnings. The behaviors can be combined. - If you pass multiple patterns, you get an orderless "and", where all of the + If you pass multiple patterns, you get an orderless `and`, where all of the warnings must be raised. - If you use the "|" operator in a pattern, you can catch one of several + If you use the `|` operator in a pattern, you can catch one of several warnings. - Finally, you can use "|\A\Z" in a pattern to signify it as optional. + Finally, you can use `|\A\Z` in a pattern to signify it as optional. """ with all_warnings() as w: diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index 29baa91e..57aac513 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -200,7 +200,7 @@ def rgba2rgb(rgba, background=(1, 1, 1)): -------- >>> from skimage import color >>> from skimage import data - >>> img_rgba = data.horse() + >>> img_rgba = data.logo() >>> img_rgb = color.rgba2rgb(img_rgba) """ arr = _prepare_rgba_array(rgba) diff --git a/skimage/data/__init__.py b/skimage/data/__init__.py index 6dc5dd8e..3a506f85 100644 --- a/skimage/data/__init__.py +++ b/skimage/data/__init__.py @@ -10,34 +10,37 @@ import os as _os from .. import data_dir from ..io import imread, use_plugin -from .._shared.utils import deprecated +from .._shared._warnings import expected_warnings from ._binary_blobs import binary_blobs +from .. import img_as_bool __all__ = ['load', + 'astronaut', 'camera', - 'lena', - 'text', 'checkerboard', + 'chelsea', + 'clock', + 'coffee', 'coins', + 'horse', + 'hubble_deep_field', + 'immunohistochemistry', + 'logo', 'moon', 'page', - 'horse', - 'clock', - 'immunohistochemistry', - 'chelsea', - 'coffee', - 'hubble_deep_field', - 'rocket', - 'astronaut'] + 'text', + 'rocket'] -def load(f): +def load(f, as_grey=False): """Load an image file located in the data directory. Parameters ---------- f : string File name. + as_grey : bool, optional + Convert to greyscale. Returns ------- @@ -45,7 +48,7 @@ def load(f): Image loaded from ``skimage.data_dir``. """ use_plugin('pil') - return imread(_os.path.join(data_dir, f)) + return imread(_os.path.join(data_dir, f), as_grey=as_grey) def camera(): @@ -57,22 +60,6 @@ def camera(): return load("camera.png") -@deprecated('skimage.data.astronaut') -def lena(): - """Colour "Lena" image. - - **This image has been removed from scikit-image due to copyright - concerns.** - - The standard, yet sometimes controversial Lena test image was - scanned from the November 1972 edition of Playboy magazine. From - an image processing perspective, this image is useful because it - contains smooth, textured, shaded as well as detail areas. - - """ - raise RuntimeError("This image has been removed due to copyright concerns.") - - def astronaut(): """Colour image of the astronaut Eileen Collins. @@ -138,6 +125,11 @@ def coins(): return load("coins.png") +def logo(): + """Scikit-image logo, a RGBA image.""" + return load("logo.png") + + def moon(): """Surface of the moon. @@ -168,7 +160,8 @@ def horse(): (marauder). """ - return load("horse.png") + with expected_warnings(['Possible precision loss', 'Possible sign loss']): + return img_as_bool(load("horse.png", as_grey=True)) def clock(): @@ -242,8 +235,8 @@ def hubble_deep_field(): `HubbleSite `__. - The image was captured by NASA and `may be freely used in the - public domain `_. + The image was captured by NASA and `may be freely used in the public domain + `_. """ return load("hubble_deep_field.jpg") diff --git a/skimage/data/logo.png b/skimage/data/logo.png new file mode 100644 index 00000000..4912fb3e Binary files /dev/null and b/skimage/data/logo.png differ diff --git a/skimage/data/tests/test_data.py b/skimage/data/tests/test_data.py index e17b2f08..028210dc 100644 --- a/skimage/data/tests/test_data.py +++ b/skimage/data/tests/test_data.py @@ -3,11 +3,6 @@ import skimage.data as data from numpy.testing import assert_equal, assert_almost_equal, assert_raises -def test_lena_removed(): - """ Test that "Lena" has been removed """ - assert_raises(RuntimeError, data.lena) - - def test_astronaut(): """ Test that "astronaut" image can be loaded. """ astronaut = data.astronaut() @@ -25,9 +20,43 @@ def test_checkerboard(): data.checkerboard() -def test_text(): - """ Test that "text" image can be loaded. """ - data.text() +def test_chelsea(): + """ Test that "chelsea" image can be loaded. """ + data.chelsea() + + +def test_clock(): + """ Test that "clock" image can be loaded. """ + data.clock() + + +def test_coffee(): + """ Test that "coffee" image can be loaded. """ + data.coffee() + + +def test_horse(): + """ Test that "horse" image can be loaded. """ + horse = data.horse() + assert_equal(horse.ndim, 2) + assert_equal(horse.dtype, np.dtype('bool')) + + +def test_hubble(): + """ Test that "Hubble" image can be loaded. """ + data.hubble_deep_field() + + +def test_immunohistochemistry(): + """ Test that "immunohistochemistry" image can be loaded. """ + data.immunohistochemistry() + + +def test_logo(): + """ Test that "logo" image can be loaded. """ + logo = data.logo() + assert_equal(logo.ndim, 3) + assert_equal(logo.shape[2], 4) def test_moon(): @@ -40,19 +69,14 @@ def test_page(): data.page() -def test_clock(): - """ Test that "clock" image can be loaded. """ - data.clock() +def test_rocket(): + """ Test that "rocket" image can be loaded. """ + data.rocket() -def test_chelsea(): - """ Test that "chelsea" image can be loaded. """ - data.chelsea() - - -def test_coffee(): - """ Test that "coffee" image can be loaded. """ - data.coffee() +def test_text(): + """ Test that "text" image can be loaded. """ + data.text() def test_binary_blobs():