00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <vil/vil_image_view.h>
00020 #include <vil/vil_load.h>
00021 #include <vil/vil_save.h>
00022
00023 #include <vipl/accessors/vipl_accessors_vil_image_view.h>
00024 #include <vipl/vipl_add_random_noise.h>
00025 #include <vcl_iostream.h>
00026 #include <vcl_cstdlib.h>
00027 #include <vxl_config.h>
00028
00029 int
00030 main(int argc, char** argv)
00031 {
00032 if (argc < 3) { vcl_cerr << "Syntax: example_add_random_noise file_in file_out [width]\n"; return 1; }
00033
00034
00035 vil_image_view<vxl_byte> in = vil_load(argv[1]);
00036 if (!in) { vcl_cerr << "Please use a ubyte image as input\n"; return 2; }
00037
00038
00039 vil_image_view<vxl_byte> out(in.ni(),in.nj(),in.nplanes());
00040
00041
00042 double sigma = (argc < 4) ? 5.0 : vcl_atof(argv[3]);
00043 vxl_byte s = (vxl_byte)(sigma+0.5);
00044
00045
00046 vipl_add_random_noise<vil_image_view<vxl_byte>,vil_image_view<vxl_byte>,vxl_byte,vxl_byte> op(GAUSSIAN_NOISE,s);
00047 op.put_in_data_ptr(&in);
00048 op.put_out_data_ptr(&out);
00049 op.filter();
00050
00051 vil_save(out, argv[2]);
00052 vcl_cout << "Noisy image written to " << argv[2] << vcl_endl;
00053 return 0;
00054 }