I'm trying to come up with an automated way to fill in shapes with randomized colors. The goal is to take a bitmap line drawing and fill in all the white areas with color, so that I can later go in with a paint program and easily drop the appropriate colors in with the paint bucket.
Using Python and PIL I was able to easily create a script that does this (here it is if you're curious: https://pastebin.com/Cc8AcNZv ), but I'd really like to come up with one that can handle gaps in the linework. This is where it got complicated.
Using the -morphology Close function in imageMagick, I was able to address a lot of the gaps, but unfortunately it also leaves a lot of white space around my linework once the result has been colorized:

After looking around more I found the Sparse-Color operator, which seems like it would be a good choice for this project, but I can't seem to figure out how best to implement it. Essentially what I want is for the edges of the "color islands" to spread out until they meet, in a voronoi-type fashion. I tried to follow the directions here but I couldn't get it to work, and as my source images are fairly large I suspect that it would probably be an inefficient way of doing this, anyway.
IM version: 6.8.9-9
Any suggestions would be appreciated. If you think I'm approaching this in the wrong way and you see a more direct way of solving the problem, that's great too! Thanks!