Go to the documentation of this file.00001
00002
00003
00004 #include <bprb/bprb_func_process.h>
00005 #include <vcl_iostream.h>
00006 #include <bbgm/bbgm_image_of.h>
00007 #include <bbgm/bbgm_image_sptr.h>
00008 #include <bbgm/bbgm_update.h>
00009 #include <bsta/bsta_attributes.h>
00010 #include <bsta/bsta_gauss_if3.h>
00011 #include <bsta/bsta_gauss_sf1.h>
00012 #include <bsta/bsta_mixture.h>
00013 #include <bsta/algo/bsta_adaptive_updater.h>
00014 #include <brdb/brdb_value.h>
00015 #include <vbl/io/vbl_io_smart_ptr.h>
00016 #include <vil/vil_image_view.h>
00017 #include <vil/vil_convert.h>
00018 #include <vil/vil_math.h>
00019
00020
00021 bool bbgm_update_dist_image_process_cons(bprb_func_process& pro)
00022 {
00023 vcl_vector<vcl_string> in_types(7), out_types(1);
00024 in_types[0] = "bbgm_image_sptr";
00025 in_types[1]= "vil_image_view_base_sptr";
00026 in_types[2]= "int";
00027 in_types[3]= "int";
00028 in_types[4]= "float";
00029 in_types[5]= "float";
00030 in_types[6]= "float";
00031 pro.set_input_types(in_types);
00032 out_types[0]= "bbgm_image_sptr";
00033 pro.set_output_types(out_types);
00034 pro.set_input(0, brdb_value_sptr(new brdb_value_t<bbgm_image_sptr>(0)));
00035 return true;
00036 }
00037
00038 bool bbgm_update_dist_image_process_init(bprb_func_process& pro)
00039 {
00040 pro.set_input(0, new brdb_value_t<bbgm_image_sptr>(0));
00041 return true;
00042 }
00043
00044
00045 bool bbgm_update_dist_image_process(bprb_func_process& pro)
00046 {
00047
00048 if (!pro.verify_inputs()){
00049 vcl_cerr << "In bbgm_update_dist_image_process::execute() -"
00050 << " invalid inputs\n";
00051 return false;
00052 }
00053
00054
00055 bbgm_image_sptr bgm = pro.get_input<bbgm_image_sptr>(0);
00056
00057
00058 vil_image_view_base_sptr update_image =
00059 pro.get_input<vil_image_view_base_sptr>(1);
00060
00061
00062 int max_components = pro.get_input<int>(2);
00063
00064
00065 int window_size = pro.get_input<int>(3);
00066
00067
00068 float initial_variance = pro.get_input<float>(4);
00069
00070
00071 float g_thresh = pro.get_input<float>(5);
00072
00073
00074 float min_stdev = pro.get_input<float>(6);
00075
00076
00077 vil_image_view<float> img = *vil_convert_cast(float(), update_image);
00078 if (update_image->pixel_format() == VIL_PIXEL_FORMAT_BYTE)
00079 vil_math_scale_values(img,1.0/255.0);
00080
00081 unsigned ni = img.ni();
00082 unsigned nj = img.nj();
00083 unsigned np = img.nplanes();
00084
00085 if (np ==1){
00086 typedef bsta_gauss_sf1 bsta_gauss1_t;
00087 typedef bsta_num_obs<bsta_gauss1_t> gauss_type1;
00088 typedef bsta_mixture<gauss_type1> mix_gauss_type1;
00089 typedef bsta_num_obs<mix_gauss_type1> obs_mix_gauss_type1;
00090
00091 bbgm_image_sptr model_sptr;
00092 if (!bgm) {
00093 model_sptr = new bbgm_image_of<obs_mix_gauss_type1>(ni,nj, obs_mix_gauss_type1());
00094 }
00095 else model_sptr = bgm;
00096 bbgm_image_of<obs_mix_gauss_type1> *model =
00097 static_cast<bbgm_image_of<obs_mix_gauss_type1>*>(model_sptr.ptr());
00098
00099 bsta_gauss1_t init_gauss(0, initial_variance);
00100
00101 bsta_mg_grimson_window_updater<mix_gauss_type1> updater(init_gauss,
00102 max_components,
00103 g_thresh,
00104 min_stdev,
00105 window_size);
00106
00107 update(*model,img,updater);
00108
00109 brdb_value_sptr output = new brdb_value_t<bbgm_image_sptr>(model);
00110 pro.set_output(0, output);
00111 return true;
00112 }
00113 if (np ==3)
00114 {
00115 typedef bsta_gauss_if3 bsta_gauss3_t;
00116 typedef bsta_gauss3_t::vector_type vector3_;
00117 typedef bsta_num_obs<bsta_gauss3_t> gauss_type3;
00118 typedef bsta_mixture<gauss_type3> mix_gauss_type3;
00119 typedef bsta_num_obs<mix_gauss_type3> obs_mix_gauss_type3;
00120
00121 bbgm_image_sptr model_sptr;
00122 if (!bgm) {
00123 model_sptr = new bbgm_image_of<obs_mix_gauss_type3>(ni,nj, obs_mix_gauss_type3());
00124 }
00125 else model_sptr = bgm;
00126 bbgm_image_of<obs_mix_gauss_type3> *model =
00127 static_cast<bbgm_image_of<obs_mix_gauss_type3>*>(model_sptr.ptr());
00128
00129 vector3_ mean, var;
00130 mean.fill(0.0f); var.fill(initial_variance);
00131 bsta_gauss3_t init_gauss(mean, var);
00132
00133 bsta_mg_grimson_window_updater<mix_gauss_type3> updater(init_gauss,
00134 max_components,
00135 g_thresh,
00136 min_stdev,
00137 window_size);
00138
00139 update(*model,img,updater);
00140
00141 brdb_value_sptr output = new brdb_value_t<bbgm_image_sptr>(model);
00142 pro.set_output(0, output);
00143 return true;
00144 }
00145 return false;
00146 }
00147