The main problem is that of stack overflow. I can suggest you to divide the total area into manageable parts by horizontal and vertical boundaries (no physical lines please), and then treat each of the segments separately. Hope you a success.
Dear Prof. Iping, basically we can use vector graphic algorithm for flood fill combine with fuzzy algorithm. As far as i knew there are four way stack based recursive algorithm easy to understand but a little bit harf implementing in java or phyton language. second are four way queue based recursive its better algorithm and the last will be using eight way recursive algorithm. This algorithm used in detection of spread flood.