Skip to content

Commit

Permalink
Revisited all examples to fix tiny titles, layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor Panfilov committed Sep 4, 2016
1 parent 493c862 commit 81d96f3
Showing 11 changed files with 113 additions and 110 deletions.
18 changes: 10 additions & 8 deletions doc/examples/edges/plot_convex_hull.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@

from skimage.morphology import convex_hull_image


image = np.array(
[[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
@@ -40,15 +41,16 @@
# [ 0. 2. 1. 1. 1. 1. 1. 2. 0.]
# [ 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(12, 4))
plt.tight_layout()
fig, axes = plt.subplots(1, 2, figsize=(9, 3))
ax = axes.ravel()

ax0.set_title('Original picture')
ax0.imshow(original_image, cmap=plt.cm.gray, interpolation='nearest')
ax0.set_xticks([]), ax0.set_yticks([])
ax[0].set_title('Original picture')
ax[0].imshow(original_image, cmap=plt.cm.gray, interpolation='nearest')
ax[0].set_axis_off()

ax1.set_title('Transformed picture')
ax1.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
ax1.set_xticks([]), ax1.set_yticks([])
ax[1].set_title('Transformed picture')
ax[1].imshow(image, cmap=plt.cm.gray, interpolation='nearest')
ax[1].set_axis_off()

plt.tight_layout()
plt.show()
4 changes: 2 additions & 2 deletions doc/examples/edges/plot_edge_filter.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
edge_sobel = sobel(image)

fig, ax = plt.subplots(ncols=2, sharex=True, sharey=True,
figsize=(12, 6))
figsize=(8, 4))

ax[0].imshow(edge_roberts, cmap=plt.cm.gray)
ax[0].set_title('Roberts Edge Detection')
@@ -68,7 +68,7 @@
max_diff = np.max(np.maximum(diff_scharr_prewitt, diff_scharr_sobel))

fig, axes = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True,
figsize=(12, 12))
figsize=(8, 8))
ax = axes.ravel()

ax[0].imshow(img, cmap=plt.cm.gray)
90 changes: 46 additions & 44 deletions doc/examples/edges/plot_line_hough_transform.py
Original file line number Diff line number Diff line change
@@ -53,81 +53,83 @@
Detect Lines and Curves in Pictures," Comm. ACM, Vol. 15,
pp. 11-15 (January, 1972)
"""
import numpy as np

from matplotlib import cm
from skimage.transform import (hough_line, hough_line_peaks,
probabilistic_hough_line)
from skimage.feature import canny
from skimage import data

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm


# Constructing test image.
# Constructing test image
image = np.zeros((100, 100))
idx = np.arange(25, 75)
image[idx[::-1], idx] = 255
image[idx, idx] = 255

# Classic straight-line Hough transform.
# Classic straight-line Hough transform
h, theta, d = hough_line(image)

# Generating figure 1.
fig, (ax0, ax1, ax2) = plt.subplots(1, 3, figsize=(12, 6))
plt.tight_layout()
# Generating figure 1
fig, axes = plt.subplots(1, 3, figsize=(15, 6),
subplot_kw={'adjustable': 'box-forced'})
ax = axes.ravel()

ax0.imshow(image, cmap=cm.gray)
ax0.set_title('Input image')
ax0.set_axis_off()
ax[0].imshow(image, cmap=cm.gray)
ax[0].set_title('Input image')
ax[0].set_axis_off()

ax1.imshow(np.log(1 + h), extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]),
d[-1], d[0]], cmap=cm.gray, aspect=1/1.5)
ax1.set_title('Hough transform')
ax1.set_xlabel('Angles (degrees)')
ax1.set_ylabel('Distance (pixels)')
ax1.axis('image')
ax[1].imshow(np.log(1 + h),
extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), d[-1], d[0]],
cmap=cm.gray, aspect=1/1.5)
ax[1].set_title('Hough transform')
ax[1].set_xlabel('Angles (degrees)')
ax[1].set_ylabel('Distance (pixels)')
ax[1].axis('image')

ax2.imshow(image, cmap=cm.gray)
row1, col1 = image.shape
ax[2].imshow(image, cmap=cm.gray)
for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
y1 = (dist - col1 * np.cos(angle)) / np.sin(angle)
ax2.plot((0, col1), (y0, y1), '-r')
ax2.axis((0, col1, row1, 0))
ax2.set_title('Detected lines')
ax2.set_axis_off()
y1 = (dist - image.shape[1] * np.cos(angle)) / np.sin(angle)
ax[2].plot((0, image.shape[1]), (y0, y1), '-r')
ax[2].set_xlim((0, image.shape[1]))
ax[2].set_ylim((image.shape[0], 0))
ax[2].set_axis_off()
ax[2].set_title('Detected lines')

# Line finding using the Probabilistic Hough Transform.
plt.tight_layout()
plt.show()

# Line finding using the Probabilistic Hough Transform
image = data.camera()
edges = canny(image, 2, 1, 25)
lines = probabilistic_hough_line(edges, threshold=10, line_length=5,
line_gap=3)

# Generating figure 2.
fig, (ax0, ax1, ax2) = plt.subplots(1, 3, figsize=(16, 6), sharex=True,
sharey=True)
plt.tight_layout()
# Generating figure 2
fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)
ax = axes.ravel()

ax0.imshow(image, cmap=cm.gray)
ax0.set_title('Input image')
ax0.set_axis_off()
ax0.set_adjustable('box-forced')
ax[0].imshow(image, cmap=cm.gray)
ax[0].set_title('Input image')

ax1.imshow(edges, cmap=cm.gray)
ax1.set_title('Canny edges')
ax1.set_axis_off()
ax1.set_adjustable('box-forced')
ax[1].imshow(edges, cmap=cm.gray)
ax[1].set_title('Canny edges')

ax2.imshow(edges * 0)
ax[2].imshow(edges * 0)
for line in lines:
p0, p1 = line
ax2.plot((p0[0], p1[0]), (p0[1], p1[1]))

row2, col2 = image.shape
ax2.axis((0, col2, row2, 0))
ax[2].plot((p0[0], p1[0]), (p0[1], p1[1]))
ax[2].set_xlim((0, image.shape[1]))
ax[2].set_ylim((image.shape[0], 0))
ax[2].set_title('Probabilistic Hough')

ax2.set_title('Probabilistic Hough')
ax2.set_axis_off()
ax2.set_adjustable('box-forced')
for a in ax:
a.set_axis_off()
a.set_adjustable('box-forced')

plt.tight_layout()
plt.show()
3 changes: 2 additions & 1 deletion doc/examples/edges/plot_marching_cubes.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
from skimage import measure
from skimage.draw import ellipsoid


# Generate a level set about zero of two identical ellipsoids in 3D
ellip_base = ellipsoid(6, 10, 16, levelset=True)
ellip_double = np.concatenate((ellip_base[:-1, ...],
@@ -37,7 +38,7 @@

# Display resulting triangular mesh using Matplotlib. This can also be done
# with mayavi (see skimage.measure.marching_cubes docstring).
fig = plt.figure(figsize=(12, 12))
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')

# Fancy indexing: `verts[faces]` to generate a collection of triangles
21 changes: 10 additions & 11 deletions doc/examples/features_detection/plot_blob.py
Original file line number Diff line number Diff line change
@@ -36,13 +36,14 @@
detected accurately. See :py:meth:`skimage.feature.blob_doh` for usage.
"""

