#include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "tip.h" // Example program for the "ConnectedComponents" function. // // Usage: // test_conn_comp <input_image> // int main(int argc, char *argv[]) { // Test for the correct number of arguments in the command line. if (argc != 2) { cout << "Usage: " << argv[0] << " <input_image>" << endl; exit(0); } char l; // Read an image from the file specified by "argv[1]" and display it. IntImage im1; im1.readImage(argv[1]); im1.setName("IntImage"); cout << "Min: " << im1.min() << "\t" << "Max: " << im1.max() << endl; im1.showImage(); cin >> l; // Compute the connected components in place using 4-connectivity. int nr_comp = ConnectedComponents(im1, FOUR_CONN); cout << "Image: \"" << argv[1] << "\" has " << nr_comp << " connected components" << endl; im1.showImage(); cin >> l; // Read the same image, but now as ByteImage. ByteImage im2; IntImage output_image; im2.readImage(argv[1]); im2.setName("ByteImage"); // Compute the connected components using 8-connectivity and store the result in "output_image". nr_comp = ConnectedComponents(im2, EIGHT_CONN, output_image); cout << "Image: \"" << argv[1] << "\" has " << nr_comp << " connected components" << endl; output_image.showImage(); cin >> l; im1.closeWindow(); output_image.closeWindow(); return(1); }