Victor Image Processing Library How-to Tips

Improve Scanned Text by Scale to Gray Image Processing

Scanned text often looks jagged and rough. An easy way to improve the text for display is a technique called "Scale to Gray."
Scanned text
Scanned image of text
Text after Scale to Gray
Text processed by Scale to Gray technique

In this example the original image containing the text is converted from bilevel to grayscale and the text is gently blurred around the edges. This Scale to Gray technique is also called "antialiasing."

The steps in Scale to Gray are:

Scale to gray - the Source Code

Requires Victor Image Processing Library v 5.3 or higher.
int scaletogray(imgdes *srcimg, imgdes *desimg)
    imgdes myimage8;
    static char kernel[] = {1, 2, 1, 2, 8, 2, 1, 2, 1};
    int divisor = 20;
    int rcode, width, length;
            // If the source is not bilevel, there's no reason to proceed.
    if(srcimg->bmh->biBitCount != 1)
            // Determine size of source image
    width = srcimg->bmh->biWidth;
    length = srcimg->bmh->biHeight;
            // Allocate space for grayscale image
    rcode = allocimage(&myimage8, width, length, 8);
    if(rcode == NO_ERROR) {
       if(width * length > 1800 * 1800) {  // Set an arbitrary limit for "large image"
            // Convert from bilevel to grayscale and perform 1-D antialias
          rcode = convert1bitto8bitsmooth(srcimg, &myimage8);
       else {  // Smaller images can spend more time for a complete 2-D antialias 
            // Convert from bilevel to grayscale
          convert1bitto8bit(srcimg, &myimage8);
            // Gently blur the edges 
          rcode = matrixconvex(3, kernel, divisor, &myimage8, &myimage8);
       if(rcode == NO_ERROR) {
            // Replace the destination image with the new grayscale image
          copyimgdes(&myimage8, desimg);
Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code

Copyright © 1995 - 2000 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.