from math import sqrt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray

import matplotlib.pyplot as plt


image = data.hubble_deep_field()[0:500, 0:500]
image_gray = rgb2gray(image)

@@ -62,20 +63,18 @@
'Determinant of Hessian']
sequence = zip(blobs_list, colors, titles)

fig, axes = plt.subplots(1, 3, figsize=(14, 4), sharex=True, sharey=True,
fig, axes = plt.subplots(1, 3, figsize=(9, 3), sharex=True, sharey=True,
subplot_kw={'adjustable': 'box-forced'})
plt.tight_layout()
ax = axes.ravel()

axes = axes.ravel()
for blobs, color, title in sequence:
ax = axes[0]
axes = axes[1:]
ax.set_title(title)
ax.imshow(image, interpolation='nearest')
ax.set_axis_off()
for idx, (blobs, color, title) in enumerate(sequence):
ax[idx].set_title(title)
ax[idx].imshow(image, interpolation='nearest')
for blob in blobs:
y, x, r = blob
c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
ax.add_patch(c)
ax[idx].add_patch(c)
ax[idx].set_axis_off()

plt.tight_layout()
plt.show()
1 change: 1 addition & 0 deletions doc/examples/features_detection/plot_censure.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@

import matplotlib.pyplot as plt


img_orig = rgb2gray(data.astronaut())
tform = tf.AffineTransform(scale=(1.5, 1.5), rotation=0.5,
translation=(150, -200))
2 changes: 1 addition & 1 deletion doc/examples/filters/plot_rank_mean.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
bilateral_result = rank.mean_bilateral(image, selem=selem, s0=500, s1=500)
normal_result = rank.mean(image, selem=selem)

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 12),
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10, 10),
sharex=True, sharey=True)
ax = axes.ravel()

6 changes: 3 additions & 3 deletions doc/examples/segmentation/plot_label.py
Original file line number Diff line number Diff line change
@@ -18,9 +18,8 @@
from skimage import data
from skimage.filters import threshold_otsu
from skimage.segmentation import clear_border
from skimage.measure import label
from skimage.measure import label, regionprops
from skimage.morphology import closing, square
from skimage.measure import regionprops
from skimage.color import label2rgb


@@ -38,7 +37,7 @@
label_image = label(cleared)
image_label_overlay = label2rgb(label_image, image=image)

fig, ax = plt.subplots(figsize=(12, 6))
fig, ax = plt.subplots(figsize=(10, 6))
ax.imshow(image_label_overlay)

