This code creates artistic halftones using a very simple (quick-and-dirty) algorithm. The algorithm: Input: a motif image M (a gray-scale image) Input: an ordered dither matrix D (Bayer, void-and-cluster, etc) Output: an ordered dither matrix Q 1. Let S be the set of all pixels in M. 2. Count the number n of gray levels in M (example: if M is a black-and white image like a line drawing or some text, then there are two gray levels, black and white). 3. Define the n subsets Si (i from 1 to n): Si is the set of all points in S having the i-th gray level. 4. Define n lists Li (i from 1 to n): Li is all the thresholds in D, at the pixels in subset Si. 5. For each i, sort the pixels in Li in order of increasing threshold value. 6. Define L by concatenating all the sorted lists Li. 7. Define Q from L: each pixel gets threshold i/|Q|, where i is the index in the list L of the pixel.