#include <vil/vil_load.h>
#include <vil/vil_save.h>
#include <vil/vil_image_view.h>
#include <vipl/accessors/vipl_accessors_vil_image_view.h>
#include <vipl/vipl_threshold.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: example1_threshold file_in file_out [threshold]\n"; return 1; }
vil_image_view<vxl_byte> in = vil_load(argv[1]);
if (!in) return 2;
vil_image_view<vxl_byte>* src = ∈
vil_image_view<vxl_byte> out(in.ni(),in.nj(),in.nplanes());
vil_image_view<vxl_byte>* dst = &out;
vxl_byte threshold = (argc < 4) ? 127 : vxl_byte(vcl_atoi(argv[3]));
vipl_threshold<vil_image_view<vxl_byte>,vil_image_view<vxl_byte>,vxl_byte,vxl_byte> op(threshold,0);
op.put_in_data_ptr(src);
op.put_out_data_ptr(dst);
op.filter();
vil_save(out, argv[2], "pnm");
vcl_cout << "Written thresholded image of type PGM to " << argv[2] << vcl_endl;
return 0;
}