The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPColorFeatSearch Struct Reference

#include <colorfeatsearch.h>

Collaboration diagram for MPColorFeatSearch:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void addBoxCorners (TIntegral< double > &ii, const double i, const double j, const double size, const double val)
double getBoxSum (const TIntegral< double > &ii, const double i, const double j, const double size)
void initPyramids (int imageWidth, int imageHeight, double scaleUpPct, double minSizePct, int minScaleUp, double shiftPct, int minStride)
 MPColorFeatSearch ()
double searchFeature (TIntegral< double > &sumlikrat, double liknorm, TBox< double > &besthyp, int scaledev, double hr, double shiftPct, double scaleUpPct, double minSizePct, int minScaleUp, int minStride)
void zeroPyramids ()

Public Attributes

ScalePyramid m_priors1
ScalePyramid m_priors2
ScalePyramidm_priors_t
ScalePyramidm_priors_tnew
bool m_recycle

Constructor & Destructor Documentation

MPColorFeatSearch  )  [inline]
 

Definition at line 15 of file colorfeatsearch.h.

00015 {};


Member Function Documentation

void addBoxCorners TIntegral< double > &  ii,
const double  i,
const double  j,
const double  size,
const double  val
 

Definition at line 351 of file colorfeatsearch.cpp.

References ASSERT, TIntegral::getImHeight(), TIntegral::getImWidth(), TIntegral::getIntPixel(), max, min(), and TIntegral::setIntPixel().

Referenced by searchFeature().

00351                                                                                                                                 {        
00352         int a = static_cast<int>(i);
00353         int b = static_cast<int>(j);
00354         
00355         int numx = ii.getImWidth();
00356         int numy = ii.getImHeight();
00357         int a0 =  max(a,0);
00358         int b0 =  max(b,0);
00359         ASSERT(a0 < numx/*+1*/ && b0 < numy/*+1*/);
00360         int a1 = min(a + size, numx/*+1*/); 
00361         int b1 = min(b + size, numy/*+1*/); 
00362         ASSERT(a1 > 0 && b1 > 0);
00363         ii.setIntPixel(a0, b0, val + ii.getIntPixel(a0, b0));
00364         ii.setIntPixel(a1, b0, -val + ii.getIntPixel(a1, b0));
00365         ii.setIntPixel(a0, b1, -val + ii.getIntPixel(a0, b1));
00366         ii.setIntPixel(a1, b1, val + ii.getIntPixel(a1, b1));
00367 
00368 //      int numx = ii.getImWidth();
00369 //      int numy = ii.getImHeight();
00370 //      ASSERT(a0 < numx && b0 < numy);
00371 //      int a1 = min(a0 + size, numx); 
00372 //      int b1 = min(b0 + size, numy); 
00373 }

Here is the call graph for this function:

double getBoxSum const TIntegral< double > &  ii,
const double  i,
const double  j,
const double  size
 

Definition at line 377 of file colorfeatsearch.cpp.

References ASSERT, TIntegral::getIntHeight(), TIntegral::getIntPixel(), TIntegral::getIntWidth(), max, and min().

Referenced by searchFeature().

00377                                                                                                                   {        
00378         int a = static_cast<int>(i);
00379         int b = static_cast<int>(j);
00380         
00381         const int numx = ii.getIntWidth();
00382         const int numy = ii.getIntHeight();
00383         const int a0 =  max(a,0);
00384         const int b0 =  max(b,0);
00385         ASSERT(a0 < numx && b0 < numy);
00386         const int a1 = min(a + size, numx); 
00387         const int b1 = min(b + size, numy);     
00388         ASSERT(a1 > 0 && b1 > 0);
00389         return( ii.getIntPixel(a0, b0) - ii.getIntPixel(a1, b0) - ii.getIntPixel(a0, b1) + ii.getIntPixel(a1, b1) );
00390 }

Here is the call graph for this function:

