[home]

mkbitmap examples

Transform images into bitmaps with scaling and filtering.


Examples

The following are examples of the operation of mkbitmap. This is a simple program for converting greymaps and color images to bilevel bitmaps. For usage information, see the mkbitmap(1) man page. The following images illustrate the effect of highpass filtering and scaling.

The original color image

This image was taken from the web cartoon Loxie and Zoot by Stephen Crowley.

Thresholding without highpass filter

If we apply a simple thresholding method for converting greytones to black/white, we can never quite find the correct threshold. The background becomes black before the foreground is satisfactory. The following images have been thresholded at different levels.

Threshold 0.2 Threshold 0.3
mkbitmap -x -t 0.2 mkbitmap -x -t 0.3
Threshold 0.4 Threshold 0.5
mkbitmap -x -t 0.4 mkbitmap -x -t 0.5

Thresholding with highpass filter

Highpass filtering suppresses large-scale irregularities such as background variations, while preserving small-scale detail such as lines. Filtering depends on a parameter called the filter radius, which corresponds roughly to the size of features that are preserved. The filter radius can also be identified with line thickness. The following sequence of images illustrates the effect of the filter radius parameter.

Highpass filter radius 1 pixel Highpass filter radius 2 pixels
mkbitmap -x -f 1 mkbitmap -x -f 2
Highpass filter radius 4 pixels Highpass filter radius 8 pixels
mkbitmap -x -f 4 mkbitmap -x -f 8

Scaling before thresholding

A greymap contains more information per pixel than a bitmap. Normally, when thresholding, this extra detail is lost. However, one can recover some of this detail by scaling the image to a higher resolution (using interpolation to calculate intermediate pixels) before applying the thresholding step. The following illustration shows our image, scaled by a factor of 2. The first illustration shows the result of scaling after thresholding, and the second illustration shows the result of scaling before thresholding. Clearly, the second image retains much more detail than the first one.
First thresholded, then scaled
mkbitmap -f 2 -s 1 -t 0.48 | pnmscale 2
First scaled, then thresholded
mkbitmap -f 2 -s 2 -t 0.48

Passing the output of mkbitmap to Potrace

The following two images illustrate how the output of mkbitmap can be passed to Potrace. The first image has not been scaled before thresholding. The second image has been scaled before thresholding, Thus, in the second image, a higher resolution bitmap was passed to Potrace. It is clearly visible that the second image shows much more detail than the first one. This is particularly evident in the text section.
Not scaled before thresholding and tracing
mkbitmap -f 2 -s 1 -t 0.48 | potrace -t 5
Scaled by factor 2 before thresholding and tracing
mkbitmap -f 2 -s 2 -t 0.48 | potrace -t 5

Summary

If the image to be traced is available as a greymap (for instance, as a result of scanning), it is a good idea to use a program such as mkbitmap to apply an optional highpass filter, and to scale the image before converting it to a bitmap, rather than using a simple-minded thresholding method of the kind which is built into Potrace itself.


Back to Potrace home.


Peter Selinger / Department of Mathematics and Statistics / Dalhousie University
selinger@users.sourceforge.net / PGP key