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