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

test_image.cpp

00001 /* Copyright (c) 2001 C. Grigorescu S.E. Grigorescu */
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <tip.h>
00007 
00008 //   Example program for the "Image" class.
00009 //
00010 //   Usage:
00011 //      test_image <input_image>
00012 //
00013 
00014 int main(int argc, char *argv[])
00015 {
00016   // Test for the correct number of arguments in the command line.
00017   if (argc != 2) {
00018     cout << "Usage: " << argv[0] << " <input_image>" << endl;
00019     exit(0);
00020   }
00021 
00022   char l;
00023 
00024   // Read an image from the file specified by "argv[1]" and display it
00025   // Store the pixel values as floats.
00026   Image< float > im1;
00027   im1.readImage(argv[1]);
00028   im1.showImage();
00029 
00030   // Create an empty image of size "128"x"128" with the name "Empty image"
00031   // and display it.
00032   Image< float > im2(128,128,"Empty image");
00033   im2.showImage();
00034   cin >> l;
00035 
00036   // Copy the image "im1" to "im2".
00037   im2 = im1;
00038 
00039   // Set the name of the image.
00040   im2.setName("Image_2.tif");
00041 
00042   // Write the copy to the file specified by "setName".
00043   im2.writeImage();
00044 
00045   // Print some statistics about the image "im2".
00046   cout << "Min:     " << im2.min() << endl;
00047   cout << "Max:     " << im2.max() << endl;
00048   cout << "Avg:     " << im2.avg() << endl;
00049   cout << "Std.dev.:" << im2.dev() << endl;
00050   im2.showImage();
00051   cin >> l;
00052 
00053   // Crop the image in such a way that only the rectangular area defined by 
00054   // point (10,10) (as the upper left corner) and 
00055   // point (100,100) (as the lower right corner) is left.
00056   im2.crop(10, 10, 100, 100); 
00057   im2.showImage(); 
00058   cin >> l;
00059 
00060   // Create a copy of "im1" in "im3" and set the pixel values
00061   // to twice their values; print some statistics and
00062   // display the new image
00063   Image< float > im3;
00064   im3 = im1;
00065   im3 *= 2;      
00066   cout << "Min:     " << im3.min() << endl;
00067   cout << "Max:     " << im3.max() << endl;
00068   cout << "Avg:     " << im3.avg() << endl;
00069   cout << "Std.dev.:" << im3.dev() << endl;
00070   im3.showImage();
00071   cin >> l;
00072 
00073   // Close all display windows
00074   im1.closeWindow();
00075   im2.closeWindow();
00076   im3.closeWindow();        
00077 
00078   return(1);
00079 }