/* Copyright (c) 2001 S.E. Grigorescu */ #include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <tip.h> // Example program for the "Histogram" class. // // Usage: // test_hist <input_image> <nr_bins> // int main(int argc, char *argv[]) { // Test for the correct number of arguments in the command line. if (argc != 3) { cout << "Usage: " << argv[0] << " <input_image> <nr_bins>" << endl; exit(0); } // Read an image from the file specified by "argv[1]" and display it. Image< float > im1; im1.readImage(argv[1]); im1.showImage(); // Compute the histogram of the input image and display the value of each bin. Histogram<float> h(im1, atoi(argv[2])); for (int i = 0; i < atoi(argv[2]); i++) cout << h.getHistogram()[i] << "\t"; cout << endl; // If you have Plotutils package with the libplotter class library installed, // you can visualize the histogram. #ifdef HAVE_LIBPLOTTER // Set some of the parameters for displaying the histogram. h.setDimensions(300, 500); h.setFillIntensity(0.5); h.setTitle("Original image"); h.setTitleFontName("Courier-Bold"); h.setTitleFontSize(0.07); h.setXLabel("a"); h.setYLabel("b"); // Display the histogram. h.showHistogram(); // Write the histogram in eps format in the file "hist.eps". h.writeHistogram("PS", "hist.ps"); #endif // Perform histogram equalization on the input image and store the result in another image. Image< float > im2; h.equalize(im2); // Display the equalized image im2.showImage(); // Compute the histogram of the equalized image and display the value of each bin. Histogram<float> h1(im2, atoi(argv[2])); for (int i = 0; i < atoi(argv[2]); i++) cout << h1.getHistogram()[i] << "\t"; cout << endl; #ifdef HAVE_LIBPLOTTER h1.setTitle("Equalized image"); // Display the histogram of the equalized image // using the default parameters for the displaying method. h1.showHistogram(); #endif char l; cin >> l; // Close all display windows. #ifdef HAVE_LIBPLOTTER h.closeWindow(); h1.closeWindow(); #endif im1.closeWindow(); im2.closeWindow(); return(1); }