mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
py3 fixes and skip test for old scipy.
This commit is contained in:
@@ -79,7 +79,7 @@ def active_contour(image, snake, alpha=0.01, beta=0.1,
|
||||
|
||||
Fit spline to image:
|
||||
|
||||
>>> snake = active_contour_model(img, init, w_edge=0, w_line=1)
|
||||
>>> snake = active_contour(img, init, w_edge=0, w_line=1)
|
||||
>>> int(np.mean(np.sqrt((45-snake[:, 0])**2 + (35-snake[:, 1])**2)))
|
||||
25
|
||||
|
||||
@@ -88,10 +88,9 @@ def active_contour(image, snake, alpha=0.01, beta=0.1,
|
||||
new_scipy = scipy_version[0] > 0 or \
|
||||
(scipy_version[0] == 0 and scipy_version[1] >= 14)
|
||||
if not new_scipy:
|
||||
warnings.warn('You are using an old version of scipy. '
|
||||
'Upgrading to a version newer than 0.14.0 '
|
||||
'will signifcantly improve the performance '
|
||||
'of this algorithm.')
|
||||
raise NotImplementedError('You are using an old version of scipy. '
|
||||
'Active contours is implemented for scipy versions '
|
||||
'0.14.0 and above.')
|
||||
|
||||
max_iterations = int(max_iterations)
|
||||
if max_iterations <= 0:
|
||||
@@ -112,7 +111,7 @@ def active_contour(image, snake, alpha=0.01, beta=0.1,
|
||||
sobel(img[:, :, 2])]
|
||||
else:
|
||||
edge = [sobel(img)]
|
||||
for i in xrange(3 if RGB else 1):
|
||||
for i in range(3 if RGB else 1):
|
||||
edge[i][0, :] = edge[i][1, :]
|
||||
edge[i][-1, :] = edge[i][-2, :]
|
||||
edge[i][:, 0] = edge[i][:, 1]
|
||||
@@ -184,7 +183,7 @@ def active_contour(image, snake, alpha=0.01, beta=0.1,
|
||||
inv = scipy.linalg.inv(A+gamma*np.eye(n))
|
||||
|
||||
# Explicit time stepping for image energy minimization:
|
||||
for i in xrange(max_iterations):
|
||||
for i in range(max_iterations):
|
||||
if new_scipy:
|
||||
fx = intp(x, y, dx=1, grid=False)
|
||||
fy = intp(x, y, dy=1, grid=False)
|
||||
|
||||
@@ -4,8 +4,13 @@ from skimage.color import rgb2gray
|
||||
from skimage.filters import gaussian_filter
|
||||
from skimage.segmentation import active_contour
|
||||
from numpy.testing import assert_equal, assert_allclose, assert_raises
|
||||
from numpy.testing.decorators import skipif
|
||||
|
||||
scipy_version = list(map(int, scipy.__version__.split('.')))
|
||||
new_scipy = scipy_version[0] > 0 or \
|
||||
(scipy_version[0] == 0 and scipy_version[1] >= 14)
|
||||
|
||||
@skipif(not new_scipy)
|
||||
def test_periodic_reference():
|
||||
img = data.astronaut()
|
||||
img = rgb2gray(img)
|
||||
@@ -20,7 +25,7 @@ def test_periodic_reference():
|
||||
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
|
||||
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
|
||||
|
||||
|
||||
@skipif(not new_scipy)
|
||||
def test_fixed_reference():
|
||||
img = data.text()
|
||||
x = np.linspace(5, 424, 100)
|
||||
@@ -33,7 +38,7 @@ def test_fixed_reference():
|
||||
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
|
||||
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
|
||||
|
||||
|
||||
@skipif(not new_scipy)
|
||||
def test_free_reference():
|
||||
img = data.text()
|
||||
x = np.linspace(5, 424, 100)
|
||||
@@ -46,7 +51,7 @@ def test_free_reference():
|
||||
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
|
||||
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
|
||||
|
||||
|
||||
@skipif(not new_scipy)
|
||||
def test_RGB():
|
||||
img = gaussian_filter(data.text(), 1)
|
||||
imgR = np.zeros((img.shape[0], img.shape[1], 3))
|
||||
@@ -73,7 +78,7 @@ def test_RGB():
|
||||
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
|
||||
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
|
||||
|
||||
|
||||
@skipif(not new_scipy)
|
||||
def test_end_points():
|
||||
img = data.astronaut()
|
||||
img = rgb2gray(img)
|
||||
@@ -94,7 +99,7 @@ def test_end_points():
|
||||
gamma=0.001, max_iterations=100)
|
||||
assert_allclose(snake[0, :], [x[0], y[0]], atol=1e-5)
|
||||
|
||||
|
||||
@skipif(not new_scipy)
|
||||
def test_bad_input():
|
||||
img = np.zeros((10, 10))
|
||||
x = np.linspace(5, 424, 100)
|
||||
|
||||
Reference in New Issue
Block a user