This here is a very naive approach to flood filling (using yout 0's and 1's as detailed in your question, but not reading an image, but with hardcoded data) circumnavigating the lack of TCO in python. Maybe it can give you some ideas:
#! /usr/bin/python3
d = '''111110001111101
110000011100000
111000010111001
111100100111111
111100000111111
111110111111111'''
def flood(grid, x, y):
toBeFilled = {(x, y)}
while toBeFilled:
tbf = set()
for x, y in toBeFilled:
try:
if grid[y][x]: continue #Pixel is already 1 -> no action
except IndexError: continue #Index is out of bounds
grid[y][x] = 1 #set Pixel to white
for xoff, yoff in ((1, -1), (1, 0), (1, 1), (0, -1), (0, 1), (-1, -1), (-1, 0), (-1, 1)):
tbf |= {(x + xoff, y + yoff)} #add adjacent pixels
toBeFilled = tbf
def pprint(grid):
print('-' * 20)
for line in grid: print(''.join(str(i) for i in line))
print('-' * 20)
d = [[int(c) for c in line] for line in d.split('\n')]
pprint(d)
flood(d, 4, 1)
pprint(d)
Output is:
--------------------
111110001111101
110000011100000
111000010111001
111100100111111
111100000111111
111110111111111
--------------------
--------------------
111111111111101
111111111100000
111111111111001
111111111111111
111111111111111
111111111111111
--------------------