Many of you know I have been obsessed with the idea of automated spacing and kerning for the past couple of years, and in particular trying to train a neural network to kern a font. A few weeks ago, armed with the tools and knowledge I'd acquired over the different experiments, I tried a new approach, and I think it's giving interesting results. But I would like other people to try playing with it and letting me know if it's worth developing.
Here is the concept behind this latest approach: the idea of kerning is to create a word image with good rhythm and texture. And we can tell when a word image has good rhythm and texture and when it doesn't. So: create a huge number of word images, of the form "OH<left glyph><right glyph>HO". For some of these images, use the correct spacing from the font and label the image as "well kerned". This is image 219 from my corpus, which is labelled well kerned:
(I am only using a restricted set of letter pairs that I think have a good chance of being correctly kerned. Some of them still won't be perfect even then, but I'm hoping that over several hundred thousand word images, it'll average out.) For other images, alter the pair's spacing by a random amount, while keeping the "OH<left>" and "<right>HO" distances the same, and label the image as either "too loose" or "too tight". This is image 223, which is artificially made "too loose".
Next, feed these word images (and their labels) into a neural network until it can discriminate between pairs which are too loose, too tight or well kerned. I am also feeding the amount of perturbation into the network as well, so it can tell me how much it thinks the image has been perturbed (and therefore how much perturbation the other way will be needed to fix it).
Once the network has been trained, you have a program which can look at a word image and tell you if it thinks it needs kerning and if so by how much. Here's a sample session with that program:
Obviously the next step, if we trust this thing, is to have it automatically make all the adjustments to the font that it finds necessary, rather than make the user go back to their font editor and do it by hand.
To me, that looks like it's making an improvement, but heck, what do I know; the reason I want automated kerning is because I'm really bad at seeing this stuff. What I would like is for people to try out the system on their fonts and let me know if it's helpful or if it's spewing out madness.
I've tried to make it easy: you will need Python 3, and then to clone or download the repository at https://github.com/simoncozens/atokern
and follow the instructions in the README. Getting all the libraries installed may take a while but you only need to do that once.
I've identified a small bug in the rendering of the word images where there's a bit of "ink bleed", meaning that the network will think some images are tighter than they really are; so it might err on the side of suggesting things are too loose. I've fixed that but it will take a while to train a new model. It's currently trained on Latin a-zA-Z, but if it genuinely has learnt what makes a "good" word image and what makes a "bad" one, it should work for other glyphs which follow the Latin model.
Any feedback would be welcome!