00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <vnl/vnl_matrix.h>
00021
00022 #include <vipl/vipl_with_vnl_matrix/accessors/vipl_accessors_vnl_matrix.h>
00023 #include <vipl/vipl_threshold.h>
00024
00025 #include <vxl_config.h>
00026 typedef vnl_matrix<vxl_byte> img_type;
00027
00028
00029 #include <vil/vil_image_view.h>
00030 #include <vil/vil_load.h>
00031 #include <vil/vil_save.h>
00032 #include <vcl_iostream.h>
00033 #include <vcl_cstdlib.h>
00034 #include <vcl_cstring.h>
00035
00036 int
00037 main(int argc, char** argv)
00038 {
00039 if (argc < 3) { vcl_cerr << "Syntax: example3_threshold file_in file_out [threshold]\n"; return 1; }
00040
00041
00042 vil_image_view<vxl_byte> in = vil_load(argv[1]);
00043 if (!in) { vcl_cerr << "Please use a ubyte image as input\n"; return 2; }
00044
00045
00046 vil_image_view<vxl_byte> out(in.ni(),in.nj(),in.nplanes());
00047
00048
00049 int xs = in.ni();
00050 int ys = in.nj();
00051
00052
00053 vxl_byte threshold = (argc < 4) ? 10 : vcl_atoi(argv[3]);
00054
00055 img_type src(xs,ys);
00056
00057
00058 vcl_memcpy(src.begin(), in.memory_chunk()->const_data(), in.size_bytes());
00059
00060
00061 vipl_threshold<img_type,img_type,vxl_byte,vxl_byte> op(threshold,0,255);
00062 op.put_in_data_ptr(&src);
00063 op.put_out_data_ptr(&src);
00064 op.filter();
00065
00066
00067 vcl_memcpy(out.memory_chunk()->data(), src.begin(), out.size_bytes());
00068 vil_save(out, argv[2], "pnm");
00069 vcl_cout << "Written image of type PGM to " << argv[2] << vcl_endl;
00070
00071 return 0;
00072 }