Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include <vcl_iostream.h>
00007 #include <vul/vul_arg.h>
00008 #include <vxl_config.h>
00009 #include <vil/vil_load.h>
00010 #include <vil/vil_save.h>
00011 #include <vil/vil_image_view.h>
00012 #include <vil/vil_convert.h>
00013 #include <vil/vil_math.h>
00014 #include <vgl/vgl_point_2d.h>
00015 #include <ipts/ipts_local_entropy.h>
00016 #include <vimt/algo/vimt_find_peaks.h>
00017 #include <ipts/ipts_draw.h>
00018
00019 void print_usage()
00020 {
00021 vcl_cout<<"show_local_entropy -i in_image -e entropy_image -o out_image -h half_width\n"
00022 <<"Load in an image and generate entropy from square regions.\n"
00023 <<"Show peaks in entropy as crosses on original image.\n";
00024 }
00025
00026 int main( int argc, char* argv[] )
00027 {
00028 vul_arg<vcl_string> in_path("-i","Input image");
00029 vul_arg<vcl_string> entropy_path("-e","Entropy image","entropy.jpg");
00030 vul_arg<vcl_string> out_path("-o","Output image","output.jpg");
00031 vul_arg<int> half_width("-h","Half width of RIO",10);
00032 vul_arg_parse(argc, argv);
00033
00034 if (in_path() == "")
00035 {
00036 print_usage();
00037 vul_arg_display_usage_and_exit();
00038 }
00039
00040 vil_image_view<vxl_byte> src_im = vil_load(in_path().c_str());
00041 if (src_im.size()==0)
00042 {
00043 vcl_cout<<"Unable to load source image from "<<in_path()<<vcl_endl;
00044 return 1;
00045 }
00046
00047 vil_image_view<vxl_byte> grey_im;
00048 vil_math_mean_over_planes(src_im,grey_im);
00049
00050 vil_image_view<float> entropy_im,entropy_max_im;
00051 ipts_local_entropy(grey_im,entropy_im,half_width());
00052
00053
00054
00055 vil_image_view<vxl_byte> dest_im;
00056 vil_convert_stretch_range(entropy_im,dest_im);
00057
00058 if (!vil_save(dest_im, entropy_path().c_str()))
00059 {
00060 vcl_cerr<<"Unable to save entropy image to "<<entropy_path()<<vcl_endl;
00061 return 1;
00062 }
00063
00064 vcl_cout<<"Saved image to "<<entropy_path()<<vcl_endl;
00065
00066 vcl_vector<vgl_point_2d<unsigned> > peaks;
00067 vimt_find_image_peaks_3x3(peaks,entropy_im);
00068 for (unsigned i=0;i<peaks.size();++i)
00069 ipts_draw_cross(grey_im,peaks[i].x()+half_width(),peaks[i].y()+half_width(),half_width(),vxl_byte(255));
00070
00071 if (!vil_save(grey_im, out_path().c_str()))
00072 {
00073 vcl_cerr<<"Unable to save result image to "<<out_path()<<vcl_endl;
00074 return 1;
00075 }
00076
00077 vcl_cout<<"Saved image to "<<out_path()<<vcl_endl;
00078
00079 return 0;
00080 }