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

test_morphop.cpp

00001 /* Copyright (c) 2001 A. Jalba */
00002 
00003 #include <stdio.h>
00004 #include <tip.h>
00005 
00006 //   Example program for the morphological operations.
00007 //
00008 //   Usage:
00009 //      test_morphop <input_image>
00010 //
00011 
00012 int main(int argc, char **argv)
00013 {
00014   // Test for the correct number of arguments in the command line.
00015   if (argc != 2) {
00016     cout << "Usage: " << argv[0] << " <input_image>" << endl;
00017     exit(0);
00018   } 
00019 
00020   char l;
00021   IntImage im1, im2, im3, im4;
00022 
00023   // Read an image from the file specified by "argv[1]" and display it.
00024   im1.readImage(argv[1]);
00025   im1.showImage();
00026 
00027   ByteKernel k(""), k1("");
00028 
00029   // Morphological operations on binary images.
00030 
00031   // Perform 11 3x3 erosions of the image using 4 connectivity.
00032   Erosion3x3(im1, 11, FOUR, im2);
00033   im2.showImage();
00034   cin >> l;  
00035 
00036   // Perform 11 3x3 dilations of the image using 4 connectivity.
00037   Dilation3x3(im2, 11, FOUR, im2);
00038   im2.showImage();
00039   cin >> l;  
00040 
00041   // Perform 11 3x3 openings of the image using 8 connectivity.
00042   Opening3x3(im1, 11, EIGHT, im2);
00043   im2.showImage();
00044   cin >> l;  
00045 
00046   // Perform 11 3x3 closings of the image using 8 connectivity.
00047   Closing3x3(im1, 11, EIGHT, im2);
00048   im2.showImage();
00049 
00050   // Morphological operations on gray level images.
00051 
00052   k.readKernel("cross5x5.pgm");
00053 
00054   // Perform a flat erosion.
00055   FlatErosion(im1, k, im3);
00056   im3.showImage();
00057   
00058   // Search for the structuring element given by the kernel k in the image im1.
00059   TemplateMatch(im1, k, im4);
00060   im4.showImage();
00061   cin >> l;  
00062 
00063   k1.readKernel("a2.pgm");
00064 
00065   // Perform a hit or miss transform.
00066   HitOrMiss(im1, k, k1, im4);
00067   im4.showImage();
00068 
00069   cin >> l;  
00070   im1.closeWindow();
00071   im2.closeWindow();
00072   im3.closeWindow();
00073   im4.closeWindow();
00074   return 1;
00075 }