To be honest there is just so much I could be blogging about in this narrow specialized space that my cup overfloweth, but also it has been an impediment, not knowing where to start. There’s so much background and new new learning (for me anyway) that it’s been daunting.
Herewith the start of my attempts to further document what I am up to.
One task I’ve taken on is prototyping a “post election audit” system (more on this soon.) Basically at the heart of that beast is a bit of code to analyze an image of a ballot and figure out what the vote was.
For now my programming language of choice is Ruby, although image processing with Ruby may still turn out to be impractical. I’ve been studying up on the task, reading books (see Practical Algorithms for Image Analysis, for example) and studying techniques and image processing code libraries that seem appropriate.
Two of the biggies I have come across are RMagick/ImageMagick and OpenCV. Both have a lot of history and dynamic communities. I don’t know yet which is the best one to use. The investigation continues.
But one idea I have started to implement which is quite fruitful on many levels is a “Domain Specific Language” for Image Analysis. There is a lot of literature on creating DSLs, and in particular DSLs hosted on Ruby. They are easy to do and in this particular domain, add a lot to my productivity and ability to frame and comprehend what the heck I am doing.
I won’t go into hairy technical detail here but I would be glad to share my approach and my code with anyone who asks. Here’s what one of my earliest test programs look like as written in this home-brew DSL:
open_image :one, "432Leon200dpibw431.tif"
open_image :target, "target2.tif"
open_image :t3, "target3.tif"
find_similar_regions :one, :target, :points
relativize_points :points, :outpoints
write_image :one, "432Deskewed.tif"
find_first_nonwhite_row :one, :nonwhite_row
See how it talks in very high level primitives about image processing? Also see how the choice between OpenCV and RMagick is totally hidden? I can change my mind later and not break anything Is it kind of readable?
I will build out this DSL just in the direction and to the extent needed for my particular task, Ballot analysis. But you can see that it can go pretty far. How’d’you like it?