From 5ee137f9044fcbb53407206a653b3661b96162ed Mon Sep 17 00:00:00 2001 From: bennlich Date: Fri, 22 May 2015 17:28:55 -0700 Subject: [PATCH 1/3] Always maximally constrain bounding_shape when creating ellipse --- skimage/draw/draw.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index dbeb6ba0..5eb935f7 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -55,24 +55,26 @@ def ellipse(cy, cx, yradius, xradius, shape=None): center = np.array([cy, cx]) radiuses = np.array([yradius, xradius]) + + # The upper_left and lower_right corners of the + # smallest rectangle containing the ellipse. + upper_left = np.ceil(center - radiuses) + lower_right = np.floor(center + radiuses) + if shape is not None: - return _ellipse_in_shape(shape, center, radiuses) - else: - # rounding here is necessary to avoid rounding issues later - upper_left = np.floor(center - radiuses).astype(int) + # Constrain upper_left and lower_right by shape boundary. + upper_left = np.maximum(upper_left, np.array([0, 0])) + lower_right = np.minimum(lower_right, np.array(shape) - 1) - shifted_center = center - upper_left + shifted_center = center - upper_left + bounding_shape = lower_right - upper_left + 1 - # Shifted center is in interval [radiuses, radiuses + 1], so - # the ellipse must fit in [0, 2*radiuses + 1]. - bounding_shape = np.ceil(2 * radiuses + 1) - - rr, cc = _ellipse_in_shape(bounding_shape, shifted_center, radiuses) - rr.flags.writeable = True - cc.flags.writeable = True - rr += upper_left[0] - cc += upper_left[1] - return rr, cc + rr, cc = _ellipse_in_shape(bounding_shape, shifted_center, radiuses) + rr.flags.writeable = True + cc.flags.writeable = True + rr += upper_left[0] + cc += upper_left[1] + return rr, cc def circle(cy, cx, radius, shape=None): From 84831fce875365332a1a8fbda6642bfda297c076 Mon Sep 17 00:00:00 2001 From: bennlich Date: Wed, 27 May 2015 14:13:19 -0700 Subject: [PATCH 2/3] Fix bug when shape parameter is passed in from color images --- skimage/draw/draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index 5eb935f7..1c0576c8 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -64,7 +64,7 @@ def ellipse(cy, cx, yradius, xradius, shape=None): if shape is not None: # Constrain upper_left and lower_right by shape boundary. upper_left = np.maximum(upper_left, np.array([0, 0])) - lower_right = np.minimum(lower_right, np.array(shape) - 1) + lower_right = np.minimum(lower_right, np.array(shape[:2]) - 1) shifted_center = center - upper_left bounding_shape = lower_right - upper_left + 1 From 23670b4f02ef1a72591c1f399917de649f94ceb1 Mon Sep 17 00:00:00 2001 From: bennlich Date: Wed, 24 Jun 2015 08:46:57 -0700 Subject: [PATCH 3/3] Explicitly cast upper_left and lower_right to ints --- skimage/draw/draw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index 1c0576c8..9a816810 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -58,8 +58,8 @@ def ellipse(cy, cx, yradius, xradius, shape=None): # The upper_left and lower_right corners of the # smallest rectangle containing the ellipse. - upper_left = np.ceil(center - radiuses) - lower_right = np.floor(center + radiuses) + upper_left = np.ceil(center - radiuses).astype(int) + lower_right = np.floor(center + radiuses).astype(int) if shape is not None: # Constrain upper_left and lower_right by shape boundary.