MCPcopy Create free account
hub / github.com/Image-Py/imagepy / fill

Function fill

imagepy/core/draw/polygonfill.py:32–55  ·  view source on GitHub ↗
(plgs, img, color = 1, o=(0,0))

Source from the content-addressed store, hash-verified

30 return np.sort(rs)
31
32def fill(plgs, img, color = 1, o=(0,0)):
33 polys = [np.array(plg[:-1])-0.5 for plg in plgs]
34 shape = img.shape[:2]
35 ys = []
36 for i in range(len(polys)):
37 for j in range(len(polys[i])):
38 ys.append((i,j,polys[i][j][1]))
39 ys = np.array(ys)
40 st = np.argsort(ys[:,2])
41 buf, rst, cur = [], [], 0
42 bot,top = np.clip([int(ys[:,2].min()-1),int(ys[:,2].max()+2)], 0, shape[0])
43 idx = ys[:,:2].astype(np.int16)
44 for y in range(bot, top):
45 cur = scan(polys, idx, ys[:,2], st, y, cur, buf)
46
47 rs = roots(polys, buf, y)
48 for i in zip(rs[::2],rs[1::2]):
49 x1, x2 = int(np.ceil(i[0])), int(np.floor(i[1])+2)
50 x1, x2 = max(x1,0), min(x2, shape[1])
51 if x1 >= shape[1] or x2 < 0: continue
52 #rst.extend([(x,y) for x in range(max(x1,o[0]), min(x2, shape[2]))])
53 img[y,x1:x2] = color
54
55 return np.array(rst).T
56
57if __name__ == '__main__':
58 import matplotlib.pyplot as plt

Callers 1

polygonfill.pyFile · 0.70

Calls 4

scanFunction · 0.85
rootsFunction · 0.85
appendMethod · 0.80
clipMethod · 0.80

Tested by

no test coverage detected