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

mp_makeindex.cc

Go to the documentation of this file.
00001 /*
00002  *  mp_makeindex.cc
00003  * 
00004  *  Create index array that will be used by matlab vaildation
00005  *
00006  *  Created by Ian Fasel on Wed May 28 2003.
00007  * 
00008  *  Copyright (c) 2003 Machine Perception Laboratory
00009  *  University of California San Diego.
00010  *
00011  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00012  *
00013  *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00014  *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00015  *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00018  *
00019  */
00020 
00021 
00022 
00023 #include <iostream>   //TESTING!
00024 #include <vector>
00025 #include "mpiimage.h"
00026 
00027 extern "C" {
00028 #include <math.h>
00029 #include <string.h>
00030 #include <stdlib.h>
00031 #include <sys/time.h>
00032 #include <unistd.h>
00033 #include "mex.h" 
00034 #include "matrix.h"  //FOR TESTING. TAKE OUT!
00035 }
00036 
00037 extern "C" {
00038 void mexFunction(int nlhs,mxArray *plhs[],int nrhs, const mxArray *prhs[]);
00039 }
00040 
00041 void mexFunction(int nlhs,mxArray*plhs[],int nrhs, const mxArray*prhs[]) 
00042 {
00043   // [inds, xs, ys] = mp_makeindex(width, height, window_size)
00044   // check arguments
00045   if (nlhs !=5 )
00046     mexErrMsgTxt("mpisearchMex: requires 5 outputs");
00047   if (nrhs != 3)
00048     mexErrMsgTxt("mpisearchMex: requires 3 inputs");
00049   
00050   int width = static_cast<int>(mxGetScalar(prhs[0]));
00051   int height = static_cast<int>(mxGetScalar(prhs[1]));
00052   int window_size = static_cast<int>(mxGetScalar(prhs[2]));
00053 
00054   // Create image
00055   // char *blank_memory;
00056   // We have to use width+1 and height+1 because of integral image madness
00057   RImage<char> image = RImage<char>(width+1, height+1);
00058   
00059   // Create image pyramid
00060   vector< RImage<char> *> images;
00061   images.push_back(&image);
00062   images.push_back(&image);
00063   images.push_back(&image);
00064   //cout << "About to create image pyramid" << endl;
00065   MPIImagePyramid<char> mpi(images, 1.2f, window_size, window_size, 1);
00066   //cout << "Created image pyramid" << endl;
00067 
00068   // Count total number of windows for this image;
00069   int num_windows = 0;
00070   int num_scales = 0;
00071   {  // create a scope for iterators
00072     MPIImagePyramid<char>::const_iterator scale = mpi.begin(), last_scale = mpi.end();
00073     for( ; scale != last_scale; ++scale){
00074       num_scales++;
00075       //cout << "scale = " << scale.getScale() << endl; 
00076       MPIScaledImage<char>::const_iterator window = (*scale).begin(), last_window = (*scale).end();
00077       for( ; window != last_window; ++window){
00078         //cout << ".";
00079         num_windows++;
00080       }
00081       //cout << endl;
00082     }
00083   }
00084 
00085   //cout << "getting pointers and things for matlab happiness" << endl;
00086   // create indexes, x, and y values for windows that will be scanned
00087   plhs[0] = mxCreateNumericMatrix(num_windows, 1, mxDOUBLE_CLASS, 0);
00088   plhs[1] = mxCreateNumericMatrix(num_windows, 1, mxDOUBLE_CLASS, 0);
00089   plhs[2] = mxCreateNumericMatrix(num_windows, 1, mxDOUBLE_CLASS, 0);
00090   plhs[3] = mxCreateNumericMatrix(num_scales, 1, mxDOUBLE_CLASS, 0);
00091   plhs[4] = mxCreateNumericMatrix(num_scales, 1, mxDOUBLE_CLASS, 0);
00092   double * indexes = mxGetPr(plhs[0]);
00093   double * xs = mxGetPr(plhs[1]);
00094   double * ys = mxGetPr(plhs[2]);
00095   double * scale_start = mxGetPr(plhs[3]);
00096   double * scale_factor = mxGetPr(plhs[4]);
00097 
00098   int ind, x, y;
00099   int w = 0, s = 0;
00100 
00101  
00102   { // create a scope for iterators
00103     // Note the "+1" on indexes -- this is for MALAB's benefit.
00104     MPIImagePyramid<char>::const_iterator scale = mpi.begin(), last_scale = mpi.end();
00105     for( ; scale != last_scale; ++scale){
00106       scale_start[s] = w + 1;
00107       scale_factor[s] = scale.getScale();
00108       MPIScaledImage<char>::const_iterator window = (*scale).begin(), last_window = (*scale).end();
00109       for( ; window != last_window; ++window){
00110         window.getIndex(ind);
00111         window.getCoords(x,y);
00112         indexes[w] = static_cast<double>(ind) + 1;
00113         xs[w] = static_cast<double>(x) + 1;
00114         ys[w] = static_cast<double>(y) + 1;
00115         w++;
00116       }
00117       s++;
00118     }
00119   }
00120 
00121 }
00122 

Generated on Mon Nov 8 17:07:42 2004 for MPT by  doxygen 1.3.9.1