From 075c43109abeec1dfd35e1a7af7365143a665649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sun, 13 Jan 2013 16:39:02 +0100 Subject: [PATCH 01/12] new method: ellipse_perimeter --- skimage/draw/__init__.py | 2 +- skimage/draw/_draw.pyx | 84 +++++++++++++++++++++++++++++++++ skimage/draw/tests/test_draw.py | 47 +++++++++++++++++- 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/skimage/draw/__init__.py b/skimage/draw/__init__.py index 4b30ea18..67692f1b 100644 --- a/skimage/draw/__init__.py +++ b/skimage/draw/__init__.py @@ -1,2 +1,2 @@ -from ._draw import line, polygon, ellipse, circle, circle_perimeter, set_color +from ._draw import line, polygon, ellipse, circle, circle_perimeter, ellipse_perimeter, set_color bresenham = line diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 66b41d2c..73c9a341 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -263,6 +263,90 @@ def circle_perimeter(int cy, int cx, int radius, method='bresenham'): return np.array(rr) + cy, np.array(cc) + cx +def ellipse_perimeter(int cy, int cx, int yradius, int xradius): + """Generate ellipse perimeter coordinates. + + Parameters + ---------- + cy, cx : int + Centre coordinate of ellipse. + yradius, xradius: int + Main radial values. + + Returns + ------- + rr, cc : (N,) ndarray of int + Indices of pixels that belong to the circle perimeter. + May be used to directly index into an array, e.g. + ``img[rr, cc] = 1``. + + References + ---------- + .. [1] J. Kennedy "A fast Bresenham type algorithm for + drawing ellipses". + """ + # If both radii == 0, return the center + # to avoid infinite loop in 2nd set + if (xradius == 0 and yradius == 0): + return np.array(cy), np.array(cx) + + # a and b are xradius an yradius + # compute 2a^2 and 2b^2 + cdef int twoasquared = 2 * xradius * xradius + cdef int twobsquared = 2 * yradius * yradius + + # Pixels + cdef list px = list() + cdef list py = list() + + # First set of points: + # start at the top + cdef int x = xradius + cdef int y = 0 + + cdef int err = 0 + cdef int xstop = twobsquared * xradius + cdef int ystop = 0 + cdef int xchange = yradius * yradius * (1 - 2 * xradius) + cdef int ychange = xradius * xradius + + while(xstop > ystop): + px.extend([x, -x, -x, x]) + py.extend([y, y, -y, -y]) + y += 1 + ystop += twoasquared + err += ychange + ychange += twoasquared + if ((2 * err + xchange) > 0): + x -= 1 + xstop -= twobsquared + err += xchange + xchange += twobsquared + + # Second set of points: + x = 0 + y = yradius + + err = 0 + xstop = 0 + ystop = twoasquared * yradius + xchange = yradius * yradius + ychange = xradius * xradius * (1 - 2 * yradius) + + while(xstop <= ystop): + px.extend([x, -x, -x, x]) + py.extend([y, y, -y, -y]) + x += 1 + xstop += twobsquared + err += xchange + xchange += twobsquared + if ((2 * err + ychange) > 0): + y -= 1 + ystop -= twoasquared + err += ychange + ychange += twobsquared + + return np.array(py) + cy, np.array(px) + cx @cython.boundscheck(False) @cython.wraparound(False) diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py index b2325015..7b4edbe4 100644 --- a/skimage/draw/tests/test_draw.py +++ b/skimage/draw/tests/test_draw.py @@ -1,7 +1,7 @@ from numpy.testing import assert_array_equal import numpy as np -from skimage.draw import line, polygon, circle, circle_perimeter, ellipse +from skimage.draw import line, polygon, circle, circle_perimeter, ellipse, ellipse_perimeter def test_line_horizontal(): @@ -210,7 +210,6 @@ def test_circle_perimeter_andres(): ) assert_array_equal(img, img_) - def test_ellipse(): img = np.zeros((15, 15), 'uint8') @@ -237,6 +236,50 @@ def test_ellipse(): assert_array_equal(img, img_) +def test_ellipse_perimeter(): + img = np.zeros((30, 15), 'uint8') + rr, cc = ellipse_perimeter(15, 7, 0, 0) + img[rr, cc] = 1 + assert(np.sum(img) == 1) + + img = np.zeros((30, 15), 'uint8') + rr, cc = ellipse_perimeter(15, 7, 14, 6) + img[rr, cc] = 1 + print(img) + img_ = np.array( + [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0]] + ) + + assert_array_equal(img, img_) if __name__ == "__main__": from numpy.testing import run_module_suite From 70825a420e35cfe72a7bde2163124b0cd2a8fd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 13 Jan 2013 11:44:09 +0100 Subject: [PATCH 02/12] Use char type for circle_perimeter method for speedup --- skimage/draw/_draw.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 73c9a341..1bcca5a6 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -231,10 +231,13 @@ def circle_perimeter(int cy, int cx, int radius, method='bresenham'): cdef int x = 0 cdef int y = radius cdef int d = 0 + cdef char cmethod if method == 'bresenham': d = 3 - 2 * radius + cmethod = 'b' elif method == 'andres': d = radius - 1 + cmethod = 'a' else: raise ValueError('Wrong method') @@ -242,14 +245,14 @@ def circle_perimeter(int cy, int cx, int radius, method='bresenham'): rr.extend([y, -y, y, -y, x, -x, x, -x]) cc.extend([x, x, -x, -x, y, y, -y, -y]) - if method == 'bresenham': + if cmethod == 'b': if d < 0: d += 4 * x + 6 else: d += 4 * (x - y) + 10 y -= 1 x += 1 - elif method == 'andres': + elif cmethod == 'a': if d >= 2 * (x - 1): d = d - 2 * x x = x + 1 From b1e5106029d010d052a7c07188dcfbd68e50d325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 13 Jan 2013 11:46:42 +0100 Subject: [PATCH 03/12] Use same cython directives for whole source file --- skimage/draw/_draw.pyx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 1bcca5a6..146197ae 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -1,3 +1,7 @@ +#cython: cdivision=True +#cython: boundscheck=False +#cython: nonecheck=False +#cython: wraparound=False import numpy as np import math from libc.math cimport sqrt @@ -6,8 +10,6 @@ cimport cython from skimage._shared.geometry cimport point_in_polygon -@cython.boundscheck(False) -@cython.wraparound(False) def line(int y, int x, int y2, int x2): """Generate line pixel coordinates. @@ -66,9 +68,6 @@ def line(int y, int x, int y2, int x2): return rr, cc -@cython.boundscheck(False) -@cython.wraparound(False) -@cython.nonecheck(False) def polygon(y, x, shape=None): """Generate coordinates of pixels within polygon. @@ -123,10 +122,6 @@ def polygon(y, x, shape=None): return np.array(rr), np.array(cc) -@cython.boundscheck(False) -@cython.wraparound(False) -@cython.nonecheck(False) -@cython.cdivision(True) def ellipse(double cy, double cx, double b, double a, shape=None): """Generate coordinates of pixels within ellipse. @@ -351,8 +346,6 @@ def ellipse_perimeter(int cy, int cx, int yradius, int xradius): return np.array(py) + cy, np.array(px) + cx -@cython.boundscheck(False) -@cython.wraparound(False) def set_color(img, coords, color): """Set pixel color in the image at the given coordinates. Coordinates that exceed the shape of the image will be ignored. From 805e554a1130448e39b326b7f4fd23d63a97e965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 13 Jan 2013 11:48:37 +0100 Subject: [PATCH 04/12] Fix PEP8 issues --- skimage/draw/_draw.pyx | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 146197ae..2576c861 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -35,15 +35,19 @@ def line(int y, int x, int y2, int x2): cdef int dy = abs(y2 - y) cdef int sx, sy, d, i - if (x2 - x) > 0: sx = 1 - else: sx = -1 - if (y2 - y) > 0: sy = 1 - else: sy = -1 + if (x2 - x) > 0: + sx = 1 + else: + sx = -1 + if (y2 - y) > 0: + sy = 1 + else: + sy = -1 if dy > dx: steep = 1 - x,y = y,x - dx,dy = dy,dx - sx,sy = sy,sx + x, y = y, x + dx, dy = dy, dx + sx, sy = sy, sx d = (2 * dy) - dx rr = np.zeros(int(dx) + 1, dtype=np.int32) @@ -97,8 +101,8 @@ def polygon(y, x, shape=None): # make sure output coordinates do not exceed image size if shape is not None: - maxr = min(shape[0]-1, maxr) - maxc = min(shape[1]-1, maxc) + maxr = min(shape[0] - 1, maxr) + maxc = min(shape[1] - 1, maxc) cdef int r, c @@ -139,15 +143,15 @@ def ellipse(double cy, double cx, double b, double a, shape=None): May be used to directly index into an array, e.g. ``img[rr, cc] = 1``. """ - cdef int minr = max(0, cy-b) - cdef int maxr = math.ceil(cy+b) - cdef int minc = max(0, cx-a) - cdef int maxc = math.ceil(cx+a) + cdef int minr = max(0, cy - b) + cdef int maxr = math.ceil(cy + b) + cdef int minc = max(0, cx - a) + cdef int maxc = math.ceil(cx + a) # make sure output coordinates do not exceed image size if shape is not None: - maxr = min(shape[0]-1, maxr) - maxc = min(shape[1]-1, maxc) + maxr = min(shape[0] - 1, maxr) + maxc = min(shape[1] - 1, maxc) cdef int r, c @@ -155,9 +159,9 @@ def ellipse(double cy, double cx, double b, double a, shape=None): cdef list rr = list() cdef list cc = list() - for r in range(minr, maxr+1): - for c in range(minc, maxc+1): - if sqrt(((r - cy)/b)**2 + ((c - cx)/a)**2) < 1: + for r in range(minr, maxr + 1): + for c in range(minc, maxc + 1): + if sqrt(((r - cy) / b)**2 + ((c - cx) / a)**2) < 1: rr.append(r) cc.append(c) From dd41c9a654555cc99b70d6684a933413d297ee3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sun, 13 Jan 2013 16:40:11 +0100 Subject: [PATCH 05/12] add myself to contributors --- CONTRIBUTORS.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 9f3f2aa7..d582ab63 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -129,3 +129,6 @@ - Anders Boesen Lindbo Larsen Dense DAISY feature description, circle perimeter drawing. + +- François Boulogne + Andres Method for circle perimeter, ellipse perimeter drawing. From cc061029f321578809052bbccfed89f61ab34032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sun, 13 Jan 2013 17:45:54 +0100 Subject: [PATCH 06/12] remove print statement --- skimage/draw/tests/test_draw.py | 1 - 1 file changed, 1 deletion(-) diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py index 7b4edbe4..e979c292 100644 --- a/skimage/draw/tests/test_draw.py +++ b/skimage/draw/tests/test_draw.py @@ -245,7 +245,6 @@ def test_ellipse_perimeter(): img = np.zeros((30, 15), 'uint8') rr, cc = ellipse_perimeter(15, 7, 14, 6) img[rr, cc] = 1 - print(img) img_ = np.array( [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0], From 843d2d11603c0fdb21283d9c83ecce379d71de02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sun, 13 Jan 2013 17:47:59 +0100 Subject: [PATCH 07/12] remove brackets --- skimage/draw/_draw.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 2576c861..904c3f82 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -289,7 +289,7 @@ def ellipse_perimeter(int cy, int cx, int yradius, int xradius): """ # If both radii == 0, return the center # to avoid infinite loop in 2nd set - if (xradius == 0 and yradius == 0): + if xradius == 0 and yradius == 0: return np.array(cy), np.array(cx) # a and b are xradius an yradius @@ -312,14 +312,14 @@ def ellipse_perimeter(int cy, int cx, int yradius, int xradius): cdef int xchange = yradius * yradius * (1 - 2 * xradius) cdef int ychange = xradius * xradius - while(xstop > ystop): + while xstop > ystop: px.extend([x, -x, -x, x]) py.extend([y, y, -y, -y]) y += 1 ystop += twoasquared err += ychange ychange += twoasquared - if ((2 * err + xchange) > 0): + if (2 * err + xchange) > 0: x -= 1 xstop -= twobsquared err += xchange @@ -335,14 +335,14 @@ def ellipse_perimeter(int cy, int cx, int yradius, int xradius): xchange = yradius * yradius ychange = xradius * xradius * (1 - 2 * yradius) - while(xstop <= ystop): + while xstop <= ystop: px.extend([x, -x, -x, x]) py.extend([y, y, -y, -y]) x += 1 xstop += twobsquared err += xchange xchange += twobsquared - if ((2 * err + ychange) > 0): + if (2 * err + ychange) > 0: y -= 1 ystop -= twoasquared err += ychange From 1400eb44b3e33784a0a583a3ab01fc5dbd73f757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Wed, 16 Jan 2013 09:33:58 +0100 Subject: [PATCH 08/12] fix for master --- skimage/draw/_draw.pyx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 904c3f82..c0fd798b 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -126,15 +126,15 @@ def polygon(y, x, shape=None): return np.array(rr), np.array(cc) -def ellipse(double cy, double cx, double b, double a, shape=None): +def ellipse(double cy, double cx, double yradius, double xradius, shape=None): """Generate coordinates of pixels within ellipse. Parameters ---------- cy, cx : double Centre coordinate of ellipse. - b, a: double - Minor and major semi-axes. ``(x/a)**2 + (y/b)**2 = 1``. + yradius, xradius: double + Minor and major semi-axes. ``(x/xradius)**2 + (y/yradius)**2 = 1``. Returns ------- @@ -143,10 +143,10 @@ def ellipse(double cy, double cx, double b, double a, shape=None): May be used to directly index into an array, e.g. ``img[rr, cc] = 1``. """ - cdef int minr = max(0, cy - b) - cdef int maxr = math.ceil(cy + b) - cdef int minc = max(0, cx - a) - cdef int maxc = math.ceil(cx + a) + cdef int minr = max(0, cy-yradius) + cdef int maxr = math.ceil(cy+yradius) + cdef int minc = max(0, cx-xradius) + cdef int maxc = math.ceil(cx+xradius) # make sure output coordinates do not exceed image size if shape is not None: @@ -159,9 +159,9 @@ def ellipse(double cy, double cx, double b, double a, shape=None): cdef list rr = list() cdef list cc = list() - for r in range(minr, maxr + 1): - for c in range(minc, maxc + 1): - if sqrt(((r - cy) / b)**2 + ((c - cx) / a)**2) < 1: + for r in range(minr, maxr+1): + for c in range(minc, maxc+1): + if sqrt(((r - cy)/yradius)**2 + ((c - cx)/xradius)**2) < 1: rr.append(r) cc.append(c) From 5711cea92d65a90ddcdfdd0dfc5001dcf842122c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Tue, 15 Jan 2013 14:35:17 +0100 Subject: [PATCH 09/12] fix docstring --- skimage/draw/_draw.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index c0fd798b..551673f0 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -133,7 +133,7 @@ def ellipse(double cy, double cx, double yradius, double xradius, shape=None): ---------- cy, cx : double Centre coordinate of ellipse. - yradius, xradius: double + yradius, xradius : double Minor and major semi-axes. ``(x/xradius)**2 + (y/yradius)**2 = 1``. Returns From 62b359a39b963e4edbd882ded5b688818b500812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Tue, 15 Jan 2013 14:57:20 +0100 Subject: [PATCH 10/12] add test point position circle-ellipse --- skimage/draw/tests/test_draw.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py index e979c292..ef09747c 100644 --- a/skimage/draw/tests/test_draw.py +++ b/skimage/draw/tests/test_draw.py @@ -155,6 +155,7 @@ def test_circle_perimeter_bresenham(): rr, cc = circle_perimeter(7, 7, 0, method='bresenham') img[rr, cc] = 1 assert(np.sum(img) == 1) + assert(img[7][7] == 1) img = np.zeros((17, 15), 'uint8') rr, cc = circle_perimeter(7, 7, 7, method='bresenham') @@ -185,6 +186,7 @@ def test_circle_perimeter_andres(): rr, cc = circle_perimeter(7, 7, 0, method='andres') img[rr, cc] = 1 assert(np.sum(img) == 1) + assert(img[7][7] == 1) img = np.zeros((17, 15), 'uint8') rr, cc = circle_perimeter(7, 7, 7, method='andres') @@ -241,6 +243,7 @@ def test_ellipse_perimeter(): rr, cc = ellipse_perimeter(15, 7, 0, 0) img[rr, cc] = 1 assert(np.sum(img) == 1) + assert(img[15][7] == 1) img = np.zeros((30, 15), 'uint8') rr, cc = ellipse_perimeter(15, 7, 14, 6) From 4b27c87385ddcee9e0f3a13f5944a0ed2d28c87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 16 Jan 2013 17:09:04 +0100 Subject: [PATCH 11/12] Fix PEP8 issues --- skimage/draw/_draw.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 551673f0..29771b28 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -143,10 +143,10 @@ def ellipse(double cy, double cx, double yradius, double xradius, shape=None): May be used to directly index into an array, e.g. ``img[rr, cc] = 1``. """ - cdef int minr = max(0, cy-yradius) - cdef int maxr = math.ceil(cy+yradius) - cdef int minc = max(0, cx-xradius) - cdef int maxc = math.ceil(cx+xradius) + cdef int minr = max(0, cy - yradius) + cdef int maxr = math.ceil(cy + yradius) + cdef int minc = max(0, cx - xradius) + cdef int maxc = math.ceil(cx + xradius) # make sure output coordinates do not exceed image size if shape is not None: @@ -161,7 +161,7 @@ def ellipse(double cy, double cx, double yradius, double xradius, shape=None): for r in range(minr, maxr+1): for c in range(minc, maxc+1): - if sqrt(((r - cy)/yradius)**2 + ((c - cx)/xradius)**2) < 1: + if sqrt(((r - cy) / yradius)**2 + ((c - cx) / xradius)**2) < 1: rr.append(r) cc.append(c) From 0f36316dd44e4cc1ef66e808bd0888a8e677ab5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 16 Jan 2013 17:18:12 +0100 Subject: [PATCH 12/12] Add empty lines between functions --- skimage/draw/_draw.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 29771b28..033de8f0 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -265,6 +265,7 @@ def circle_perimeter(int cy, int cx, int radius, method='bresenham'): return np.array(rr) + cy, np.array(cc) + cx + def ellipse_perimeter(int cy, int cx, int yradius, int xradius): """Generate ellipse perimeter coordinates. @@ -350,6 +351,7 @@ def ellipse_perimeter(int cy, int cx, int yradius, int xradius): return np.array(py) + cy, np.array(px) + cx + def set_color(img, coords, color): """Set pixel color in the image at the given coordinates. Coordinates that exceed the shape of the image will be ignored.