Go to the documentation of this file.00001
00002
00003 #include <vil/vil_convert.h>
00004 #include <vul/vul_arg.h>
00005 #include <vil/vil_load.h>
00006 #include <vil/vil_save.h>
00007 #include <vil/vil_math.h>
00008 #include <vgl/vgl_point_3d.h>
00009 #include <ipts/ipts_corner_pyramid.h>
00010 #include <ipts/ipts_scale_space_peaks.h>
00011 #include <ipts/ipts_draw.h>
00012
00013 void print_usage()
00014 {
00015 vcl_cout<<"find_scale_corners -i input_image -s scale_step -t threshold -o out_image -c corner_pyramid\n"
00016 <<"Generates scale pyramid, computes corners and looks for local peaks\n";
00017 }
00018
00019
00020 int main( int argc, char* argv[] )
00021 {
00022 vul_arg<vcl_string> in_path("-i","Input image path");
00023 vul_arg<vcl_string> out_path("-o","Output image file (peaks)","output.pnm");
00024 vul_arg<vcl_string> corner_path("-c","Output image file (corners)");
00025 vul_arg<float> threshold("-t","Threshold on corner response",100.0f);
00026 vul_arg<double> scale("-s","Scale step",1.41);
00027
00028
00029 vul_arg_parse(argc, argv);
00030
00031 if (in_path() == "")
00032 {
00033 print_usage();
00034 vul_arg_display_usage_and_exit();
00035 }
00036
00037 vil_image_view<vxl_byte> image = vil_load(in_path().c_str());
00038 if (image.ni()==0)
00039 {
00040 vcl_cout<<"Failed to load image.\n";
00041 return 1;
00042 }
00043
00044 vimt_image_2d_of<float> image_f,flat_corners,flat_smooth;
00045 vil_convert_cast(image,image_f.image());
00046 vimt_image_pyramid smooth_pyramid,corner_pyramid;
00047 ipts_corner_pyramid(image_f,corner_pyramid,smooth_pyramid,scale());
00048
00049 vcl_vector<vgl_point_3d<double> > peak_pts;
00050 ipts_scale_space_peaks_2d(peak_pts,corner_pyramid,threshold());
00051 vcl_cout<<"Found "<<peak_pts.size()<<" peaks.\n";
00052
00053 for (unsigned i=0;i<peak_pts.size();++i)
00054 {
00055 if (peak_pts[i].z()>1.1)
00056 ipts_draw_cross(image,int(peak_pts[i].x()+0.5),
00057 int(peak_pts[i].y()+0.5),
00058 int(peak_pts[i].z()+0.5), vxl_byte(255) );
00059 }
00060
00061 vimt_image_pyramid_flatten(flat_corners,corner_pyramid);
00062
00063 vil_save(image,out_path().c_str());
00064 vcl_cout<<"Image + pts saved to "<<out_path()<<vcl_endl;
00065
00066 if (corner_path()!="")
00067 {
00068 vil_image_view<vxl_byte> out_corners;
00069
00070 vil_math_sqrt(flat_corners.image());
00071 vil_convert_stretch_range(flat_corners.image(),out_corners);
00072 vil_save(out_corners,corner_path().c_str());
00073 vcl_cout<<"(sqrt) Corner pyramid saved to "<<corner_path()<<vcl_endl;
00074 }
00075
00076 return 0;
00077 }