Victor Image Processing Library How-to Tips

Create a 64-bit C# App with the Victor Library

The Victor Image Processing Library for 64-bit Windows has all the same functions and capabilities that the 32-bit version of the library has. In the .net world we use a viclib64 interface to simplify calls into the Victor Library dlls.

Begin by starting Visual Studio and creating a new C# desktop app. Then follow these steps

Updating a C# app from 32- to 64-bit

Existing 32-bit C# apps will need to be changed somewhat to accomodate the new 64-bit interface.

The Victor Library function calls are identical in the 32- and 64-bit versions of the library, but if you use VB or C# it is necessary to update the source code for the new 64-bit interface.

Converting 32-bit C# app to 64-bit


Comparator

Comparator is an application that demonstrates the Victor Library multiimage functions. With this app you can combine, compare, and analyze images.

Download the C# source code for the VIC64 vic_comparator sample. This contains the 64-bit versions of the .cs files from the 32-bit example program vic_comparator.



Victor Library 64-bit VB.NET Sample Application Source Code

This is a snippet from the imageform.cs module of the vic_comparator app. It demonstrates simple image processing using the Victor Library for 64-bit Windows. Requires Victor Image Processing Library for 64-bit Windows.
    
using viclib64;
. . . 
     private void mnu_removenoise_Click(object sender, System.EventArgs e)
      {
         menu_processInPlace("removenoise");
      }
      private void  menu_processInPlace(string process) 
      {
         int rcode = vicwin.NO_ERROR;
         vicwin.imgdes tmpimgdes;
    // vimage is the global image descriptor for the current Victor Library image in memory
         tmpimgdes = vimage;    // Copy vimage image descriptor 
         switch (process) // These functions won't process a 1-bit image, have to promote image to 8-bit
         {
            case "equalize":       // Equalize
            case "expandcontrast": // Expand contrast
            case "gammabrighten":  // Gammabrighten
            case "negative":       // Negative
            case "gentlysharpen":  // Gently sharpen
            case "posterize":      // Posterize 
            case "removenoise":    // Remove noise
            case "blur":           // Blur
            case "sharpen":        // Sharpen
            case "addagrid":       // Add a grid
            case "exchangelevels": // Exchange levels
            case "medianfilter":   // Median filter
            case "kodalith":       // Median filter
               if(vicwinex.getbpp(ref tmpimgdes) == 1)
                  promoteimage(ref tmpimgdes, 8);        // Defined below
               break;
         }
         switch (process) 
         {
            case "equalize":       // Equalize
               rcode = vicwin.histoequalize(ref tmpimgdes, ref tmpimgdes);
               break;
            case "expandcontrast": // Expand contrast
               rcode = vicwin.expandcontrast(min, max, ref tmpimgdes, ref tmpimgdes);
               break;
            case "gammabrighten":  // Gamma brighten
               rcode = vicwin.gammabrighten(gamma, ref tmpimgdes, ref tmpimgdes);
               break;
            case "negative":       // Negative
               rcode = vicwin.negative(ref tmpimgdes, ref tmpimgdes);
               break;
            case "flip":           // Flip
               rcode = vicwin.flipimage(ref tmpimgdes, ref tmpimgdes);
               break;
            case "gentlysharpen":  // Gently sharpen
               rcode = vicwin.sharpengentle(ref tmpimgdes, ref tmpimgdes);
               break;
            case "mirror":         // Mirror
               rcode = vicwin.mirrorimage(ref tmpimgdes, ref tmpimgdes);
               break;
            case "posterize":      // Posterize 
               int j;
               byte[] tab = new byte[256];
               for(j = 0; j < 256; j++) 
                  tab[j] = (byte)((j / (int)(256 / levels) * 255 / levels));
               rcode = vicwin.usetable(tab, tab, tab, ref tmpimgdes, ref tmpimgdes); // The arrays are sent over, not just the first elements
               break;
            case "removenoise":    // Remove noise
               rcode = vicwin.removenoise(ref tmpimgdes, ref tmpimgdes);
               break;
            case "blur":           // Blur
               rcode = vicwin.blur(ref tmpimgdes, ref tmpimgdes);
               break;
            case "sharpen":        // Sharpen
               rcode = vicwin.sharpen(ref tmpimgdes, ref tmpimgdes);
               break;
            case "addagrid":       // Add a grid
               vicwinex.addgrid(gridsize, ref tmpimgdes);
               rcode = 0;
               break;
            case "exchangelevels": // Exchange levels
               rcode = vicwin.exchangelevel(excmin, excmax, newval, ref tmpimgdes, ref tmpimgdes);
               break;
            case "medianfilter":   // Median filter
               rcode = vicwin.medianfilter(ksize, ref tmpimgdes, ref tmpimgdes);
               break;
            case "kodalith":       // Kodalith
               rcode = vicwin.kodalith(threshold, ref tmpimgdes, ref tmpimgdes);
               break;
         }
         if(rcode == vicwin.NO_ERROR) 
         {
    // Display it in pictureBox1
            vicimagetoPicturebox(ref tmpimgdes, pictureBox1); // Defined below
            pictureBox1.Refresh();
         }
         else
            error_handler(rcode, ""); // Not shown here for simplicity
      }
     unsafe public int promoteimage(ref vicwin.imgdes lsrcimg, int bpphi)
      {
         int rcode = vicwin.NO_ERROR;
         vicwin.imgdes timg;
         int bpp;
         int lswidth=0;
         int lslength=0;
         timg = new vicwin.imgdes();
         vicwinex.calc_image_dimensions(ref lsrcimg, ref lswidth, ref lslength); // Not shown here for simplicity
         bpp = vicwinex.getbpp(ref lsrcimg); // Not shown here for simplicity
         if(bpp == 1) 
         {
            rcode = vicwin.allocimage(ref timg, lswidth, lslength, 8);
            if(rcode == vicwin.NO_ERROR) 
            {
               rcode = vicwin.convert1bitto8bit(ref lsrcimg, ref timg);
               if(rcode == vicwin.NO_ERROR) 
               {
                  vicwin.freeimage(ref lsrcimg);
                  vicwin.copyimgdes(ref timg, ref lsrcimg);
               }
               else
                  vicwin.freeimage(ref timg);   
            }
         }
    
         if(bpp == 24)
            goto done;
         if(bpphi == 24) 
         {
            rcode = vicwin.allocimage(ref timg, lswidth, lslength, 24);
            if(rcode == vicwin.NO_ERROR) 
            {
               rcode = vicwin.convertpaltorgb(ref lsrcimg, ref timg);
               if(rcode == vicwin.NO_ERROR) 
               {
                  vicwin.freeimage(ref lsrcimg);
                  vicwin.copyimgdes(ref timg, ref lsrcimg);
               }
               else
                  vicwin.freeimage(ref timg);   
            }
         }
         done:
            return (rcode);
      }
 
    // Generic function to put a Victor image into a Picturebox
      unsafe public  void vicimagetoPicturebox(ref vicwin.imgdes srcimg, PictureBox pb)
      {
         int swidth = 0, slength = 0;
         if(srcimg.hBitmap != (IntPtr)0) 
         {
            vicwinex.calc_image_dimensions(ref srcimg, ref swidth, ref slength);
            pb.Image = Image.FromHbitmap(srcimg.hBitmap);
            pb.Width = swidth;
            pb.Height = slength;
         }
      }
Victor Image Processing Library

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




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