Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Gabor.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008 by Tim Nugent *
3  * timnugent@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ***************************************************************************/
18 
19 #include <iostream>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <stdlib.h>
23 #include "GaborGlobal.h"
24 #include "GaborJet.h"
25 #include "ContrastFilter.h"
26 //#include "PGMImage.h"
27 #include "Utilities.h"
28 #include "CelesteGlobals.h"
29 #define kUseContrast 1
30 
31 namespace celeste
32 {
33 float* ProcessChannel( float** image, int w, int h, int gNumLocs, int**& gLocations, int gRadius, float* response, int* len){
34 
35  ContrastFilter* contrastFilter = NULL;
36  GaborJet* gaborJet = NULL;
37  int height = h;
38  int width = w;
39  float** pixels;
40  int gflen, dummy;
41  int i, j, offset = 0;
42 
43  // copy pointer
44  pixels = image;
45 
46 #if kUseContrast
47 
48  // apply contrast filter to image
49  contrastFilter = new ContrastFilter( image, height, width );
50  char file[] = "gabor_filters/celeste";
51  // set filename if intermediate files should be saved
52  if ( kSaveFilter == 1 ) {
53  contrastFilter->Save( file ); // save contrast image
54  }
55  pixels = contrastFilter->GetContrast(); // get contrast map
56  width = contrastFilter->GetWidth(); // obtain contrast dimensions
57  height = contrastFilter->GetHeight();
58 #endif
59 
60 // initialize gabor jet for the first fiducial point
61  gaborJet = new GaborJet;
62  if ( kSaveFilter == 1 )
63  {
64  char filename[256], suffix[5];
65  strcpy(filename, file);
66  sprintf( suffix, "%d-", 0 );
67  strcat( filename, suffix );
68  gaborJet->Initialize(height, width, gLocations[0][0], gLocations[0][1],
69  gRadius, gS, gF, gU, gL, gA, filename);
70  }
71  else
72  {
73  gaborJet->Initialize(height, width, gLocations[0][0], gLocations[0][1],
74  gRadius, gS, gF, gU, gL, gA);
75  };
76 
77 // filter image
78  // response vector is initialized here, but needs to be disposed by user
79 
80  gaborJet->Filter( pixels, &gflen );
81 
82  if ( *len == 0 )
83  {
84  *len = gflen * gNumLocs;
85  response = new float[(*len)]; // numLocs locations
86 
87  }
88 
89  //std::cout << "off " << offset << " gflen " << gflen << " len " << *len << std::endl;
90 
91  for ( i = 0; i < gflen; i++ ){
92 
93 
94  response[i+offset] = gaborJet->GetResponse(i);
95  //std::cout << i << " / " << gaborJet->GetResponse(i) << std::endl;
96  }
97 
98  delete gaborJet;
99 
100 // we already save the filters for the first fiducial, so turn it off for the others
101  kSaveFilter = 0;
102 
103 
104 // process the rest of the fiducial points
105  for ( i = 1; i < gNumLocs; i++ )
106  {
107  offset = offset + gflen;
108 
109  gaborJet = new GaborJet;
110  gaborJet->Initialize( height, width, gLocations[i][0], gLocations[i][1],
111  gRadius, gS, gF, gU, gL, gA );
112 
113  // filter image
114  // response vector is initialized here, but needs to be disposed by user
115  gaborJet->Filter( pixels, &dummy );
116  for ( j = 0; j < gflen; j++ ) response[j+offset] = gaborJet->GetResponse(j);
117  delete gaborJet;
118  }
119 
120 #if kUseContrast
121  delete contrastFilter;
122 #endif
123 
124  return response;
125 }
126 }; // namespace
bool kSaveFilter
void Filter(float **image, int *len)
Definition: GaborJet.cpp:109
float * ProcessChannel(float **image, int w, int h, int gNumLocs, int **&gLocations, int gRadius, float *response, int *len)
Definition: Gabor.cpp:33
static deghosting::EMoR response(0.0f)
IMPEX double h[25][1024]
Definition: emor.cpp:169
float ** GetContrast(void)
float GetResponse(int idx)
Definition: GaborJet.h:50
void Initialize(int y, int x, int x0, int y0, int r, float s=2.0, int f=2, float maxF=2, float minF=1, int a=8, char *file=NULL)
Definition: GaborJet.cpp:64