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

test_morphop.cpp

/* Copyright (c) 2001 A. Jalba */

#include <stdio.h>
#include <tip.h>

//   Example program for the morphological operations.
//
//   Usage:
//      test_morphop <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;
  IntImage im1, im2, im3, im4;

  // Read an image from the file specified by "argv[1]" and display it.
  im1.readImage(argv[1]);
  im1.showImage();

  ByteKernel k(""), k1("");

  // Morphological operations on binary images.

  // Perform 11 3x3 erosions of the image using 4 connectivity.
  Erosion3x3(im1, 11, FOUR, im2);
  im2.showImage();
  cin >> l;  

  // Perform 11 3x3 dilations of the image using 4 connectivity.
  Dilation3x3(im2, 11, FOUR, im2);
  im2.showImage();
  cin >> l;  

  // Perform 11 3x3 openings of the image using 8 connectivity.
  Opening3x3(im1, 11, EIGHT, im2);
  im2.showImage();
  cin >> l;  

  // Perform 11 3x3 closings of the image using 8 connectivity.
  Closing3x3(im1, 11, EIGHT, im2);
  im2.showImage();

  // Morphological operations on gray level images.

  k.readKernel("cross5x5.pgm");

  // Perform a flat erosion.
  FlatErosion(im1, k, im3);
  im3.showImage();
  
  // Search for the structuring element given by the kernel k in the image im1.
  TemplateMatch(im1, k, im4);
  im4.showImage();
  cin >> l;  

  k1.readKernel("a2.pgm");

  // Perform a hit or miss transform.
  HitOrMiss(im1, k, k1, im4);
  im4.showImage();

  cin >> l;  
  im1.closeWindow();
  im2.closeWindow();
  im3.closeWindow();
  im4.closeWindow();
  return 1;
}