« Fragment Program Snippets | Main | Random Numbers in Fragment Programs »

May 10, 2005

Quick and Dirty Vectorization

There aren't many fast techniques for vectorizing an image into polygons that approximate the original, or that take advantage of 3d hardware, so here's one I've used.


Take the original image, blur it to taste to remove noise and leave lots of smooth gradients.

Chose a function that will divide the image into seperate regions. The simplest one would be:

if (brightness<50%)
color = black;
else
color = white;

Split the image into grid squares of some fairly small size. For each corner of a square, work out the brightness value of the pixel underneath it.

Use this value as the horizontal texture coordinate for a 1 dimensional texture that encodes the function you chose. For the example function, this could be a texture 1 pixel high, and 100 pixels wide. The pixels from 0-49 would be black, the ones from 50-99 would be white.

If you then draw each square as two triangles, with the texture coordinates you calculated and with the 1D texture applied, you'll get an image that looks vectorized.



You have to chose a blur amount and grid resolution manually. You have two different ways to split a square into triangles, with a join running from top left to bottom right, or from top right to bottom left. Either one will cause zig-zagging for image edges that go at right angles to the chosen one. It seems like it should be possible to detect this with some clever coding.

This technique is not 'real' vectorization, but is useful for getting that kind of look. Though it's easiest with graphics hardware, the same approach is possible using a very simple software renderer.

Posted by petewarden at May 10, 2005 05:05 PM

Comments

Post a comment




Remember Me?