psycho-skin-mapgenerator.C

00001 // //////////////////////////////////////////////////////////////////// //
00002 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00003 // University of Southern California (USC) and the iLab at USC.         //
00004 // See http://iLab.usc.edu for information about this project.          //
00005 // //////////////////////////////////////////////////////////////////// //
00006 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00007 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00008 // in Visual Environments, and Applications'' by Christof Koch and      //
00009 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00010 // pending; application number 09/912,225 filed July 23, 2001; see      //
00011 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00012 // //////////////////////////////////////////////////////////////////// //
00013 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00014 //                                                                      //
00015 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00016 // redistribute it and/or modify it under the terms of the GNU General  //
00017 // Public License as published by the Free Software Foundation; either  //
00018 // version 2 of the License, or (at your option) any later version.     //
00019 //                                                                      //
00020 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00021 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00022 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00023 // PURPOSE.  See the GNU General Public License for more details.       //
00024 //                                                                      //
00025 // You should have received a copy of the GNU General Public License    //
00026 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00027 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00028 // Boston, MA 02111-1307 USA.                                           //
00029 // //////////////////////////////////////////////////////////////////// //
00030 //written by Nader Noori, March 2008
00031 
00032 #include "psycho-skin-mapgenerator.h"
00033 #include <vector>
00034 #include <iostream>
00035 #include <string>
00036 #include "psycho-skin-mapgenerator.h"
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <sstream>
00040 #include <time.h>
00041 
00042 using namespace std ;
00043 
00044 Matrix::Matrix(int row , int col , int** m)
00045 {
00046         mems =         *m ;
00047         r = row ;
00048         c = col ;
00049 }
00050 
00051 // ######################################################################
00052 Matrix::~Matrix()
00053 
00054 {
00055         delete[] mems;
00056 }
00057 // ######################################################################
00058 int Matrix::getNumOfRows()
00059 {
00060         return r ;
00061 }
00062 // ######################################################################
00063 int Matrix::getNumOfColumns()
00064 {
00065         return c ;
00066 }
00067 // ######################################################################
00068 int Matrix::get(int row , int col)
00069 {
00070         int index = row*c + col ;
00071         return *(mems + index);
00072 }
00073 // ######################################################################
00074 void Matrix::set(int row , int col , int val)
00075 {
00076         int index = row*c+col ;
00077         *(mems + index) = val ;
00078 }
00079 // ######################################################################
00080 void Matrix::setNumOfRows(int nr)
00081 {
00082         r = nr ;
00083 }
00084 // ######################################################################
00085 void Matrix::setNumOfColumns(int nc)
00086 {
00087         c = nc ;
00088 }
00089 // ######################################################################
00090 string Matrix::toFormattedString()
00091 {
00092         string s("") ;
00093         for (int i = 0 ; i < r ; i++){
00094                 s += "<" ;
00095                 for(int j = 0 ; j < c ; j++){
00096                         int index = i*c + j;
00097                         int m = *(mems + index);
00098                         s+=stringify(m)+" " ;
00099                 }
00100                 s += ">" ;
00101         }
00102         return s ;
00103 }
00104 // ######################################################################
00105 string Matrix::toString()
00106 {
00107         string s("") ;
00108         for (int i = 0 ; i < r ; i++){
00109                 for(int j = 0 ; j < c ; j++){
00110                         int index = i*c + j;
00111                         int m = *(mems + index);
00112                         s+=stringify(m)+" " ;
00113                 }
00114         }
00115         return s ;
00116 }
00117 // ######################################################################
00118 string Matrix::stringify(int i)
00119 {
00120         ostringstream o ;
00121         o << i ;
00122         return o.str();
00123 }
00124 
00125 // ######################################################################
00126 Matrix* getARandomMap(int row , int col , int channel)
00127 {
00128 
00129         int* a = new int[row*col] ;
00130         srand ( time(NULL) );
00131         for (int i = 0 ; i < row*col ; i++){
00132                 a[i] = rand()%channel +1 ;
00133         }
00134         Matrix* matrix= new Matrix(row,col,&a) ;
00135         //delete[] a ;
00136         return matrix ;
00137 }
00138 // ######################################################################
00139 Matrix* getAnEmptyMap(int row , int col){
00140         int* a = new int[row*col] ;
00141         for (int i = 0 ; i < row*col ; i++){
00142                 a[i] = 0 ;
00143         }
00144         Matrix* matrix= new Matrix(row,col,&a) ;
00145         //delete[] a ;
00146         return matrix ;
00147 }
00148 // ######################################################################
00149 
00150 Matrix* getASeededMap(int row , int col , int numOfChannels , Matrix& p , int ch)
00151 {
00152 
00153         srand ( time(NULL) );
00154         Matrix* m = getAnEmptyMap(row,col) ;
00155         int ix = rand()%(row - p.getNumOfRows()) ;
00156         int iy = rand()%(col - p.getNumOfColumns()) ;
00157 
00158         for(int x = 0 ; x < p.getNumOfRows() ; x++){
00159                 for(int y = 0 ; y < p.getNumOfColumns() ; y++){
00160                         int f = p.get(x,y);
00161                         if( f != 0 ){
00162                                 m->set(ix+x,iy+y,ch) ;
00163                         } else {
00164                                 int temp = rand()%numOfChannels+1;
00165                                 while( temp == ch){
00166                                         temp = rand()%numOfChannels+1;
00167                                 }
00168                                 m->set(ix+x,iy+y,temp) ;
00169                         }
00170 
00171                 }
00172         }
00173 
00174         for(int i = 0; i < row ; i++){
00175                 for(int j = 0 ; j < col ; j++){
00176                         if (m->get(i,j) == 0) m->set(i,j,rand()%numOfChannels +1) ;
00177                 }
00178         }
00179 
00180         return m ;
00181 }
00182 
00183 // ######################################################################
00184 Matrix* getTheChannelMap(Matrix& map , int ch)
00185 {
00186         Matrix *e = getAnEmptyMap(map.getNumOfRows(),map.getNumOfColumns()) ;
00187         for(int i  = 0 ; i < map.getNumOfRows() ; i ++){
00188                 for (int j = 0 ;  j< map.getNumOfColumns() ; j++){
00189                         if(map.get(i,j)==ch) e->set(i,j,1) ;
00190                 }
00191         }
00192         return e ;
00193 }
00194 // ######################################################################
00195 int getNumberOfMatches(Matrix& ormap , Matrix& pattern , int channel)
00196 {
00197         int mapRows = ormap.getNumOfRows();
00198         int mapCols = ormap.getNumOfColumns();
00199         int patternRows = pattern.getNumOfRows();
00200         int patternCols = pattern.getNumOfColumns() ;
00201         Matrix* map = getTheChannelMap(ormap , channel);
00202         int result = 0 ;
00203         for(int i = 0 ; i < mapRows ; i++ ){
00204                 for(int j = 0 ;  j < mapCols ; j++){
00205 
00206                         bool matchFlag = true ;
00207                         if(i+ patternRows <= mapRows && j+ patternCols <= mapCols){
00208                                 for(int i1 = 0 ; i1 < patternRows ; i1++){
00209                                         for (int j1 = 0 ; j1 < patternCols ; j1++){
00210                                                 if(pattern.get(i1,j1)> map->get(i+i1,j+j1)) {
00211                                                         matchFlag = false ;
00212                                                         break;
00213                                                 }
00214                                                 if(!matchFlag) break;
00215                                         }
00216                                         if(!matchFlag) break;
00217                                 }
00218 
00219                         }else{
00220 
00221                                 matchFlag = false ;
00222                         }
00223 
00224                         if(matchFlag){
00225                                 result++ ;
00226                         }
00227 
00228                 }
00229         }
00230 
00231         delete map ;
00232         return result ;
00233 }
00234 // ######################################################################
00235 Matrix* getMatchMatrix(Matrix& ormap , Matrix& pattern , int channel){
00236         int mapRows = ormap.getNumOfRows();
00237         int mapCols = ormap.getNumOfColumns();
00238         int patternRows = pattern.getNumOfRows();
00239         int patternCols = pattern.getNumOfColumns() ;
00240         Matrix* result = getAnEmptyMap(mapRows,mapCols) ;
00241         Matrix* map = getTheChannelMap(ormap , channel);
00242         for(int i = 0 ; i < mapRows ; i++ ){
00243                 for(int j = 0 ;  j < mapCols ; j++){
00244 
00245                         bool matchFlag = true ;
00246                         if(i+ patternRows <= mapRows && j+ patternCols <= mapCols){
00247                                 for(int i1 = 0 ; i1 < patternRows ; i1++){
00248                                         for (int j1 = 0 ; j1 < patternCols ; j1++){
00249 
00250                                                 if(pattern.get(i1,j1)> map->get(i+i1,j+j1) ){
00251                                                         matchFlag = false ;
00252                                                         break;
00253                                                 }
00254                                                 if(!matchFlag) break ;
00255                                         }
00256                                         if(!matchFlag) break ;
00257                                 }
00258 
00259                         }else{
00260 
00261                                 matchFlag = false ;
00262                         }
00263 
00264                         if(matchFlag){
00265                                 result->set(i,j,1) ;
00266                         }else {result->set(i,j,0) ;}
00267 
00268                 }
00269         }
00270         delete map ;
00271         return result;
00272 
00273 }
00274 // ######################################################################
00275 Matrix* getPattenByString(std::string patStr){
00276 
00277         int rn = 1 ;
00278         int cn = 1 ;
00279         for(int i = 0 ; i< (int)patStr.size() ; i++) if( patStr[i]==char('_')) rn++ ;
00280         if(rn == 1)
00281         {
00282                 cn = patStr.size();
00283         }else
00284         {
00285                 string::size_type position = patStr.find("_");
00286                 cn = int(position) ;
00287         }
00288         Matrix* t = getAnEmptyMap(rn,cn);
00289         for(int i = 0 ; i < rn ; i++)
00290         {
00291                 for (int j = 0 ; j < cn ; j++)
00292                 {
00293                         if(patStr.at( i*(cn+1) + j )=='1') t->set(i,j,1) ;
00294                 }
00295 
00296         }
00297 
00298         return t ;
00299 }
00300 
00301 // ######################################################################
00302 
00303 Matrix* getMapByString(std::string mapStr){
00304         int rn = 1 ;
00305         int cn = 1 ;
00306         for(int i = 0 ; i< (int)mapStr.size() ; i++) if( mapStr[i]==char('_')) rn++ ;
00307         if(rn == 1)
00308         {
00309                 cn = mapStr.size();
00310         }else
00311         {
00312                 string::size_type position = mapStr.find("_");
00313                 cn = int(position) ;
00314         }
00315         Matrix* t = getAnEmptyMap(rn,cn);
00316         for(int i = 0 ; i < rn ; i++)
00317         {
00318                 for (int j = 0 ; j < cn ; j++)
00319                 {
00320                         char rf[2] ;
00321                         strcpy(rf,mapStr.substr(i*(cn+1) + j ,1 ).c_str());
00322                         t->set(i,j,atoi(rf)) ;
00323                 }
00324 
00325         }
00326 
00327         return t ;
00328 }
00329 
00330 // ######################################################################
00331 
00332 Matrix* getTranspose(Matrix& m , bool replace)
00333 {
00334         int mRs = m.getNumOfRows() ;
00335         int mCs = m.getNumOfColumns() ;
00336         Matrix* nM = getAnEmptyMap(mCs,mRs);
00337         for(int i = 0 ; i < mRs ; i++){
00338                 for(int j = 0 ; j < mCs ; j++){
00339                         nM->set(j,i,m.get(i,j)) ;
00340                 }
00341         }
00342         if(replace) {
00343                 m.setNumOfRows(mCs);
00344                 m.setNumOfColumns(mRs) ;
00345                 for(int i = 0 ; i < nM->getNumOfRows() ; i++){
00346                         for(int j = 0 ; j < nM->getNumOfColumns() ; j++){
00347                                 m.set(i,j,nM->get(i,j));
00348 
00349                         }
00350                 }
00351                 nM->Matrix::~Matrix() ;
00352                 return &m ;
00353         }
00354         return nM ;
00355 }
00356 // ######################################################################
00357 Matrix* getHorizontalReverse(Matrix& m , bool replace)
00358 {
00359         int mRs = m.getNumOfRows() ;
00360         int mCs = m.getNumOfColumns() ;
00361         Matrix* nM = getAnEmptyMap(mRs,mCs);
00362         for(int i = 0 ; i < mRs ; i++){
00363                 for(int j = 0 ; j < mCs ; j++){
00364 
00365                         nM->set(i,j,m.get(mRs-i-1,j)) ;
00366                 }
00367         }
00368 
00369         if(replace) {
00370                 for(int i = 0 ; i < mRs ; i++){
00371                         for(int j = 0 ; j < mCs ; j++){
00372                                 m.set(i,j,nM->get(i,j));
00373 
00374                         }
00375                 }
00376                 nM->Matrix::~Matrix() ;
00377                 return &m ;
00378         }
00379         return nM ;
00380 }
00381 // ######################################################################
00382 Matrix* getVerticalReverse(Matrix& m , bool  replace)
00383 {
00384         int mRs = m.getNumOfRows() ;
00385         int mCs = m.getNumOfColumns() ;
00386         Matrix* nM = getAnEmptyMap(mRs,mCs);
00387         for(int i = 0 ; i < mRs ; i++){
00388                 for(int j = 0 ; j < mCs ; j++){
00389 
00390                         nM->set(i,j,m.get(i,mCs - j -1)) ;
00391                 }
00392         }
00393         if(replace) {
00394                 for(int i = 0 ; i < mRs ; i++){
00395                         for(int j = 0 ; j < mCs ; j++){
00396                                 m.set(i,j,nM->get(i,j));
00397 
00398                         }
00399                 }
00400                 nM->Matrix::~Matrix() ;
00401                 return &m ;
00402         }
00403         return nM ;
00404 }
00405 // ######################################################################
00406 /*
00407 THis function is used for purification of the maps, this is the way it works: it
00408 sees which row or column has the most number of non-zero elements alignment
00409 then replicates that row or columns and returns it.
00410 */
00411 Matrix* getDominantLinedupFeaturePattern(Matrix& p){
00412 
00413         int* colSum = new int[p.getNumOfColumns()] ;
00414         int* rowSum = new int[p.getNumOfRows()] ;
00415         int colSumMax = -1 ;
00416         int rowSumMax = -1 ;
00417         int mRow = 0 ;
00418         int mCol = 0 ;
00419 
00420         for( int r = 0 ; r < p.getNumOfRows(); r++ ){
00421                 rowSum[r] = 0;
00422                 for( int c = 0 ; c < p.getNumOfColumns() ; c++){
00423                         rowSum[r] += p.get(r,c);
00424                 }
00425                 rowSumMax = max(rowSumMax,rowSum[r]);
00426                 if(rowSumMax == rowSum[r]) mRow = r ;
00427         }
00428 
00429         for( int c = 0 ; c < p.getNumOfColumns() ;c++ ){
00430                 colSum[c] = 0 ;
00431                 for( int r = 0 ; r < p.getNumOfRows() ; r++ ){
00432                         colSum[c] += p.get(r,c) ;
00433                 }
00434                 colSumMax = max(colSumMax,colSum[c]) ;
00435                 if(colSumMax == colSum[c]) mCol = c ;
00436         }
00437 
00438         if(colSumMax > rowSumMax){
00439                 Matrix* d = getAnEmptyMap(colSumMax , 1) ;
00440                 for( int r = 0 ; r < p.getNumOfRows() ; r++){
00441                         d->set(r,0,1);
00442                 }
00443                 delete[] colSum ;
00444                 delete[] rowSum ;
00445                 return d ;
00446 
00447         }else{
00448                 Matrix* d = getAnEmptyMap(1,rowSumMax);
00449                 for(int c = 0 ; c < p.getNumOfColumns() ; c++ ){
00450                         d->set(0,c,1);
00451                 }
00452                 delete[] colSum ;
00453                 delete[] rowSum ;
00454                 return d ;
00455         }
00456 
00457 }
00458 
00459 // ######################################################################
00460 bool areTheyEqual(Matrix& a , Matrix& b){
00461         int aR = a.getNumOfRows() ;
00462         int aC = a.getNumOfColumns() ;
00463         int bR = b.getNumOfRows() ;
00464         int bC = b.getNumOfColumns() ;
00465         if(aC != bC || aR!=bR ) return false ;
00466         for(int i = 0 ; i < aR ; i++)
00467         {
00468                 for(int j = 0 ; j < aC ; j++)
00469                 {
00470                         if(a.get(i,j)!=b.get(i,j)) return false ;
00471                 }
00472         }
00473         return true ;
00474 }
00475 // ######################################################################
00476 vector<Matrix*> *getAllVariations(Matrix& p)
00477 {
00478 
00479         vector<Matrix*>* v = new vector<Matrix*>();
00480         v->push_back(&p) ;
00481 
00482         Matrix* p1 = getTranspose(p) ;
00483         if(!isInTheBag(*p1 ,*v)){
00484                 v->push_back(p1) ;
00485         }else{
00486                 p1->Matrix::~Matrix();
00487         }
00488 
00489         Matrix* p2 = getHorizontalReverse(p) ;
00490         if(!isInTheBag(*p2 ,*v)){
00491                 v->push_back(p2) ;
00492         }else{
00493                 p2->Matrix::~Matrix();
00494         }
00495 
00496         Matrix* p3 = getVerticalReverse(p) ;
00497         if(!isInTheBag(*p3 ,*v)){
00498                 v->push_back(p3) ;
00499         }else{
00500                 p3->Matrix::~Matrix();
00501         }
00502 
00503         Matrix* p4 = getVerticalReverse(*(getTranspose(p)),true) ;
00504         if(!isInTheBag(*p4 ,*v)){
00505                 v->push_back(p4) ;
00506         }else{
00507                 p4->Matrix::~Matrix();
00508         }
00509 
00510         Matrix* p5 = getHorizontalReverse(*(getTranspose(p)),true) ;
00511         if(!isInTheBag(*p5 ,*v)){
00512                 v->push_back(p5) ;
00513         }else{
00514                 p5->Matrix::~Matrix();
00515         }
00516 
00517         Matrix* p6 = getVerticalReverse(*(getHorizontalReverse(p)),true) ;
00518         if(!isInTheBag(*p6 ,*v)){
00519                 v->push_back(p6) ;
00520         }else{
00521                 p6->Matrix::~Matrix();
00522         }
00523 
00524         Matrix* p7 = getHorizontalReverse(*(getVerticalReverse(p)),true) ;
00525         if(!isInTheBag(*p7 ,*v)){
00526                 v->push_back(p7) ;
00527         }else{
00528                 p7->Matrix::~Matrix();
00529         }
00530 
00531 
00532         Matrix* p8 = getVerticalReverse(*getHorizontalReverse(*(getTranspose(p)),true),true) ;
00533         if(!isInTheBag(*p8 ,*v)){
00534                 v->push_back(p8) ;
00535         }else{
00536                 p8->Matrix::~Matrix();
00537         }
00538 
00539 
00540         return v ;
00541 }
00542 // ######################################################################
00543 bool isInTheBag(Matrix& p , vector<Matrix*>& v)
00544 {
00545         bool flag = false ;
00546         for ( vector<Matrix*>::iterator it=v.begin() ; it < v.end(); it++ )
00547                 if(areTheyEqual(*(*it),p))
00548         {
00549                 flag = true ;
00550                 break;
00551         }
00552 
00553         return flag ;
00554 }
00555 // ######################################################################
00556 int getNumberOfMatchesAgainstAllVariationsForAllChannels(Matrix& map ,  Matrix& pattern , int numOfChannels)
00557 {
00558         int n= 0 ;
00559         vector<Matrix*> * v = getAllVariations(pattern) ;
00560         for(int c = 1 ;  c <= numOfChannels ; c++ ){
00561                 for(vector<Matrix*>::iterator it=v->begin() ; it < v->end(); it++){
00562                         n += getNumberOfMatches(map ,*(*it) , c);
00563                 }
00564 
00565         }
00566         return n;
00567 }
00568 // ######################################################################
00569 vector<Matrix*> *getMapsWithExactPattenAndExactChannel(int rs , int cs , int numOfch , int ch , Matrix& pattern , int numOfMatches , int n )
00570 {
00571         vector<Matrix*>* v = new vector<Matrix*>();
00572         //Matrix* p = getPattenByString(pS) ;
00573         //cout<< p->toFormattedString() ;
00574 
00575         while( (int)(v->size())!=n )
00576         {
00577                 Matrix *m ;
00578                 if( numOfMatches != 0 ){
00579                         m = getASeededMap(rs , cs , numOfch , pattern , ch) ;
00580                 }else{
00581                         m = getARandomMap(rs , cs , numOfch ) ;
00582 
00583                 }
00584 
00585                 if(getNumberOfMatches(*m , pattern , ch) == numOfMatches && !isInTheBag(*m,*v))
00586                 {
00587                         v->push_back(m) ;
00588                 }else{
00589                         delete m;
00590 
00591                 }
00592 
00593         }
00594 
00595         return v ;
00596 
00597 }
00598 
00599 // ######################################################################
00600 vector<Matrix*> *getMapsWithExactPattenAndExactChannelWithExclusionList(int rs , int cs , int numOfch , int ch , Matrix& pattern ,vector<string>& exList, int numOfMatches , int n )
00601 {
00602         vector<Matrix*>* v = new vector<Matrix*>();
00603         vector<Matrix*>* exvector = new vector<Matrix*>() ;
00604         vector<int>::size_type sz = exList.size();
00605         for( uint i = 0 ; i < sz ; i++){
00606                 vector<Matrix*>* vars = getAllVariations(*getPattenByString(exList[i]));
00607                 vector<int>::size_type vs = vars->size() ;
00608                 for( uint j = 0 ; j < vs ; j++ ){
00609                         exvector->push_back((*vars)[j]) ;
00610                 }
00611         }
00612 
00613         while( (int)(v->size())!=n )
00614         {
00615                 Matrix *m = getASeededMap(rs , cs , numOfch , pattern , ch) ;
00616                 if(getNumberOfMatches(*m , pattern , ch) == numOfMatches && !isInTheBag(*m,*v))
00617                 {
00618                         bool exFlag = true ;
00619                         for( uint i = 0 ; i < exvector->size() ; i++){
00620                                 for( int j = 0 ; j < numOfch  ; j++){
00621                                         if(getNumberOfMatches(*m,*((*exvector)[i]),j+1)!= 0 )
00622                                                 exFlag = false ;
00623                                 }
00624                         }
00625                         if(exFlag) v->push_back(m) ;
00626                 }
00627 
00628         }
00629         exvector->~vector<Matrix*>() ;
00630         return v ;
00631 
00632 }
00633 
00634 // #########################################################################
00635 vector<Matrix*> *getPureMapsWithExactPatternAndExactChannel(int rs , int cs , int numOfch , int ch , Matrix& pattern , int numOfMatches , int n){
00636 
00637         vector<Matrix*>* v = new vector<Matrix*>();
00638         Matrix *m ;
00639         Matrix* dominantPattern ;
00640         Matrix* tm = 0;
00641         while( (int)(v->size())!=n )
00642         {
00643 
00644                 if( numOfMatches != 0 ){
00645                         tm = getASeededMap(rs , cs , numOfch , pattern , ch) ;
00646                 }else{
00647                         tm = getARandomMap(rs , cs , numOfch ) ;
00648                 }
00649                 dominantPattern = getDominantLinedupFeaturePattern(pattern) ;
00650                 if(getNumberOfMatches(*tm , pattern , ch) == numOfMatches && getNumberOfMatches(*tm,*dominantPattern,ch)==numOfMatches && !isInTheBag(*tm,*v))
00651                 {
00652                         m = getAnEmptyMap(rs,cs) ;
00653                         for(int r = 0 ; r < rs ; r++){
00654                                 for(int  c = 0 ; c <cs ; c++){
00655                                         m->set(r,c,tm->get(r,c));
00656                                 }
00657                         }
00658                         v->push_back(m) ;
00659                 }
00660                 delete dominantPattern ;
00661                 delete tm;
00662         }
00663         return v ;
00664 
00665 }
00666 
00667 // ######################################################################
00668 // Matrix *getAMapWithExactPatternAndExactChannel(int rs , int cs , int numOfch, int ch , Matrix& pattern , int numOfMatches= 1 , std::vector<std::string> exList){
00669 //         bool flag = true
00670 //         Matrix* m = getASeededMap(rs,cs, numOfch, pattern , ch );
00671 //         do{
00672 //                 if(getNumberOfMatches(*m,pattern,ch) != 1 ) flag = false;
00673 //
00674 //         }while( !flag );
00675 //
00676 //         return m;
00677 // }
00678 
00679 //int main(){
00680 //        cout<<"Hi there!"<<endl ;
00681 //        string pS = "101_010";
00682 //        vector<Matrix*>* v = getMapsWithExactPattenAndExactChannel(9 , 9 , 6 , 3 , pS , 1 , 1 );
00683 //        for ( vector<Matrix*>::iterator it=v->begin() ; it < v->end(); it++ )
00684 //                cout<< (*it)->toFormattedString()<<endl ;
00685         /*
00686         Matrix *t = getARandomMap(9,9,6) ;
00687         cout<<t->toFormattedString()<<endl ;
00688         string s = (*t).toString();
00689         string p1 = string("110");
00690         string p2 = string("exit");
00691         while (p1.compare(p2)!=0){
00692                 cout<<"enter the patten string"<<endl;
00693                 cin >> p1 ;
00694                 Matrix *ps1 = getPattenByString(p1) ;
00695                 vector<Matrix*>* v = getAllVariations(*ps1);
00696                 for ( vector<Matrix*>::iterator it=v->begin() ; it < v->end(); it++ )
00697                 cout<< (*it)->toFormattedString()<<endl ;
00698                 cout<<"matches for all channels : " << getNumberOfMatchesAgainstAllVariationsForAllChannels(*t,*ps1)<<endl;
00699 }
00700         */
00701 
00702         //cout<< ps1->toFormattedString()<<endl ;
00703         //getTranspose(*ps1,false) ;
00704         //cout<< ps1->toFormattedString()<<endl ;
00705         //getVerticalReverse(*ps1 ,true) ;
00706         //cout<< ps1->toFormattedString()<<endl ;
00707 /*        getVerticalReverse
00708         //Matrix *ps2 = getPattenByString(p2) ;
00709         Matrix *ps2 = getHorizontalReverse(*ps1) ;
00710         cout<< ps1->toFormattedString()<<endl;
00711         cout<< ps2->toFormattedString()<<endl;
00712         //cout << getNumberOfMatches(*t , *ps1 , 9)<< endl;
00713         int matches1 = 0 ;
00714         int matches2 = 0 ;
00715         for (int i = 1 ; i <=9 ; i++ ) matches1 += getNumberOfMatches(*t , *ps1 , i);
00716         for (int i = 1 ; i <=9 ; i++ ) matches2 += getNumberOfMatches(*t , *ps2 , i);
00717         cout << t->toFormattedString()<<endl ;
00718         cout<< matches1 << endl ;
00719         cout<< matches2 << endl ;
00720         Matrix* match1 = getMatchMatrix(*t,*ps1,1);
00721         Matrix* match2 = getMatchMatrix(*t,*ps2,1);
00722         cout<< match1->toFormattedString()<< endl;
00723         cout<< match2->toFormattedString()<< endl;
00724 */
00725 //        return 0 ;
00726 //}
00727 
Generated on Sun May 8 08:40:10 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3