Go to the documentation of this file.00001
00002
00003 #include <ipts/ipts_entropy_pyramid.h>
00004 #include <ipts/ipts_orientation_pyramid.h>
00005 #include <vimt/vimt_scale_pyramid_builder_2d.h>
00006 #include <vil/vil_convert.h>
00007 #include <vul/vul_arg.h>
00008 #include <vil/vil_load.h>
00009 #include <vil/vil_save.h>
00010 #include <vgl/vgl_point_3d.h>
00011 #include <ipts/ipts_scale_space_peaks.h>
00012 #include <ipts/ipts_draw.h>
00013
00014 void print_usage()
00015 {
00016 vcl_cout<<"find_scale_orient_entropy_peaks "
00017 <<"-i input_image -s scale_step -h half_width -t threshold -o out_image -e entropy_pyramid\n"
00018 <<"Generates scale pyramid, computes orientations at each level then\n"
00019 <<"computes local orientation entropy in squares with given half width\n"
00020 <<"looks for local peaks in the entropy pyramid\n";
00021 }
00022
00023 int main( int argc, char* argv[] )
00024 {
00025 vul_arg<vcl_string> in_path("-i","Input image path");
00026 vul_arg<vcl_string> out_path("-o","Output image file (peaks)","output.pnm");
00027 vul_arg<int> half_width("-h","Half-width of square for entropy measurements",5);
00028 vul_arg<float> grad_threshold("-gt","Threshold on gradients",10.0f);
00029 vul_arg<float> threshold("-t","Threshold for peak detection",-999);
00030 vul_arg<vcl_string> entropy_path("-e","Output image file for entropy pyramid)");
00031 vul_arg<double> scale("-s","Scale step",1.41);
00032
00033 vul_arg_parse(argc, argv);
00034
00035 if (in_path() == "")
00036 {
00037 print_usage();
00038 vul_arg_display_usage_and_exit();
00039 }
00040
00041 vil_image_view<vxl_byte> image = vil_load(in_path().c_str());
00042 if (image.ni()==0)
00043 {
00044 vcl_cout<<"Failed to load image.\n";
00045 return 1;
00046 }
00047
00048 vimt_image_2d_of<vxl_byte> image0,flat_smooth;
00049 vimt_image_2d_of<float> image_f,flat_entropy;
00050
00051 vil_convert_cast(image,image_f.image());
00052
00053 unsigned n_orientations = 64;
00054
00055 vimt_image_pyramid smooth_pyramid,entropy_pyramid,orient_pyramid;
00056
00057 vimt_scale_pyramid_builder_2d<float> pyr_builder;
00058 pyr_builder.set_scale_step(scale());
00059 pyr_builder.build(smooth_pyramid,image_f);
00060
00061 ipts_orientation_pyramid(smooth_pyramid,orient_pyramid,grad_threshold(),n_orientations);
00062
00063 ipts_entropy_pyramid(orient_pyramid,entropy_pyramid,
00064 half_width(),0,n_orientations);
00065
00066
00067 vcl_vector<vgl_point_3d<double> > peak_pts;
00068 ipts_scale_space_peaks_2d(peak_pts,entropy_pyramid,threshold());
00069 vcl_cout<<"Found "<<peak_pts.size()<<" peaks.\n";
00070
00071 for (unsigned i=0;i<peak_pts.size();++i)
00072 {
00073 if (peak_pts[i].z()>1.1)
00074 ipts_draw_cross(image,int(peak_pts[i].x()+0.5),
00075 int(peak_pts[i].y()+0.5),
00076 int(peak_pts[i].z()+0.5), vxl_byte(255) );
00077 }
00078
00079 vimt_image_pyramid_flatten(flat_entropy,entropy_pyramid);
00080
00081
00082 vil_save(image,out_path().c_str());
00083 vcl_cout<<"Image + pts saved to "<<out_path()<<vcl_endl;
00084
00085
00086 if (entropy_path()!="")
00087 {
00088 vil_image_view<vxl_byte> out_entropy;
00089 vil_convert_stretch_range(flat_entropy.image(),out_entropy);
00090 vil_save(out_entropy,entropy_path().c_str());
00091 vcl_cout<<"entropy pyramid saved to "<<entropy_path()<<vcl_endl;
00092 }
00093
00094 return 0;
00095 }