contrib/brl/bseg/sdet/sdet_texture_classifier_params.cxx
Go to the documentation of this file.
00001 // This is brl/bseg/sdet/sdet_texture_classifier_params.cxx
00002 #include "sdet_texture_classifier_params.h"
00003 //:
00004 // \file
00005 // See sdet_texture_classifier_params.h
00006 //
00007 //-----------------------------------------------------------------------------
00008 #include <vcl_sstream.h>
00009 #include <vcl_iostream.h>
00010 
00011 //------------------------------------------------------------------------
00012 // Constructors
00013 //
00014 sdet_texture_classifier_params::sdet_texture_classifier_params():
00015   n_scales_(3), scale_interval_(45.0f), angle_interval_(30.0f)
00016   {
00017     lambda0_=4.0f;  lambda1_=1.6f; //was 3.0/1.2
00018     laplace_radius_ = 1.5f;
00019     gauss_radius_ = 1.5f;
00020     cutoff_per_ = 0.01f;
00021     signed_response_ = true;
00022     mag_ = false;
00023     fast_ = true;
00024     k_ = 100;
00025     n_samples_ = 200000;
00026     block_size_ = 64;
00027     weight_offset_ = 0.01f;
00028   }
00029 
00030 sdet_texture_classifier_params::
00031 sdet_texture_classifier_params(const sdet_texture_classifier_params& dmp)
00032   : gevd_param_mixin()
00033 {
00034   InitParams(dmp.n_scales_, dmp.scale_interval_, dmp.angle_interval_,
00035              dmp.lambda0_, dmp.lambda1_,dmp.laplace_radius_,
00036              dmp.gauss_radius_,dmp.cutoff_per_, dmp.signed_response_,
00037              dmp.mag_, dmp.fast_, dmp.k_, dmp.n_samples_, dmp.block_size_,
00038              dmp.weight_offset_);
00039 }
00040 
00041 sdet_texture_classifier_params::
00042 sdet_texture_classifier_params(unsigned n_scales,
00043                                float scale_interval,
00044                                float angle_interval,
00045                                float lambda0,
00046                                float lambda1,
00047                                float laplace_radius, 
00048                                float gauss_radius, 
00049                                float cutoff_per,
00050                                bool signed_response,
00051                                bool mag,
00052                                bool fast,
00053                                unsigned k,
00054                                unsigned n_samples,
00055                                unsigned block_size,
00056                                float weight_offset
00057                                )
00058 {
00059   InitParams(n_scales, angle_interval,scale_interval, 
00060              lambda0, lambda1, laplace_radius, gauss_radius,
00061              cutoff_per, signed_response, mag, fast, k, n_samples,
00062              block_size, weight_offset);
00063 }
00064 
00065 void sdet_texture_classifier_params::
00066 InitParams(unsigned n_scales, float scale_interval, float angle_interval,
00067            float lambda0, float lambda1,
00068            float laplace_radius, float gauss_radius, 
00069            float cutoff_per, bool signed_response,
00070            bool mag, bool fast, unsigned k, unsigned n_samples,
00071            unsigned block_size,
00072            float weight_offset)
00073 {
00074   n_scales_ = n_scales;
00075   scale_interval_ = scale_interval;
00076   angle_interval_ = angle_interval;
00077   lambda0_ = lambda0;
00078   lambda1_ = lambda1;
00079   laplace_radius_ = laplace_radius;
00080   gauss_radius_ = gauss_radius;
00081   cutoff_per_ = cutoff_per;
00082   signed_response_ = signed_response;
00083   mag_ = mag;
00084   fast_ = fast;
00085   k_ = k;
00086   n_samples_ = n_samples;
00087   block_size_ = block_size;
00088   weight_offset_ =   weight_offset;
00089 }
00090 
00091 //-----------------------------------------------------------------------------
00092 //
00093 //:   Checks that parameters are within acceptable bounds
00094 bool sdet_texture_classifier_params::SanityCheck()
00095 {
00096   //  Note that msg << ends seems to restart the string and erase the
00097   //  previous string. We should only use it as the last call, use
00098   //  vcl_endl otherwise.
00099   vcl_stringstream msg;
00100   bool valid = true;
00101 
00102   if (n_scales_ < 3)
00103     {
00104       msg << "ERROR: at least 3 filters are needed!\n";
00105       valid = false;
00106     }
00107   if(mag_&&signed_response_){
00108       msg << "ERROR: can't have both abs mag and signed responses!\n";
00109       valid = false;
00110     }
00111 
00112 
00113   msg << vcl_ends;
00114 
00115   SetErrorMsg(msg.str().c_str());
00116   return valid;
00117 }
00118 
00119 vcl_ostream& operator << (vcl_ostream& os, const sdet_texture_classifier_params& dmp)
00120 {
00121   os << "sdet_texture_classifier_params:\n[---\n"
00122      << "n scales " << dmp.n_scales_ << " scale interval " 
00123      << dmp.scale_interval_ << '\n'
00124      << "angle interval " << dmp.angle_interval_ << '\n'
00125      << "lambda0 " << dmp.lambda0_ << " lambda1 " << dmp.lambda1_ << '\n';
00126   os << "laplace lambda " << dmp.laplace_radius_ << '\n';
00127   os << "gauss lambda " << dmp.gauss_radius_ << '\n';
00128   os << "gauss cutoff thresh " << dmp.cutoff_per_ << '\n';
00129   os << "signed response " << dmp.signed_response_ << '\n';
00130   os << "magnitude " << dmp.mag_ << '\n';
00131   os << "fast " << dmp.fast_ << '\n';
00132   os << "k " << dmp.k_ << '\n';
00133   os << "n_samples " << dmp.n_samples_ << '\n';
00134   os << "block size " << dmp.block_size_ << '\n';
00135   os << "weight offset " << dmp.weight_offset_ << '\n';
00136   os << "---]\n";
00137   return os;
00138 }
00139 //: Binary save vgl_point_2d to stream.
00140 void vsl_b_write(vsl_b_ostream &os, 
00141                  const sdet_texture_classifier_params & tcp)
00142 {
00143   sdet_texture_classifier_params& tcpnc = 
00144     const_cast<sdet_texture_classifier_params&>(tcp);
00145   vsl_b_write(os,tcpnc.n_scales_);
00146   vsl_b_write(os,tcpnc.scale_interval_);
00147   vsl_b_write(os,tcpnc.angle_interval_);
00148   vsl_b_write(os,tcpnc.lambda0_);
00149   vsl_b_write(os,tcpnc.lambda1_);
00150   vsl_b_write(os,tcpnc.laplace_radius_);
00151   vsl_b_write(os,tcpnc.gauss_radius_);
00152   vsl_b_write(os,tcpnc.cutoff_per_);
00153   vsl_b_write(os,tcpnc.signed_response_);
00154   vsl_b_write(os,tcpnc.mag_);
00155   vsl_b_write(os,tcpnc.fast_);
00156   vsl_b_write(os,tcpnc.k_);
00157   vsl_b_write(os,tcpnc.n_samples_);
00158   vsl_b_write(os,tcpnc.block_size_);
00159   vsl_b_write(os,tcpnc.weight_offset_);
00160 }
00161 
00162 //: Binary load vgl_point_2d from stream.
00163 void vsl_b_read(vsl_b_istream &is, sdet_texture_classifier_params & tcp)
00164 {
00165   vsl_b_read(is,tcp.n_scales_);
00166   vsl_b_read(is,tcp.scale_interval_);
00167   vsl_b_read(is,tcp.angle_interval_);
00168   vsl_b_read(is,tcp.lambda0_);
00169   vsl_b_read(is,tcp.lambda1_);
00170   vsl_b_read(is,tcp.laplace_radius_);
00171   vsl_b_read(is,tcp.gauss_radius_);
00172   vsl_b_read(is,tcp.cutoff_per_);
00173   vsl_b_read(is,tcp.signed_response_);
00174   vsl_b_read(is,tcp.mag_);
00175   vsl_b_read(is,tcp.fast_);
00176   vsl_b_read(is,tcp.k_);
00177   vsl_b_read(is,tcp.n_samples_);
00178   vsl_b_read(is,tcp.block_size_);
00179   vsl_b_read(is,tcp.weight_offset_);
00180 }
00181 //: Print human readable summary of object to a stream
00182 void vsl_print_summary(vcl_ostream& os,
00183                        const sdet_texture_classifier_params & tcp)
00184 {
00185   os << tcp; 
00186 }