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