1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
import numpy as np
import PIL.Image
import PIL.ImageDraw
from .. import utils
def line(src, yx, fill, width=1):
dst = utils.numpy_to_pillow(src)
line_(img=dst, yx=yx, fill=fill, width=width)
return utils.pillow_to_numpy(dst)
def line_(img, yx, fill, width=1):
assert isinstance(img, PIL.Image.Image)
yx = np.asarray(yx)
assert yx.ndim == 2
assert yx.shape[1] == 2
fill = tuple(fill)
draw = PIL.ImageDraw.Draw(img)
xy = yx[:, ::-1]
xy = xy.flatten().tolist()
draw.line(xy, fill=fill, width=width)
|