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_parzen_sphere.h>
00011 #include <bsta/io/bsta_io_parzen_sphere.h>
00012 #include <bsta/algo/bsta_parzen_updater.h>
00013 #include <brdb/brdb_value.h>
00014 #include <vbl/io/vbl_io_smart_ptr.h>
00015 #include <vil/vil_image_view.h>
00016 #include <vil/vil_convert.h>
00017 #include <vil/vil_math.h>
00018
00019
00020 bool bbgm_update_parzen_dist_image_process_cons(bprb_func_process& pro)
00021 {
00022
00023 vcl_vector<vcl_string> in_types(5), out_types(1);
00024 in_types[0]= "bbgm_image_sptr";
00025 in_types[1]= "vil_image_view_base_sptr";
00026 in_types[2]= "float";
00027 in_types[3]= "int";
00028 in_types[4]= "float";
00029 pro.set_input_types(in_types);
00030
00031
00032 out_types[0]="bbgm_image_sptr";
00033 pro.set_output_types(out_types);
00034 return true;
00035 }
00036
00037
00038 bool bbgm_update_parzen_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_parzen_dist_image_process(bprb_func_process& pro)
00046 {
00047
00048 if (pro.verify_inputs()){
00049 vcl_cerr << "In bbgm_update_parzen_dist_image_process::execute() -"
00050 << " invalid inputs\n";
00051 return false;
00052 }
00053
00054 bbgm_image_sptr bgm = pro.get_input<bbgm_image_sptr>(0);
00055
00056
00057 vil_image_view_base_sptr update_image =
00058 pro.get_input<vil_image_view_base_sptr>(1);
00059
00060 vil_image_view<float> img = *vil_convert_cast(float(), update_image);
00061 if (update_image->pixel_format() == VIL_PIXEL_FORMAT_BYTE)
00062 vil_math_scale_values(img,1.0/255.0);
00063
00064 unsigned ni = img.ni();
00065 unsigned nj = img.nj();
00066 unsigned np = img.nplanes();
00067
00068
00069 float bandwidth = pro.get_input<float>(2);
00070
00071
00072 unsigned max_samples = pro.get_input<unsigned>(3);
00073
00074 float tol = pro.get_input<float>(4);
00075
00076 if(np!=3)
00077 {
00078 vcl_cout << "Parzen update only implemented for color\n";
00079 return false;
00080 }
00081
00082 typedef bsta_parzen_sphere<float,3> parzen_f3_t;
00083
00084
00085 bbgm_image_sptr model_sptr;
00086 if (!bgm) {
00087 parzen_f3_t par;
00088 par.set_bandwidth(bandwidth);
00089 model_sptr = new bbgm_image_of<parzen_f3_t>(ni,nj,par);
00090 }
00091 else model_sptr = bgm;
00092 bbgm_image_of<parzen_f3_t> *model =
00093 static_cast<bbgm_image_of<parzen_f3_t>*>(model_sptr.ptr());
00094
00095 float frac_back = 0.5f;
00096 bsta_parzen_adapt_bw_updater<parzen_f3_t> updater(tol*bandwidth, max_samples,
00097 frac_back);
00098
00099 update(*model,img,updater);
00100
00101 brdb_value_sptr output = new brdb_value_t<bbgm_image_sptr>(model);
00102 pro.set_output(0, output);
00103 return true;
00104 }
00105