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