Victor Image Processing Library How-to Tips

Embossing

An image appears to be embossed when highlights and shadows replace light/dark boundries and low contrast areas are set to a gray background.
unembossed
Original
true emboss
True emboss
quick emboss
Quick emboss

Here are two methods for creating an embossed image. The true emboss calculates the first derivative of the image and combines it with a uniform grayscale. The quick emboss creates an emboss-like effect by combining the image with its negative at a slight offset.

True Emboss - the Source Code

Use the colortogray function to convert a color image to grayscale before calling this function. Requires Victor Image Processing Library v 4.1x or higher
int true_emboss(imgdes *srcimg, imgdes *resimg)
{
   imgdes image1;
   imgdes image2;
   imgdes tmpsrc;
   int cols, rows, rcode;
   static UCHAR kern1[10] = {-2,-2,0,-2,6,0,0,0,0,1};
   static UCHAR kern2[10] = {0,0,0,0,-6,2,0,2,2,1};
   cols = CALC_WIDTH(srcimg);
   rows = CALC_HEIGHT(srcimg);
   allocimage(&tmpsrc, cols, rows, 8); // Assumes 8-bit source image
   copyimage(srcimg, &tmpsrc);
   
   allocimage(&image1, cols, rows, 8);
   allocimage(&image2, cols, rows, 8);
   matrixconv(kern1, &tmpsrc, &image1);
   matrixconv(kern2, &tmpsrc, &image2);
   zeroimage(128, &tmpsrc);
   addimage(&tmpsrc, &image1, &tmpsrc);
   subimage(&tmpsrc, &image2, &tmpsrc);
   rcode = copyimage(&tmpsrc, resimg); // Assumes 8-bit result image 
   freeimage(&image2);
   freeimage(&image1);
   freeimage(&tmpsrc);
   return(rcode);
}
To increase the emboss effect increase the magnitude of the kernel elements.
Instead of
   -2  -2  0
   -2   6  0
    0   0  0
and its partner . . .
Try
   -4  -4  0
   -4  12  0
    0   0  0
and its partner. Be sure the kernel elements sum to zero.
 
To change the direction, change the relative positions of the kernel elements.
Instead of
   -2  -2  0
   -2   6  0
    0   0  0
and its partner . . .
Try
    0   0   0
    0   6  -2
    0  -2  -2
and its partner.




Quick Emboss - the Source Code

Requires Victor Image Processing Library v 4.1x or higher.
int quick_emboss(imgdes *srcimg, imgdes *resimg)// Assumes 8-bit grayscale source image
{
   imgdes image1;
   imgdes tmpsrc;
   int cols, rows, rcode;
   cols = CALC_WIDTH(srcimg);
   rows = CALC_HEIGHT(srcimg);
   allocimage(&tmpsrc, cols, rows, 8);
   copyimage(srcimg, &tmpsrc);
   
   allocimage(&image1, cols, rows, 8);
   negative(&tmpsrc, &image1);
   image1.stx = 1;
   image1.sty = 1;
   wtaverage(50, &tmpsrc, &image1, &tmpsrc);
   rcode = copyimage(&tmpsrc, resimg);
   freeimage(&image1);
   freeimage(&tmpsrc);
   return(rcode);
}

quick emboss 2 The above code quickly generated the simulated emboss shown at the top of the page. It is possible to increase the emboss effect by increasing the contrast of the result. Here's the quick emboss image after adding the following line after the call to wtaverage:
   expandcontrast(100, 155, &tmpsrc, &tmpsrc); 

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


Victor Image Processing Library homepage | Victor Sample Code