for region in regionprops(label_image):
@@ -50,5 +49,6 @@
fill=False, edgecolor='red', linewidth=2)
ax.add_patch(rect)

ax.set_axis_off()
plt.tight_layout()
plt.show()
19 changes: 10 additions & 9 deletions doc/examples/segmentation/plot_segmentations.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
Comparison of segmentation and superpixel algorithms
====================================================
This example compares three popular low-level image segmentation methods. As
This example compares four popular low-level image segmentation methods. As
it is difficult to obtain good segmentations, and the definition of "good"
often depends on the application, these methods are usually used for obtaining
an oversegmentation, also known as superpixels. These superpixels then serve as
@@ -95,20 +95,19 @@
from skimage.util import img_as_float

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)
gradient = sobel(rgb2gray(img))
segments_watershed = watershed(gradient, markers=250, compactness=0.001)

print("Felzenszwalb's number of segments: %d" % len(np.unique(segments_fz)))
print('SLIC number of segments: %d' % len(np.unique(segments_slic)))
print('Quickshift number of segments: %d' % len(np.unique(segments_quick)))
print("Felzenszwalb number of segments: {}".format(len(np.unique(segments_fz))))
print('SLIC number of segments: {}'.format(len(np.unique(segments_slic))))
print('Quickshift number of segments: {}'.format(len(np.unique(segments_quick))))

fig, ax = plt.subplots(2, 2, sharex=True, sharey=True,
fig, ax = plt.subplots(2, 2, figsize=(10, 10), sharex=True, sharey=True,
subplot_kw={'adjustable': 'box-forced'})
fig.set_size_inches(8, 3, forward=True)
fig.tight_layout()

ax[0, 0].imshow(mark_boundaries(img, segments_fz))
ax[0, 0].set_title("Felzenszwalbs's method")
@@ -118,7 +117,9 @@
ax[1, 0].set_title('Quickshift')
ax[1, 1].imshow(mark_boundaries(img, segments_watershed))
ax[1, 1].set_title('Compact watershed')

for a in ax.ravel():
a.set_xticks(())
a.set_yticks(())
a.set_axis_off()

plt.tight_layout()
plt.show()
34 changes: 16 additions & 18 deletions doc/examples/transform/plot_ssim.py
Original file line number Diff line number Diff line change
@@ -27,23 +27,23 @@
from skimage import data, img_as_float
from skimage.measure import compare_ssim as ssim


img = img_as_float(data.camera())
rows, cols = img.shape

noise = np.ones_like(img) * 0.2 * (img.max() - img.min())
noise[np.random.random(size=noise.shape) > 0.5] *= -1


def mse(x, y):
return np.linalg.norm(x - y)

img_noise = img + noise
img_const = img + abs(noise)

fig, (ax0, ax1, ax2) = plt.subplots(nrows=1, ncols=3, figsize=(16, 6),
sharex=True, sharey=True,
subplot_kw={'adjustable': 'box-forced'})
plt.tight_layout()
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(10, 4),
sharex=True, sharey=True,
subplot_kw={'adjustable': 'box-forced'})
ax = axes.ravel()

mse_none = mse(img, img)
ssim_none = ssim(img, img, dynamic_range=img.max() - img.min())
@@ -56,21 +56,19 @@ def mse(x, y):
ssim_const = ssim(img, img_const,
dynamic_range=img_const.max() - img_const.min())

label = 'MSE: %2.f, SSIM: %.2f'
label = 'MSE: {:.2f}, SSIM: {:.2f}'

ax0.imshow(img, cmap=plt.cm.gray, vmin=0, vmax=1)
ax0.set_xlabel(label % (mse_none, ssim_none))
ax0.set_title('Original image')
ax0.axes.get_yaxis().set_visible(False)
ax[0].imshow(img, cmap=plt.cm.gray, vmin=0, vmax=1)
ax[0].set_xlabel(label.format(mse_none, ssim_none))
ax[0].set_title('Original image')

ax1.imshow(img_noise, cmap=plt.cm.gray, vmin=0, vmax=1)
ax1.set_xlabel(label % (mse_noise, ssim_noise))
ax1.set_title('Image with noise')
ax1.axes.get_yaxis().set_visible(False)
ax[1].imshow(img_noise, cmap=plt.cm.gray, vmin=0, vmax=1)
ax[1].set_xlabel(label.format(mse_noise, ssim_noise))
ax[1].set_title('Image with noise')

ax2.imshow(img_const, cmap=plt.cm.gray, vmin=0, vmax=1)
ax2.set_xlabel(label % (mse_const, ssim_const))
ax2.set_title('Image plus constant')
ax2.axes.get_yaxis().set_visible(False)
ax[2].imshow(img_const, cmap=plt.cm.gray, vmin=0, vmax=1)
ax[2].set_xlabel(label.format(mse_const, ssim_const))
ax[2].set_title('Image plus constant')

plt.tight_layout()
plt.show()
Loading

0 comments on commit 81d96f3

Please sign in to comment.