00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <vil1/vil1_memory_image_of.h>
00018 #include <vil1/vil1_pixel.h>
00019 #include <vipl/accessors/vipl_accessors_vil1_image.h>
00020 #include <vipl/vipl_threshold.h>
00021
00022 #include <vxl_config.h>
00023 typedef vil1_image img_type;
00024
00025
00026 #include <vil1/vil1_load.h>
00027 #include <vil1/vil1_save.h>
00028 #include <vcl_iostream.h>
00029 #include <vcl_cstdlib.h>
00030
00031 int
00032 main(int argc, char** argv) {
00033 if (argc < 3) { vcl_cerr << "Syntax: example4_threshold file_in file_out [threshold]\n"; return 1; }
00034
00035
00036 vil1_image in = vil1_load(argv[1]);
00037 if (vil1_pixel_format(in) != VIL1_BYTE) { vcl_cerr << "Please use a ubyte image as input\n"; return 2; }
00038
00039
00040 vil1_memory_image_of<vxl_byte> out(in);
00041
00042
00043 int xs = in.width();
00044 int ys = in.height();
00045
00046
00047 vxl_byte threshold = (argc < 4) ? 64 : vcl_atoi(argv[3]);
00048
00049 vil1_memory_image_of<vxl_byte> src(in);
00050 vxl_byte* buf = new vxl_byte[in.get_size_bytes()];
00051
00052
00053 in.get_section(buf,0,0,xs,ys);
00054 src.put_section(buf,0,0,xs,ys);
00055
00056
00057 vipl_threshold<img_type,img_type,vxl_byte,vxl_byte> op(threshold,0,255);
00058 op.put_in_data_ptr(&src);
00059 op.put_out_data_ptr(&src);
00060 op.filter();
00061
00062
00063 src.get_section(buf,0,0,xs,ys);
00064 out.put_section(buf,0,0,xs,ys);
00065 vil1_save(out, argv[2], "pnm");
00066 vcl_cout << "Written image of type PGM to " << argv[2] << vcl_endl;
00067
00068 delete[] buf;
00069 return 0;
00070 }