diff --git a/skimage/segmentation/_felzenszwalb_cy.pyx b/skimage/segmentation/_felzenszwalb_cy.pyx index 3babb86e..8590e17d 100644 --- a/skimage/segmentation/_felzenszwalb_cy.pyx +++ b/skimage/segmentation/_felzenszwalb_cy.pyx @@ -12,7 +12,8 @@ from skimage.morphology.ccomp cimport find_root, join_trees from ..util import img_as_float -def _felzenszwalb_grey(image, double scale=1, sigma=0.8, Py_ssize_t min_size=20): +def _felzenszwalb_grey(image, double scale=1, sigma=0.8, + Py_ssize_t min_size=20): """Felzenszwalb's efficient graph based segmentation for a single channel. Produces an oversegmentation of a 2d image using a fast, minimum spanning diff --git a/skimage/segmentation/_slic.pyx b/skimage/segmentation/_slic.pyx index bfa6cd1a..5df747ad 100644 --- a/skimage/segmentation/_slic.pyx +++ b/skimage/segmentation/_slic.pyx @@ -2,15 +2,11 @@ #cython: boundscheck=False #cython: nonecheck=False #cython: wraparound=False -import collections as coll import numpy as np -from time import time from scipy import ndimage -cimport numpy as cnp - -from ..util import img_as_float, regular_grid -from ..color import rgb2lab, gray2rgb +from skimage.util import img_as_float, regular_grid +from skimage.color import rgb2lab, gray2rgb def _slic_cython(double[:, :, :, ::1] image_zyx, @@ -19,18 +15,18 @@ def _slic_cython(double[:, :, :, ::1] image_zyx, double[:, ::1] means, Py_ssize_t max_iter, Py_ssize_t n_segments): """Helper function for SLIC segmentation. - + Parameters ---------- - image_zyx : 4D np.ndarray of double, shape (Z, Y, X, 6) + image_zyx : 4D array of double, shape (Z, Y, X, 6) The image with embedded coordinates, that is, `image_zyx[i, j, k]` is `array([i, j, k, r, g, b])` or `array([i, j, k, L, a, b])`, depending on the colorspace. - nearest_mean : 3D np.ndarray of int, shape (Z, Y, X) + nearest_mean : 3D array of int, shape (Z, Y, X) The (initially empty) label field. - distance : 3D np.ndarray of double, shape (Z, Y, X) + distance : 3D array of double, shape (Z, Y, X) The (initially infinity) array of distances to the nearest centroid. - means : 2D np.ndarray of double, shape (n_segments, 6) + means : 2D array of double, shape (n_segments, 6) The centroids obtained by SLIC. max_iter : int The maximum number of k-means iterations. @@ -39,7 +35,7 @@ def _slic_cython(double[:, :, :, ::1] image_zyx, Returns ------- - nearest_mean : 3D np.ndarray of int, shape (Z, Y, X) + nearest_mean : 3D array of int, shape (Z, Y, X) The label field/superpixels found by SLIC. """ diff --git a/skimage/transform/_warps_cy.pyx b/skimage/transform/_warps_cy.pyx index f51eb8d3..0eb7efdd 100644 --- a/skimage/transform/_warps_cy.pyx +++ b/skimage/transform/_warps_cy.pyx @@ -83,10 +83,8 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, """ - cdef cnp.ndarray[dtype=cnp.double_t, ndim=2, mode="c"] img = \ - np.ascontiguousarray(image, dtype=np.double) - cdef cnp.ndarray[dtype=cnp.double_t, ndim=2, mode="c"] M = \ - np.ascontiguousarray(H) + cdef double[:, ::1] img = np.ascontiguousarray(image, dtype=np.double) + cdef double[:, ::1] M = np.ascontiguousarray(H) if mode not in ('constant', 'wrap', 'reflect', 'nearest'): raise ValueError("Invalid mode specified. Please use " @@ -101,8 +99,7 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, out_r = output_shape[0] out_c = output_shape[1] - cdef cnp.ndarray[dtype=cnp.double_t, ndim=2] out = \ - np.zeros((out_r, out_c), dtype=np.double) + cdef double[:, ::1] out = np.zeros((out_r, out_c), dtype=np.double) cdef Py_ssize_t tfr, tfc cdef double r, c @@ -122,8 +119,8 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, for tfr in range(out_r): for tfc in range(out_c): - _matrix_transform(tfc, tfr, M.data, &c, &r) - out[tfr, tfc] = interp_func(img.data, rows, cols, r, c, + _matrix_transform(tfc, tfr, &M[0, 0], &c, &r) + out[tfr, tfc] = interp_func(&img[0, 0], rows, cols, r, c, mode_c, cval) return out