From 9f55fa2112ab10c8112276bb15b24a4284164a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 22 Jan 2013 22:23:54 +0100 Subject: [PATCH] Change type to ssize_t for all index and size variables --- skimage/segmentation/_felzenszwalb_cy.pyx | 2 +- skimage/segmentation/_quickshift.pyx | 10 ++++++---- skimage/segmentation/_slic.pyx | 13 +++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/skimage/segmentation/_felzenszwalb_cy.pyx b/skimage/segmentation/_felzenszwalb_cy.pyx index 79131eac..2a4ea173 100644 --- a/skimage/segmentation/_felzenszwalb_cy.pyx +++ b/skimage/segmentation/_felzenszwalb_cy.pyx @@ -10,7 +10,7 @@ from ..util import img_as_float @cython.boundscheck(False) @cython.wraparound(False) @cython.cdivision(True) -def _felzenszwalb_grey(image, double scale=1, sigma=0.8, int min_size=20): +def _felzenszwalb_grey(image, double scale=1, sigma=0.8, 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/_quickshift.pyx b/skimage/segmentation/_quickshift.pyx index b465eb08..4362725c 100644 --- a/skimage/segmentation/_quickshift.pyx +++ b/skimage/segmentation/_quickshift.pyx @@ -85,18 +85,19 @@ def quickshift(image, ratio=1., float kernel_size=5, max_dist=10, raise ValueError("Sigma should be >= 1") cdef int w = int(3 * kernel_size) - cdef int height = image_c.shape[0] - cdef int width = image_c.shape[1] - cdef int channels = image_c.shape[2] + cdef ssize_t height = image_c.shape[0] + cdef ssize_t width = image_c.shape[1] + cdef ssize_t channels = image_c.shape[2] cdef double current_density, closest, dist - cdef int r, c, r_, c_, channel + cdef ssize_t r, c, r_, c_, channel, r_min, c_min cdef np.float_t* image_p = image_c.data cdef np.float_t* current_pixel_p = image_p cdef np.ndarray[dtype=np.float_t, ndim=2] densities \ = np.zeros((height, width)) + # compute densities for r in range(height): for c in range(width): @@ -120,6 +121,7 @@ def quickshift(image, ratio=1., float kernel_size=5, max_dist=10, = np.arange(width * height).reshape(height, width) cdef np.ndarray[dtype=np.float_t, ndim=2] dist_parent \ = np.zeros((height, width)) + # find nearest node with higher density current_pixel_p = image_p for r in range(height): diff --git a/skimage/segmentation/_slic.pyx b/skimage/segmentation/_slic.pyx index dfb37a7c..260b7689 100644 --- a/skimage/segmentation/_slic.pyx +++ b/skimage/segmentation/_slic.pyx @@ -1,3 +1,4 @@ +#cython: boundscheck=False import numpy as np cimport numpy as np from time import time @@ -7,7 +8,7 @@ from ..color import rgb2lab, gray2rgb def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1, - convert2lab=True): + convert2lab=True): """Segments image using k-means clustering in Color-(x,y) space. Parameters @@ -62,10 +63,10 @@ def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1, image = rgb2lab(image) # initialize on grid: - cdef int height, width + cdef ssize_t height, width height, width = image.shape[:2] # approximate grid size for desired n_segments - cdef int step = np.ceil(np.sqrt(height * width / n_segments)) + cdef ssize_t step = np.ceil(np.sqrt(height * width / n_segments)) grid_y, grid_x = np.mgrid[:height, :width] means_y = grid_y[::step, ::step] means_x = grid_x[::step, ::step] @@ -81,11 +82,11 @@ def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1, ratio = (ratio / float(step)) ** 2 cdef np.ndarray[dtype=np.float_t, ndim=3] image_yx \ = np.dstack([grid_y, grid_x, image / ratio]).copy("C") - cdef int i, k, x, y, x_min, x_max, y_min, y_max, changes + cdef ssize_t i, k, x, y, x_min, x_max, y_min, y_max, changes cdef double dist_mean - cdef np.ndarray[dtype=np.int_t, ndim=2] nearest_mean \ - = np.zeros((height, width), dtype=np.int) + cdef np.ndarray[dtype=np.intp_t, ndim=2] nearest_mean \ + = np.zeros((height, width), dtype=np.intp) cdef np.ndarray[dtype=np.float_t, ndim=2] distance \ = np.empty((height, width)) cdef np.float_t* image_p = image_yx.data