pep8 and other small changes

This commit is contained in:
Julius Bier Kirekgaard
2015-08-31 20:28:28 +01:00
parent 7c30f36d85
commit 96847f2652
3 changed files with 18 additions and 14 deletions
+2 -1
View File
@@ -11,7 +11,8 @@ image energy.
In the following two examples the active contour model is used (1) to segment
the face of a person from the rest of an image by fitting a closed curve
to the edges of the face and (2) to find the darkest curve between two fixed
points while obeying smoothness considerations.
points while obeying smoothness considerations. Typically it is a good idea to
smooth images a bit before analyzing, as done in the following examples.
.. [1] *Snakes: Active contour models*. Kass, M.; Witkin, A.; Terzopoulos, D.
International Journal of Computer Vision 1 (4): 321 (1988).
+10 -7
View File
@@ -8,7 +8,7 @@ def active_contour_model(image, snake, alpha=0.01, beta=0.1,
w_line=0, w_edge=1, gamma=0.01,
bc='periodic', max_px_move=1.0,
max_iterations=2500, convergence=0.1):
"""Active contour model
"""Active contour model.
Active contours by fitting snakes to features of images. Supports single
and multichannel 2D images. Snakes can be periodic (for segmentation) or
@@ -52,21 +52,24 @@ def active_contour_model(image, snake, alpha=0.01, beta=0.1,
References
----------
.. [1] Kass, M.; Witkin, A.; Terzopoulos, D. "Snakes: Active contour models". International Journal of Computer Vision 1 (4): 321 (1988).
.. [1] Kass, M.; Witkin, A.; Terzopoulos, D. "Snakes: Active contour
models". International Journal of Computer Vision 1 (4): 321 (1988).
Examples
--------
>>> #from skimage.segmentation import active_contour_model
>>> from skimage.draw import circle_perimeter
>>> from skimage.filters import gaussian_filter
Create and smooth image:
>>> img = np.zeros((100, 100))
>>> rr, cc = circle_perimeter(35, 45, 25)
>>> img[rr, cc] = 1
>>> img = gaussian_filter(img,2)
>>> s = np.linspace(0,2*np.pi,100)
>>> init = 50*np.array([np.cos(s),np.sin(s)]).T+50
>>> img = gaussian_filter(img, 2)
Initiliaze spline:
>>> s = np.linspace(0, 2*np.pi,100)
>>> init = 50*np.array([np.cos(s), np.sin(s)]).T+50
Fit spline to image:
>>> snake = active_contour_model(img, init, w_edge=0, w_line=1)
>>> int(np.mean(np.sqrt((45-snake[:,0])**2 + (35-snake[:,1])**2)))
>>> int(np.mean(np.sqrt((45-snake[:, 0])**2 + (35-snake[:, 1])**2)))
25
"""
@@ -5,7 +5,7 @@ from skimage.filters import gaussian_filter
from skimage.segmentation import active_contour_model
from numpy.testing import assert_equal, assert_allclose, assert_raises
def periodic_reference_test():
def test_periodic_reference():
img = data.astronaut()
img = rgb2gray(img)
s = np.linspace(0, 2*np.pi, 400)
@@ -20,7 +20,7 @@ def periodic_reference_test():
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
def fixed_reference_test():
def test_fixed_reference():
img = data.text()
x = np.linspace(5, 424, 100)
y = np.linspace(136, 50, 100)
@@ -33,7 +33,7 @@ def fixed_reference_test():
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
def free_reference_test():
def test_free_reference():
img = data.text()
x = np.linspace(5, 424, 100)
y = np.linspace(70, 40, 100)
@@ -46,7 +46,7 @@ def free_reference_test():
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
def RGB_test():
def test_RGB():
img = gaussian_filter(data.text(), 1)
imgR = np.zeros((img.shape[0], img.shape[1], 3))
imgG = np.zeros((img.shape[0], img.shape[1], 3))
@@ -73,7 +73,7 @@ def RGB_test():
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
def end_points_tests():
def test_end_points_tests():
img = data.astronaut()
img = rgb2gray(img)
s = np.linspace(0, 2*np.pi, 400)
@@ -94,7 +94,7 @@ def end_points_tests():
assert_allclose(snake[0, :], [x[0], y[0]], atol=1e-5)
def bad_input_tests():
def test_bad_input_tests():
img = np.zeros((10, 10))
x = np.linspace(5, 424, 100)
y = np.linspace(136, 50, 100)