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, see <http://www.gnu.org/licenses/>. *
00017  ***************************************************************************/
00018 
00019 #include <iostream>
00020 #include <sys/types.h>
00021 #include <sys/stat.h>
00022 #include <stdlib.h>
00023 #include "GaborGlobal.h"
00024 #include "GaborJet.h"
00025 #include "ContrastFilter.h"
00026 //#include "PGMImage.h"
00027 #include "Utilities.h"
00028 #include "CelesteGlobals.h"
00029 #define kUseContrast 1
00030 
00031 using namespace std; 
00032 
00033 namespace celeste
00034 {
00035 float* ProcessChannel( float** image, int w, int h, int gNumLocs, int**& gLocations, int gRadius, float* response, int* len){
00036 
00037         ContrastFilter* contrastFilter = NULL;
00038         GaborJet* gaborJet = NULL;
00039         int height = h;
00040         int width = w;
00041         float** pixels;
00042         int gflen, dummy;
00043         int i, j, offset = 0;
00044 
00045         // copy pointer
00046         pixels = image;
00047 
00048 #if kUseContrast
00049 
00050         // apply contrast filter to image
00051         contrastFilter = new ContrastFilter( image, height, width );
00052     char file[] = "gabor_filters/celeste"; 
00053         // set filename if intermediate files should be saved
00054         if ( kSaveFilter == 1 ) {
00055                 contrastFilter->Save( file );                   // save contrast image
00056         }
00057         pixels = contrastFilter->GetContrast();         // get contrast map
00058         width = contrastFilter->GetWidth();             // obtain contrast dimensions
00059         height = contrastFilter->GetHeight();
00060 #endif
00061 
00062 // initialize gabor jet for the first fiducial point
00063         gaborJet = new GaborJet;
00064         if ( kSaveFilter == 1 )
00065         {
00066         char filename[256], suffix[5];
00067         strcpy(filename, file);
00068                 sprintf( suffix, "%d-", 0 );
00069                 strcat( filename, suffix );
00070         gaborJet->Initialize(height, width, gLocations[0][0], gLocations[0][1],
00071             gRadius, gS, gF, gU, gL, gA, filename);
00072         }
00073     else
00074     {
00075         gaborJet->Initialize(height, width, gLocations[0][0], gLocations[0][1],
00076             gRadius, gS, gF, gU, gL, gA);
00077     };
00078 
00079 // filter image
00080         // response vector is initialized here, but needs to be disposed by user
00081  
00082         gaborJet->Filter( pixels, &gflen );
00083 
00084         if ( *len == 0 ) 
00085         {
00086                 *len = gflen * gNumLocs;
00087                 response = new float[(*len)]; // numLocs locations
00088 
00089         }
00090 
00091         //cout << "off " << offset << " gflen " << gflen << " len " << *len << endl; 
00092 
00093         for ( i = 0; i < gflen; i++ ){
00094                 
00095                 
00096                 response[i+offset] = gaborJet->GetResponse(i);
00097                 //cout << i << " / " << gaborJet->GetResponse(i) << endl;
00098         }
00099 
00100         delete gaborJet;
00101 
00102 // we already save the filters for the first fiducial, so turn it off for the others
00103         kSaveFilter = 0;
00104         
00105                 
00106 // process the rest of the fiducial points
00107         for ( i = 1; i < gNumLocs; i++ )
00108         {
00109                 offset = offset + gflen;
00110 
00111                 gaborJet = new GaborJet;
00112                 gaborJet->Initialize( height, width, gLocations[i][0], gLocations[i][1], 
00113                                                           gRadius, gS, gF, gU, gL, gA );
00114                 
00115         // filter image
00116                 // response vector is initialized here, but needs to be disposed by user
00117                 gaborJet->Filter( pixels, &dummy );
00118                 for ( j = 0; j < gflen; j++ ) response[j+offset] = gaborJet->GetResponse(j);
00119                 delete gaborJet;
00120         }       
00121         
00122 #if kUseContrast
00123         delete contrastFilter;
00124 #endif
00125 
00126         return response;
00127 }
00128 }; // namespace

Generated on 1 Sep 2015 for Hugintrunk by  doxygen 1.4.7