A few weeks ago I posted about how to generate stippled images from regular input images. The code was garbage at the time so I've improved it and posted it for people to use or learn from. I only just remembered why I started this project. I found the StippleGen program from EvilMadScientist (EMS) but it was written in the processing development environment which I didn't have much luck with. I thought it'd be great to have a Python version out there as well and along the way added my own tweaks.

- Better initial distribution of seed points via a PseudoHilbert Curve
- Dithering to make points distribute more evenly
- A term that sets how much points are attracted to darker areas

Since I'm using trying to replicate the work of EMS It thought I'd use their test image of Grace Kelly. Their interface is beautiful and has a few bells and whistles that mine doesn't because I figured that I could do any pre-processing in something like GIMP.

Grace Kelly test image 943x834 |

For an initial test I'll use 2000 points with 5 rounds of dithering and 5 rounds without dithering. The simplest way to think of the adjustment parameter is like a contrast setting. In this case it is three. This will cube the value of each pixel and re-scale all the data to a 0-255 range.

number_of_points = 2000

dot_radius = 2.5

non_dithering_iterations = 5

dithering_iterations = 5

adjustment_parameter = 3

Processing the image with the above settings took about 90 seconds and produces the following SVG file.

Large Grace Kelly test image - 2000 points |

To demonstrate another quirk I noticed, take a look at the smaller image below. It contains the same number of dots as the image above. As a matter of fact, it's the exact same image just scaled down. However the dots start to look more like a face. So scale is important. If I were to do an 8 foot print of this for a wall in my house it wouldn't look that good because I couldn't get far enough away from it for the image to emerge. I would need to use more points.

Small Grace Kelly test image - 2000 points |

The image below uses 30000 points and takes about 25 minutes to generate. Writing this in something like C would help a lot.. Calculating the centroids of the Voronoi regions can be done in parallel to speed things up as well.

Grace Kelly test image - 30000 points |

You may notice that some of the darker regions look a little strange. This is caused by points aligning, as can be seen in the close up below. This can be solved by reducing the number of points, dropping the adjustment parameter so the area isn't so crowded, performing more dithering steps, or just enlarging the source image before processing.

Alignment artefacts |

Get the Code! |

The posts below are my train of thought while developing this script. It may help if you get a bit lost.

Voronoi Stippling

Entry and Exit Points for Space Filling Paths on a Grid

Hilbert Curve Generation With Lookup Tables

Converting Binary to Gray Code with XOR

Calculating Hilbert Curve Coordinates

Pseudo Hilbert Curve for Arbitrary Rectangular Regions - Part 1

Pseudo Hilbert Curve for Arbitrary Rectangular Regions - Part 2

Efficient Centroid Calculation for Discrete Areas

Generating Seed Points For Voronoi Stippling

Generating Stippled Images with Stiptacular

Here's a picture of a Atlantis during the STS-132 shuttle launch made of 30000 points. To infinity and beyond!

STS-132 |

## No comments:

## Post a Comment