Hugin trunk 0.1
Loading...
Searching...
No Matches
GaborJet.cpp
Go to the documentation of this file.
1/* Import from Gabor API
2
3Copyright (c) 2002-3 Adriaan Tijsseling
4
5
6 All Rights Reserved
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22/*
23 Description: Implementation for GaborJet class
24 Author: Adriaan Tijsseling (AGT)
25 Copyright: (c) Copyright 2002-3 Adriaan Tijsseling. All rights reserved.
26*/
27
28#include "GaborJet.h"
29#include "CelesteGlobals.h"
30
31#ifndef M_PI
32#define M_PI 3.1415926535897932384626433832795
33#endif
34
35namespace celeste
36{
37// default constructor just sets everything to default
39{
40 mHeight = 512;
41 mWidth = 512;
42 mX = 128;
43 mY = 128;
44 mFilters = NULL;
45 mFiducials = NULL;
46 mAngles = 0;
47 mFreqs = 0;
48 mRadius = 0;
49}
50
51// destructor: free up memory
53{
54 if ( mFilters != NULL )
55 {
56 for ( int i = 0; i < mAngles; i++ ) delete[] mFilters[i];
57 delete[] mFilters;
58 }
59 if ( mFiducials != NULL ) delete[] mFiducials;
60}
61
62
63// set up the filter
64void GaborJet::Initialize( int y, int x, int x0, int y0, int r,
65 float s, int f, float maxF, float minF, int a, char* file)
66{
67 int i, j;
68 float freq;
69
70// set internal variables
71 mHeight = y;
72 mWidth = x;
73 mX = x0;
74 mY = y0;
75 float sigma = (float)(s * M_PI * M_PI);
76 mAngles = a;
77 mFreqs = f;
78 mRadius = r;
79 mFiducials = new float[mAngles * mFreqs];
80
81// allocate memory for filters (angles * freqs = total filters)
83 for ( i = 0; i < mAngles; i++ )
84 {
85 // calculate angle
86 float angle = (float)((float)i * M_PI / (float)mAngles);
87
88 // allocate filters for this angle
89 mFilters[i] = new GaborFilter[mFreqs];
90
91 // initialize each one
92 for ( j = 0; j < mFreqs; j++ )
93 {
94 // calculate frequency
95 freq = minF + ( j * ( maxF - minF ) ) / (float)mFreqs;
96
97 // initialize filter
98 mFilters[i][j].Initialize( mRadius, angle, freq, sigma );
99 if (file!=NULL && strlen(file)>0)
100 {
101 mFilters[i][j].Save(file, i, j);
102 };
103 }
104 }
105}
106
107
108// process an image
109void GaborJet::Filter( float** image, int* len )
110{
111 int x, y; // iterating over location
112 int gx, gy; // iterating over filters
113 int a, f; // iterating over angles and frequencies
114 int h, i, j; // iterating over filter field
115 float sumI, sumR; // sum of imaginary and of real parts
116
117 if ( kVerbosity ) std::cerr << "convoluting..." << std::endl;
118
119// convolve at center of filter location
120 // collect responses over angles and frequencies
121 h = 0;
122 for ( a = 0; a < mAngles; a++ )
123 {
124 for ( f = 0; f < mFreqs; f++ )
125 {
126 sumR = 0.0;
127 sumI = 0.0;
128
129 // start from bottom-left corner of filter location
130 y = mY - mRadius;
131 for ( gy = y; gy < y + 2 * mRadius; gy++ )
132 {
133 // make sure we are not out of bounds
134 if ( gy < 0 || gy >= mHeight ) break;
135
136 // offset to local coordinates of filter
137 i = gy - y;
138
139 x = mX - mRadius;
140 for ( gx = x; gx < x + 2 * mRadius; gx++ )
141 {
142 // make sure we are not out of bounds
143 if ( gx < 0 || gx >= mWidth ) break;
144
145 // offset to local coordinates of filter
146 j = gx - x;
147
148 sumR += image[gy][gx] * mFilters[a][f].GetReal(i,j);
149 sumI += image[gy][gx] * mFilters[a][f].GetImaginary(i,j);
150 }
151 }
152 mFiducials[h] = sqrt( sumR*sumR + sumI*sumI );
153 h++;
154 } // f
155 } // a
156
157 *len = mAngles * mFreqs;
158}
159
160}; // namespace
#define M_PI
void Initialize(int radius, float a, float f, float s, float p=0)
float GetImaginary(int x, int y)
Definition GaborFilter.h:48
void Save(char *file, int angle, int freq)
float GetReal(int x, int y)
Definition GaborFilter.h:47
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
float * mFiducials
Definition GaborJet.h:62
void Filter(float **image, int *len)
Definition GaborJet.cpp:109
GaborFilter ** mFilters
Definition GaborJet.h:61
static double sigma