diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index a166598b..ec9798aa 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -176,16 +176,19 @@ - François Orieux Image deconvolution http://research.orieux.fr - + - Vighnesh Birodkar Blob Detection - + - Axel Donath Blob Detection - Adam Feuer PIL Image import and export improvements +- Rebecca Murphy + astronaut in examples + - Geoffrey French skimage.filters.rank.windowed_histogram and plot_windowed_histogram example. diff --git a/doc/examples/plot_brief.py b/doc/examples/plot_brief.py index 47c9ad5f..247cf1dd 100644 --- a/doc/examples/plot_brief.py +++ b/doc/examples/plot_brief.py @@ -22,7 +22,7 @@ from skimage.color import rgb2gray import matplotlib.pyplot as plt -img1 = rgb2gray(data.lena()) +img1 = rgb2gray(data.astronaut()) tform = tf.AffineTransform(scale=(1.2, 1.2), translation=(0, -100)) img2 = tf.warp(img1, tform) img3 = tf.rotate(img1, 25) diff --git a/doc/examples/plot_censure.py b/doc/examples/plot_censure.py index c7d70ea5..b2a52440 100644 --- a/doc/examples/plot_censure.py +++ b/doc/examples/plot_censure.py @@ -15,7 +15,7 @@ from skimage.color import rgb2gray import matplotlib.pyplot as plt -img1 = rgb2gray(data.lena()) +img1 = rgb2gray(data.astronaut()) tform = tf.AffineTransform(scale=(1.5, 1.5), rotation=0.5, translation=(150, -200)) img2 = tf.warp(img1, tform) diff --git a/doc/examples/plot_denoise.py b/doc/examples/plot_denoise.py index 3a05c99f..1313bc04 100644 --- a/doc/examples/plot_denoise.py +++ b/doc/examples/plot_denoise.py @@ -1,10 +1,10 @@ """ -============================= -Denoising the picture of Lena -============================= +==================== +Denoising a picture +==================== -In this example, we denoise a noisy version of the picture of Lena using the -total variation and bilateral denoising filter. +In this example, we denoise a noisy version of the picture of the astronaut +Eileen Collins using the total variation and bilateral denoising filter. These algorithms typically produce "posterized" images with flat domains separated by sharp edges. It is possible to change the degree of posterization @@ -32,10 +32,10 @@ from skimage import data, img_as_float from skimage.restoration import denoise_tv_chambolle, denoise_bilateral -lena = img_as_float(data.lena()) -lena = lena[220:300, 220:320] +astro = img_as_float(data.astronaut()) +astro = astro[220:300, 220:320] -noisy = lena + 0.6 * lena.std() * np.random.random(lena.shape) +noisy = astro + 0.6 * astro.std() * np.random.random(astro.shape) noisy = np.clip(noisy, 0, 1) fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5)) @@ -58,7 +58,7 @@ ax[1, 0].set_title('(more) TV') ax[1, 1].imshow(denoise_bilateral(noisy, sigma_range=0.1, sigma_spatial=15)) ax[1, 1].axis('off') ax[1, 1].set_title('(more) Bilateral') -ax[1, 2].imshow(lena) +ax[1, 2].imshow(astro) ax[1, 2].axis('off') ax[1, 2].set_title('original') diff --git a/doc/examples/plot_gabors_from_lena.py b/doc/examples/plot_gabors_from_astronaut.py similarity index 64% rename from doc/examples/plot_gabors_from_lena.py rename to doc/examples/plot_gabors_from_astronaut.py index 207230aa..d7edfa51 100644 --- a/doc/examples/plot_gabors_from_lena.py +++ b/doc/examples/plot_gabors_from_astronaut.py @@ -1,7 +1,7 @@ """ -======================================================= -Gabors / Primary Visual Cortex "Simple Cells" from Lena -======================================================= +============================================================ +Gabors / Primary Visual Cortex "Simple Cells" from an Image +============================================================ How to build a (bio-plausible) "sparse" dictionary (or 'codebook', or 'filterbank') for e.g. image classification without any fancy math and @@ -10,15 +10,16 @@ with just standard python scientific libraries? Please find below a short answer ;-) This simple example shows how to get Gabor-like filters [1]_ using just -the famous Lena image. Gabor filters are good approximations of the -"Simple Cells" [2]_ receptive fields [3]_ found in the mammalian primary -visual cortex (V1) (for details, see e.g. the Nobel-prize winning work -of Hubel & Wiesel done in the 60s [4]_ [5]_). +a simple image. In our example, we use a photograph of the astronaut Eileen +Collins. Gabor filters are good approximations of the "Simple Cells" [2]_ +receptive fields [3]_ found in the mammalian primary visual cortex (V1) +(for details, see e.g. the Nobel-prize winning work of Hubel & Wiesel done +in the 60s [4]_ [5]_). Here we use McQueen's 'kmeans' algorithm [6]_, as a simple biologically plausible hebbian-like learning rule and we apply it (a) to patches of -the original Lena image (retinal projection), and (b) to patches of an -LGN-like [7]_ Lena image using a simple difference of gaussians (DoG) +the original image (retinal projection), and (b) to patches of an +LGN-like [7]_ image using a simple difference of gaussians (DoG) approximation. Enjoy ;-) And keep in mind that getting Gabors on natural image patches @@ -50,18 +51,18 @@ np.random.seed(42) patch_shape = 8, 8 n_filters = 49 -lena = color.rgb2gray(data.lena()) +astro = color.rgb2gray(data.astronaut()) -# -- filterbank1 on original Lena -patches1 = view_as_windows(lena, patch_shape) +# -- filterbank1 on original image +patches1 = view_as_windows(astro, patch_shape) patches1 = patches1.reshape(-1, patch_shape[0] * patch_shape[1])[::8] fb1, _ = kmeans2(patches1, n_filters, minit='points') fb1 = fb1.reshape((-1,) + patch_shape) fb1_montage = montage2d(fb1, rescale_intensity=True) -# -- filterbank2 LGN-like Lena -lena_dog = ndi.gaussian_filter(lena, .5) - ndi.gaussian_filter(lena, 1) -patches2 = view_as_windows(lena_dog, patch_shape) +# -- filterbank2 LGN-like image +astro_dog = ndi.gaussian_filter(astro, .5) - ndi.gaussian_filter(astro, 1) +patches2 = view_as_windows(astro_dog, patch_shape) patches2 = patches2.reshape(-1, patch_shape[0] * patch_shape[1])[::8] fb2, _ = kmeans2(patches2, n_filters, minit='points') fb2 = fb2.reshape((-1,) + patch_shape) @@ -71,17 +72,17 @@ fb2_montage = montage2d(fb2, rescale_intensity=True) fig, axes = plt.subplots(2, 2, figsize=(7, 6)) ax0, ax1, ax2, ax3 = axes.ravel() -ax0.imshow(lena, cmap=plt.cm.gray) -ax0.set_title("Lena (original)") +ax0.imshow(astro, cmap=plt.cm.gray) +ax0.set_title("Image (original)") ax1.imshow(fb1_montage, cmap=plt.cm.gray, interpolation='nearest') -ax1.set_title("K-means filterbank (codebook)\non Lena (original)") +ax1.set_title("K-means filterbank (codebook)\non original image") -ax2.imshow(lena_dog, cmap=plt.cm.gray) -ax2.set_title("Lena (LGN-like DoG)") +ax2.imshow(astro_dog, cmap=plt.cm.gray) +ax2.set_title("Image (LGN-like DoG)") ax3.imshow(fb2_montage, cmap=plt.cm.gray, interpolation='nearest') -ax3.set_title("K-means filterbank (codebook)\non Lena (LGN-like DoG)") +ax3.set_title("K-means filterbank (codebook)\non LGN-like DoG image") for ax in axes.ravel(): ax.axis('off') diff --git a/doc/examples/plot_hog.py b/doc/examples/plot_hog.py index 4899c590..15b279bd 100644 --- a/doc/examples/plot_hog.py +++ b/doc/examples/plot_hog.py @@ -85,7 +85,7 @@ from skimage.feature import hog from skimage import data, color, exposure -image = color.rgb2gray(data.lena()) +image = color.rgb2gray(data.astronaut()) fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualise=True) diff --git a/doc/examples/plot_orb.py b/doc/examples/plot_orb.py index 1a73fc7f..8d4e1485 100644 --- a/doc/examples/plot_orb.py +++ b/doc/examples/plot_orb.py @@ -20,7 +20,7 @@ from skimage.color import rgb2gray import matplotlib.pyplot as plt -img1 = rgb2gray(data.lena()) +img1 = rgb2gray(data.astronaut()) img2 = tf.rotate(img1, 180) tform = tf.AffineTransform(scale=(1.3, 1.1), rotation=0.5, translation=(0, -200)) diff --git a/doc/examples/plot_piecewise_affine.py b/doc/examples/plot_piecewise_affine.py index b1fb551f..d05986ca 100644 --- a/doc/examples/plot_piecewise_affine.py +++ b/doc/examples/plot_piecewise_affine.py @@ -12,7 +12,7 @@ from skimage.transform import PiecewiseAffineTransform, warp from skimage import data -image = data.lena() +image = data.astronaut() rows, cols = image.shape[0], image.shape[1] src_cols = np.linspace(0, cols, 20) diff --git a/doc/examples/plot_pyramid.py b/doc/examples/plot_pyramid.py index 8e309edf..b1e22022 100644 --- a/doc/examples/plot_pyramid.py +++ b/doc/examples/plot_pyramid.py @@ -16,7 +16,7 @@ from skimage import data from skimage.transform import pyramid_gaussian -image = data.lena() +image = data.astronaut() rows, cols, dim = image.shape pyramid = tuple(pyramid_gaussian(image, downscale=2)) diff --git a/doc/examples/plot_restoration.py b/doc/examples/plot_restoration.py index fdffd953..52cbec27 100644 --- a/doc/examples/plot_restoration.py +++ b/doc/examples/plot_restoration.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- """ ===================== -Deconvolution of Lena +Image Deconvolution ===================== -In this example, we deconvolve a noisy version of Lena using Wiener +In this example, we deconvolve a noisy version of an image using Wiener and unsupervised Wiener algorithms. This algorithms are based on linear models that can't restore sharp edge as much as non-linear methods (like TV restoration) but are much faster. @@ -34,19 +34,19 @@ import matplotlib.pyplot as plt from skimage import color, data, restoration -lena = color.rgb2gray(data.lena()) +astro = color.rgb2gray(data.astronaut()) from scipy.signal import convolve2d as conv2 psf = np.ones((5, 5)) / 25 -lena = conv2(lena, psf, 'same') -lena += 0.1 * lena.std() * np.random.standard_normal(lena.shape) +astro = conv2(astro, psf, 'same') +astro += 0.1 * astro.std() * np.random.standard_normal(astro.shape) -deconvolved, _ = restoration.unsupervised_wiener(lena, psf) +deconvolved, _ = restoration.unsupervised_wiener(astro, psf) fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(8, 5)) plt.gray() -ax[0].imshow(lena, vmin=deconvolved.min(), vmax=deconvolved.max()) +ax[0].imshow(astro, vmin=deconvolved.min(), vmax=deconvolved.max()) ax[0].axis('off') ax[0].set_title('Data') diff --git a/doc/examples/plot_segmentations.py b/doc/examples/plot_segmentations.py index abbf352d..d62d12a9 100644 --- a/doc/examples/plot_segmentations.py +++ b/doc/examples/plot_segmentations.py @@ -63,12 +63,12 @@ from __future__ import print_function import matplotlib.pyplot as plt import numpy as np -from skimage.data import lena +from skimage.data import astronaut from skimage.segmentation import felzenszwalb, slic, quickshift from skimage.segmentation import mark_boundaries from skimage.util import img_as_float -img = img_as_float(lena()[::2, ::2]) +img = img_as_float(astronaut()[::2, ::2]) segments_fz = felzenszwalb(img, scale=100, sigma=0.5, min_size=50) segments_slic = slic(img, n_segments=250, compactness=10, sigma=1) segments_quick = quickshift(img, kernel_size=3, max_dist=6, ratio=0.5) diff --git a/doc/examples/plot_view_as_blocks.py b/doc/examples/plot_view_as_blocks.py index 2237e50b..eeb510ed 100644 --- a/doc/examples/plot_view_as_blocks.py +++ b/doc/examples/plot_view_as_blocks.py @@ -7,10 +7,10 @@ This example illustrates the use of `view_as_blocks` from `skimage.util.shape`. Block views can be incredibly useful when one wants to perform local operations on non-overlapping image patches. -We use `lena` from `skimage.data` and virtually 'slice' it into square +We use `astronaut` from `skimage.data` and virtually 'slice' it into square blocks. Then, on each block, we either pool the mean, the max or the median value of that block. The results are displayed altogether, along -with a spline interpolation of order 3 rescaling of the original `lena` +with a spline interpolation of order 3 rescaling of the original `astronaut` image. """ @@ -24,20 +24,20 @@ from skimage import color from skimage.util.shape import view_as_blocks -# -- get `lena` from skimage.data in grayscale -l = color.rgb2gray(data.lena()) +# -- get `astronaut` from skimage.data in grayscale +l = color.rgb2gray(data.astronaut()) # -- size of blocks block_shape = (4, 4) -# -- see `lena` as a matrix of blocks (of shape +# -- see `astronaut` as a matrix of blocks (of shape # `block_shape`) view = view_as_blocks(l, block_shape) # -- collapse the last two dimensions in one flatten_view = view.reshape(view.shape[0], view.shape[1], -1) -# -- resampling `lena` by taking either the `mean`, +# -- resampling `astronaut` by taking either the `mean`, # the `max` or the `median` value of each blocks. mean_view = np.mean(flatten_view, axis=2) max_view = np.max(flatten_view, axis=2) diff --git a/doc/logo/scipy_logo.py b/doc/logo/scipy_logo.py index bc145069..b23787c8 100644 --- a/doc/logo/scipy_logo.py +++ b/doc/logo/scipy_logo.py @@ -241,18 +241,8 @@ def plot_snake_overlay(): plt.imshow(img) -def plot_lena_overlay(): - plt.figure() - logo = ScipyLogo((300, 300), 180) - logo.plot_snake_curve() - logo.plot_circle() - img = data.lena() - plt.imshow(img) - - if __name__ == '__main__': plot_scipy_trace() plot_snake_overlay() - plot_lena_overlay() plt.show() diff --git a/doc/source/api_changes.txt b/doc/source/api_changes.txt index 0271bec0..8ebcc6ed 100644 --- a/doc/source/api_changes.txt +++ b/doc/source/api_changes.txt @@ -1,3 +1,8 @@ +Version 0.11 +------------ +- Some edge detectors returned values greater than 1--their results are now + appropriately scaled with a factor of ``sqrt(2)``. + Version 0.10 ------------ - Removed ``skimage.io.video`` functionality due to broken gstreamer bindings diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index 6e92c210..6469be59 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -119,8 +119,8 @@ def convert_colorspace(arr, fromspace, tospace): Examples -------- >>> from skimage import data - >>> lena = data.lena() - >>> lena_hsv = convert_colorspace(lena, 'RGB', 'HSV') + >>> img = data.astronaut() + >>> img_hsv = convert_colorspace(img, 'RGB', 'HSV') """ fromdict = {'RGB': lambda im: im, 'HSV': hsv2rgb, 'RGB CIE': rgbcie2rgb, 'XYZ': xyz2rgb} @@ -186,8 +186,8 @@ def rgb2hsv(rgb): -------- >>> from skimage import color >>> from skimage import data - >>> lena = data.lena() - >>> lena_hsv = color.rgb2hsv(lena) + >>> img = data.astronaut() + >>> img_hsv = color.rgb2hsv(img) """ arr = _prepare_colorarray(rgb) out = np.empty_like(arr) @@ -263,9 +263,9 @@ def hsv2rgb(hsv): Examples -------- >>> from skimage import data - >>> lena = data.lena() - >>> lena_hsv = rgb2hsv(lena) - >>> lena_rgb = hsv2rgb(lena_hsv) + >>> img = data.astronaut() + >>> img_hsv = rgb2hsv(img) + >>> img_rgb = hsv2rgb(img_hsv) """ arr = _prepare_colorarray(hsv) @@ -542,9 +542,9 @@ def xyz2rgb(xyz): -------- >>> from skimage import data >>> from skimage.color import rgb2xyz, xyz2rgb - >>> lena = data.lena() - >>> lena_xyz = rgb2xyz(lena) - >>> lena_rgb = xyz2rgb(lena_xyz) + >>> img = data.astronaut() + >>> img_xyz = rgb2xyz(img) + >>> img_rgb = xyz2rgb(img_xyz) """ # Follow the algorithm from http://www.easyrgb.com/index.php # except we don't multiply/divide by 100 in the conversion @@ -587,8 +587,8 @@ def rgb2xyz(rgb): Examples -------- >>> from skimage import data - >>> lena = data.lena() - >>> lena_xyz = rgb2xyz(lena) + >>> img = data.astronaut() + >>> img_xyz = rgb2xyz(img) """ # Follow the algorithm from http://www.easyrgb.com/index.php # except we don't multiply/divide by 100 in the conversion @@ -625,8 +625,8 @@ def rgb2rgbcie(rgb): -------- >>> from skimage import data >>> from skimage.color import rgb2rgbcie - >>> lena = data.lena() - >>> lena_rgbcie = rgb2rgbcie(lena) + >>> img = data.astronaut() + >>> img_rgbcie = rgb2rgbcie(img) """ return _convert(rgbcie_from_rgb, rgb) @@ -657,9 +657,9 @@ def rgbcie2rgb(rgbcie): -------- >>> from skimage import data >>> from skimage.color import rgb2rgbcie, rgbcie2rgb - >>> lena = data.lena() - >>> lena_rgbcie = rgb2rgbcie(lena) - >>> lena_rgb = rgbcie2rgb(lena_rgbcie) + >>> img = data.astronaut() + >>> img_rgbcie = rgb2rgbcie(img) + >>> img_rgb = rgbcie2rgb(img_rgbcie) """ return _convert(rgb_from_rgbcie, rgbcie) @@ -701,8 +701,8 @@ def rgb2gray(rgb): -------- >>> from skimage.color import rgb2gray >>> from skimage import data - >>> lena = data.lena() - >>> lena_gray = rgb2gray(lena) + >>> img = data.astronaut() + >>> img_gray = rgb2gray(img) """ if rgb.ndim == 2: return rgb @@ -782,10 +782,9 @@ def xyz2lab(xyz, illuminant="D65", observer="2"): -------- >>> from skimage import data >>> from skimage.color import rgb2xyz, xyz2lab - >>> lena = data.lena() - >>> lena_xyz = rgb2xyz(lena) - >>> lena_lab = xyz2lab(lena_xyz) - + >>> img = data.astronaut() + >>> img_xyz = rgb2xyz(img) + >>> img_lab = xyz2lab(img_xyz) """ arr = _prepare_colorarray(xyz) @@ -961,9 +960,9 @@ def xyz2luv(xyz, illuminant="D65", observer="2"): -------- >>> from skimage import data >>> from skimage.color import rgb2xyz, xyz2luv - >>> lena = data.lena() - >>> lena_xyz = rgb2xyz(lena) - >>> lena_luv = xyz2luv(lena_xyz) + >>> img = data.astronaut() + >>> img_xyz = rgb2xyz(img) + >>> img_luv = xyz2luv(img_xyz) """ arr = _prepare_colorarray(xyz) @@ -1339,9 +1338,9 @@ def lab2lch(lab): -------- >>> from skimage import data >>> from skimage.color import rgb2lab, lab2lch - >>> lena = data.lena() - >>> lena_lab = rgb2lab(lena) - >>> lena_lch = lab2lch(lena_lab) + >>> img = data.astronaut() + >>> img_lab = rgb2lab(img) + >>> img_lch = lab2lch(img_lab) """ lch = _prepare_lab_array(lab) @@ -1386,10 +1385,10 @@ def lch2lab(lch): -------- >>> from skimage import data >>> from skimage.color import rgb2lab, lch2lab - >>> lena = data.lena() - >>> lena_lab = rgb2lab(lena) - >>> lena_lch = lab2lch(lena_lab) - >>> lena_lab2 = lch2lab(lena_lch) + >>> img = data.astronaut() + >>> img_lab = rgb2lab(img) + >>> img_lch = lab2lch(img_lab) + >>> img_lab2 = lch2lab(img_lch) """ lch = _prepare_lab_array(lch) diff --git a/skimage/color/tests/test_adapt_rgb.py b/skimage/color/tests/test_adapt_rgb.py index 869a1ccc..2f3060c5 100644 --- a/skimage/color/tests/test_adapt_rgb.py +++ b/skimage/color/tests/test_adapt_rgb.py @@ -8,7 +8,7 @@ from skimage.color.adapt_rgb import adapt_rgb, each_channel, hsv_value # Down-sample image for quicker testing. -COLOR_IMAGE = data.lena()[::5, ::5] +COLOR_IMAGE = data.astronaut()[::5, ::5] GRAY_IMAGE = data.camera()[::5, ::5] SIGMA = 3 diff --git a/skimage/data/__init__.py b/skimage/data/__init__.py index b06c1f83..ae8d00b0 100644 --- a/skimage/data/__init__.py +++ b/skimage/data/__init__.py @@ -25,7 +25,8 @@ __all__ = ['load', 'immunohistochemistry', 'chelsea', 'coffee', - 'hubble_deep_field'] + 'hubble_deep_field', + 'astronaut'] def load(f): @@ -64,6 +65,23 @@ def lena(): """ return load("lena.png") +def astronaut(): + """Colour image of the astronaut Eileen Collins. + + Photograph of Eileen Collins, an American astronaut. She was selected + as an astronaut in 1992 and first piloted the space shuttle STS-63 in + 1995. She retired in 2006 after spending a total of 38 days, 8 hours + and 10 minutes in outer space. + + This image was downloaded from the NASA Great Images database + `__. + + No known copyright restrictions, released into the public domain. + + """ + + return load("astronaut.png") + def text(): """Gray-level "text" image used for corner detection. diff --git a/skimage/data/astronaut.png b/skimage/data/astronaut.png new file mode 100644 index 00000000..834cda00 Binary files /dev/null and b/skimage/data/astronaut.png differ diff --git a/skimage/data/tests/test_data.py b/skimage/data/tests/test_data.py index 49cd4b5a..bfcdc571 100644 --- a/skimage/data/tests/test_data.py +++ b/skimage/data/tests/test_data.py @@ -7,6 +7,11 @@ def test_lena(): lena = data.lena() assert_equal(lena.shape, (512, 512, 3)) +def test_astronaut(): + """ Test that "astronaut" image can be loaded. """ + astronaut = data.astronaut() + assert_equal(astronaut.shape, (512, 512, 3)) + def test_camera(): """ Test that "camera" image can be loaded. """ diff --git a/skimage/exposure/tests/test_exposure.py b/skimage/exposure/tests/test_exposure.py index 5361a221..bb114e4f 100644 --- a/skimage/exposure/tests/test_exposure.py +++ b/skimage/exposure/tests/test_exposure.py @@ -177,22 +177,22 @@ def test_adapthist_scalar(): def test_adapthist_grayscale(): """Test a grayscale float image """ - img = skimage.img_as_float(data.lena()) + 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) assert_almost_equal = np.testing.assert_almost_equal assert img.shape == adapted.shape - assert_almost_equal(peak_snr(img, adapted), 104.3277, 3) - assert_almost_equal(norm_brightness_err(img, adapted), 0.0265, 3) + assert_almost_equal(peak_snr(img, adapted), 97.6876, 3) + assert_almost_equal(norm_brightness_err(img, adapted), 0.0591, 3) return data, adapted def test_adapthist_color(): """Test an RGB color uint16 image """ - img = skimage.img_as_uint(data.lena()) + img = skimage.img_as_uint(data.astronaut()) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') hist, bin_centers = exposure.histogram(img) @@ -204,15 +204,15 @@ def test_adapthist_color(): assert adapted.max() == 1.0 assert img.shape == adapted.shape full_scale = skimage.exposure.rescale_intensity(img) - assert_almost_equal(peak_snr(full_scale, adapted), 106.9, 1) - assert_almost_equal(norm_brightness_err(full_scale, adapted), 0.05, 2) + assert_almost_equal(peak_snr(full_scale, adapted), 109.6, 1) + assert_almost_equal(norm_brightness_err(full_scale, adapted), 0.02, 2) return data, adapted def test_adapthist_alpha(): """Test an RGBA color image """ - img = skimage.img_as_float(data.lena()) + 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) @@ -221,8 +221,8 @@ def test_adapthist_alpha(): full_scale = skimage.exposure.rescale_intensity(img) assert img.shape == adapted.shape assert_almost_equal = np.testing.assert_almost_equal - assert_almost_equal(peak_snr(full_scale, adapted), 106.86, 2) - assert_almost_equal(norm_brightness_err(full_scale, adapted), 0.0509, 3) + assert_almost_equal(peak_snr(full_scale, adapted), 109.60, 2) + assert_almost_equal(norm_brightness_err(full_scale, adapted), 0.0235, 3) def peak_snr(img1, img2): diff --git a/skimage/feature/censure.py b/skimage/feature/censure.py index 1b1754a7..0814b195 100644 --- a/skimage/feature/censure.py +++ b/skimage/feature/censure.py @@ -160,30 +160,38 @@ class CENSURE(FeatureDetector): Examples -------- - >>> from skimage.data import lena + >>> from skimage.data import astronaut >>> from skimage.color import rgb2gray >>> from skimage.feature import CENSURE - >>> img = rgb2gray(lena()[100:300, 100:300]) + >>> img = rgb2gray(astronaut()[100:300, 100:300]) >>> censure = CENSURE() >>> censure.detect(img) >>> censure.keypoints - array([[ 71, 148], - [ 77, 186], - [ 78, 189], - [ 89, 174], - [127, 134], - [131, 133], - [134, 125], - [137, 125], - [149, 36], - [162, 165], - [168, 167], - [170, 5], - [171, 29], - [179, 20], - [194, 65]]) + array([[ 4, 148], + [ 12, 73], + [ 21, 176], + [ 91, 22], + [ 93, 56], + [ 94, 22], + [ 95, 54], + [100, 51], + [103, 51], + [106, 67], + [108, 15], + [117, 20], + [122, 60], + [125, 37], + [129, 37], + [133, 76], + [145, 44], + [146, 94], + [150, 114], + [153, 33], + [154, 156], + [155, 151], + [184, 63]]) >>> censure.scales - array([2, 4, 2, 3, 4, 2, 2, 3, 4, 6, 3, 2, 3, 4, 2]) + array([2, 6, 6, 2, 4, 3, 2, 3, 2, 6, 3, 2, 2, 3, 2, 2, 2, 3, 2, 2, 4, 2, 2]) """ diff --git a/skimage/feature/tests/test_corner.py b/skimage/feature/tests/test_corner.py index 1c39dd2d..a9f5bb91 100644 --- a/skimage/feature/tests/test_corner.py +++ b/skimage/feature/tests/test_corner.py @@ -161,12 +161,12 @@ def test_squared_dot(): assert (results == np.array([[6, 6]])).all() -def test_rotated_lena(): +def test_rotated_img(): """ The harris filter should yield the same results with an image and it's rotation. """ - im = img_as_float(data.lena().mean(axis=2)) + im = img_as_float(data.astronaut().mean(axis=2)) im_rotated = im.T # Moravec @@ -235,13 +235,13 @@ def test_subpix_border(): def test_num_peaks(): """For a bunch of different values of num_peaks, check that peak_local_max returns exactly the right amount of peaks. Test - is run on Lena in order to produce a sufficient number of corners""" + is run on the astronaut image in order to produce a sufficient number of corners""" - lena_corners = corner_harris(rgb2gray(data.lena())) + img_corners = corner_harris(rgb2gray(data.astronaut())) for i in range(20): n = np.random.random_integers(20) - results = peak_local_max(lena_corners, num_peaks=n) + results = peak_local_max(img_corners, num_peaks=n) assert (results.shape[0] == n) @@ -281,17 +281,44 @@ def test_corner_fast_image_unsupported_error(): def test_corner_fast_lena(): - img = rgb2gray(data.lena()) - expected = np.array([[ 67, 157], - [204, 261], - [247, 146], - [269, 111], - [318, 158], - [386, 73], - [413, 70], - [435, 180], - [455, 177], - [461, 160]]) + img = rgb2gray(data.astronaut()) + expected = np.array([[101, 198], + [140, 205], + [141, 242], + [177, 156], + [188, 113], + [197, 148], + [213, 117], + [223, 375], + [232, 266], + [245, 137], + [249, 171], + [300, 244], + [305, 57], + [325, 245], + [339, 242], + [346, 279], + [353, 172], + [358, 307], + [362, 252], + [362, 328], + [363, 192], + [364, 147], + [369, 159], + [374, 171], + [379, 183], + [387, 195], + [390, 149], + [401, 197], + [403, 162], + [413, 181], + [444, 310], + [464, 251], + [476, 250], + [489, 155], + [492, 139], + [494, 169], + [496, 266]]) actual = corner_peaks(corner_fast(img, 12, 0.3)) assert_array_equal(actual, expected) diff --git a/skimage/feature/tests/test_daisy.py b/skimage/feature/tests/test_daisy.py index 32a7a5df..2e3b766c 100644 --- a/skimage/feature/tests/test_daisy.py +++ b/skimage/feature/tests/test_daisy.py @@ -13,7 +13,7 @@ def test_daisy_color_image_unsupported_error(): def test_daisy_desc_dims(): - img = img_as_float(data.lena()[:128, :128].mean(axis=2)) + img = img_as_float(data.astronaut()[:128, :128].mean(axis=2)) rings = 2 histograms = 4 orientations = 3 @@ -30,7 +30,7 @@ def test_daisy_desc_dims(): def test_descs_shape(): - img = img_as_float(data.lena()[:256, :256].mean(axis=2)) + img = img_as_float(data.astronaut()[:256, :256].mean(axis=2)) radius = 20 step = 8 descs = daisy(img, radius=radius, step=step) @@ -46,21 +46,21 @@ def test_descs_shape(): def test_daisy_sigmas_and_radii(): - img = img_as_float(data.lena()[:64, :64].mean(axis=2)) + img = img_as_float(data.astronaut()[:64, :64].mean(axis=2)) sigmas = [1, 2, 3] radii = [1, 2] daisy(img, sigmas=sigmas, ring_radii=radii) def test_daisy_incompatible_sigmas_and_radii(): - img = img_as_float(data.lena()[:64, :64].mean(axis=2)) + img = img_as_float(data.astronaut()[:64, :64].mean(axis=2)) sigmas = [1, 2] radii = [1, 2] assert_raises(ValueError, daisy, img, sigmas=sigmas, ring_radii=radii) def test_daisy_normalization(): - img = img_as_float(data.lena()[:64, :64].mean(axis=2)) + img = img_as_float(data.astronaut()[:64, :64].mean(axis=2)) descs = daisy(img, normalization='l1') for i in range(descs.shape[0]): @@ -93,7 +93,7 @@ def test_daisy_normalization(): def test_daisy_visualization(): - img = img_as_float(data.lena()[:32, :32].mean(axis=2)) + img = img_as_float(data.astronaut()[:32, :32].mean(axis=2)) descs, descs_img = daisy(img, visualize=True) assert(descs_img.shape == (32, 32, 3)) diff --git a/skimage/feature/tests/test_hog.py b/skimage/feature/tests/test_hog.py index 8cab52f7..855bb557 100644 --- a/skimage/feature/tests/test_hog.py +++ b/skimage/feature/tests/test_hog.py @@ -10,7 +10,7 @@ from numpy.testing import (assert_raises, def test_histogram_of_oriented_gradients(): - img = img_as_float(data.lena()[:256, :].mean(axis=2)) + img = img_as_float(data.astronaut()[:256, :].mean(axis=2)) fd = feature.hog(img, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(1, 1)) diff --git a/skimage/filter/_gaussian.py b/skimage/filter/_gaussian.py index af63ba10..b8c230d4 100644 --- a/skimage/filter/_gaussian.py +++ b/skimage/filter/_gaussian.py @@ -84,9 +84,9 @@ def gaussian_filter(image, sigma, output=None, mode='nearest', cval=0, [ 0.12075024, 0.16630671, 0.12075024], [ 0.08767308, 0.12075024, 0.08767308]]) >>> # For RGB images, each is filtered separately - >>> from skimage.data import lena - >>> image = lena() - >>> filtered_lena = gaussian_filter(image, sigma=1, multichannel=True) + >>> from skimage.data import astronaut + >>> image = astronaut() + >>> filtered_img = gaussian_filter(image, sigma=1, multichannel=True) """ spatial_dims = guess_spatial_dimensions(image) if spatial_dims is None and multichannel is None: diff --git a/skimage/filter/edges.py b/skimage/filter/edges.py index ff3b6b03..55799c0a 100644 --- a/skimage/filter/edges.py +++ b/skimage/filter/edges.py @@ -82,7 +82,9 @@ def sobel(image, mask=None): has to be further processed to perform edge detection. """ assert_nD(image, 2) - return np.sqrt(hsobel(image, mask)**2 + vsobel(image, mask)**2) + out = np.sqrt(hsobel(image, mask)**2 + vsobel(image, mask)**2) + out /= np.sqrt(2) + return out def hsobel(image, mask=None): @@ -176,11 +178,13 @@ def scharr(image, mask=None): References ---------- - .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical Optimization - of Kernel Based Image Derivatives. + .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical + Optimization of Kernel Based Image Derivatives. """ - return np.sqrt(hscharr(image, mask)**2 + vscharr(image, mask)**2) + out = np.sqrt(hscharr(image, mask)**2 + vscharr(image, mask)**2) + out /= np.sqrt(2) + return out def hscharr(image, mask=None): @@ -211,8 +215,8 @@ def hscharr(image, mask=None): References ---------- - .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical Optimization - of Kernel Based Image Derivatives. + .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical + Optimization of Kernel Based Image Derivatives. """ assert_nD(image, 2) @@ -249,8 +253,8 @@ def vscharr(image, mask=None): References ---------- - .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical Optimization - of Kernel Based Image Derivatives. + .. [1] D. Kroon, 2009, Short Paper University Twente, Numerical + Optimization of Kernel Based Image Derivatives. """ assert_nD(image, 2) @@ -282,7 +286,9 @@ def prewitt(image, mask=None): and vertical Prewitt transforms. """ assert_nD(image, 2) - return np.sqrt(hprewitt(image, mask)**2 + vprewitt(image, mask)**2) + out = np.sqrt(hprewitt(image, mask)**2 + vprewitt(image, mask)**2) + out /= np.sqrt(2) + return out def hprewitt(image, mask=None): @@ -369,8 +375,10 @@ def roberts(image, mask=None): The Roberts' Cross edge map. """ assert_nD(image, 2) - return np.sqrt(roberts_positive_diagonal(image, mask)**2 + - roberts_negative_diagonal(image, mask)**2) + out = np.sqrt(roberts_positive_diagonal(image, mask)**2 + + roberts_negative_diagonal(image, mask)**2) + out /= np.sqrt(2) + return out def roberts_positive_diagonal(image, mask=None): diff --git a/skimage/filter/tests/test_edges.py b/skimage/filter/tests/test_edges.py index 523d6dd8..ac363e52 100644 --- a/skimage/filter/tests/test_edges.py +++ b/skimage/filter/tests/test_edges.py @@ -1,5 +1,6 @@ import numpy as np -from numpy.testing import assert_array_almost_equal as assert_close +from numpy.testing import (assert_array_almost_equal as assert_close, + assert_, assert_allclose) import skimage.filter as F from skimage.filter.edges import _mask_filter_result @@ -49,10 +50,10 @@ def test_sobel_horizontal(): """Sobel on a horizontal edge should be a horizontal line.""" i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) - result = F.sobel(image) + result = F.sobel(image) * np.sqrt(2) # Fudge the eroded points i[np.abs(j) == 5] = 10000 - assert (np.all(result[i == 0] == 1)) + assert_allclose(result[i == 0], 1) assert (np.all(result[np.abs(i) > 1] == 0)) @@ -60,7 +61,7 @@ def test_sobel_vertical(): """Sobel on a vertical edge should be a vertical line.""" i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) - result = F.sobel(image) + result = F.sobel(image) * np.sqrt(2) j[np.abs(i) == 5] = 10000 assert (np.all(result[j == 0] == 1)) assert (np.all(result[np.abs(j) > 1] == 0)) @@ -94,15 +95,15 @@ def test_hsobel_horizontal(): def test_hsobel_vertical(): """Horizontal Sobel on a vertical edge should be zero.""" i, j = np.mgrid[-5:6, -5:6] - image = (j >= 0).astype(float) + image = (j >= 0).astype(float) * np.sqrt(2) result = F.hsobel(image) - assert (np.all(result == 0)) + assert_allclose(result, 0, atol=1e-10) def test_vsobel_zeros(): """Vertical sobel on an array of all zeros.""" result = F.vsobel(np.zeros((10, 10)), np.ones((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_vsobel_mask(): @@ -110,7 +111,7 @@ def test_vsobel_mask(): np.random.seed(0) result = F.vsobel(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_vsobel_vertical(): @@ -129,32 +130,31 @@ def test_vsobel_horizontal(): i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) result = F.vsobel(image) - eps = .000001 - assert (np.all(np.abs(result) < eps)) + assert_allclose(result, 0) def test_scharr_zeros(): """Scharr on an array of all zeros.""" result = F.scharr(np.zeros((10, 10)), np.ones((10, 10), bool)) - assert (np.all(result == 0)) + assert (np.all(result < 1e-16)) def test_scharr_mask(): """Scharr on a masked array should be zero.""" np.random.seed(0) result = F.scharr(np.random.uniform(size=(10, 10)), - np.zeros((10, 10), bool)) - assert (np.all(result == 0)) + np.zeros((10, 10), bool)) + assert_allclose(result, 0) def test_scharr_horizontal(): """Scharr on an edge should be a horizontal line.""" i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) - result = F.scharr(image) + result = F.scharr(image) * np.sqrt(2) # Fudge the eroded points i[np.abs(j) == 5] = 10000 - assert (np.all(result[i == 0] == 1)) + assert_allclose(result[i == 0], 1) assert (np.all(result[np.abs(i) > 1] == 0)) @@ -162,24 +162,24 @@ def test_scharr_vertical(): """Scharr on a vertical edge should be a vertical line.""" i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) - result = F.scharr(image) + result = F.scharr(image) * np.sqrt(2) j[np.abs(i) == 5] = 10000 - assert (np.all(result[j == 0] == 1)) + assert_allclose(result[j == 0], 1) assert (np.all(result[np.abs(j) > 1] == 0)) def test_hscharr_zeros(): """Horizontal Scharr on an array of all zeros.""" result = F.hscharr(np.zeros((10, 10)), np.ones((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_hscharr_mask(): """Horizontal Scharr on a masked array should be zero.""" np.random.seed(0) result = F.hscharr(np.random.uniform(size=(10, 10)), - np.zeros((10, 10), bool)) - assert (np.all(result == 0)) + np.zeros((10, 10), bool)) + assert_allclose(result, 0) def test_hscharr_horizontal(): @@ -198,21 +198,21 @@ def test_hscharr_vertical(): i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) result = F.hscharr(image) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_vscharr_zeros(): """Vertical Scharr on an array of all zeros.""" result = F.vscharr(np.zeros((10, 10)), np.ones((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_vscharr_mask(): """Vertical Scharr on a masked array should be zero.""" np.random.seed(0) result = F.vscharr(np.random.uniform(size=(10, 10)), - np.zeros((10, 10), bool)) - assert (np.all(result == 0)) + np.zeros((10, 10), bool)) + assert_allclose(result, 0) def test_vscharr_vertical(): @@ -231,14 +231,13 @@ def test_vscharr_horizontal(): i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) result = F.vscharr(image) - eps = .000001 - assert (np.all(np.abs(result) < eps)) + assert_allclose(result, 0) def test_prewitt_zeros(): """Prewitt on an array of all zeros.""" result = F.prewitt(np.zeros((10, 10)), np.ones((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_prewitt_mask(): @@ -246,37 +245,34 @@ def test_prewitt_mask(): np.random.seed(0) result = F.prewitt(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) - eps = .000001 - assert (np.all(np.abs(result) < eps)) + assert_allclose(np.abs(result), 0) def test_prewitt_horizontal(): """Prewitt on an edge should be a horizontal line.""" i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) - result = F.prewitt(image) + result = F.prewitt(image) * np.sqrt(2) # Fudge the eroded points i[np.abs(j) == 5] = 10000 - eps = .000001 assert (np.all(result[i == 0] == 1)) - assert (np.all(np.abs(result[np.abs(i) > 1]) < eps)) + assert_allclose(result[np.abs(i) > 1], 0, atol=1e-10) def test_prewitt_vertical(): """Prewitt on a vertical edge should be a vertical line.""" i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) - result = F.prewitt(image) - eps = .000001 + result = F.prewitt(image) * np.sqrt(2) j[np.abs(i) == 5] = 10000 - assert (np.all(result[j == 0] == 1)) - assert (np.all(np.abs(result[np.abs(j) > 1]) < eps)) + assert_allclose(result[j == 0], 1) + assert_allclose(result[np.abs(j) > 1], 0, atol=1e-10) def test_hprewitt_zeros(): """Horizontal prewitt on an array of all zeros.""" result = F.hprewitt(np.zeros((10, 10)), np.ones((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_hprewitt_mask(): @@ -284,8 +280,7 @@ def test_hprewitt_mask(): np.random.seed(0) result = F.hprewitt(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) - eps = .000001 - assert (np.all(np.abs(result) < eps)) + assert_allclose(result, 0) def test_hprewitt_horizontal(): @@ -295,9 +290,8 @@ def test_hprewitt_horizontal(): result = F.hprewitt(image) # Fudge the eroded points i[np.abs(j) == 5] = 10000 - eps = .000001 assert (np.all(result[i == 0] == 1)) - assert (np.all(np.abs(result[np.abs(i) > 1]) < eps)) + assert_allclose(result[np.abs(i) > 1], 0, atol=1e-10) def test_hprewitt_vertical(): @@ -305,14 +299,13 @@ def test_hprewitt_vertical(): i, j = np.mgrid[-5:6, -5:6] image = (j >= 0).astype(float) result = F.hprewitt(image) - eps = .000001 - assert (np.all(np.abs(result) < eps)) + assert_allclose(result, 0, atol=1e-10) def test_vprewitt_zeros(): """Vertical prewitt on an array of all zeros.""" result = F.vprewitt(np.zeros((10, 10)), np.ones((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_vprewitt_mask(): @@ -320,7 +313,7 @@ def test_vprewitt_mask(): np.random.seed(0) result = F.vprewitt(np.random.uniform(size=(10, 10)), np.zeros((10, 10), bool)) - assert (np.all(result == 0)) + assert_allclose(result, 0) def test_vprewitt_vertical(): @@ -331,8 +324,7 @@ def test_vprewitt_vertical(): # Fudge the eroded points j[np.abs(i) == 5] = 10000 assert (np.all(result[j == 0] == 1)) - eps = .000001 - assert (np.all(np.abs(result[np.abs(j) > 1]) < eps)) + assert_allclose(result[np.abs(j) > 1], 0, atol=1e-10) def test_vprewitt_horizontal(): @@ -340,21 +332,20 @@ def test_vprewitt_horizontal(): i, j = np.mgrid[-5:6, -5:6] image = (i >= 0).astype(float) result = F.vprewitt(image) - eps = .000001 - assert (np.all(np.abs(result) < eps)) + assert_allclose(result, 0) def test_horizontal_mask_line(): """Horizontal edge filters mask pixels surrounding input mask.""" - vgrad, _ = np.mgrid[:1:11j, :1:11j] # vertical gradient with spacing 0.1 - vgrad[5, :] = 1 # bad horizontal line + vgrad, _ = np.mgrid[:1:11j, :1:11j] # vertical gradient with spacing 0.1 + vgrad[5, :] = 1 # bad horizontal line mask = np.ones_like(vgrad) - mask[5, :] = 0 # mask bad line + mask[5, :] = 0 # mask bad line expected = np.zeros_like(vgrad) - expected[1:-1, 1:-1] = 0.2 # constant gradient for most of image, - expected[4:7, 1:-1] = 0 # but line and neighbors masked + expected[1:-1, 1:-1] = 0.2 # constant gradient for most of image, + expected[4:7, 1:-1] = 0 # but line and neighbors masked for grad_func in (F.hprewitt, F.hsobel, F.hscharr): result = grad_func(vgrad, mask) @@ -363,21 +354,36 @@ def test_horizontal_mask_line(): def test_vertical_mask_line(): """Vertical edge filters mask pixels surrounding input mask.""" - _, hgrad = np.mgrid[:1:11j, :1:11j] # horizontal gradient with spacing 0.1 - hgrad[:, 5] = 1 # bad vertical line + _, hgrad = np.mgrid[:1:11j, :1:11j] # horizontal gradient with spacing 0.1 + hgrad[:, 5] = 1 # bad vertical line mask = np.ones_like(hgrad) - mask[:, 5] = 0 # mask bad line + mask[:, 5] = 0 # mask bad line expected = np.zeros_like(hgrad) - expected[1:-1, 1:-1] = 0.2 # constant gradient for most of image, - expected[1:-1, 4:7] = 0 # but line and neighbors masked + expected[1:-1, 1:-1] = 0.2 # constant gradient for most of image, + expected[1:-1, 4:7] = 0 # but line and neighbors masked for grad_func in (F.vprewitt, F.vsobel, F.vscharr): result = grad_func(hgrad, mask) yield assert_close, result, expected +def test_range(): + """Output of edge detection should be in [0, 1]""" + image = np.random.random((100, 100)) + for detector in (F.sobel, F.scharr, F.prewitt, F.roberts): + out = detector(image) + assert_(out.min() >= 0, + "Minimum of `{0}` is smaller than zero".format( + detector.__name__) + ) + assert_(out.max() <= 1, + "Maximum of `{0}` is larger than 1".format( + detector.__name__) + ) + + if __name__ == "__main__": from numpy import testing testing.run_module_suite() diff --git a/skimage/filter/tests/test_thresholding.py b/skimage/filter/tests/test_thresholding.py index 69b56cde..cd9cc553 100644 --- a/skimage/filter/tests/test_thresholding.py +++ b/skimage/filter/tests/test_thresholding.py @@ -145,9 +145,12 @@ def test_otsu_coins_image_as_float(): def test_otsu_lena_image(): - lena = skimage.img_as_ubyte(data.lena()) - assert 140 < threshold_otsu(lena) < 142 + img = skimage.img_as_ubyte(data.lena()) + assert 140 < threshold_otsu(img) < 142 +def test_otsu_astro_image(): + img = skimage.img_as_ubyte(data.astronaut()) + assert 109 < threshold_otsu(img) < 111 def test_yen_camera_image(): camera = skimage.img_as_ubyte(data.camera()) diff --git a/skimage/graph/graph_cut.py b/skimage/graph/graph_cut.py index 068e2150..b14b6a34 100644 --- a/skimage/graph/graph_cut.py +++ b/skimage/graph/graph_cut.py @@ -38,7 +38,7 @@ def cut_threshold(labels, rag, thresh, in_place=True): Examples -------- >>> from skimage import data, graph, segmentation - >>> img = data.lena() + >>> img = data.astronaut() >>> labels = segmentation.slic(img) >>> rag = graph.rag_mean_color(img, labels) >>> new_labels = graph.cut_threshold(labels, rag, 10) @@ -108,7 +108,7 @@ def cut_normalized(labels, rag, thresh=0.001, num_cuts=10, in_place=True, Examples -------- >>> from skimage import data, graph, segmentation - >>> img = data.lena() + >>> img = data.astronaut() >>> labels = segmentation.slic(img, compactness=30, n_segments=400) >>> rag = graph.rag_mean_color(img, labels, mode='similarity') >>> new_labels = graph.cut_normalized(labels, rag) diff --git a/skimage/graph/rag.py b/skimage/graph/rag.py index 81b3c0d6..5950dfdc 100644 --- a/skimage/graph/rag.py +++ b/skimage/graph/rag.py @@ -244,7 +244,7 @@ def rag_mean_color(image, labels, connectivity=2, mode='distance', Examples -------- >>> from skimage import data, graph, segmentation - >>> img = data.lena() + >>> img = data.astronaut() >>> labels = segmentation.slic(img) >>> rag = graph.rag_mean_color(img, labels) diff --git a/skimage/morphology/tests/test_binary.py b/skimage/morphology/tests/test_binary.py index a8284103..53ad504e 100644 --- a/skimage/morphology/tests/test_binary.py +++ b/skimage/morphology/tests/test_binary.py @@ -7,42 +7,42 @@ from skimage.morphology import binary, grey, selem from scipy import ndimage -lena = color.rgb2gray(data.lena()) -bw_lena = lena > 100 +img = color.rgb2gray(data.astronaut()) +bw_img = img > 100 def test_non_square_image(): strel = selem.square(3) - binary_res = binary.binary_erosion(bw_lena[:100, :200], strel) - grey_res = img_as_bool(grey.erosion(bw_lena[:100, :200], strel)) + binary_res = binary.binary_erosion(bw_img[:100, :200], strel) + grey_res = img_as_bool(grey.erosion(bw_img[:100, :200], strel)) testing.assert_array_equal(binary_res, grey_res) def test_binary_erosion(): strel = selem.square(3) - binary_res = binary.binary_erosion(bw_lena, strel) - grey_res = img_as_bool(grey.erosion(bw_lena, strel)) + binary_res = binary.binary_erosion(bw_img, strel) + grey_res = img_as_bool(grey.erosion(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) def test_binary_dilation(): strel = selem.square(3) - binary_res = binary.binary_dilation(bw_lena, strel) - grey_res = img_as_bool(grey.dilation(bw_lena, strel)) + binary_res = binary.binary_dilation(bw_img, strel) + grey_res = img_as_bool(grey.dilation(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) def test_binary_closing(): strel = selem.square(3) - binary_res = binary.binary_closing(bw_lena, strel) - grey_res = img_as_bool(grey.closing(bw_lena, strel)) + binary_res = binary.binary_closing(bw_img, strel) + grey_res = img_as_bool(grey.closing(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) def test_binary_opening(): strel = selem.square(3) - binary_res = binary.binary_opening(bw_lena, strel) - grey_res = img_as_bool(grey.opening(bw_lena, strel)) + binary_res = binary.binary_opening(bw_img, strel) + grey_res = img_as_bool(grey.opening(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) diff --git a/skimage/restoration/_denoise.py b/skimage/restoration/_denoise.py index 047d7388..a73f50e3 100644 --- a/skimage/restoration/_denoise.py +++ b/skimage/restoration/_denoise.py @@ -310,12 +310,12 @@ def denoise_tv_chambolle(im, weight=50, eps=2.e-4, n_iter_max=200, Examples -------- - 2D example on Lena image: + 2D example on astronaut image: >>> from skimage import color, data - >>> lena = color.rgb2gray(data.lena())[:50, :50] - >>> lena += 0.5 * lena.std() * np.random.randn(*lena.shape) - >>> denoised_lena = denoise_tv_chambolle(lena, weight=60) + >>> img = color.rgb2gray(data.astronaut())[:50, :50] + >>> img += 0.5 * img.std() * np.random.randn(*astro.shape) + >>> denoised_img = denoise_tv_chambolle(img, weight=60) 3D example on synthetic data: diff --git a/skimage/restoration/deconvolution.py b/skimage/restoration/deconvolution.py index 60be08ca..eedb8dee 100644 --- a/skimage/restoration/deconvolution.py +++ b/skimage/restoration/deconvolution.py @@ -60,12 +60,12 @@ def wiener(image, psf, balance, reg=None, is_real=True, clip=True): Examples -------- >>> from skimage import color, data, restoration - >>> lena = color.rgb2gray(data.lena()) + >>> img = color.rgb2gray(data.astronaut()) >>> from scipy.signal import convolve2d >>> psf = np.ones((5, 5)) / 25 - >>> lena = convolve2d(lena, psf, 'same') - >>> lena += 0.1 * lena.std() * np.random.standard_normal(lena.shape) - >>> deconvolved_lena = restoration.wiener(lena, psf, 1100) + >>> img = convolve2d(img, psf, 'same') + >>> img += 0.1 * img.std() * np.random.standard_normal(img.shape) + >>> deconvolved_img = restoration.wiener(img, psf, 1100) Notes ----- @@ -202,12 +202,12 @@ def unsupervised_wiener(image, psf, reg=None, user_params=None, is_real=True, Examples -------- >>> from skimage import color, data, restoration - >>> lena = color.rgb2gray(data.lena()) + >>> img = color.rgb2gray(data.astronaut()) >>> from scipy.signal import convolve2d >>> psf = np.ones((5, 5)) / 25 - >>> lena = convolve2d(lena, psf, 'same') - >>> lena += 0.1 * lena.std() * np.random.standard_normal(lena.shape) - >>> deconvolved_lena = restoration.unsupervised_wiener(lena, psf) + >>> img = convolve2d(img, psf, 'same') + >>> img += 0.1 * img.std() * np.random.standard_normal(img.shape) + >>> deconvolved_img = restoration.unsupervised_wiener(img, psf) Notes ----- diff --git a/skimage/restoration/tests/test_denoise.py b/skimage/restoration/tests/test_denoise.py index fe4ce59a..46ed4b35 100644 --- a/skimage/restoration/tests/test_denoise.py +++ b/skimage/restoration/tests/test_denoise.py @@ -7,27 +7,27 @@ from skimage import restoration, data, color, img_as_float np.random.seed(1234) -lena = img_as_float(data.lena()[:128, :128]) -lena_gray = color.rgb2gray(lena) +astro = img_as_float(data.astronaut()[:128, :128]) +astro_gray = color.rgb2gray(astro) checkerboard_gray = img_as_float(data.checkerboard()) checkerboard = color.gray2rgb(checkerboard_gray) def test_denoise_tv_chambolle_2d(): - # lena image - img = lena_gray.copy() - # add noise to lena + # astronaut image + img = astro_gray.copy() + # add noise to astronaut img += 0.5 * img.std() * np.random.rand(*img.shape) # clip noise so that it does not exceed allowed range for float images. img = np.clip(img, 0, 1) # denoise - denoised_lena = restoration.denoise_tv_chambolle(img, weight=60.0) + denoised_astro = restoration.denoise_tv_chambolle(img, weight=60.0) # which dtype? - assert denoised_lena.dtype in [np.float, np.float32, np.float64] + assert denoised_astro.dtype in [np.float, np.float32, np.float64] from scipy import ndimage grad = ndimage.morphological_gradient(img, size=((3, 3))) grad_denoised = ndimage.morphological_gradient( - denoised_lena, size=((3, 3))) + denoised_astro, size=((3, 3))) # test if the total variation has decreased assert grad_denoised.dtype == np.float assert (np.sqrt((grad_denoised**2).sum()) @@ -35,22 +35,22 @@ def test_denoise_tv_chambolle_2d(): def test_denoise_tv_chambolle_multichannel(): - denoised0 = restoration.denoise_tv_chambolle(lena[..., 0], weight=60.0) - denoised = restoration.denoise_tv_chambolle(lena, weight=60.0, + denoised0 = restoration.denoise_tv_chambolle(astro[..., 0], weight=60.0) + denoised = restoration.denoise_tv_chambolle(astro, weight=60.0, multichannel=True) assert_equal(denoised[..., 0], denoised0) def test_denoise_tv_chambolle_float_result_range(): - # lena image - img = lena_gray - int_lena = np.multiply(img, 255).astype(np.uint8) - assert np.max(int_lena) > 1 - denoised_int_lena = restoration.denoise_tv_chambolle(int_lena, weight=60.0) + # astronaut image + img = astro_gray + int_astro = np.multiply(img, 255).astype(np.uint8) + assert np.max(int_astro) > 1 + denoised_int_astro = restoration.denoise_tv_chambolle(int_astro, weight=60.0) # test if the value range of output float data is within [0.0:1.0] - assert denoised_int_lena.dtype == np.float - assert np.max(denoised_int_lena) <= 1.0 - assert np.min(denoised_int_lena) >= 0.0 + assert denoised_int_astro.dtype == np.float + assert np.max(denoised_int_astro) <= 1.0 + assert np.min(denoised_int_astro) >= 0.0 def test_denoise_tv_chambolle_3d(): @@ -86,15 +86,15 @@ def test_denoise_tv_bregman_2d(): def test_denoise_tv_bregman_float_result_range(): - # lena image - img = lena_gray.copy() - int_lena = np.multiply(img, 255).astype(np.uint8) - assert np.max(int_lena) > 1 - denoised_int_lena = restoration.denoise_tv_bregman(int_lena, weight=60.0) + # astronaut image + img = astro_gray.copy() + int_astro = np.multiply(img, 255).astype(np.uint8) + assert np.max(int_astro) > 1 + denoised_int_astro = restoration.denoise_tv_bregman(int_astro, weight=60.0) # test if the value range of output float data is within [0.0:1.0] - assert denoised_int_lena.dtype == np.float - assert np.max(denoised_int_lena) <= 1.0 - assert np.min(denoised_int_lena) >= 0.0 + assert denoised_int_astro.dtype == np.float + assert np.max(denoised_int_astro) <= 1.0 + assert np.min(denoised_int_astro) >= 0.0 def test_denoise_tv_bregman_3d(): diff --git a/skimage/restoration/tests/test_unwrap.py b/skimage/restoration/tests/test_unwrap.py index 764e8b74..8c2a6487 100644 --- a/skimage/restoration/tests/test_unwrap.py +++ b/skimage/restoration/tests/test_unwrap.py @@ -1,7 +1,7 @@ from __future__ import print_function, division import numpy as np -from numpy.testing import (run_module_suite, assert_array_almost_equal, +from numpy.testing import (run_module_suite, assert_array_almost_equal_nulp, assert_almost_equal, assert_array_equal, assert_raises) import warnings @@ -28,7 +28,7 @@ def assert_phase_almost_equal(a, b, *args, **kwargs): np.max(np.abs(au - (bu - shift)))) print('assert_phase_allclose, no mask, rel', np.max(np.abs((au - (bu - shift)) / au))) - assert_array_almost_equal(a + shift, b, *args, **kwargs) + assert_array_almost_equal_nulp(a + shift, b, *args, **kwargs) def check_unwrap(image, mask=None): @@ -128,13 +128,13 @@ def test_mask(): image_unwrapped -= image_unwrapped[0, 0] # remove phase shift # The end of the unwrapped array should have value equal to the # endpoint of the unmasked ramp - assert_array_almost_equal(image_unwrapped[:, -1], image[i, -1]) + assert_array_almost_equal_nulp(image_unwrapped[:, -1], image[i, -1]) # Same tests, but forcing use of the 3D unwrapper by reshaping image_wrapped_3d = image_wrapped.reshape((1,) + image_wrapped.shape) image_unwrapped_3d = unwrap_phase(image_wrapped_3d) image_unwrapped_3d -= image_unwrapped_3d[0, 0, 0] # remove phase shift - assert_array_almost_equal(image_unwrapped_3d[:, :, -1], image[i, -1]) + assert_array_almost_equal_nulp(image_unwrapped_3d[:, :, -1], image[i, -1]) def test_invalid_input(): diff --git a/skimage/segmentation/slic_superpixels.py b/skimage/segmentation/slic_superpixels.py index 7135047e..b877310c 100644 --- a/skimage/segmentation/slic_superpixels.py +++ b/skimage/segmentation/slic_superpixels.py @@ -96,8 +96,8 @@ def slic(image, n_segments=100, compactness=10., max_iter=10, sigma=0, Examples -------- >>> from skimage.segmentation import slic - >>> from skimage.data import lena - >>> img = lena() + >>> from skimage.data import astronaut + >>> img = astronaut() >>> segments = slic(img, n_segments=100, compactness=10) Increasing the compactness parameter yields more square regions: diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 3437945d..e6e26930 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -960,7 +960,7 @@ def warp_coords(coord_map, shape, dtype=np.float64): >>> def shift_up10_left20(xy): ... return xy - np.array([-20, 10])[None, :] >>> - >>> image = data.lena().astype(np.float32) + >>> image = data.astronaut().astype(np.float32) >>> coords = warp_coords(shift_up10_left20, image.shape) >>> warped_image = map_coordinates(image, coords) diff --git a/skimage/transform/tests/test_pyramids.py b/skimage/transform/tests/test_pyramids.py index 6d0609e0..078eb37d 100644 --- a/skimage/transform/tests/test_pyramids.py +++ b/skimage/transform/tests/test_pyramids.py @@ -3,7 +3,7 @@ from skimage import data from skimage.transform import pyramids -image = data.lena() +image = data.astronaut() image_gray = image[..., 0] diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index 1d7ac473..b5206414 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -100,7 +100,7 @@ def test_homography(): def test_fast_homography(): - img = rgb2gray(data.lena()).astype(np.uint8) + img = rgb2gray(data.astronaut()).astype(np.uint8) img = img[:, :100] theta = np.deg2rad(30) @@ -244,21 +244,21 @@ def test_const_cval_out_of_range(): def test_warp_identity(): - lena = img_as_float(rgb2gray(data.lena())) - assert len(lena.shape) == 2 - assert np.allclose(lena, warp(lena, AffineTransform(rotation=0))) - assert not np.allclose(lena, warp(lena, AffineTransform(rotation=0.1))) - rgb_lena = np.transpose(np.asarray([lena, np.zeros_like(lena), lena]), + img = img_as_float(rgb2gray(data.astronaut())) + assert len(img.shape) == 2 + assert np.allclose(img, warp(img, AffineTransform(rotation=0))) + assert not np.allclose(img, warp(img, AffineTransform(rotation=0.1))) + rgb_img = np.transpose(np.asarray([img, np.zeros_like(img), img]), (1, 2, 0)) - warped_rgb_lena = warp(rgb_lena, AffineTransform(rotation=0.1)) - assert np.allclose(rgb_lena, warp(rgb_lena, AffineTransform(rotation=0))) - assert not np.allclose(rgb_lena, warped_rgb_lena) + warped_rgb_img = warp(rgb_img, AffineTransform(rotation=0.1)) + assert np.allclose(rgb_img, warp(rgb_img, AffineTransform(rotation=0))) + assert not np.allclose(rgb_img, warped_rgb_img) # assert no cross-talk between bands - assert np.all(0 == warped_rgb_lena[:, :, 1]) + assert np.all(0 == warped_rgb_img[:, :, 1]) def test_warp_coords_example(): - image = data.lena().astype(np.float32) + image = data.astronaut().astype(np.float32) assert 3 == image.shape[2] tform = SimilarityTransform(translation=(0, -10)) coords = warp_coords(tform, (30, 30, 3)) diff --git a/skimage/viewer/tests/test_viewer.py b/skimage/viewer/tests/test_viewer.py index 1b93ff52..7a110953 100644 --- a/skimage/viewer/tests/test_viewer.py +++ b/skimage/viewer/tests/test_viewer.py @@ -12,10 +12,10 @@ from skimage._shared.version_requirements import is_installed @skipif(not viewer_available) def test_viewer(): - lena = data.lena() + astro = data.astronaut() coins = data.coins() - view = ImageViewer(lena) + view = ImageViewer(astro) import tempfile _, filename = tempfile.mkstemp(suffix='.png') @@ -23,7 +23,7 @@ def test_viewer(): view.close() view.save_to_file(filename) view.open_file(filename) - assert_equal(view.image, lena) + assert_equal(view.image, astro) view.image = coins assert_equal(view.image, coins), view.save_to_file(filename), @@ -40,7 +40,7 @@ def make_key_event(key): @skipif(not viewer_available) def test_collection_viewer(): - img = data.lena() + img = data.astronaut() img_collection = tuple(pyramid_gaussian(img)) view = CollectionViewer(img_collection) @@ -74,4 +74,3 @@ def test_viewer_with_overlay(): ov.overlay = img assert_equal(ov.overlay, img) assert_equal(ov.filtered_image, img) - diff --git a/viewer_examples/viewers/collection_viewer.py b/viewer_examples/viewers/collection_viewer.py index 61df3dd9..6083e9b1 100644 --- a/viewer_examples/viewers/collection_viewer.py +++ b/viewer_examples/viewers/collection_viewer.py @@ -23,7 +23,7 @@ from skimage.viewer import CollectionViewer from skimage.transform import pyramid_gaussian -img = data.lena() +img = data.astronaut() img_collection = tuple(pyramid_gaussian(img)) view = CollectionViewer(img_collection)