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 "flgrLinearGaussian.h"
00030
00031
00032
00039
00040
00042 #define FLGR_MACRO_SET_GAUSSIAN_KER_1D(dtype) \
00043 FLGR_Vector *vec; \
00044 fgFLOAT64 M; \
00045 int v; \
00046 fgFLOAT64 tmp,b,c,d; \
00047 \
00048 \
00049 \
00050 vec = flgr_vector_create(nhb->spp,nhb->type); \
00051 \
00052 M = (fgFLOAT64) (nhb->length-1); \
00053 \
00054 for(v=0 ; v<nhb->length ; v++) { \
00055 b = pow((v-M/2),2); \
00056 c = pow(sigma,2); \
00057 d = b/c; \
00058 tmp = exp(-0.5*d) * levelMax; \
00059 flgr_vector_populate_from_scalar_##dtype(vec, (dtype) tmp); \
00060 flgr1d_set_data_vector_##dtype(nhb,v,vec); \
00061 } \
00062 \
00063 flgr_vector_destroy(vec); \
00064 return
00065
00066 void flgr1d_set_gaussian_kernel_fgBIT(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00067 flgr_no_define_type_function(FLGR_BIT);
00068 }
00069 void flgr1d_set_gaussian_kernel_fgUINT8(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00070 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgUINT8);
00071 }
00072 void flgr1d_set_gaussian_kernel_fgUINT16(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00073 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgUINT16);
00074 }
00075 void flgr1d_set_gaussian_kernel_fgUINT32(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00076 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgUINT32);
00077 }
00078 void flgr1d_set_gaussian_kernel_fgINT8(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00079 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgINT8);
00080 }
00081 void flgr1d_set_gaussian_kernel_fgINT16(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00082 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgINT16);
00083 }
00084 void flgr1d_set_gaussian_kernel_fgINT32(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00085 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgINT32);
00086 }
00087 void flgr1d_set_gaussian_kernel_fgFLOAT32(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00088 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgFLOAT32);
00089 }
00090 void flgr1d_set_gaussian_kernel_fgFLOAT64(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00091 FLGR_MACRO_SET_GAUSSIAN_KER_1D(fgFLOAT64);
00092 }
00093
00094
00095
00097
00103
00104 FLGR_Ret flgr1d_set_gaussian_kernel(FLGR_Data1D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00105
00106
00107 if(nhb==NULL){
00108 POST_ERROR("Null objects!\n");
00109 return FLGR_RET_NULL_OBJECT;
00110 }
00111
00112 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr1d_set_gaussian_kernel,nhb, sigma, levelMax);
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00128
00130 #define FLGR_MACRO_SET_GAUSSIAN_KER_2D(dtype) \
00131 FLGR_Vector *vec; \
00132 fgFLOAT64 N,M; \
00133 int v,u; \
00134 fgFLOAT64 tmp,a,b,c,d; \
00135 \
00136 \
00137 \
00138 vec = flgr_vector_create(nhb->spp,nhb->type); \
00139 \
00140 N = (fgFLOAT64) (nhb->size_y-1); \
00141 M = (fgFLOAT64) (nhb->size_x-1); \
00142 \
00143 for(u=0 ; u<nhb->size_y ; u++) { \
00144 for(v=0 ; v<nhb->size_x ; v++) { \
00145 a = pow((u-N/2),2); \
00146 b = pow((v-M/2),2); \
00147 c = pow(sigma,2); \
00148 d =(a+b)/c; \
00149 tmp = exp(-0.5*d) * levelMax; \
00150 flgr_vector_populate_from_scalar_##dtype(vec, (dtype) tmp); \
00151 flgr2d_set_data_vector_##dtype(nhb,u,v,vec); \
00152 } \
00153 } \
00154 \
00155 flgr_vector_destroy(vec); \
00156 return
00157
00158 void flgr2d_set_gaussian_kernel_fgBIT(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00159 flgr_no_define_type_function(FLGR_BIT);
00160 }
00161 void flgr2d_set_gaussian_kernel_fgUINT8(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00162 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgUINT8);
00163 }
00164 void flgr2d_set_gaussian_kernel_fgUINT16(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00165 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgUINT16);
00166 }
00167 void flgr2d_set_gaussian_kernel_fgUINT32(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00168 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgUINT32);
00169 }
00170 void flgr2d_set_gaussian_kernel_fgINT8(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00171 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgINT8);
00172 }
00173 void flgr2d_set_gaussian_kernel_fgINT16(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00174 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgINT16);
00175 }
00176 void flgr2d_set_gaussian_kernel_fgINT32(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00177 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgINT32);
00178 }
00179 void flgr2d_set_gaussian_kernel_fgFLOAT32(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00180 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgFLOAT32);
00181 }
00182 void flgr2d_set_gaussian_kernel_fgFLOAT64(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00183 FLGR_MACRO_SET_GAUSSIAN_KER_2D(fgFLOAT64);
00184 }
00185
00186
00187
00189
00195
00196 FLGR_Ret flgr2d_set_gaussian_kernel(FLGR_Data2D *nhb, fgFLOAT64 sigma, fgFLOAT64 levelMax) {
00197
00198
00199 if(nhb==NULL){
00200 POST_ERROR("Null objects!\n");
00201 return FLGR_RET_NULL_OBJECT;
00202 }
00203
00204 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_set_gaussian_kernel,nhb, sigma, levelMax);
00205 }
00206
00207
00208
00209
00210