examples/example1_threshold.cxx

00001 //:
00002 // \file
00003 //  This example program shows a typical use of the vipl_threshold IP class on
00004 //  a ubyte image.  The input image (argv[1]) must be ubyte, and in that
00005 //  case is thresholded (threshold value argv[3], default 127) to argv[2]
00006 //  which is always a PGM file image.
00007 //  Uses vipl_threshold<vil_image_view<ubyte>,vil_image_view<ubyte>,ubyte,ubyte>.
00008 //  The input and output images are directly passed to the filter.
00009 //
00010 // \author Peter Vanroose, K.U.Leuven, ESAT/PSI
00011 // \date   15 nov. 1997
00012 //
00013 // \verbatim
00014 // Modifications:
00015 //   Peter Vanroose, Aug.2000 - adapted to vxl
00016 //   Peter Vanroose, Feb.2004 - replaced vil1_image by vil2_image_view<T>
00017 // \endverbatim
00018 //
00019 #include <vil/vil_load.h>
00020 #include <vil/vil_save.h>
00021 #include <vil/vil_image_view.h>
00022 #include <vipl/accessors/vipl_accessors_vil_image_view.h>
00023 #include <vipl/vipl_threshold.h>
00024 #include <vcl_iostream.h>
00025 #include <vcl_cstdlib.h> // for atoi()
00026 #include <vxl_config.h> // for vxl_byte
00027 
00028 int
00029 main(int argc, char** argv)
00030 {
00031   if (argc < 3) { vcl_cerr << "Syntax: example1_threshold file_in file_out [threshold]\n"; return 1; }
00032 
00033   // The input image:
00034   vil_image_view<vxl_byte> in = vil_load(argv[1]);
00035   if (!in) return 2;
00036   vil_image_view<vxl_byte>* src = &in;
00037 
00038   // The output image:
00039   vil_image_view<vxl_byte> out(in.ni(),in.nj(),in.nplanes());
00040   vil_image_view<vxl_byte>* dst = &out;
00041 
00042   // The threshold value:
00043   vxl_byte threshold = (argc < 4) ? 127 : vcl_atoi(argv[3]);
00044 
00045   // The filter:
00046   vipl_threshold<vil_image_view<vxl_byte>,vil_image_view<vxl_byte>,vxl_byte,vxl_byte> op(threshold,0);
00047   // without third argument, only set below threshold to 0
00048   op.put_in_data_ptr(src);
00049   op.put_out_data_ptr(dst);
00050   op.filter();
00051 
00052   vil_save(out, argv[2], "pnm");
00053   vcl_cout << "Written thresholded image of type PGM to " << argv[2] << vcl_endl;
00054   return 0;
00055 }

Generated on Sun Oct 12 05:13:23 2008 for contrib/tbl/vipl by  doxygen 1.5.1