Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages   Examples  

test_kernel.cpp

00001 /* Copyright (c) 2001 C. Grigorescu */
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <tip.h>
00006 
00007 //  Example program for the "Kernel" class.
00008 //
00009 //  Usage:
00010 //     test_kernel <sigma> <aspect> <orientation>
00011 //
00012 
00013 int main(int argc, char *argv[])
00014 {
00015   // Test for the correct number of arguments.
00016   if (argc != 4) {
00017     cout << "Usage: " << argv[0] << " <sigma> <aspect> <orientation> " << endl;
00018     exit(0);
00019   }
00020 
00021   // Create a kernel of size 32x32 with the name "gabor.pgm".
00022   FloatKernel k1(32,32, "gabor.pgm"); 
00023   float sigma = atof(argv[1]);
00024   float aspect = atof(argv[2]);
00025   float orientation = atof(argv[3]);
00026 
00027   // Generate a discrete Gabor function. 
00028   k1.makeGabor(sigma, aspect, 0.0, 10.0, 0.0);
00029   // Save current kernel as an image.
00030   k1.writeKernel();
00031   // Display the kernel as an image.
00032   k1.showKernel();
00033 
00034   // Generate an oriented Gaussian and display it.
00035   FloatKernel k2(128, 128, "Test Gauss"); 
00036   k2.makeGauss(sigma,aspect,orientation);
00037   k2.showKernel();
00038 
00039   // Generate a triangular pulse of size 32x32,
00040   // set the maximum amplitude to "sigma" and the support to 12 pixels.
00041   FloatKernel tri(32,32,"Triang. pulse");
00042   tri.makeRectangularPulse(sigma,12);
00043   tri.makeTriangularPulse(sigma,12);
00044 
00045   // Write the kernel coefficients to the file "test.coeff" in ASCII
00046   // format and with the comment "Triangular pulse: supp. = 12".
00047   tri.writeKernelCoeffs("test.coeff", "Triangular pulse: supp. = 12");
00048   tri.showKernel();
00049 
00050   // Read the kernel coefficients from the ASCII file and display it.
00051   FloatKernel re("Read");
00052   re.readKernelCoeffs("test.coeff");
00053   re.showKernel();
00054 
00055   char l;
00056   cin >> l;
00057   return(1);
00058 }