Scanned image of text |
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:
1 2 1
2 8 2
1 2 1
and divisor equal to 20 (that's the sum of the kernel elements).
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)
return(BAD_BPP);
// 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
freeimage(desimg);
copyimgdes(&myimage8, desimg);
}
else
freeimage(&myimage8);
}
return(rcode);
}
Victor Image Processing Library homepage | Victor Product Summary | more source code