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

test_convol.cpp

00001 /* Copyright (c) 2001 C. Grigorescu */
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <tip.h>
00007 
00008 //   Example program for the "Convolution" function.
00009 //
00010 //   Usage:
00011 //      test_convol <input_image>
00012 //
00013 
00014 int main(int argc, char *argv[])
00015 {
00016   // Test for the correct number of arguments in the command line.
00017   if (argc != 2) {
00018     cout << "Usage: " << argv[0] << " <input_image>" << endl;
00019     exit(0);
00020   }
00021 
00022   FloatImage im1;
00023   im1.readImage(argv[1]);
00024   // Build a Gaussian kernel.
00025   FloatKernel k(im1.getWidth(),im1.getHeight(), "Gauss");
00026   k.makeGauss(3.0);
00027 
00028   // Perform a couple of convolutions and time them.
00029   // At each iteration the support of the Gaussian 
00030   // kernel is increased and the elapsed time printed out.
00031   Timer t;
00032   FloatImage res1(im1.getWidth(), im1.getHeight(), "Result");
00033   t.Start();
00034   float t1 = t.getTime();
00035   float t2;
00036   for (int i=0;i<40;i++) {
00037     k.makeGauss(4*i+0.75);
00038     Convolution(im1, k, res1);
00039     t2 = t.getTime();
00040     cout << t2 - t1 << endl;
00041   }
00042 
00043   // Show the result of the convolution and print the time needed 
00044   // to execute all of them.
00045   res1.showImage();
00046   t.Stop();
00047   t.Print();
00048   char c;
00049   cin >> c;
00050 }