Gabor.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Tim Nugent                                      *
00003  *   timnugent@gmail.com                                                   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <iostream>
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <stdlib.h>
00025 #include "GaborGlobal.h"
00026 #include "GaborJet.h"
00027 #include "ContrastFilter.h"
00028 //#include "PGMImage.h"
00029 #include "Utilities.h"
00030 #include "CelesteGlobals.h"
00031 #define kUseContrast 1
00032 
00033 using namespace std; 
00034 
00035 namespace celeste
00036 {
00037 float* ProcessChannel( float** image, int w, int h, int gNumLocs, int**& gLocations, int gRadius, float* response, int* len){
00038 
00039         ContrastFilter* contrastFilter = NULL;
00040         GaborJet* gaborJet = NULL;
00041         int height = h;
00042         int width = w;
00043         float** pixels;
00044         int gflen, dummy;
00045         int i, j, offset = 0;
00046         char filename[256], suffix[5];
00047 
00048         // copy pointer
00049         pixels = image;
00050 
00051 #if kUseContrast
00052 
00053         // apply contrast filter to image
00054         contrastFilter = new ContrastFilter( image, height, width );
00055     char file[] = "gabor_filters/celeste"; 
00056         // set filename if intermediate files should be saved
00057         if ( kSaveFilter == 1 ) {
00058                 contrastFilter->SetFileName( file );    
00059                 contrastFilter->Save();                 // save contrast image
00060         }
00061         pixels = contrastFilter->GetContrast();         // get contrast map
00062         width = contrastFilter->GetWidth();             // obtain contrast dimensions
00063         height = contrastFilter->GetHeight();
00064 #endif
00065 
00066 // initialize gabor jet for the first fiducial point
00067         gaborJet = new GaborJet;
00068         if ( kSaveFilter == 1 )
00069         {
00070                 strcpy( filename, file );
00071                 sprintf( suffix, "%d-", 0 );
00072                 strcat( filename, suffix );
00073                 gaborJet->SetFileName( filename );
00074         }
00075         gaborJet->Initialize( height, width, gLocations[0][0], gLocations[0][1],
00076                                                   gRadius, gS, gF, gU, gL, gA, kSaveFilter );
00077 
00078 // filter image
00079         // response vector is initialized here, but needs to be disposed by user
00080  
00081         gaborJet->Filter( pixels, &gflen );
00082 
00083         if ( *len == 0 ) 
00084         {
00085                 *len = gflen * gNumLocs;
00086                 response = new float[(*len)]; // numLocs locations
00087 
00088         }
00089 
00090         //cout << "off " << offset << " gflen " << gflen << " len " << *len << endl; 
00091 
00092         for ( i = 0; i < gflen; i++ ){
00093                 
00094                 
00095                 response[i+offset] = gaborJet->GetResponse(i);
00096                 //cout << i << " / " << gaborJet->GetResponse(i) << endl;
00097         }
00098 
00099         delete gaborJet;
00100 
00101 // we already save the filters for the first fiducial, so turn it off for the others
00102         kSaveFilter = 0;
00103         
00104                 
00105 // process the rest of the fiducial points
00106         for ( i = 1; i < gNumLocs; i++ )
00107         {
00108                 offset = offset + gflen;
00109 
00110                 gaborJet = new GaborJet;
00111                 if ( kSaveFilter == 1 )
00112                 {
00113                         strcpy( filename, file );
00114                         sprintf( suffix, "%d-", i );
00115                         strcat( filename, suffix );
00116                         gaborJet->SetFileName( filename );
00117                 }
00118                 gaborJet->Initialize( height, width, gLocations[i][0], gLocations[i][1], 
00119                                                           gRadius, gS, gF, gU, gL, gA );
00120                 
00121         // filter image
00122                 // response vector is initialized here, but needs to be disposed by user
00123                 gaborJet->Filter( pixels, &dummy );
00124                 for ( j = 0; j < gflen; j++ ) response[j+offset] = gaborJet->GetResponse(j);
00125                 delete gaborJet;
00126         }       
00127         
00128 #if kUseContrast
00129         delete contrastFilter;
00130 #endif
00131 
00132         return response;
00133 }
00134 }; // namespace

Generated on Wed Sep 3 01:25:32 2014 for Hugintrunk by  doxygen 1.3.9.1