replacing lena in examples and most tests

This commit is contained in:
Rebecca
2014-08-31 16:06:54 +01:00
committed by Stefan van der Walt
parent e8967abe78
commit 1b217f971e
36 changed files with 216 additions and 199 deletions
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+9 -9
View File
@@ -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')
+22 -21
View File
@@ -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')
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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))
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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))
+7 -7
View File
@@ -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')
+2 -2
View File
@@ -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)
+6 -6
View File
@@ -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)
-10
View File
@@ -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()
+32 -33
View File
@@ -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)
+1 -1
View File
@@ -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
+19 -1
View File
@@ -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. Possible replacement for Lena.
This image was downloaded from the NASA Great Images database
<http://grin.hq.nasa.gov/ABSTRACTS/GPN-2000-001177.html>`__.
No known copyright restrictions, released into the public domain.
"""
return load("astronaut.png")
def text():
"""Gray-level "text" image used for corner detection.
Binary file not shown.

After

Width:  |  Height:  |  Size: 773 KiB

+5
View File
@@ -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. """
+9 -9
View File
@@ -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):
+2 -2
View File
@@ -160,10 +160,10 @@ 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
+7 -6
View File
@@ -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,7 +281,7 @@ def test_corner_fast_image_unsupported_error():
def test_corner_fast_lena():
img = rgb2gray(data.lena())
img = rgb2gray(data.astronaut())
expected = np.array([[ 67, 157],
[204, 261],
[247, 146],
@@ -293,6 +293,7 @@ def test_corner_fast_lena():
[455, 177],
[461, 160]])
actual = corner_peaks(corner_fast(img, 12, 0.3))
print actual
assert_array_equal(actual, expected)
+6 -6
View File
@@ -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))
+1 -1
View File
@@ -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))
+3 -3
View File
@@ -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:
+6 -2
View File
@@ -145,9 +145,13 @@ 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())
print threshold_otsu(img)
assert 109 < threshold_otsu(img) < 111
def test_yen_camera_image():
camera = skimage.img_as_ubyte(data.camera())
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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)
+12 -12
View File
@@ -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)
+4 -4
View File
@@ -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:
+8 -8
View File
@@ -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
-----
+26 -26
View File
@@ -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():
+2 -2
View File
@@ -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:
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -3,7 +3,7 @@ from skimage import data
from skimage.transform import pyramids
image = data.lena()
image = data.astronaut()
image_gray = image[..., 0]
+11 -11
View File
@@ -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))
+4 -5
View File
@@ -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.astro()
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)
+1 -1
View File
@@ -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)