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

Function floodfill

imagepy/core/draw/fill.py:5–19  ·  view source on GitHub ↗
(img, x, y, thr, con)

Source from the content-addressed store, hash-verified

3from scipy.ndimage import label, generate_binary_structure
4
5def floodfill(img, x, y, thr, con):
6 color = img[int(y), int(x)]
7 buf = np.subtract(img, color, dtype=np.int16)
8 msk = np.abs(buf)<=thr
9 if buf.ndim==3:
10 msk = np.min(msk, axis=2)
11 buf = buf[:,:,0]
12 strc = generate_binary_structure(2, con+1)
13 label(msk, strc, output = buf)
14 msk = buf == buf[int(y), int(x)]
15 #msk[[0,-1],:], msk[:,[0,-1]] = 0, 0
16
17 #imsave('test.png', msk.astype(np.uint8))
18
19 return msk

Callers 3

mouse_downMethod · 0.90
mouse_downMethod · 0.90
mouse_downMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected