Merge pull request #783 from ahojnnes/draw

Remove set_color duplicate and add test case
This commit is contained in:
Stefan van der Walt
2013-10-14 10:45:26 -07:00
2 changed files with 14 additions and 31 deletions
-28
View File
@@ -834,31 +834,3 @@ def bezier_curve(Py_ssize_t y0, Py_ssize_t x0,
px.extend(rr)
py.extend(cc)
return np.array(px, dtype=np.intp), np.array(py, dtype=np.intp)
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.
Parameters
----------
img : (M, N, D) ndarray
Image
coords : ((P,) ndarray, (P,) ndarray)
Coordinates of pixels to be colored.
color : (D,) ndarray
Color to be assigned to coordinates in the image.
Returns
-------
img : (M, N, D) ndarray
The updated image.
"""
rr, cc = coords
rr_inside = np.logical_and(rr >= 0, rr < img.shape[0])
cc_inside = np.logical_and(cc >= 0, cc < img.shape[1])
inside = np.logical_and(rr_inside, cc_inside)
img[rr[inside], cc[inside]] = color
+14 -3
View File
@@ -1,11 +1,22 @@
from numpy.testing import assert_array_equal, assert_equal
import numpy as np
from skimage.draw import (line, line_aa, polygon,
from skimage.draw import (set_color, line, line_aa, polygon,
circle, circle_perimeter, circle_perimeter_aa,
ellipse, ellipse_perimeter,
_bezier_segment, bezier_curve,
)
_bezier_segment, bezier_curve)
def test_set_color():
img = np.zeros((10, 10))
rr, cc = line(0, 0, 0, 30)
set_color(img, (rr, cc), 1)
img_ = np.zeros((10, 10))
img_[0, :] = 1
assert_array_equal(img, img_)
def test_line_horizontal():