Happy New Year

All the holidays after the solstice tend to blur together. We’re at the third day of Kwanzaa—Ujima, the day of collective work and responsibility—in African-American communities, but we’re also coming in on the end of a chaotic year.

Anyway…

Picture-to-Nonogram

This was the start of my new little project, a program to use ImageMagick in order to create a nonogram puzzle based on an image file.

The short version on the overall algorithm is (or will be) approximately as follows.

  • Call identify on the image to find out its size.
  • Find the largest common factor of the dimensions in order to reduce the ratio to the smallest equivalent image.
  • Resize the image to that target size.
  • Convert the image to black and white with something like convert smaller.jpg -negate -threshold 66% -negate bw.jpg
  • Dump the color of each pixel with convert bw.jpg txt:

From here—which is roughly where the repository currently stands—it’s just a matter of run-length encoding the black and white pixels in each direction and discarding one set of pixels.

That’s not perfect, of course. It’ll need some extra fussing in the second step to make sure that the image isn’t collapsed to a size that’s far too big or far too small. The code may also need to iterate to find the best threshold setting. But I’ll get to that, and—with any luck—eventually turn it into a game.

Next

I’ll continue on with Picture-to-Nonogram, of course, but don’t really have much of a plan beyond that. That might be enough.


Credits: The header image is untitled by an unidentified photographer, released under the terms of the Creative Commons CC0 1.0 Universal Public Domain Dedication.