| 10 | |
| 11 | @jit |
| 12 | def floodfill(img, x, y): |
| 13 | buf = np.zeros((131072,2), dtype=np.uint16) |
| 14 | color = img[int(y), int(x)] |
| 15 | img[int(y), int(x)] = 0 |
| 16 | buf[0,0] = x; buf[0,1] = y; |
| 17 | cur = 0; s = 1; |
| 18 | |
| 19 | while True: |
| 20 | xy = buf[cur] |
| 21 | for dx in (-1,0,1): |
| 22 | for dy in (-1,0,1): |
| 23 | cx = xy[0]+dx; cy = xy[1]+dy |
| 24 | if cx<0 or cx>=img.shape[1]:continue |
| 25 | if cy<0 or cy>=img.shape[0]:continue |
| 26 | if img[cy, cx]!=color:continue |
| 27 | img[cy, cx] = 0 |
| 28 | buf[s,0] = cx; buf[s,1] = cy |
| 29 | s+=1 |
| 30 | if s==len(buf): |
| 31 | buf[:len(buf)-cur] = buf[cur:] |
| 32 | s -= cur; cur=0 |
| 33 | cur += 1 |
| 34 | if cur==s:break |
| 35 | |
| 36 | def cut(img, lines): |
| 37 | if len(lines)<2:return |