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

test_noise.cpp

00001 /* Copyright (c) 2001 S.E. Grigorescu */
00002 
00003 #include <iostream.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <tip.h>
00007 
00008 //   Example program for the "Noise" function.
00009 //
00010 //   Usage:
00011 //      test_noise <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   // Read an image from the file specified by "argv[1]" and display it.
00023   Image< float > img, im1;
00024   im1.readImage(argv[1]);
00025   im1.setName("test_image");
00026   im1.showImage();          
00027 
00028   char l;
00029 
00030   // Add noise having a uniform distribution in the interval [0, 1] to the image. 
00031   // Initialize the random number generator with 16.
00032   img = im1;
00033   Noise(img, "uniform", 16);
00034   img.showImage();
00035   cin >> l;
00036 
00037   // Add Gaussian noise with mean 0 and standard deviation 1 to the image. 
00038   img = im1;
00039   Noise(img);
00040   img.showImage();
00041   cin >> l;
00042 
00043   // Add salt and pepper noise to the image. 
00044   // Initialize the random number generator with 8.
00045   img = im1;
00046   Noise(img, "salt&pepper", 8);
00047   img.showImage();
00048   cin >> l;
00049 
00050   // Add noise having a uniform distribution in the interval [-60, 10] to the image. 
00051   img = im1;
00052   Noise(img, "uniform", -60, 10);
00053   img.showImage();
00054   cin >> l;
00055 
00056   // Add Gaussian noise with mean 10 and standard deviation 30 to the image. 
00057   // Initialize the random number generator with 9.
00058   img = im1;
00059   Noise(img, 10, 30, 9);
00060   img.showImage();
00061   cin >> l;
00062 
00063   // Add salt and pepper noise to the image, in such a way that 15% of the image pixels are affected. 
00064   // Initialize the random number generator with 71.
00065   img = im1;
00066   Noise(img, "salt&pepper", 15, 0, 71);
00067   img.showImage();
00068   cin >> l;
00069   
00070   return(1);
00071 }