00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <math.h>
00026 #include <flgrCoreDataIO.h>
00027 #include <flgrCoreVector.h>
00028 #include <flgrCoreDispatch.h>
00029 #include <flgrCoreSlideWindow.h>
00030 #include <flgrCoreNhbManage.h>
00031 #include "flgrLinearGabor.h"
00032
00033
00042
00043
00045 #define FLGR_MACRO_SET_GABOR_KERNEL_1D(dtype) \
00046 FLGR_Vector *vec; \
00047 fgFLOAT64 M; \
00048 int v; \
00049 fgFLOAT64 tmp,tmpx,tmpy,tmpexp,tmpcos; \
00050 fgFLOAT64 sigma; \
00051 fgFLOAT64 vv; \
00052 \
00053 \
00054 \
00055 vec = flgr_vector_create(nhb->spp,nhb->type); \
00056 \
00057 sigma = sqrt(log(2)/2)/FLGR_PI*((pow(2,bandwidth)+1) / \
00058 (pow(2,bandwidth)-1)*lambda); \
00059 \
00060 M = (fgFLOAT64) (nhb->length-1); \
00061 \
00062 for(v=0 ; v<nhb->length ; v++) { \
00063 vv=((fgFLOAT64) (v))-M/2; \
00064 \
00065 tmpx = vv*cos(theta); \
00066 tmpy = -vv*sin(theta); \
00067 tmpexp = exp(-1*(pow(tmpx,2)+pow(gamma,2)*pow(tmpy,2)) \
00068 / (2*pow(sigma,2))); \
00069 tmpcos = cos(2*FLGR_PI*tmpx/lambda+phi); \
00070 tmp = ((tmpcos*tmpexp)+offset)*amplitude; \
00071 \
00072 flgr_vector_populate_from_scalar_##dtype(vec, (dtype) tmp); \
00073 flgr1d_set_data_vector(nhb,v,vec); \
00074 } \
00075 \
00076 flgr_vector_destroy(vec); \
00077 return
00078
00079 void flgr1d_set_gabor_kernel_fgBIT(FLGR_Data1D *nhb,
00080 fgFLOAT64 lambda,
00081 fgFLOAT64 theta,
00082 fgFLOAT64 phi,
00083 fgFLOAT64 gamma,
00084 fgFLOAT64 bandwidth,
00085 fgFLOAT64 offset,
00086 fgFLOAT64 amplitude) {
00087 flgr_no_define_type_function(FLGR_BIT);
00088 }
00089 void flgr1d_set_gabor_kernel_fgUINT8(FLGR_Data1D *nhb,
00090 fgFLOAT64 lambda,
00091 fgFLOAT64 theta,
00092 fgFLOAT64 phi,
00093 fgFLOAT64 gamma,
00094 fgFLOAT64 bandwidth,
00095 fgFLOAT64 offset,
00096 fgFLOAT64 amplitude) {
00097 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgUINT8);
00098 }
00099 void flgr1d_set_gabor_kernel_fgUINT16(FLGR_Data1D *nhb,
00100 fgFLOAT64 lambda,
00101 fgFLOAT64 theta,
00102 fgFLOAT64 phi,
00103 fgFLOAT64 gamma,
00104 fgFLOAT64 bandwidth,
00105 fgFLOAT64 offset,
00106 fgFLOAT64 amplitude) {
00107 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgUINT16);
00108 }
00109 void flgr1d_set_gabor_kernel_fgUINT32(FLGR_Data1D *nhb,
00110 fgFLOAT64 lambda,
00111 fgFLOAT64 theta,
00112 fgFLOAT64 phi,
00113 fgFLOAT64 gamma,
00114 fgFLOAT64 bandwidth,
00115 fgFLOAT64 offset,
00116 fgFLOAT64 amplitude) {
00117 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgUINT32);
00118 }
00119 void flgr1d_set_gabor_kernel_fgINT8(FLGR_Data1D *nhb,
00120 fgFLOAT64 lambda,
00121 fgFLOAT64 theta,
00122 fgFLOAT64 phi,
00123 fgFLOAT64 gamma,
00124 fgFLOAT64 bandwidth,
00125 fgFLOAT64 offset,
00126 fgFLOAT64 amplitude) {
00127 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgINT8);
00128 }
00129 void flgr1d_set_gabor_kernel_fgINT16(FLGR_Data1D *nhb,
00130 fgFLOAT64 lambda,
00131 fgFLOAT64 theta,
00132 fgFLOAT64 phi,
00133 fgFLOAT64 gamma,
00134 fgFLOAT64 bandwidth,
00135 fgFLOAT64 offset,
00136 fgFLOAT64 amplitude) {
00137 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgINT16);
00138 }
00139 void flgr1d_set_gabor_kernel_fgINT32(FLGR_Data1D *nhb,
00140 fgFLOAT64 lambda,
00141 fgFLOAT64 theta,
00142 fgFLOAT64 phi,
00143 fgFLOAT64 gamma,
00144 fgFLOAT64 bandwidth,
00145 fgFLOAT64 offset,
00146 fgFLOAT64 amplitude) {
00147 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgINT32);
00148 }
00149 void flgr1d_set_gabor_kernel_fgFLOAT32(FLGR_Data1D *nhb,
00150 fgFLOAT64 lambda,
00151 fgFLOAT64 theta,
00152 fgFLOAT64 phi,
00153 fgFLOAT64 gamma,
00154 fgFLOAT64 bandwidth,
00155 fgFLOAT64 offset,
00156 fgFLOAT64 amplitude) {
00157 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgFLOAT32);
00158 }
00159 void flgr1d_set_gabor_kernel_fgFLOAT64(FLGR_Data1D *nhb,
00160 fgFLOAT64 lambda,
00161 fgFLOAT64 theta,
00162 fgFLOAT64 phi,
00163 fgFLOAT64 gamma,
00164 fgFLOAT64 bandwidth,
00165 fgFLOAT64 offset,
00166 fgFLOAT64 amplitude) {
00167 FLGR_MACRO_SET_GABOR_KERNEL_1D(fgFLOAT64);
00168 }
00169
00170
00171
00173
00184
00185 FLGR_Ret flgr1d_set_gabor_kernel(FLGR_Data1D *nhb,
00186 fgFLOAT64 lambda,
00187 fgFLOAT64 theta,
00188 fgFLOAT64 phi,
00189 fgFLOAT64 gamma,
00190 fgFLOAT64 bandwidth,
00191 fgFLOAT64 offset,
00192 fgFLOAT64 amplitude) {
00193
00194
00195
00196 if(nhb==NULL){
00197 POST_ERROR("Null objects!\n");
00198 return FLGR_RET_NULL_OBJECT;
00199 }
00200
00201 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr1d_set_gabor_kernel,nhb, lambda,theta,phi,gamma,bandwidth,offset,amplitude);
00202
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00221
00223 #define FLGR_MACRO_SET_GABOR_KERNEL_2D(dtype) \
00224 FLGR_Vector *vec; \
00225 fgFLOAT64 N,M; \
00226 int v,u; \
00227 fgFLOAT64 tmp,tmpx,tmpy,tmpexp,tmpcos; \
00228 fgFLOAT64 sigma; \
00229 fgFLOAT64 uu,vv; \
00230 \
00231 \
00232 \
00233 vec = flgr_vector_create(nhb->spp,nhb->type); \
00234 \
00235 sigma = sqrt(log(2)/2)/FLGR_PI*((pow(2,bandwidth)+1) / \
00236 (pow(2,bandwidth)-1)*lambda); \
00237 \
00238 N = (fgFLOAT64) (nhb->size_y-1); \
00239 M = (fgFLOAT64) (nhb->size_x-1); \
00240 \
00241 for(u=0 ; u<nhb->size_y ; u++) { \
00242 uu=((fgFLOAT64) (u))-N/2; \
00243 \
00244 for(v=0 ; v<nhb->size_x ; v++) { \
00245 vv=((fgFLOAT64) (v))-M/2; \
00246 \
00247 tmpx = uu*sin(theta)+vv*cos(theta); \
00248 tmpy = uu*cos(theta)-vv*sin(theta); \
00249 tmpexp = exp(-1*(pow(tmpx,2)+pow(gamma,2)*pow(tmpy,2)) \
00250 / (2*pow(sigma,2))); \
00251 tmpcos = cos(2*FLGR_PI*tmpx/lambda+phi); \
00252 tmp = ((tmpcos*tmpexp)+offset)*amplitude; \
00253 \
00254 flgr_vector_populate_from_scalar_##dtype(vec, (dtype) tmp); \
00255 flgr2d_set_data_vector(nhb,u,v,vec); \
00256 } \
00257 } \
00258 \
00259 flgr_vector_destroy(vec); \
00260 return
00261
00262 void flgr2d_set_gabor_kernel_fgBIT(FLGR_Data2D *nhb,
00263 fgFLOAT64 lambda,
00264 fgFLOAT64 theta,
00265 fgFLOAT64 phi,
00266 fgFLOAT64 gamma,
00267 fgFLOAT64 bandwidth,
00268 fgFLOAT64 offset,
00269 fgFLOAT64 amplitude) {
00270 flgr_no_define_type_function(FLGR_BIT);
00271 }
00272 void flgr2d_set_gabor_kernel_fgUINT8(FLGR_Data2D *nhb,
00273 fgFLOAT64 lambda,
00274 fgFLOAT64 theta,
00275 fgFLOAT64 phi,
00276 fgFLOAT64 gamma,
00277 fgFLOAT64 bandwidth,
00278 fgFLOAT64 offset,
00279 fgFLOAT64 amplitude) {
00280 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgUINT8);
00281 }
00282 void flgr2d_set_gabor_kernel_fgUINT16(FLGR_Data2D *nhb,
00283 fgFLOAT64 lambda,
00284 fgFLOAT64 theta,
00285 fgFLOAT64 phi,
00286 fgFLOAT64 gamma,
00287 fgFLOAT64 bandwidth,
00288 fgFLOAT64 offset,
00289 fgFLOAT64 amplitude) {
00290 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgUINT16);
00291 }
00292 void flgr2d_set_gabor_kernel_fgUINT32(FLGR_Data2D *nhb,
00293 fgFLOAT64 lambda,
00294 fgFLOAT64 theta,
00295 fgFLOAT64 phi,
00296 fgFLOAT64 gamma,
00297 fgFLOAT64 bandwidth,
00298 fgFLOAT64 offset,
00299 fgFLOAT64 amplitude) {
00300 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgUINT32);
00301 }
00302 void flgr2d_set_gabor_kernel_fgINT8(FLGR_Data2D *nhb,
00303 fgFLOAT64 lambda,
00304 fgFLOAT64 theta,
00305 fgFLOAT64 phi,
00306 fgFLOAT64 gamma,
00307 fgFLOAT64 bandwidth,
00308 fgFLOAT64 offset,
00309 fgFLOAT64 amplitude) {
00310 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgINT8);
00311 }
00312 void flgr2d_set_gabor_kernel_fgINT16(FLGR_Data2D *nhb,
00313 fgFLOAT64 lambda,
00314 fgFLOAT64 theta,
00315 fgFLOAT64 phi,
00316 fgFLOAT64 gamma,
00317 fgFLOAT64 bandwidth,
00318 fgFLOAT64 offset,
00319 fgFLOAT64 amplitude) {
00320 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgINT16);
00321 }
00322 void flgr2d_set_gabor_kernel_fgINT32(FLGR_Data2D *nhb,
00323 fgFLOAT64 lambda,
00324 fgFLOAT64 theta,
00325 fgFLOAT64 phi,
00326 fgFLOAT64 gamma,
00327 fgFLOAT64 bandwidth,
00328 fgFLOAT64 offset,
00329 fgFLOAT64 amplitude) {
00330 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgINT32);
00331 }
00332 void flgr2d_set_gabor_kernel_fgFLOAT32(FLGR_Data2D *nhb,
00333 fgFLOAT64 lambda,
00334 fgFLOAT64 theta,
00335 fgFLOAT64 phi,
00336 fgFLOAT64 gamma,
00337 fgFLOAT64 bandwidth,
00338 fgFLOAT64 offset,
00339 fgFLOAT64 amplitude) {
00340 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgFLOAT32);
00341 }
00342 void flgr2d_set_gabor_kernel_fgFLOAT64(FLGR_Data2D *nhb,
00343 fgFLOAT64 lambda,
00344 fgFLOAT64 theta,
00345 fgFLOAT64 phi,
00346 fgFLOAT64 gamma,
00347 fgFLOAT64 bandwidth,
00348 fgFLOAT64 offset,
00349 fgFLOAT64 amplitude) {
00350 FLGR_MACRO_SET_GABOR_KERNEL_2D(fgFLOAT64);
00351 }
00352
00353
00354
00356
00367
00368 FLGR_Ret flgr2d_set_gabor_kernel(FLGR_Data2D *nhb,
00369 fgFLOAT64 lambda,
00370 fgFLOAT64 theta,
00371 fgFLOAT64 phi,
00372 fgFLOAT64 gamma,
00373 fgFLOAT64 bandwidth,
00374 fgFLOAT64 offset,
00375 fgFLOAT64 amplitude) {
00376
00377
00378
00379 if(nhb==NULL){
00380 POST_ERROR("Null objects!\n");
00381 return FLGR_RET_NULL_OBJECT;
00382 }
00383
00384 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_set_gabor_kernel,nhb, lambda,theta,phi,gamma,bandwidth,offset,amplitude);
00385
00386 }
00387
00388