Go to the documentation of this file.00001
00002
00003
00004
00005 #include <bprb/bprb_func_process.h>
00006 #include <vcl_iostream.h>
00007 #include <bbgm/bbgm_image_of.h>
00008 #include <bbgm/bbgm_image_sptr.h>
00009 #include <bbgm/bbgm_update.h>
00010 #include <bsta/bsta_attributes.h>
00011 #include <bsta/bsta_gauss_if3.h>
00012 #include <bsta/bsta_gauss_sf1.h>
00013 #include <bsta/bsta_mixture.h>
00014 #include <bsta/bsta_basic_functors.h>
00015 #include <bsta/algo/bsta_adaptive_updater.h>
00016 #include <brdb/brdb_value.h>
00017 #include <vbl/io/vbl_io_smart_ptr.h>
00018 #include <vil/vil_image_view.h>
00019 #include <vil/vil_convert.h>
00020 #include <vil/vil_math.h>
00021 #include <bbgm/bbgm_viewer.h>
00022 #include <bbgm/bbgm_viewer_sptr.h>
00023
00024
00025 namespace type_definitions {
00026
00027 typedef bsta_num_obs<bsta_mixture<bsta_num_obs<bsta_gauss_if3> > > mix_gauss_type_if3;
00028 typedef bsta_num_obs<bsta_mixture_fixed<bsta_num_obs<bsta_gauss_sf1>, 3> > mix_fixed_gauss_type_sf1;
00029 typedef bsta_num_obs<bsta_mixture<bsta_num_obs<bsta_gauss_sf1> > > mix_gauss_type_sf1;
00030 }
00031
00032
00033 void register_mean_viewers()
00034 {
00035 using namespace type_definitions;
00036 bbgm_mean_viewer::register_view_maker(new bbgm_view_maker<mix_gauss_type_if3, bsta_mean_functor<mix_gauss_type_if3> >);
00037 bbgm_mean_viewer::register_view_maker(new bbgm_view_maker<mix_fixed_gauss_type_sf1, bsta_mean_functor<mix_fixed_gauss_type_sf1> >);
00038 bbgm_mean_viewer::register_view_maker(new bbgm_view_maker<mix_gauss_type_sf1, bsta_mean_functor<mix_gauss_type_sf1> >);
00039 }
00040
00041 void register_variance_viewers()
00042 {
00043 using namespace type_definitions;
00044 bbgm_variance_viewer::register_view_maker(new bbgm_view_maker<mix_gauss_type_if3, bsta_diag_covar_functor<mix_gauss_type_if3> >);
00045 bbgm_variance_viewer::register_view_maker(new bbgm_view_maker<mix_fixed_gauss_type_sf1, bsta_var_functor<mix_fixed_gauss_type_sf1> >);
00046 bbgm_variance_viewer::register_view_maker(new bbgm_view_maker<mix_gauss_type_sf1, bsta_var_functor<mix_gauss_type_sf1> >);
00047 }
00048
00049 void register_weight_viewers()
00050 {
00051 using namespace type_definitions;
00052 bbgm_weight_viewer::register_view_maker(new bbgm_view_maker<mix_gauss_type_if3, bsta_weight_functor<mix_gauss_type_if3> >);
00053 bbgm_weight_viewer::register_view_maker(new bbgm_view_maker<mix_fixed_gauss_type_sf1, bsta_weight_functor<mix_fixed_gauss_type_sf1> >);
00054 bbgm_weight_viewer::register_view_maker(new bbgm_view_maker<mix_gauss_type_sf1, bsta_weight_functor<mix_gauss_type_sf1> >);
00055 }
00056
00057
00058
00059 bool bbgm_display_dist_image_process_cons(bprb_func_process& pro)
00060 {
00061
00062 vcl_vector<vcl_string> in_types(4), out_types(1);
00063 in_types[0]= "bbgm_image_sptr";
00064 in_types[1]= "vcl_string";
00065 in_types[2]= "int";
00066 in_types[3]= "bool";
00067 pro.set_input_types(in_types);
00068
00069
00070 out_types[0]= "vil_image_view_base_sptr";
00071 pro.set_output_types(out_types);
00072 return true;
00073 }
00074
00075
00076 bool bbgm_display_dist_image_process(bprb_func_process& pro)
00077 {
00078
00079 if (!pro.verify_inputs()){
00080 vcl_cerr << "In bbgm_display_dist_image_process::execute() -"
00081 << " invalid inputs\n";
00082 return false;
00083 }
00084
00085
00086 bbgm_image_sptr bgm = pro.get_input<bbgm_image_sptr>(0);
00087 if (!bgm){
00088 vcl_cerr << "In bbgm_display_dist_image_process::execute() -"
00089 << " null distribution image\n";
00090 return false;
00091 }
00092
00093
00094 vcl_string attr = pro.get_input<vcl_string>(1);
00095
00096
00097 int comp_index = pro.get_input<int>(2);
00098
00099
00100 bool scale = pro.get_input<bool>(3);
00101
00102 vcl_vector<vcl_string> output_types(1);
00103 output_types[0]= "vil_image_view_base_sptr";
00104 pro.set_output_types(output_types);
00105
00106 bbgm_viewer_sptr viewer;
00107 if (attr=="mean") {
00108 viewer = new bbgm_mean_viewer();
00109 register_mean_viewers();
00110 }
00111 else if (attr == "variance"||attr == "std_dev") {
00112 viewer = new bbgm_variance_viewer();
00113 register_variance_viewers();
00114 }
00115 else if (attr == "weight") {
00116 viewer = new bbgm_weight_viewer();
00117 register_weight_viewers();
00118 }
00119 else {
00120 vcl_cout << "In bbgm_display_dist_image_process::execute() -"
00121 << " display attribute not available\n";
00122 return false;
00123 }
00124 if (!viewer->probe(bgm)){
00125 vcl_cout << "In bbgm_display_dist_image_process::execute() -"
00126 << " displayer cannot process distribution image type\n"
00127 << bgm->is_a() << '\n';
00128 return false;
00129 }
00130 viewer->set_active_component(comp_index);
00131 vil_image_view<double> d_image;
00132 if (!viewer->apply(bgm, d_image)){
00133 vcl_cout << "In bbgm_display_dist_image_process::execute() -"
00134 << " extract view (apply) failed\n";
00135 return false;
00136 }
00137 brdb_value_sptr output0;
00138
00139 vil_image_view<vxl_byte> byte_image;
00140 if (attr == "variance"||attr == "std_dev"){
00141 if (attr == "std_dev") vil_math_sqrt(d_image);
00142 if (scale){
00143 double dmin, dmax;
00144 vil_math_value_range(d_image, dmin, dmax);
00145 vil_convert_stretch_range_limited(d_image, byte_image, dmin, dmax);
00146 output0 =
00147 new brdb_value_t<vil_image_view_base_sptr>(new vil_image_view<vxl_byte>(byte_image));
00148 }
00149 else{
00150 vil_image_view<float> fimg;
00151 vil_convert_cast(d_image, fimg);
00152 output0 =
00153 new brdb_value_t<vil_image_view_base_sptr>(new vil_image_view<float>(fimg));
00154 }
00155 }
00156 else if (scale){
00157 vil_convert_stretch_range_limited(d_image, byte_image, 0.0, 1.0);
00158 output0 =
00159 new brdb_value_t<vil_image_view_base_sptr>(new vil_image_view<vxl_byte>(byte_image));
00160 }
00161 else{
00162 vil_image_view<float> fimg;
00163 vil_convert_cast(d_image, fimg);
00164 output0 =
00165 new brdb_value_t<vil_image_view_base_sptr>(new vil_image_view<float>(fimg));
00166 }
00167 pro.set_output(0, output0);
00168 return true;
00169 }
00170