From 96847f26526f64e29a790d6766164bd62b97b39f Mon Sep 17 00:00:00 2001 From: Julius Bier Kirekgaard Date: Mon, 31 Aug 2015 20:28:28 +0100 Subject: [PATCH] pep8 and other small changes --- doc/examples/plot_active_contours.py | 3 ++- skimage/segmentation/active_contour_model.py | 17 ++++++++++------- .../tests/test_active_contour_model.py | 12 ++++++------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/doc/examples/plot_active_contours.py b/doc/examples/plot_active_contours.py index fb003526..0ad7ebb4 100644 --- a/doc/examples/plot_active_contours.py +++ b/doc/examples/plot_active_contours.py @@ -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). diff --git a/skimage/segmentation/active_contour_model.py b/skimage/segmentation/active_contour_model.py index c13f56e2..ece8847d 100644 --- a/skimage/segmentation/active_contour_model.py +++ b/skimage/segmentation/active_contour_model.py @@ -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 """ diff --git a/skimage/segmentation/tests/test_active_contour_model.py b/skimage/segmentation/tests/test_active_contour_model.py index 73289fd7..3e866aef 100644 --- a/skimage/segmentation/tests/test_active_contour_model.py +++ b/skimage/segmentation/tests/test_active_contour_model.py @@ -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)