Change type to ssize_t for all index and size variables

This commit is contained in:
Johannes Schönberger
2013-02-22 17:05:10 +01:00
parent c9f72e93d6
commit 9f55fa2112
3 changed files with 14 additions and 11 deletions
+1 -1
View File
@@ -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
+6 -4
View File
@@ -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 = <np.float_t*> 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):
+7 -6
View File
@@ -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 = <np.float_t*> image_yx.data