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

test_conn_comp.cpp

00001 #include <iostream.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include "tip.h"
00006 
00007 //   Example program for the "ConnectedComponents" function.
00008 //
00009 //   Usage:
00010 //      test_conn_comp <input_image>
00011 //
00012 
00013 int main(int argc, char *argv[])
00014 {
00015   // Test for the correct number of arguments in the command line.
00016   if (argc != 2) {
00017     cout << "Usage: " << argv[0] << " <input_image>" << endl;
00018     exit(0);
00019   }
00020 
00021   char l;
00022 
00023   // Read an image from the file specified by "argv[1]" and display it.
00024   IntImage im1; 
00025   im1.readImage(argv[1]);
00026   im1.setName("IntImage");
00027   cout << "Min: " << im1.min() << "\t" << "Max: " << im1.max() << endl;
00028   im1.showImage();
00029   cin >> l;
00030 
00031   // Compute the connected components in place using 4-connectivity.
00032   int nr_comp = ConnectedComponents(im1, FOUR_CONN);
00033   cout << "Image: \"" << argv[1] << "\" has " << nr_comp << " connected components" << endl; 
00034   im1.showImage();
00035   cin >> l;
00036 
00037   // Read the same image, but now as ByteImage.
00038   ByteImage im2;
00039   IntImage output_image;
00040   im2.readImage(argv[1]);
00041   im2.setName("ByteImage");
00042 
00043   // Compute the connected components using 8-connectivity and store the result in "output_image".
00044   nr_comp = ConnectedComponents(im2, EIGHT_CONN, output_image);
00045   cout << "Image: \"" << argv[1] << "\" has " << nr_comp << " connected components" << endl; 
00046   output_image.showImage();
00047 
00048   cin >> l;
00049   im1.closeWindow();
00050   output_image.closeWindow();
00051   return(1);
00052 }