#include <vil1/vil1_memory_image_of.h>
#include <vil1/vil1_pixel.h>
#include <vipl/accessors/vipl_accessors_vil1_image.h>
#include <vipl/vipl_threshold.h>
#include <vxl_config.h>
typedef vil1_image img_type;
#include <vil1/vil1_load.h>
#include <vil1/vil1_save.h>
#include <vcl_iostream.h>
#include <vcl_cstdlib.h>
int
main(int argc, char** argv)
{
if (argc < 3) { vcl_cerr << "Syntax: example4_threshold file_in file_out [threshold]\n"; return 1; }
vil1_image in = vil1_load(argv[1]);
if (vil1_pixel_format(in) != VIL1_BYTE) { vcl_cerr << "Please use a ubyte image as input\n"; return 2; }
vil1_memory_image_of<vxl_byte> out(in);
int xs = in.width();
int ys = in.height();
vxl_byte threshold = (argc < 4) ? 64 : vxl_byte(vcl_atoi(argv[3]));
vil1_memory_image_of<vxl_byte> src(in);
vxl_byte* buf = new vxl_byte[in.get_size_bytes()];
in.get_section(buf,0,0,xs,ys);
src.put_section(buf,0,0,xs,ys);
vipl_threshold<img_type,img_type,vxl_byte,vxl_byte> op(threshold,0,255);
op.put_in_data_ptr(&src);
op.put_out_data_ptr(&src);
op.filter();
src.get_section(buf,0,0,xs,ys);
out.put_section(buf,0,0,xs,ys);
vil1_save(out, argv[2], "pnm");
vcl_cout << "Written image of type PGM to " << argv[2] << vcl_endl;
delete[] buf;
return 0;
}