From a16c530322576f328d79d5b4681c16d1343ce3c4 Mon Sep 17 00:00:00 2001 From: emmanuelle Date: Fri, 11 Dec 2015 17:21:17 +0100 Subject: [PATCH] Some minor PEP8 issues --- doc/examples/plot_active_contours.py | 4 +-- skimage/segmentation/active_contour_model.py | 33 ++++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/doc/examples/plot_active_contours.py b/doc/examples/plot_active_contours.py index c4f30c04..bfcd0b43 100644 --- a/doc/examples/plot_active_contours.py +++ b/doc/examples/plot_active_contours.py @@ -40,7 +40,7 @@ y = 100 + 100*np.sin(s) init = np.array([x, y]).T snake = active_contour(gaussian_filter(img, 3), - init, alpha=0.015, beta=10, gamma=0.001) + init, alpha=0.015, beta=10, gamma=0.001) fig = plt.figure(figsize=(7, 7)) ax = fig.add_subplot(111) @@ -67,7 +67,7 @@ y = np.linspace(136, 50, 100) init = np.array([x, y]).T snake = active_contour(gaussian_filter(img, 1), init, bc='fixed', - alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1) + alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1) fig = plt.figure(figsize=(9, 5)) ax = fig.add_subplot(111) diff --git a/skimage/segmentation/active_contour_model.py b/skimage/segmentation/active_contour_model.py index 43904306..b2f89b3b 100644 --- a/skimage/segmentation/active_contour_model.py +++ b/skimage/segmentation/active_contour_model.py @@ -1,4 +1,3 @@ -import warnings import numpy as np from skimage import img_as_float import scipy @@ -6,6 +5,7 @@ import scipy.linalg from scipy.interpolate import RectBivariateSpline, interp2d from skimage.filters import sobel + def active_contour(image, snake, alpha=0.01, beta=0.1, w_line=0, w_edge=1, gamma=0.01, bc='periodic', max_px_move=1.0, @@ -100,7 +100,7 @@ def active_contour(image, snake, alpha=0.01, beta=0.1, valid_bcs = ['periodic', 'free', 'fixed', 'free-fixed', 'fixed-free', 'fixed-fixed', 'free-free'] if bc not in valid_bcs: - raise ValueError("Invalid boundary condition.\n"+ + raise ValueError("Invalid boundary condition.\n" + "Should be one of: "+", ".join(valid_bcs)+'.') img = img_as_float(image) RGB = img.ndim == 3 @@ -130,11 +130,12 @@ def active_contour(image, snake, alpha=0.01, beta=0.1, # Interpolate for smoothness: if new_scipy: intp = RectBivariateSpline(np.arange(img.shape[1]), - np.arange(img.shape[0]), img.T, kx=2, ky=2, s=0) + np.arange(img.shape[0]), + img.T, kx=2, ky=2, s=0) else: intp = np.vectorize(interp2d(np.arange(img.shape[1]), - np.arange(img.shape[0]), img, kind='cubic', copy=False, - bounds_error=False, fill_value=0)) + np.arange(img.shape[0]), img, kind='cubic', + copy=False, bounds_error=False, fill_value=0)) x, y = snake[:, 0].copy(), snake[:, 1].copy() xsave = np.empty((convergence_order, len(x))) @@ -142,14 +143,14 @@ def active_contour(image, snake, alpha=0.01, beta=0.1, # Build snake shape matrix for Euler equation n = len(x) - a = np.roll(np.eye(n), -1, axis=0) \ - + np.roll(np.eye(n), -1, axis=1) \ - - 2*np.eye(n) # second order derivative, central difference - b = np.roll(np.eye(n), -2, axis=0) \ - + np.roll(np.eye(n), -2, axis=1) \ - - 4*np.roll(np.eye(n), -1, axis=0) \ - - 4*np.roll(np.eye(n), -1, axis=1) \ - + 6*np.eye(n) # fourth order derivative, central difference + a = np.roll(np.eye(n), -1, axis=0) + \ + np.roll(np.eye(n), -1, axis=1) - \ + 2*np.eye(n) # second order derivative, central difference + b = np.roll(np.eye(n), -2, axis=0) + \ + np.roll(np.eye(n), -2, axis=1) - \ + 4*np.roll(np.eye(n), -1, axis=0) - \ + 4*np.roll(np.eye(n), -1, axis=1) + \ + 6*np.eye(n) # fourth order derivative, central difference A = -alpha*a + beta*b # Impose boundary conditions different from periodic: @@ -220,13 +221,13 @@ def active_contour(image, snake, alpha=0.01, beta=0.1, # Convergence criteria needs to compare to a number of previous # configurations since oscillations can occur. - j = i%(convergence_order+1) + j = i % (convergence_order+1) if j < convergence_order: xsave[j, :] = x ysave[j, :] = y else: - dist = np.min(np.max(np.abs(xsave-x[None, :]) - + np.abs(ysave-y[None, :]), 1)) + dist = np.min(np.max(np.abs(xsave-x[None, :]) + + np.abs(ysave-y[None, :]), 1)) if dist < convergence: break