examples/example_dilate_disk.cxx

00001 // This is tbl/vipl/examples/example_dilate_disk.cxx
00002 
00003 //:
00004 // \file
00005 //  This example program shows a typical use of a morphological IP class on
00006 //  a grey image.  The input image (argv[1]) must be 8 bit (grey), and in
00007 //  that case is dilated (circular kernel, default 3+3 cross) to argv[2]
00008 //  which is always a PGM file image.
00009 //  Uses vipl_dilate_disk<section<ubyte,2>,section<ubyte,2>,ubyte,ubyte>.
00010 //  The conversion between vil_image_view<ubyte> and the in-memory section<ubyte,2>
00011 //  is done explicitly.
00012 //
00013 //  Note that this cannot work with colour images unless a function
00014 //  max(rgbcell,rgbcell) is provided.
00015 //
00016 // \author Peter Vanroose, K.U.Leuven, ESAT/PSI
00017 // \date   15 nov. 1997
00018 //
00019 // \verbatim
00020 // Modifications:
00021 //   Peter Vanroose, Aug.2000 - adapted to vxl
00022 //   Peter Vanroose, Feb.2004 - replaced vil1_load by vil2_load
00023 // \endverbatim
00024 //
00025 #include <section/section.h>
00026 #include <vipl/vipl_with_section/accessors/vipl_accessors_section.h>
00027 
00028 #include <vipl/vipl_dilate_disk.h>
00029 
00030 #include <vxl_config.h> // for vxl_byte
00031 typedef section<vxl_byte,2> img_type;
00032 
00033 // for I/O:
00034 #include <vil/vil_image_view.h>
00035 #include <vil/vil_load.h>
00036 #include <vil/vil_save.h>
00037 #include <vcl_iostream.h>
00038 #include <vcl_cstdlib.h> // for atof()
00039 #include <vcl_cstring.h> // for memcpy()
00040 
00041 int
00042 main(int argc, char** argv) {
00043   if (argc < 3) { vcl_cerr << "Syntax: example_dilate_disk file_in file_out [radius]\n"; return 1; }
00044 
00045   // The input image:
00046   vil_image_view<vxl_byte> in = vil_load(argv[1]);
00047   if (!in) { vcl_cerr << "Please use a greyscale image as input\n"; return 2; }
00048 
00049   // The output image:
00050   vil_image_view<vxl_byte> out(in.ni(),in.nj(),in.nplanes());
00051 
00052   // The image sizes:
00053   int xs = in.ni();
00054   int ys = in.nj();
00055 
00056   // The radius: (default is 3+3 cross)
00057   float radius = (argc < 4) ? 1.0f : (float)vcl_atof(argv[3]);
00058 
00059   img_type src(xs,ys); // in-memory 2D images
00060   img_type dst(xs,ys);
00061 
00062   // set the input image:
00063   vcl_memcpy(src.buffer, in.memory_chunk()->const_data(), in.size_bytes());
00064 
00065   // The filter:
00066   vipl_dilate_disk<img_type,img_type,vxl_byte,vxl_byte> op(radius);
00067   op.put_in_data_ptr(&src);
00068   op.put_out_data_ptr(&dst);
00069   op.filter();
00070 
00071   // Write output:
00072   vcl_memcpy(out.memory_chunk()->data(), dst.buffer, out.size_bytes());
00073   vil_save(out, argv[2], "pnm");
00074   vcl_cout << "Written image of type PPM to " << argv[2] << vcl_endl;
00075 
00076   return 0;
00077 }
00078 
00079 // instantiation of the filter;
00080 // this should normally go into a separate file in the Templates subdirectory
00081 #include <vipl/vipl_with_section/accessors/vipl_accessors_section.txx>
00082 #include <vipl/vipl_dilate_disk.txx>
00083 
00084 template class vipl_dilate_disk<img_type,img_type,vxl_byte,vxl_byte>;

Generated on Sat Nov 22 05:13:27 2008 for contrib/tbl/vipl by  doxygen 1.5.1