Move set_color() to draw module.

This commit is contained in:
Anders Boesen Lindbo Larsen
2012-12-27 20:42:01 +01:00
parent 74e6c38d6f
commit b770578aae
3 changed files with 35 additions and 18 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
from ._draw import line, polygon, ellipse, circle, circle_perimeter
from ._draw import line, polygon, ellipse, circle, circle_perimeter, set_color
bresenham = line
+27
View File
@@ -226,3 +226,30 @@ def circle_perimeter(int cy, int cx, int radius):
x += 1
return np.array(rr) + cy, np.array(cc) + cx
@cython.boundscheck(False)
@cython.wraparound(False)
def set_color(img, coords, color):
"""Set pixel color in the image at the given coordiantes. Coordinates that
exceeed 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