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

test_hist.cpp

00001 /* Copyright (c) 2001 S.E. Grigorescu */
00002 
00003 #include <iostream.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include <tip.h>
00008 
00009 //   Example program for the "Histogram" class.
00010 //
00011 //   Usage:
00012 //      test_hist <input_image> <nr_bins>
00013 //
00014 
00015 int main(int argc, char *argv[])
00016 {
00017   // Test for the correct number of arguments in the command line.
00018   if (argc != 3) {
00019     cout << "Usage: " << argv[0] << " <input_image> <nr_bins>" << endl;
00020     exit(0);
00021   } 
00022 
00023   // Read an image from the file specified by "argv[1]" and display it.
00024   Image< float > im1;
00025   im1.readImage(argv[1]);
00026   im1.showImage(); 
00027 
00028   // Compute the histogram of the input image and display the value of each bin.
00029   Histogram<float> h(im1, atoi(argv[2]));
00030   for (int i = 0; i < atoi(argv[2]); i++)
00031     cout << h.getHistogram()[i] << "\t";
00032   cout << endl;
00033 
00034   // If you have Plotutils package with the libplotter class library installed, 
00035   // you can visualize the histogram.
00036 #ifdef HAVE_LIBPLOTTER
00037   // Set some of the parameters for displaying the histogram.
00038   h.setDimensions(300, 500); 
00039   h.setFillIntensity(0.5);   
00040   h.setTitle("Original image");
00041   h.setTitleFontName("Courier-Bold");
00042   h.setTitleFontSize(0.07);
00043   h.setXLabel("a");
00044   h.setYLabel("b");
00045 
00046   // Display the histogram.
00047   h.showHistogram();
00048 
00049   // Write the histogram in eps format in the file "hist.eps".
00050   h.writeHistogram("PS", "hist.ps");
00051 #endif
00052 
00053   // Perform histogram equalization on the input image and store the result in another image.
00054   Image< float > im2;
00055   h.equalize(im2); 
00056 
00057   // Display the equalized image
00058   im2.showImage();
00059 
00060   // Compute the histogram of the equalized image and display the value of each bin.
00061   Histogram<float> h1(im2, atoi(argv[2]));
00062   for (int i = 0; i < atoi(argv[2]); i++)
00063     cout << h1.getHistogram()[i] << "\t";
00064   cout << endl;
00065 
00066 #ifdef HAVE_LIBPLOTTER
00067   h1.setTitle("Equalized image");
00068 
00069   // Display the histogram of the equalized image 
00070   // using the default parameters for the displaying method.
00071   h1.showHistogram();
00072 #endif
00073   char l;
00074   cin >> l; 
00075 
00076   // Close all display windows.
00077 #ifdef HAVE_LIBPLOTTER
00078   h.closeWindow();
00079   h1.closeWindow();
00080 #endif
00081   im1.closeWindow();
00082   im2.closeWindow();
00083   return(1);
00084 }