diff --git a/skimage/segmentation/_slic.pyx b/skimage/segmentation/_slic.pyx index ea5d9a30..51505cae 100644 --- a/skimage/segmentation/_slic.pyx +++ b/skimage/segmentation/_slic.pyx @@ -16,7 +16,7 @@ def _slic_cython(double[:, :, :, ::1] image_zyx, float step, Py_ssize_t max_iter, double[::1] spacing, - bint slic_zero, + bint slic_zero ): """Helper function for SLIC segmentation. @@ -177,8 +177,8 @@ def _slic_cython(double[:, :, :, ::1] image_zyx, dist_color = 0 for c in range(3, n_features): - dist_color += (image_zyx[z, y, x, c - 3] - - segments[k, c]) ** 2 + dist_color += (image_zyx[z, y, x, c - 3] - + segments[k, c]) ** 2 # The reference implementation seems to only change # the color if it increases from previous iteration diff --git a/skimage/segmentation/slic_superpixels.py b/skimage/segmentation/slic_superpixels.py index b0175b71..11373381 100644 --- a/skimage/segmentation/slic_superpixels.py +++ b/skimage/segmentation/slic_superpixels.py @@ -59,7 +59,8 @@ def slic(image, n_segments=100, compactness=10., max_iter=10, sigma=None, Proportion of the maximum connected segment size. A value of 3 works in most of the cases. slic_zero: bool, optional - True to run SLIC-zero, False to run original SLIC. + Run SLIC-zero, the zero-parameter mode of SLIC + Returns ------- labels : 2D or 3D array @@ -169,8 +170,8 @@ def slic(image, n_segments=100, compactness=10., max_iter=10, sigma=None, segments = np.concatenate([segments_z[..., np.newaxis], segments_y[..., np.newaxis], segments_x[..., np.newaxis], - segments_color - ], axis=-1).reshape(-1, 3 + image.shape[3]) + segments_color], + axis=-1).reshape(-1, 3 + image.shape[3]) segments = np.ascontiguousarray(segments) # we do the scaling of ratio in the same way as in the SLIC paper @@ -178,10 +179,7 @@ def slic(image, n_segments=100, compactness=10., max_iter=10, sigma=None, step = float(max((step_z, step_y, step_x))) ratio = 1.0 / compactness - if slic_zero: - image = np.ascontiguousarray(image * ratio) - else: - image = np.ascontiguousarray(image * ratio) + image = np.ascontiguousarray(image * ratio) labels = _slic_cython(image, segments, step, max_iter, spacing, slic_zero)