Victor Image Processing Library How-to Tips

Graphic Pen Drawing from an Image

A graphic pen drawing is usually characterized by outlines of the subject and a series of parallel pen strokes that create shading.

To simulate a graphic pen drawing from a photographic image we create an ordered dither matrix of the same dimensions as the image, fill the matrix with diagonal lines, and apply the dither.

     
Original image   Graphic pen version


The steps used to create the graphic pen drawing are



Graphic pen drawing without the sharpen.

The creategraphicpenscreen function below creates the screen and the graphicpendrawing function prepares the source image and applies the screen.

To save the image, call one of the Victor savefile functions in the Victor Library.


C# Source Code | C# and XAML Source Code for a Windows Store app adding a color tint


Graphic Pen Drawing of an Image - the C# Source Code

Requires Victor Image Processing Library for 32-bit Windows v 6.0 or higher, eval or commercial release.
   public static int graphicpendrawing(ref vicwin.imgdes src, ref vicwin.imgdes result)
  {
      vicwin.imgdes tempimg1, tempimg2, tempimg3;
      int rcode;
      int redavg=0, grnavg=0, bluavg=0;
      int j;
      int swidth = 0, slength = 0;
      tempimg1 = new vicwin.imgdes();
      tempimg2 = new vicwin.imgdes();
      swidth = src.endx - src.stx + 1;
      slength = src.endy - src.sty + 1;
      rcode = vicwin.allocimage(ref tempimg1, swidth, slength, 8); // Allocate new 8-bit image to be src
      rcode = vicwin.allocimage(ref tempimg2, swidth, slength, 8); // Allocate new 8-bit image to be opr
      if (rcode == vicwin.NO_ERROR)
      {
          rcode = vicwin.colortogray(ref src, ref tempimg1);
          vicwin.calcavglevel(ref tempimg1, ref redavg, ref grnavg, ref bluavg);
          for (j = 0; j < 3; j++)
          {
              if (redavg < 150)
                  rcode = vicwin.gammabrighten(.8, ref tempimg1, ref tempimg1);
              vicwin.calcavglevel(ref tempimg1, ref redavg, ref grnavg, ref bluavg);
          }
          rcode = vicwin.sharpen(ref tempimg1, ref tempimg1);  // For more pen strokes and less detail, remove the sharpen
          if (rcode == vicwin.NO_ERROR)
          {
              rcode = creategraphicpenscreen(ref tempimg1, ref tempimg2); // Create the graphic screen
              rcode = vicwin.screen(ref tempimg1, ref tempimg2, ref tempimg2); // Apply the graphic screen
              if (rcode == vicwin.NO_ERROR)
              {    // Success, replace result with the new image
                  vicwin.freeimage(ref result);
                  vicwin.copyimgdes(ref tempimg2, ref result);
              }
              else
                  vicwin.freeimage(ref tempimg2);  // Failure, release the temp image, no harm done
          }
          vicwin.freeimage(ref tempimg1);  // Release the other temp image
      }
      return (rcode);
  }
   public static int creategraphicpenscreen(ref vicwin.imgdes src, ref vicwin.imgdes result)
  {
      vicwin.imgdes tempimg;
      int rcode;
      int swidth = 0, slength = 0;
      byte[] matrixkernel = new byte[81]{
   1,0,0,0,0,0,0,0,0,
   0,1,0,0,0,0,0,0,0,
   0,0,1,0,0,0,0,0,0,
   0,0,0,1,0,0,0,0,0,
   0,0,0,0,1,0,0,0,0,
   0,0,0,0,0,1,0,0,0,
   0,0,0,0,0,0,1,0,0,
   0,0,0,0,0,0,0,1,0,
   0,0,0,0,0,0,0,0,1};
      tempimg = new vicwin.imgdes();
      swidth = src.endx - src.stx + 1;
      slength = src.endy - src.sty + 1;
      rcode = vicwin.allocimage(ref tempimg, swidth, slength, 8); // Allocate new 8-bit image
      if (rcode == vicwin.NO_ERROR)
      {
          rcode = vicwin.addnoise(255, ref tempimg, ref tempimg);
          rcode = vicwin.matrixconvex(9, ref matrixkernel[0], 9, ref tempimg, ref result);
          vicwin.freeimage(ref tempimg);
      }
      return (rcode);
  }

Victor Image Processing Library

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




Copyright  2006 - 2007 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.