00001
00002 #ifndef bbgm_measure_h_
00003 #define bbgm_measure_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vcl_cassert.h>
00016 #include <vil/vil_image_view.h>
00017 #include <vbl/vbl_array_2d.h>
00018 #include "bbgm_image_of.h"
00019 #include "bbgm_planes_to_sample.h"
00020
00021
00022
00023
00024
00025 template <class dist_, class measure_functor_>
00026 void measure(bbgm_image_of<dist_>& dimg,
00027 const vil_image_view<typename dist_::math_type>& image,
00028 vil_image_view<typename dist_::math_type>& result,
00029 const measure_functor_& prop,
00030 typename dist_::math_type delta)
00031 {
00032 typedef typename dist_::vector_type vector_;
00033 typedef typename dist_::math_type T;
00034
00035 const unsigned ni = dimg.ni();
00036 const unsigned nj = dimg.nj();
00037 const unsigned d_np = dist_::dimension;
00038
00039 assert(image.ni() == ni);
00040 assert(image.nj() == nj);
00041 assert(image.nplanes() == d_np);
00042
00043 result.set_size(ni,nj,1);
00044
00045 const vcl_ptrdiff_t pstep = image.planestep();
00046
00047 vector_ del(delta);
00048 typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00049 for ( unsigned j=0; j<nj; ++j)
00050 for ( unsigned i=0; i<ni; ++i, ++itr) {
00051 vector_ sample;
00052 const T* iptr = &image(i,j);
00053 bbgm_planes_to_sample<T, vector_, d_np>::apply(iptr, sample, pstep);
00054 T temp_val;
00055 vector_ r_min = sample-del, r_max = sample+del;
00056 prop(*itr, r_min, r_max, temp_val);
00057 result(i,j) = temp_val;
00058 }
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 template <class dist_, class measure_functor_>
00071 void measure_bkground(bbgm_image_of<dist_>& dimg,
00072 const vil_image_view<typename dist_::math_type>& image,
00073 vil_image_view<typename dist_::math_type>& result,
00074 const measure_functor_& prop,
00075 typename dist_::math_type pf)
00076 {
00077 typedef typename dist_::vector_type vector_;
00078 typedef typename dist_::math_type T;
00079
00080 const unsigned ni = dimg.ni();
00081 const unsigned nj = dimg.nj();
00082 const unsigned d_np = dist_::dimension;
00083
00084 assert(image.ni() == ni);
00085 assert(image.nj() == nj);
00086 assert(image.nplanes() == d_np);
00087
00088 result.set_size(ni,nj,1);
00089
00090 const vcl_ptrdiff_t pstep = image.planestep();
00091
00092 typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00093 for ( unsigned j=0; j<nj; ++j)
00094 for ( unsigned i=0; i<ni; ++i, ++itr) {
00095 vector_ sample;
00096 const T* iptr = &image(i,j);
00097 bbgm_planes_to_sample<T, vector_, d_np>::apply(iptr, sample, pstep);
00098 T temp_val;
00099 prop(*itr, sample, temp_val);
00100 temp_val = temp_val*(T(1)-pf);
00101 temp_val = (temp_val)/(temp_val + pf);
00102 result(i,j) = temp_val;
00103 }
00104 }
00105
00106
00107
00108
00109
00110
00111 template <class dist_, class measure_functor_>
00112 void measure(bbgm_image_of<dist_>& dimg,
00113 const vil_image_view<typename dist_::math_type>& image,
00114 vil_image_view<typename dist_::math_type>& var,
00115 vil_image_view<typename dist_::math_type>& result,
00116 const measure_functor_& prop,
00117 typename dist_::math_type delta)
00118 {
00119 typedef typename dist_::vector_type vector_;
00120 typedef typename dist_::math_type T;
00121
00122 const unsigned ni = dimg.ni();
00123 const unsigned nj = dimg.nj();
00124 const unsigned d_np = dist_::dimension;
00125
00126 assert(image.ni() == ni);
00127 assert(image.nj() == nj);
00128 assert(image.nplanes() == d_np);
00129
00130 result.set_size(ni,nj,1);
00131
00132 const vcl_ptrdiff_t pstep = image.planestep();
00133
00134 vector_ sample;
00135 typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00136 for ( unsigned j=0; j<nj; ++j)
00137 for ( unsigned i=0; i<ni; ++i, ++itr) {
00138 vector_ sample, var_val;
00139 const T* iptr = &image(i,j);
00140 bbgm_planes_to_sample<T, vector_, d_np>::apply(iptr, sample, pstep);
00141 const T* vptr = &var(i,j);
00142 bbgm_planes_to_sample<T, vector_, d_np>::apply(vptr, var_val, pstep);
00143 T temp_val;
00144 vector_ r_min = sample-delta-var_val, r_max = sample+delta+var_val;
00145 prop(*itr, r_min, r_max, temp_val);
00146 result(i,j) = temp_val;
00147 }
00148 }
00149
00150
00151
00152
00153
00154
00155 template <class dist_, class measure_functor_>
00156 void measure(bbgm_image_of<dist_>& dimg,
00157 const vil_image_view<typename dist_::math_type>& image,
00158 const vbl_array_2d<typename dist_::dist_type::covar_type> & covar,
00159 vil_image_view<typename dist_::math_type>& result,
00160 const measure_functor_& prop,
00161 const typename dist_::math_type delta)
00162 {
00163 typedef typename dist_::vector_type vector_;
00164 typedef typename dist_::math_type T;
00165 typedef typename dist_::dist_type::covar_type covar_t;
00166 const unsigned ni = dimg.ni();
00167 const unsigned nj = dimg.nj();
00168 const unsigned d_np = dist_::dimension;
00169
00170 assert(image.ni() == ni);
00171 assert(image.nj() == nj);
00172 assert(image.nplanes() == d_np);
00173
00174 result.set_size(ni,nj,1);
00175
00176 const vcl_ptrdiff_t pstep = image.planestep();
00177
00178 vector_ sample;
00179 vector_ del(delta);
00180 typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00181 for ( unsigned j=0; j<nj; ++j)
00182 for ( unsigned i=0; i<ni; ++i, ++itr) {
00183 vector_ sample;
00184 const T* iptr = &image(i,j);
00185 bbgm_planes_to_sample<T, vector_, d_np>::apply(iptr, sample, pstep);
00186 T temp_val;
00187 vector_ r_min = sample-del, r_max = sample+del;
00188 covar_t add_cov = covar[j][i];
00189 prop(*itr, r_min, r_max, add_cov, temp_val);
00190 result(i,j) = temp_val;
00191 }
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201 template <class dist_, class measure_functor_>
00202 void measure(bbgm_image_of<dist_>& dimg,
00203 vil_image_view<typename dist_::math_type>& result,
00204 const measure_functor_& prop,
00205 typename dist_::vector_type min_value,
00206 typename dist_::vector_type max_value)
00207 {
00208 typedef typename dist_::vector_type vector_;
00209 typedef typename dist_::math_type T;
00210
00211 const unsigned ni = dimg.ni();
00212 const unsigned nj = dimg.nj();
00213
00214 result.set_size(ni,nj,1);
00215
00216 typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00217 for ( unsigned j=0; j<nj; ++j)
00218 for ( unsigned i=0; i<ni; ++i, ++itr) {
00219 T temp_val;
00220 prop(*itr, min_value, max_value, temp_val);
00221 result(i,j) = temp_val;
00222 }
00223 }
00224
00225 #endif // bbgm_measure_h_