Programmers’ solution to Expert Coloring

Programmers’ solution to Expert Coloring

Enjoy this post by Josh Erickson, who recently hacked his way into coloring a near impossible looking coloring page of mine:

“This past week, Mike of Subconscious Sketches, shared an “adult coloring page” on Facebook asking…no…daring anyone to try coloring it. The image was a 2550×3300 densely packed jumble of shapes that I imagine would be difficult for an adult to stay in the lines like a child in their coloring books.

My children, probably like most, love coloring and drawing with crayons but often just clutch the crayon and make random shapes and squiggly lines all over the page. I figured it would be funny if I did something similar but with more adult flare. Instead on printing out the page and taking crayon to paper, I would use my laptop. And instead of Photoshop or Gimp, use scripting to draw the scribbles.

Take 1: Colored TV Snow

At first I thought I’d just generate random numbers as the script ran. That would mean whenever the script ran, it would be a unique image and no sort of rebuilding or fine tuning could be done. To keep the “random” but have predictability, I opted for a pre-generated list of numbers. To start me off, I decided to go for 4 bytes (Int32) for each pixel of the original image, red, green, blue, and alpha channel. With this ~33MB file in hand, I started off just setting each pixel to the the RGBa. This looked horrible (like colored TV snow) and I essentially had just made a bitmap image file with some unnecessary steps in between. Not very creative but at least I knew things were working.


Adding lines and ellipses with their inputs generated by re-purposing and massaging the same RGBa numbers, it started looking better. During these iterations I decided it would be more fitting to have the colors derived from the raw binary data of the original jpg instead of random data. This way, even though Mike didn’t color the image originally, his own work would provide the basis for the colors and shapes chosen.

But with bed time approaching, it was time to finish. So the generated image was imported into Gimp (an open source Photoshop or PaintshopPro like program). A slight gaussian blur applied and then took the original was added it as a layer with the “Grain extract” mode.

Though it still looked a bit like colored TV snow. Though it still looked a bit like colored TV snow.

Take 2: Lisa Frank Swag

The next day I found my mind still on the challenge. This time though, I would do flood filling instead of shapes. However this proved more difficult at first because while the image looked black and white, the details were shades of gray. Attempting to flood fill the original resulted in a snowy mess so a cleanup was in order. To do this, I iterated over the image and converted anything with a red value over 40 to white (#FFFFFF) and anything else to black (#000000).

With this new slate in place, flood filling produced a much better result. Instead of snow, each of shape had it’s own color. Plus with some added testing for already filled spaces, the process took far less time to complete (seconds vs. minutes). The end result reminds me a lot of stained glass, Cra-Z-Art, or Lisa Frank swag.

I sure hope we don't get sued by Lisa over this. I sure hope we don’t get sued by Lisa over this.

What’s next?

What could be done differently next time? I’d definitely want to do more in scripting instead of relying on Gimp for some of the steps. I might also want to explore grouping areas together somehow. There might also be some fun in passing stuff through image recognition software like Google’s deep dream and using that data group shapes together for coloring or find “hidden” items.Thanks for reading. I hope you all had as much fun reading this as I had over the weekend with Mike’s adult coloring page.

PS. For those of you who’d like to take a look at the scripts I wrote to do this, you can check them out over on Github. They were done using PHP7 on Ubuntu 16, but I’m sure they could be massaged to run on Windows or OS X.

You can find more from Josh at his blog snoj.us and also check out his wife Katrina’s charming & inspirational Etsy Shop KitericPrints.

Send a raven for the Subconscious Scrolls

Comments

comments