Dataset generation

As we wrote in the first article, there are multiple databases available for working on the field of optical or handwritten character recognition. But, why not create your own database that meets your criteria. After implementing and exploring some of your ideas, you can always adapt the work to other sources.

Puffins Scotland

Puffins, Catterline, Scotland, 1995

Our goal here is to create a fairly large test dataset that is representative of our goal, which is the recognition of manuscript characters, without having to digitize and segment dozens of handwritten scripts.

There are some very nice fonts that can be used to simulate handwriting. We say simulate because they are much more regular than the original ones.

Allura script font

Figure 1 – Allura script font

Brush script font

Figure 2 – Brush script font

Buxton script font

Figure 3 – Buxton script font

 Edwardian script font

Figure 4 – Edwardian script font

Therefore, we have first to make a list of fonts we will use later to generate square images of 2304 pixels (48×48).

Below the python script called to list the fonts installed on our laptop.

Without installing each font you want to use to create your dataset, you could download the font files into a folder and use it as source to generate the images.

The next script called is an adaptation of a script from 8bitavenue, here. We added the part to generate images with a slight rotation.

The picture below shows samples of the images generated.

Images of chars

Figure 5 – Images of chars

The filename of each image is like this:


number + ‘_’ + font name + ‘_fs_’ + font size + ‘_bc_’ + background color + ‘_s_’ + skew + ‘.’ + char + ‘.png’

This format is quite handy when you build your training and test datasets, as the label is included at the end.

The usage of this script is:

And the code.

With this python script and a list of 37 fonts we generated 289,044 images in the twinkling of an eye.

A little work of reorganization of the code is desirable. Some lines of this script could be grouped in a small function.

On the other hand, it is also interesting to include the possibility of producing shifted images.

That’s all for this article, and in the next we will use the datasets to build, train, evaluate and make predictions with a convolutional neuron network.

Leave a Comment

Your email address will not be published. Required fields are marked *

÷ 4 = 1


Social Media