void initPyramids int  imageWidth,
int  imageHeight,
double  scaleUpPct,
double  minSizePct,
int  minScaleUp,
double  shiftPct,
int  minStride
 

Definition at line 15 of file colorfeatsearch.cpp.

References ScalePyramid::compute_scales(), ScalePyramid::initPyramid(), m_priors1, m_priors2, m_recycle, and ScalePyramid::set_imagedims().

Referenced by main().

00016 { 
00017         /* create pyramids of posterior images per scale */
00018         m_priors1.set_imagedims(imageWidth, imageHeight);
00019         m_priors2.set_imagedims(imageWidth, imageHeight);
00020         m_priors1.compute_scales(scaleUpPct, minSizePct*imageWidth, minScaleUp);
00021         m_priors1.initPyramid(shiftPct, minStride);
00022         m_priors2.compute_scales(scaleUpPct, minSizePct*imageWidth, minScaleUp);
00023         m_priors2.initPyramid(shiftPct, minStride);
00024         
00025         m_recycle = false;      
00026 }

Here is the call graph for this function:

double searchFeature TIntegral< double > &  sumlikrat,
double  liknorm,
TBox< double > &  besthyp,
int  scaledev,
double  hr,
double  shiftPct,
double  scaleUpPct,
double  minSizePct,
int  minScaleUp,
int  minStride
 

Definition at line 39 of file colorfeatsearch.cpp.

References addBoxCorners(), ScalePyramid::copy(), ScalePyramid::get_hypothesesPerScale(), UniformWindow::get_location_window(), ScalePyramid::get_numhyp(), ScalePyramid::get_numScales(), TImage::getArray(), getBoxSum(), TIntegral::getImHeight(), TIntegral::getImPixel(), TIntegral::getImWidth(), TIntegral::getIntNumPix(), TIntegral::getIntPixel(), i, TIntegral::integrate(), UniformWindow::is_validscale(), HypothesesPerScale::m_intimage, HypothesesPerScale::m_intones, HypothesesPerScale::m_numX, HypothesesPerScale::m_numY, m_priors_t, m_priors_tnew, m_recycle, HypothesesPerScale::m_scale, ScalePyramid::makezero(), max, min(), TIntegral::printIntBin(), TBox::scale, UniformWindow::set_scalebounds(), TBox::size, sprintf(), TBox::x, and TBox::y.

Referenced by main().

