mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-13 12:40:24 +08:00
Move set_color() to draw module.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user