Merge pull request #1970 from alexandrejaguar/master

Format clean-ups in convex hull and otsu
This commit is contained in:
Stefan van der Walt
2016-03-04 11:23:45 -08:00
3 changed files with 21 additions and 20 deletions
+9 -8
View File
@@ -13,12 +13,12 @@ A good overview of the algorithm is given on `Steve Eddin's blog
<http://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/>`__.
"""
import numpy as np
import matplotlib.pyplot as plt
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],
@@ -31,6 +31,7 @@ original_image = np.copy(image)
chull = convex_hull_image(image)
image[chull] += 1
# image is now:
# [[ 0. 0. 0. 0. 0. 0. 0. 0. 0.]
# [ 0. 0. 0. 0. 2. 0. 0. 0. 0.]
@@ -39,15 +40,15 @@ image[chull] += 1
# [ 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, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 6))
ax0.set_title('Original picture')
ax0.imshow(original_image, cmap=plt.cm.gray, interpolation='nearest')
ax0.set_xticks([]), ax0.set_yticks([])
ax1.set_title('Original picture')
ax1.imshow(original_image, cmap=plt.cm.gray, interpolation='nearest')
ax1.set_title('Transformed picture')
ax1.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
ax1.set_xticks([]), ax1.set_yticks([])
ax2.set_title('Transformed picture')
ax2.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
ax2.set_xticks([]), ax2.set_yticks([])
plt.show()
+10 -11
View File
@@ -6,36 +6,35 @@ CENSURE feature detector
The CENSURE feature detector is a scale-invariant center-surround detector
(CENSURE) that claims to outperform other detectors and is capable of real-time
implementation.
"""
from skimage import data
from skimage import transform as tf
from skimage.feature import CENSURE
from skimage.color import rgb2gray
import matplotlib.pyplot as plt
img1 = rgb2gray(data.astronaut())
img_orig = rgb2gray(data.astronaut())
tform = tf.AffineTransform(scale=(1.5, 1.5), rotation=0.5,
translation=(150, -200))
img2 = tf.warp(img1, tform)
img_warp = tf.warp(img_orig, tform)
detector = CENSURE()
fig, ax = plt.subplots(nrows=1, ncols=2)
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(12, 6))
plt.tight_layout()
plt.gray()
detector.detect(img_orig)
detector.detect(img1)
ax[0].imshow(img1)
ax[0].imshow(img_orig, cmap=plt.cm.gray)
ax[0].axis('off')
ax[0].scatter(detector.keypoints[:, 1], detector.keypoints[:, 0],
2 ** detector.scales, facecolors='none', edgecolors='r')
detector.detect(img2)
detector.detect(img_warp)
ax[1].imshow(img2)
ax[1].imshow(img_warp, cmap=plt.cm.gray)
ax[1].axis('off')
ax[1].scatter(detector.keypoints[:, 1], detector.keypoints[:, 0],
2 ** detector.scales, facecolors='none', edgecolors='r')
+2 -1
View File
@@ -10,7 +10,7 @@ structuring element.
The example compares the local threshold with the global threshold.
.. Note: local is much slower than global thresholding
.. note: local is much slower than global thresholding
.. [1] http://en.wikipedia.org/wiki/Otsu's_method
@@ -37,6 +37,7 @@ global_otsu = img >= threshold_global_otsu
fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True,
subplot_kw={'adjustable': 'box-forced'})
ax0, ax1, ax2, ax3 = ax.ravel()
plt.tight_layout()
fig.colorbar(ax0.imshow(img, cmap=plt.cm.gray),
ax=ax0, orientation='horizontal')