00039                                                                                                                                                                                                                           {
00040         int imageWidth = sumlikrat.getImWidth();
00041         int imageHeight = sumlikrat.getImHeight();
00042 
00043         static const double minlog = -500;
00044 
00045         /* swap the image pyramids after every frame instead of having to reallocate (reset) each time */
00046         if (m_recycle) {
00047                 m_priors_t = &m_priors1;
00048                 m_priors_tnew = &m_priors2;
00049                 m_recycle = false;
00050         } else {
00051                 m_priors_t = &m_priors2;
00052                 m_priors_tnew = &m_priors1;
00053                 m_recycle = true;
00054         }       
00055         
00056         static double priorsum = 1.0;
00057         double postsum = 0;
00058 
00059         int numscales = m_priors_t->get_numScales();
00060 
00061         UniformWindow window(scaledev, numscales);
00062 
00063         m_priors_tnew->makezero();
00064         int numhyp = m_priors_t->get_numhyp();
00065         
00066         double prevPostT = minlog;
00067         static double maxLogPostT = minlog;
00068 
00069         int scaleind;
00070         
00071         /* fix this, needs to be shiftPct*scale */
00072         double shift = (shiftPct > minStride) ? shiftPct : minStride;
00073         
00074         double unboost = 1.0/1.0;
00075         static int frames = 0;
00076         
00077         double oneoverpriorsum = 1.0/priorsum;
00078 
00079         /* this loop determines the max log posterior hypothesis 
00080                  in order to offset logpost values to be in range of exp function */
00081         for (scaleind=0; scaleind < numscales; scaleind++) {
00082                 HypothesesPerScale &scaleptr_t = m_priors_t->get_hypothesesPerScale(scaleind);
00083                 double &scale_t = scaleptr_t.m_scale;
00084 
00085                 for (int j=0; j < scaleptr_t.m_numY; j++) {
00086                         for (int i=0; i < scaleptr_t.m_numX; i++) {
00087                                 double prior_t = 0;
00088                                 if (frames == 0) prior_t = scaleptr_t.m_intimage.getImPixel(i, j);
00089                                 else prior_t = scaleptr_t.m_intimage.getIntPixel(i, j);
00090 
00091                                 prior_t *= oneoverpriorsum;
00092                                 /* fix this, needs to be shiftPct*scale */
00093                                 double shift = (shiftPct > minStride) ? shiftPct : minStride;
00094  
00095                                 int h_x = i * shift;
00096                                 int h_y = j * shift;
00097 
00098                                 /* get the likelihood ratio for hypothesis h at time t */
00099 #ifdef  SPIKETEST
00100 #ifdef  ONESPIKE
00101                                 double loglikrat = -50;
00102                                 if (frames == 0 && scaleind == numscales/2
00103                                                                                                 && i == scaleptr_t.m_numX/2 && j == scaleptr_t.m_numY/2)
00104                                         loglikrat = 50;
00105 #else           ONESPIKE
00106                                 double loglikrat = -50;
00107                                 if (frames == 0) {
00108                                         double alpha = -2.0;
00109                                         if (scaleind == 4 && i == 6 && j == 6) {
00110                                                 int numh = scale_t*scale_t;
00111                                                 loglikrat = alpha * numh;
00112                                         } else if (scaleind == 6 && i == 12 && j == 12) {
00113                                                 int numh = scale_t*scale_t;
00114                                                 loglikrat = alpha * numh;       
00115                                         }
00116                                 }
00117 #endif  ONESPIKE
00118 #else           SPIKETEST
00119                                 //unboost = 1/(scale_t*scale_t)
00120                                 double loglikrat = getBoxSum(sumlikrat, h_x, h_y, scale_t)*unboost;                             
00121 #endif  SPIKETEST
00122 
00123                                 double logprior_t = log(prior_t);
00124                                 double logpost_t = loglikrat + logprior_t;
00125                                 
00126                                 /* max code */
00127                                 if (logpost_t >= maxLogPostT) maxLogPostT = logpost_t;
00128                         }
00129                 }
00130         }
00131 
00132         /* this loop determines the normalizing constant for the posterior */
00133         for (scaleind=0; scaleind < numscales; scaleind++) {
00134                 HypothesesPerScale &scaleptr_t = m_priors_t->get_hypothesesPerScale(scaleind);
00135                 double &scale_t = scaleptr_t.m_scale;
00136 
00137                 for (int j=0; j < scaleptr_t.m_numY; j++) {
00138                         for (int i=0; i < scaleptr_t.m_numX; i++) {
00139                                 double prior_t = 0;
00140                                 if (frames == 0) prior_t = scaleptr_t.m_intimage.getImPixel(i, j);
00141                                 else prior_t = scaleptr_t.m_intimage.getIntPixel(i, j);
00142 
00143                                 prior_t *= oneoverpriorsum;
00144                                 /* fix this, needs to be shiftPct*scale */
00145                                 double shift = (shiftPct > minStride) ? shiftPct : minStride;
00146  
00147                                 int h_x = i * shift;
00148                                 int h_y = j * shift;
00149 
00150                                 /* get the likelihood ratio for hypothesis h at time t */
00151 #ifdef  SPIKETEST
00152 #ifdef  ONESPIKE
00153                                 double loglikrat = -50;
00154                                 if (frames == 0 && scaleind == numscales/2
00155                                                                                                 && i == scaleptr_t.m_numX/2 && j == scaleptr_t.m_numY/2)
00156                                         loglikrat = 50;
00157 #else           ONESPIKE
00158                                 double loglikrat = -50;
00159                                 if (frames == 0) {
00160                                         double alpha = -2.0;
00161                                         if (scaleind == 4 && i == 6 && j == 6) {
00162                                                 int numh = scale_t*scale_t;
00163                                                 loglikrat = alpha * numh;
00164                                         } else if (scaleind == 6 && i == 12 && j == 12) {
00165                                                 int numh = scale_t*scale_t;
00166                                                 loglikrat = alpha * numh;       
00167                                         }
00168                                 }
00169 #endif  ONESPIKE
00170 #else           SPIKETEST
00171                                 //unboost = 1/((scale_t+1)*(scale_t+1));
00172                                 double loglikrat = getBoxSum(sumlikrat, h_x, h_y, scale_t)*unboost;                             
00173 #endif  SPIKETEST
00174 
00175                                 double logprior_t = log(prior_t);
00176                                 double logpost_t = loglikrat + logprior_t - maxLogPostT;
00177                                 logpost_t = max(logpost_t, minlog);
00178                                 postsum += exp(logpost_t);
00179                         }
00180                 }
00181         }
00182 
00183         /* calculates posterior probabilities and projects to predictive distribution for time t+1 */
00184         for (scaleind=0; scaleind < numscales; scaleind++) {
00185                 HypothesesPerScale &scaleptr_t = m_priors_t->get_hypothesesPerScale(scaleind);
00186                 HypothesesPerScale &scaleptr_tnew = m_priors_tnew->get_hypothesesPerScale(scaleind);
00187                 double &scale_t = scaleptr_t.m_scale;
00188                 
00189                 for (int j=0; j < scaleptr_t.m_numY; j++) {
00190                         for (int i=0; i < scaleptr_t.m_numX; i++) {
00191                                 double prior_t = 0;
00192                         
00193                                 if (frames == 0) prior_t = scaleptr_t.m_intimage.getImPixel(i, j);
00194                                 else prior_t = scaleptr_t.m_intimage.getIntPixel(i, j);
00195 
00196                                 prior_t *= oneoverpriorsum;
00197 
00198                                 /* fix this, needs to be shiftPct*scale */
00199                                 double shift = (shiftPct > minStride) ? shiftPct : minStride;
00200  
00201                                 int h_x = i * shift;
00202                                 int h_y = j * shift;
00203                                 
00204                                 window.set_scalebounds(scaleind);
00205                                 
00206                                 /* get the likelihood ratio for hypothesis h at time t */
00207 #ifdef  SPIKETEST
00208 #ifdef  ONESPIKE
00209                                 double loglikrat = -50;
00210                                 if (frames == 0 && scaleind == numscales/2
00211                                                                                                 && i == scaleptr_t.m_numX/2 && j == scaleptr_t.m_numY/2)
00212                                         loglikrat = 50;
00213 #else           ONESPIKE
00214                                 double loglikrat = -50;
00215                                 if (frames == 0) {
00216                                         double alpha = -2.0;
00217                                         if (scaleind == 4 && i == 6 && j == 6) {
00218                                                 int numh = scale_t*scale_t;
00219                                                 loglikrat = alpha * numh;
00220                                         } else if (scaleind == 6 && i == 12 && j == 12) {
00221                                                 int numh = scale_t*scale_t;
00222                                                 loglikrat = alpha * numh;       
00223                                         }
00224                                 }
00225 #endif  ONESPIKE
00226 #else           SPIKETEST
00227                                 //unboost = 1/((scale_t+1)*(scale_t+1));
00228                                 double loglikrat = getBoxSum(sumlikrat, h_x, h_y, scale_t)*unboost;                             
00229 #endif  SPIKETEST
00230 
00231                                 double logprior_t = log(prior_t);
00232                                 double logpost_t = (loglikrat + logprior_t) - maxLogPostT;
00233 
00234                                 logpost_t = max(logpost_t, minlog);
00235 
00236                                 logpost_t = min(logpost_t, -minlog);
00237                                 double post_t = exp(logpost_t);
00238 
00239                                 post_t /= postsum;
00240 
00241 #ifdef  SPIKETEST
00242 #ifndef ONESPIKE
00243                                 if (frames == 0) {
00244                                         if (scaleind == 4 && i == 6 && j == 6)
00245                                                 printf("H1: llr = %g\tn = %g\tpost = %g\n", loglikrat, scale_t*scale_t, post_t);
00246                                         else if (scaleind == 6 && i == 12 && j == 12)
00247                                                 printf("H2: llr = %g\tn = %g\tpost = %g\n", loglikrat, scale_t*scale_t, post_t);
00248                                 }
00249 #endif  ONESPIKE
00250 #endif  SPIKETEST
00251 
00252                                 /* max code */
00253                                 if (post_t >= prevPostT) {
00254                                         besthyp.x = h_x; 
00255                                         besthyp.y = h_y; 
00256                                         besthyp.size = scale_t; 
00257                                         prevPostT = post_t;
00258                                 }
00259 
00260                                 int innerscaleind, boxsum;
00261                                 TBox<double> lw;
00262 
00263                                 /* determine normalizing constant for p(h_t+1 | h_t) */
00264                                 int numh = 0;
00265                                 for (innerscaleind=0; innerscaleind < m_priors_tnew->get_numScales(); innerscaleind++) {
00266                                         HypothesesPerScale &scaleptr = m_priors_tnew->get_hypothesesPerScale(innerscaleind);
00267                                         if (true) {
00268 //                                      if (((int)scale_t % 2 != 0 && (int)scaleptr.m_scale % 2 != 0) ||
00269 //                                                      ((int)scale_t % 2 == 0 && (int)scaleptr.m_scale % 2 == 0) ) {
00270 //                                      if ((int)scaleptr.m_scale % 2 != 0) {
00271                                                 if (window.is_validscale(innerscaleind)) {                                      
00272                                                         lw.scale = scaleptr.m_scale;
00273                                                         window.get_location_window(scale_t, lw, hr, h_x, h_y, shiftPct, minStride,scaleptr.m_numX,scaleptr.m_numY);
00274                                                         boxsum = getBoxSum(scaleptr.m_intones, lw.x, lw.y, lw.size);
00275                                                         numh += boxsum;
00276                                                 }
00277                                         }
00278                                 }
00279 
00280                                 /* compute normalized prior for t+1 */
00281                                 double val = (post_t/static_cast<double>(numh));
00282                                 for (innerscaleind=0; innerscaleind < m_priors_tnew->get_numScales(); innerscaleind++) {
00283                                         HypothesesPerScale &scaleptr = m_priors_tnew->get_hypothesesPerScale(innerscaleind);
00284                                         if (true) {
00285 //                                      if (((int)scale_t % 2 != 0 && (int)scaleptr.m_scale % 2 != 0) ||
00286 //                                                      ((int)scale_t % 2 == 0 && (int)scaleptr.m_scale % 2 == 0) ) {
00287 //                                      if ((int)scaleptr.m_scale % 2 != 0) {
00288                                                 if (window.is_validscale(innerscaleind)) {
00289                                                         lw.scale = scaleptr.m_scale;
00290                                                         window.get_location_window(scale_t, lw, hr, h_x, h_y, shiftPct, minStride, scaleptr.m_numX,scaleptr.m_numY);                    
00291                                                         addBoxCorners(scaleptr.m_intimage, lw.x, lw.y, lw.size, val);
00292                                                 }
00293                                         }
00294                                 }
00295                         }
00296                 }
00297         }
00298 
00299         // #ifdef SIMULATE
00300 //      bool headerflag_dd = false;
00301 //      if (frames == 0) headerflag_dd = true;
00302 //      ScalePyramid priorsnewcopy_dd;
00303 //      m_priors_tnew->copy(priorsnewcopy_dd);
00304 //      for (scaleind=0; scaleind < numscales; scaleind++) {
00305 //              HypothesesPerScale &scaleptr_tnew = priorsnewcopy_dd.get_hypothesesPerScale(scaleind);
00306 //              char ddfile[100];//, iifileraw[100];
00307 //              sprintf(ddfile, "temp/ddimage_scale%d.bin", scaleind);
00308 // //           sprintf(iifileraw, "temp/iiimage_frame%d_scale%d.txt", frames, scaleind);
00309 //              scaleptr_tnew.m_intimage.printIntBin(ddfile, headerflag_dd);
00310 // //           scaleptr_tnew.m_intimage.printInt(iifileraw);
00311 //      }
00312 // #endif
00313 
00314         /* determine normalizing constant for prior (so prior sums to 1) */
00315         priorsum = 0;
00316         for (scaleind=0; scaleind < numscales; scaleind++) {
00317                 HypothesesPerScale &scaleptr_tnew = m_priors_tnew->get_hypothesesPerScale(scaleind);
00318 
00319                 /* integrating the derivative image gives us unnormalized probabilities */
00320                 scaleptr_tnew.m_intimage.integrate();
00321 
00322                 double sum = 0;
00323                 for (int z=0;z < scaleptr_tnew.m_intimage.getIntNumPix(); z++) {
00324                         scaleptr_tnew.m_intimage.getArray()[z] = fabs(scaleptr_tnew.m_intimage.getArray()[z]);
00325                         sum += scaleptr_tnew.m_intimage.getArray()[z];
00326                 }
00327                 priorsum += sum;
00328         }
00329 
00330 #ifdef SIMULATE
00331         bool headerflag = false;
00332         if (frames == 0) headerflag = true;
00333         ScalePyramid priorsnewcopy;
00334         m_priors_tnew->copy(priorsnewcopy);
00335         for (scaleind=0; scaleind < numscales; scaleind++) {
00336                 HypothesesPerScale &scaleptr_tnew = priorsnewcopy.get_hypothesesPerScale(scaleind);
00337                 char iifile[100];//, iifileraw[100];
00338                 sprintf(iifile, "temp/iiimage_scale%d.bin", scaleind);
00339 //              sprintf(iifileraw, "temp/iiimage_frame%d_scale%d.txt", frames, scaleind);
00340                 scaleptr_tnew.m_intimage.printIntBin(iifile, headerflag);
00341 //              scaleptr_tnew.m_intimage.printInt(iifileraw);
00342         }
00343 #endif
00344 
00345         frames++;
00346         return(0);
00347 }

Here is the call graph for this function:

void zeroPyramids  ) 
 

Definition at line 30 of file colorfeatsearch.cpp.

References m_priors1, m_priors2, and ScalePyramid::makezero().

00031 { 
00032         /* create pyramids of posterior images per scale */
00033         m_priors1.makezero();
00034         m_priors2.makezero();
00035 }

Here is the call graph for this function:


Member Data Documentation

ScalePyramid m_priors1
 

Definition at line 10 of file colorfeatsearch.h.

Referenced by initPyramids(), and zeroPyramids().

ScalePyramid m_priors2
 

Definition at line 10 of file colorfeatsearch.h.

Referenced by initPyramids(), and zeroPyramids().

ScalePyramid* m_priors_t
 

Definition at line 11 of file colorfeatsearch.h.

Referenced by searchFeature().

ScalePyramid * m_priors_tnew
 

Definition at line 11 of file colorfeatsearch.h.

Referenced by searchFeature().

bool m_recycle
 

Definition at line 13 of file colorfeatsearch.h.

Referenced by initPyramids(), and searchFeature().


The documentation for this struct was generated from the following files:
Generated on Mon Nov 8 17:08:33 2004 for MPT by  doxygen 1.3.9.1