(img, x, y, thr, con)
| 3 | from scipy.ndimage import label, generate_binary_structure |
| 4 | |
| 5 | def 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 |
no outgoing calls
no test coverage detected