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