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

Generated on 28 Sep 2016 for Hugintrunk by  doxygen 1.4.7