Welcome

Generative art, data visualisation etc.

Sunday, June 10, 2012

Angels of Monte Carlo

I love the work of this chap who layers packing tape onto glass to create images like this.


I thought I would have a go at writing a program to do the same. Initially tried to have a genetic algorithm placing virtual pieces of tape to try and match a target image. Results weren't great. Think I would need a massive population and an awful lot of computation to get anything half decent. I'll probably try again some time though.

So I tried a Monte Carlo approach. My code starts with a blank image and draws a random line (either black or white, random start and end, random thickness). If the line makes the image more like a given target image, it is retained other wise it is discarded and another random line is drawn (and so on).

I gave it a target image of the Angel of the North because I thought the clearly defined shape should be quite easy to find. Here's what it looked like after running for half an hour or so...

and then after around two hours...


More detail in the second image but perhaps not as pleasingly 'arty'. Quite pleased with how they're looking though. Am going to try a few different target images and see what I get.

3 comments:

  1. I guess it's more of a hill climber than a monte carlo thing - oh well.

    ReplyDelete
  2. Very nice approach! However how did you measure "makes the image more like a given target image"?
    I guess it was something like:
    pixel_distance_vs_original = original_pixel - new_pixel;

    when calculating this "distances" for all the image you would get
    a total number, which can be used as a "measure"?

    ReplyDelete
  3. This is great! I wonder whether you could use something like a CNN to evaluate the perceptual distance decrease as your cost function. You could select from a few different random brushstrokes each iteration to get the gist of the target image in fewer strokes. By laying down the perceptually importany strokes quickly you may be able to replicate more detailed images whilst retaining that nice course-grained artiness in the first example.

    ReplyDelete