Merge pull request #1918 from ahojnnes/examples

Several fixes
This commit is contained in:
Steven Silvester
2016-02-01 03:58:11 -06:00
16 changed files with 66 additions and 55 deletions
@@ -49,7 +49,8 @@ image = data.astronaut()
fig = plt.figure(figsize=(14, 7))
ax_each = fig.add_subplot(121, adjustable='box-forced')
ax_hsv = fig.add_subplot(122, sharex=ax_each, sharey=ax_each, adjustable='box-forced')
ax_hsv = fig.add_subplot(122, sharex=ax_each, sharey=ax_each,
adjustable='box-forced')
# We use 1 - sobel_each(image)
# but this will not work if image is not normalized
@@ -107,7 +108,8 @@ def sobel_gray(image):
return filters.sobel(image)
fig = plt.figure(figsize=(7, 7))
ax = fig.add_subplot(111, sharex=ax_each, sharey=ax_each, adjustable='box-forced')
ax = fig.add_subplot(111, sharex=ax_each, sharey=ax_each,
adjustable='box-forced')
# We use 1 - sobel_gray(image)
# but this will not work if image is not normalized
+3 -3
View File
@@ -28,7 +28,7 @@ import numpy as np
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
from skimage import data
from skimage.filters import gaussian_filter
from skimage.filters import gaussian
from skimage.segmentation import active_contour
# Test scipy version, since active contour is only possible
@@ -52,7 +52,7 @@ if not new_scipy:
'0.14.0 and above.')
if new_scipy:
snake = active_contour(gaussian_filter(img, 3),
snake = active_contour(gaussian(img, 3),
init, alpha=0.015, beta=10, gamma=0.001)
fig = plt.figure(figsize=(7, 7))
@@ -80,7 +80,7 @@ y = np.linspace(136, 50, 100)
init = np.array([x, y]).T
if new_scipy:
snake = active_contour(gaussian_filter(img, 1), init, bc='fixed',
snake = active_contour(gaussian(img, 1), init, bc='fixed',
alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1)
fig = plt.figure(figsize=(9, 5))
@@ -138,7 +138,9 @@ image_rgb[cy, cx] = (0, 0, 255)
edges = color.gray2rgb(edges)
edges[cy, cx] = (250, 0, 0)
fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'})
fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True,
sharey=True,
subplot_kw={'adjustable':'box-forced'})
ax1.set_title('Original picture')
ax1.imshow(image_rgb)
+1 -2
View File
@@ -26,7 +26,7 @@ from skimage.morphology import disk
from skimage.filters import rank
image = (data.coins()).astype(np.uint16) * 16
image = data.coins()
selem = disk(20)
percentile_result = rank.mean_percentile(image, selem=selem, p0=.1, p1=.9)
@@ -46,5 +46,4 @@ for n in range(0, len(imgs)):
ax[n].set_adjustable('box-forced')
ax[n].axis('off')
plt.show()
+3 -3
View File
@@ -10,7 +10,7 @@ the RANSAC algorithm.
import numpy as np
from matplotlib import pyplot as plt
from skimage.measure import LineModel, ransac
from skimage.measure import LineModelND, ransac
np.random.seed(seed=1)
@@ -32,11 +32,11 @@ data[::2] += 5 * noise[::2]
data[::4] += 20 * noise[::4]
# fit line using all data
model = LineModel()
model = LineModelND()
model.estimate(data)
# robustly fit line only using inlier data with RANSAC algorithm
model_robust, inliers = ransac(data, LineModel, min_samples=2,
model_robust, inliers = ransac(data, LineModelND, min_samples=2,
residual_threshold=1, max_trials=1000)
outliers = inliers == False
+4 -2
View File
@@ -72,9 +72,11 @@ from skimage.transform import swirl
image = data.checkerboard()
swirled = swirl(image, rotation=0, strength=10, radius=120, order=2)
swirled = swirl(image, rotation=0, strength=10, radius=120)
fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(8, 3), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'})
fig, (ax0, ax1) = plt.subplots(nrows=1, ncols=2, figsize=(8, 3),
sharex=True, sharey=True,
subplot_kw={'adjustable':'box-forced'})
ax0.imshow(image, cmap=plt.cm.gray, interpolation='none')
ax0.axis('off')
+21 -19
View File
@@ -25,14 +25,16 @@ To get started, let's load an image using ``io.imread``. Note that morphology
functions only work on gray-scale or binary images, so we set ``as_grey=True``.
"""
import os
import matplotlib.pyplot as plt
from skimage.data import data_dir
from skimage.util import img_as_ubyte
from skimage import io
phantom = img_as_ubyte(io.imread(data_dir+'/phantom.png', as_grey=True))
orig_phantom = img_as_ubyte(io.imread(os.path.join(data_dir, "phantom.png"),
as_grey=True))
fig, ax = plt.subplots()
ax.imshow(phantom, cmap=plt.cm.gray)
ax.imshow(orig_phantom, cmap=plt.cm.gray)
"""
.. image:: PLOT2RST.current_figure
@@ -42,7 +44,8 @@ Let's also define a convenience function for plotting comparisons:
def plot_comparison(original, filtered, filter_name):
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4), sharex=True, sharey=True)
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4), sharex=True,
sharey=True)
ax1.imshow(original, cmap=plt.cm.gray)
ax1.set_title('original')
ax1.axis('off')
@@ -68,8 +71,8 @@ from skimage.morphology import black_tophat, skeletonize, convex_hull_image
from skimage.morphology import disk
selem = disk(6)
eroded = erosion(phantom, selem)
plot_comparison(phantom, eroded, 'erosion')
eroded = erosion(orig_phantom, selem)
plot_comparison(orig_phantom, eroded, 'erosion')
"""
.. image:: PLOT2RST.current_figure
@@ -88,8 +91,8 @@ pixels in the neighborhood centered at (i, j)*. Dilation enlarges bright
regions and shrinks dark regions.
"""
dilated = dilation(phantom, selem)
plot_comparison(phantom, dilated, 'dilation')
dilated = dilation(orig_phantom, selem)
plot_comparison(orig_phantom, dilated, 'dilation')
"""
.. image:: PLOT2RST.current_figure
@@ -108,8 +111,8 @@ dilation*. Opening can remove small bright spots (i.e. "salt") and connect
small dark cracks.
"""
opened = opening(phantom, selem)
plot_comparison(phantom, opened, 'opening')
opened = opening(orig_phantom, selem)
plot_comparison(orig_phantom, opened, 'opening')
"""
.. image:: PLOT2RST.current_figure
@@ -134,7 +137,7 @@ small bright cracks.
To illustrate this more clearly, let's add a small crack to the white border:
"""
phantom = img_as_ubyte(io.imread(data_dir+'/phantom.png', as_grey=True))
phantom = orig_phantom.copy()
phantom[10:30, 200:210] = 0
closed = closing(phantom, selem)
@@ -161,7 +164,7 @@ that are smaller than the structuring element.
To make things interesting, we'll add bright and dark spots to the image:
"""
phantom = img_as_ubyte(io.imread(data_dir+'/phantom.png', as_grey=True))
phantom = orig_phantom.copy()
phantom[340:350, 200:210] = 255
phantom[100:110, 200:210] = 0
@@ -215,10 +218,9 @@ on binary images only.
"""
from skimage import img_as_bool
horse = ~img_as_bool(io.imread(data_dir+'/horse.png', as_grey=True))
horse = io.imread(os.path.join(data_dir, "horse.png"), as_grey=True)
sk = skeletonize(horse)
sk = skeletonize(horse == 0)
plot_comparison(horse, sk, 'skeletonize')
"""
@@ -237,7 +239,7 @@ that this is also performed on binary images.
"""
hull1 = convex_hull_image(horse)
hull1 = convex_hull_image(horse == 0)
plot_comparison(horse, hull1, 'convex hull')
"""
@@ -252,11 +254,11 @@ enclose that grain:
import numpy as np
horse2 = np.copy(horse)
horse2[45:50, 75:80] = 1
horse_mask = horse == 0
horse_mask[45:50, 75:80] = 1
hull2 = convex_hull_image(horse2)
plot_comparison(horse2, hull2, 'convex hull')
hull2 = convex_hull_image(horse_mask)
plot_comparison(horse_mask, hull2, 'convex hull')
"""
.. image:: PLOT2RST.current_figure
+2 -2
View File
@@ -57,8 +57,8 @@ def is_installed(name, version=None):
out : bool
True if `name` is installed matching the optional version.
Note
----
Notes
-----
Original Copyright (C) 2009-2011 Pierre Raybaut
Licensed under the terms of the MIT License.
"""
+4 -2
View File
@@ -25,7 +25,7 @@ NR_OF_GREY = 2 ** 14 # number of grayscale levels to use in CLAHE algorithm
@adapt_rgb(hsv_value)
def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
def equalize_adapthist(image, ntiles_x=None, ntiles_y=None, clip_limit=0.01,
nbins=256, kernel_size=None):
"""Contrast Limited Adaptive Histogram Equalization (CLAHE).
@@ -76,10 +76,12 @@ def equalize_adapthist(image, ntiles_x=8, ntiles_y=8, clip_limit=0.01,
image = img_as_uint(image)
image = rescale_intensity(image, out_range=(0, NR_OF_GREY - 1))
if kernel_size is None:
if ntiles_x is not None or ntiles_y is not None:
warn('`ntiles_*` have been deprecated in favor of '
'`kernel_size`. The `ntiles_*` keyword arguments '
'will be removed in v0.14', skimage_deprecation)
if kernel_size is None:
ntiles_x = ntiles_x or 8
ntiles_y = ntiles_y or 8
kernel_size = (np.round(image.shape[0] / ntiles_y),
+6 -4
View File
@@ -211,11 +211,13 @@ def test_adapthist_grayscale():
img = skimage.img_as_float(data.astronaut())
img = rgb2gray(img)
img = np.dstack((img, img, img))
with expected_warnings(['precision loss|non-contiguous input',
with expected_warnings(['precision loss|non-contiguous input',
'deprecated']):
adapted_old = exposure.equalize_adapthist(img, 10, 9, clip_limit=0.001,
nbins=128)
adapted = exposure.equalize_adapthist(img, kernel_size=(57, 51), clip_limit=0.01, nbins=128)
with expected_warnings(['precision loss|non-contiguous input']):
adapted = exposure.equalize_adapthist(img, kernel_size=(57, 51),
clip_limit=0.01, nbins=128)
assert img.shape == adapted.shape
assert_almost_equal(peak_snr(img, adapted), 102.078, 3)
assert_almost_equal(norm_brightness_err(img, adapted), 0.0529, 3)
@@ -230,7 +232,7 @@ def test_adapthist_color():
warnings.simplefilter('always')
hist, bin_centers = exposure.histogram(img)
assert len(w) > 0
with expected_warnings(['precision loss', 'deprecated']):
with expected_warnings(['precision loss']):
adapted = exposure.equalize_adapthist(img, clip_limit=0.01)
assert_almost_equal = np.testing.assert_almost_equal
@@ -249,7 +251,7 @@ def test_adapthist_alpha():
img = skimage.img_as_float(data.astronaut())
alpha = np.ones((img.shape[0], img.shape[1]), dtype=float)
img = np.dstack((img, alpha))
with expected_warnings(['precision loss', 'deprecated']):
with expected_warnings(['precision loss']):
adapted = exposure.equalize_adapthist(img)
assert adapted.shape != img.shape
img = img[:, :, :3]
+3 -3
View File
@@ -2208,7 +2208,7 @@ class TiffSequence(object):
The data shape and dtype of all files must match.
Properties
Attributes
----------
files : list
List of file names.
@@ -3104,8 +3104,8 @@ def _replace_by(module_function, package=None, warn=False):
func : function
Wrapped function, hopefully calling a function in another module.
Example
-------
Examples
--------
>>> @_replace_by('_tifffile.decodepackbits')
... def decodepackbits(encoded):
... raise NotImplementedError
+2 -2
View File
@@ -19,8 +19,8 @@ the normal, array-oriented image functions used by scikit-image.
instead of row, column.
Example
-------
Examples
--------
We can create a Picture object open opening an image file:
>>> from skimage import novice
+2 -2
View File
@@ -55,8 +55,8 @@ def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1,
----------
.. [1] http://users.soe.ucsc.edu/~manduchi/Papers/ICCV98.pdf
Example
-------
Examples
--------
>>> from skimage import data, img_as_float
>>> astro = img_as_float(data.astronaut())
>>> astro = astro[220:300, 220:320]
+4 -4
View File
@@ -92,8 +92,8 @@ def inpaint_biharmonic(img, mask, multichannel=False):
out : (M[, N[, ..., P]][, C]) ndarray
Input image with masked pixels inpainted.
Example
-------
Examples
--------
>>> img = np.tile(np.square(np.linspace(0, 1, 5)), (5, 1))
>>> mask = np.zeros_like(img)
>>> mask[2, 2:] = 1
@@ -111,11 +111,11 @@ def inpaint_biharmonic(img, mask, multichannel=False):
if img.ndim < 1:
raise ValueError('Input array has to be at least 1D')
img_baseshape = img.shape[:-1] if multichannel else img.shape
if img_baseshape != mask.shape:
raise ValueError('Input arrays have to be the same shape')
if np.ma.isMaskedArray(img):
raise TypeError('Masked arrays are not supported')
+2 -2
View File
@@ -50,8 +50,8 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,
Whether to keep the original range of values. Otherwise, the input
image is converted according to the conventions of `img_as_float`.
Note
----
Notes
-----
Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
pixels are duplicated during the reflection. As an example, if an array
has values [0, 1, 2] and was padded to the right by four values using
+2 -2
View File
@@ -77,8 +77,8 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None,
Used in conjunction with mode 'C' (constant), the value
outside the image boundaries.
Note
----
Notes
-----
Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
pixels are duplicated during the reflection. As an example, if an array
has values [0, 1, 2] and was padded to the right by four values using