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

test_dist_trans.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 "DistanceTransform" function.
00009 //
00010 //   Usage:
00011 //      test_dist_trans <input_image> <distance_type>
00012 //   where <distance_type> can be:
00013 //      0 - Euclidian distance using chamfer (5,7,11)
00014 //      1 - Euclidian distance using chamfer (3,4)
00015 //      2 - City-block distance 
00016 //      3 - Chessboard distance
00017 //
00018 
00019 int main(int argc, char *argv[])
00020 {
00021   // Test for the correct number of arguments in the command line
00022   if (argc != 3) {
00023     cout << endl << "Usage: " << argv[0] << " <input_image> <distance_type>" << endl << endl;
00024     cout << "    where <distance_type> can be: " << endl;
00025     cout << " 0 - Euclidian distance using chamfer (5,7,11)" << endl; 
00026     cout << " 1 - Euclidian distance using chamfer (3,4) " << endl; 
00027     cout << " 2 - City-block distance " << endl; 
00028     cout << " 3 - Chessboard distance " << endl; 
00029     exit(0);
00030   }
00031 
00032   // Read an image from the file specified by "argv[1]" and display it
00033   ByteImage im1;
00034   im1.readImage(argv[1]);
00035   im1.showImage();
00036 
00037   // Set the distance type
00038   int dist_type = atoi(argv[2]);
00039   IntImage im2;
00040 
00041   // Perform the distance transform and
00042   // display the output image
00043   switch(dist_type) {
00044   case 0: 
00045     DistanceTransform(im1, EUCLID, im2);
00046     break;
00047   case 1: 
00048     DistanceTransform(im1, EUCLID_1, im2);
00049     break;
00050   case 2:
00051     DistanceTransform(im1, CITY_BLOCK, im2);
00052     break;
00053   case 3:
00054     DistanceTransform(im1, CHESSBOARD, im2);
00055     break;
00056   default:;
00057   }
00058   im2.showImage();
00059   
00060   char l;
00061   cin >> l;
00062   
00063   im1.closeWindow();
00064   im2.closeWindow();
00065   return(1);
00066 }