#include <vil/vil_image_view.h>
#include <vil/vil_load.h>
#include <vil/vil_save.h>
#include <vipl/accessors/vipl_accessors_vil_image_view.h>
#include <vipl/vipl_add_random_noise.h>
#include <vcl_iostream.h>
#include <vcl_cstdlib.h>
#include <vxl_config.h>
int
main(int argc, char** argv)
{
if (argc < 3) { vcl_cerr << "Syntax: example_add_random_noise file_in file_out [width]\n"; return 1; }
vil_image_view<vxl_byte> in = vil_load(argv[1]);
if (!in) { vcl_cerr << "Please use a ubyte image as input\n"; return 2; }
vil_image_view<vxl_byte> out(in.ni(),in.nj(),in.nplanes());
double sigma = (argc < 4) ? 5.0 : vcl_atof(argv[3]);
vxl_byte s = (vxl_byte)(sigma+0.5);
vipl_add_random_noise<vil_image_view<vxl_byte>,vil_image_view<vxl_byte>,vxl_byte,vxl_byte> op(GAUSSIAN_NOISE,s);
op.put_in_data_ptr(&in);
op.put_out_data_ptr(&out);
op.filter();
vil_save(out, argv[2]);
vcl_cout << "Noisy image written to " << argv[2] << vcl_endl;
return 0;
}