Repository: scikit-image/scikit-image

Issue:
Draw circle does not obey shape argument - v0.93
In previous version worked fine, but I just installed new version 0.93 and draw.circle is not working properly. When I apply the circle for image 1024x1024 with following arguments:
rr,cc=circle(-5.2796287128712879E+02, 1.5003712871287132E+02, 9.8910961199417170E+02, (1024,1024))

I get negative values in rr and cc arrays. Which obviously leads to errors when applied to:
img[rr,cc]=0



Discussion:
Have you tried to use the skimage.draw.set_color function to set the color?

Am 26.11.2013 um 08:50 schrieb JuraK notifications@github.com:

> In previous version worked fine, but I just installed new version 0.93 and draw.circle is not working properly. When I apply the circle for image 1024x1024 with following arguments:
> rr,cc=circle(-5.2796287128712879E+02, 1.5003712871287132E+02, 9.8910961199417170E+02, (1024,1024))
> 
> I get negative values in rr and cc arrays. Which obviously leads to errors when applied to:
> img[rr,cc]=0
> 
> —
> Reply to this email directly or view it on GitHub.

Thanks, this workaround works nice.

By the way - I'm getting exception - might it be related to this problem as well?
Exception TypeError: TypeError("'NoneType' object is not callable",) in <bound method UmfpackContext.new_del of <scipy.sparse.linalg.dsolve.umfpack.umfpack.UmfpackContext object at 0x20a3110>> ignored

You must elaborate a bit more… I cannot figure out what’s causing this exception from your short description…

Am 26.11.2013 um 09:23 schrieb JuraK notifications@github.com:

> Thanks, this workaround works nice.
> 
> By the way - I'm getting exception - might it be related to this problem as well?
> Exception TypeError: TypeError("'NoneType' object is not callable",) in > ignored
> 
> —
> Reply to this email directly or view it on GitHub.

The error is from UMFPack in SciPy, because of some magic we do when it is
not found--I've noticed it as well.

Summary of what needs to be done here: prevent `skimage.draw.ellipse` from returning row, column coordinates outside the image.

@stefanv The bug is stupid. I submit a PR in few minutes.


Resolving patch:
diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py
--- a/skimage/draw/draw.py
+++ b/skimage/draw/draw.py
@@ -60,7 +60,7 @@ def ellipse(cy, cx, yradius, xradius, shape=None):
     cc += cx - xradius
 
     if shape is not None:
-        _coords_inside_image(rr, cc, shape)
+        return _coords_inside_image(rr, cc, shape)
 
     return rr, cc
 


Test patch:
diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py
--- a/skimage/draw/tests/test_draw.py
+++ b/skimage/draw/tests/test_draw.py
@@ -325,6 +325,33 @@ def test_ellipse():
     assert_array_equal(img, img_)
 
 
+def test_ellipse_with_shape():
+    img = np.zeros((15, 15), 'uint8')
+
+    rr, cc = ellipse(7, 7, 3, 10, shape=img.shape)
+    img[rr, cc] = 1
+
+    img_ = np.array(
+      [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
+    )
+
+    assert_array_equal(img, img_)
+
+
 def test_ellipse_perimeter_dot_zeroangle():
     # dot, angle == 0
     img = np.zeros((30, 15), 'uint8')