From 0aa008712ac83188d9586de54a5137b3f0ce8c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Scho=CC=88nberger?= Date: Sat, 21 Apr 2012 16:56:14 +0200 Subject: [PATCH] replaced fixed output array size with dynamic lists area of polygon is not suitable to determine the size of the number of filled pixels for output array --- skimage/draw/_draw.pyx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index df59fadc..01b6b17d 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -1,6 +1,5 @@ import numpy as np import math -from libc.stdlib cimport malloc, free cimport numpy as np cimport cython @@ -125,7 +124,6 @@ def polygon(verts, shape=None): maxc = min(shape[1]-1, maxc) cdef int r, c - cdef int i = 0 #: make contigous arrays for r, c coordinates verts = verts.astype('double') @@ -134,20 +132,15 @@ def polygon(verts, shape=None): cdef np.double_t* rptr = contiguous_rdata.data cdef np.double_t* cptr = contiguous_cdata.data - # use area of polygon to determine the rough size of the output arrays - cdef double area = _polygon_area(contiguous_cdata, contiguous_rdata) - #: output coordinate arrays - cdef np.ndarray[np.int32_t, ndim=1, mode="c"] rr, cc - rr = np.zeros(int(area), dtype=np.int32) - cc = np.zeros(int(area), dtype=np.int32) + rr = list() + cc = list() for r in range(minr, maxr+1): for c in range(minc, maxc+1): if pnpoly(nr_verts, cptr, rptr, c, r): - rr[i] = r - cc[i] = c - i += 1 + rr.append(r) + cc.append(c) # area >= number of points in polygon, so crop actual points - return rr[:i], cc[:i] + return np.array(rr), np.array(cc)