examples/example_x_gradient.cxx

00001 //:
00002 // \file
00003 //  This example program shows a typical use of a gradient IP class on
00004 //  a colour image.  The input image (argv[1]) must be 24 bit (colour), and in
00005 //  that case its X gradient is written to argv[2] which is always a PPM file.
00006 //  Uses vipl_x_gradient<section<rgbcell,2>,section<rgbcell,2>,rgbcell,rgbcell>.
00007 //  Note that this requires operator-() on the vil_rgb<ubyte> data type.
00008 //  But this indeed produces a *colour* gradient!
00009 //
00010 // \author Peter Vanroose, K.U.Leuven, ESAT/PSI
00011 // \date   29 may 1998.
00012 //
00013 // \verbatim
00014 // Modifications:
00015 //   Peter Vanroose, Aug.2000 - adapted to vxl
00016 //   Peter Vanroose, Feb.2004 - replaced vil1_load by vil2_load
00017 // \endverbatim
00018 //
00019 #include <section/section.h>
00020 #include <vipl/vipl_with_section/accessors/vipl_accessors_section.h>
00021 #include <vil/vil_rgb.h>
00022 
00023 #include <vipl/vipl_x_gradient.h>
00024 
00025 #include <vxl_config.h> // for vxl_byte
00026 typedef vil_rgb<vxl_byte> rgbcell;
00027 typedef section<rgbcell,2> img_type;
00028 
00029 // for I/O:
00030 #include <vil/vil_image_view.h>
00031 #include <vil/vil_load.h>
00032 #include <vil/vil_save.h>
00033 #include <vcl_iostream.h>
00034 #include <vcl_cstring.h> // for memcpy()
00035 
00036 int
00037 main(int argc, char** argv)
00038 {
00039   if (argc < 3) { vcl_cerr << "Syntax: example_x_gradient file_in file_out\n"; return 1; }
00040 
00041   // The input image:
00042   vil_image_view<rgbcell> in = vil_load(argv[1]);
00043   if (!in) { vcl_cerr << "Please use a colour image as input\n"; return 2; }
00044 
00045   // The output image:
00046   vil_image_view<rgbcell> out(in.ni(),in.nj(),in.nplanes());
00047 
00048   // The image sizes:
00049   int xs = in.ni();
00050   int ys = in.nj();
00051 
00052   img_type src(xs,ys); // in-memory 2D images
00053   img_type dst(xs,ys);
00054 
00055   // set the input image:
00056   vcl_memcpy(src.buffer, in.memory_chunk()->const_data(), in.size_bytes());
00057 
00058   // The filter:
00059   vipl_x_gradient<img_type,img_type,rgbcell,rgbcell> op;
00060   op.put_in_data_ptr(&src);
00061   op.put_out_data_ptr(&dst);
00062   op.filter();
00063 
00064   // Write output:
00065   vcl_memcpy(out.memory_chunk()->data(), dst.buffer, out.size_bytes());
00066   vil_save(out, argv[2], "pnm");
00067   vcl_cout << "Written image of type PPM to " << argv[2] << vcl_endl;
00068 
00069   return 0;
00070 }

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