00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "libAuxiliary.h"
00021
00050 void wxRgb2Yuv(float *r,float *g,float *b,float *y,float *u,float *v,int width,int height)
00051 {
00052 int size=height*width;
00053
00054 for(int i=0;i<size;i++){
00055 y[i] = ( COEFF_YR * r[i] + COEFF_YG * g[i] + COEFF_YB * b[i]);
00056 u[i] = ( r[i] - y[i]);
00057 v[i] = ( b[i] - y[i]);
00058 }
00059
00060 }
00061
00062
00063
00075 void wxYuv2Rgb(float *r,float *g,float *b,float *y,float *u,float *v, int width,int height)
00076 {
00077
00078
00079 int iwh=height*width;
00080
00081 for(int i=0;i<iwh;i++){
00082
00083 g[i] = ( y[i] - COEFF_YR * (u[i] + y[i]) - COEFF_YB * (v[i] + y[i]) ) / COEFF_YG;
00084 r[i] = ( u[i] + y[i]);
00085 b[i] = ( v[i] + y[i]);
00086
00087 }
00088
00089 }
00090
00091
00092
00102 void wxCopy(float *tpI,float *tpO, int ilength)
00103 {
00104 memcpy((void *) tpO, (const void *) tpI, ilength * sizeof(float));
00105 }
00106
00107
00108
00109
00110
00111
00122 void sFillLut(float *lut, int size)
00123 {
00124 for(int i=0; i< size;i++) lut[i]= expf( - (float) i / LUTPRECISION);
00125 }
00126
00127
00128
00129
00130
00131
00142 float sLUT(float dif, float *lut)
00143 {
00144
00145 if (dif >= (float) LUTMAXM1) return 0.0;
00146
00147 int x= (int) floor( (double) dif * (float) LUTPRECISION);
00148
00149 float y1=lut[x];
00150 float y2=lut[x+1];
00151
00152 return y1 + (y2-y1)*(dif*LUTPRECISION - x);
00153 }
00154
00155
00156
00157
00158
00159
00171 float l2_distance_r1(float *u0, int i0, int j0, int i1,
00172 int j1, int width)
00173 {
00174
00175 float diff, dist = 0.0;
00176
00177 float *ptr0, *ptr1;
00178
00179 ptr0 = u0 + (j0 - 1) * width + i0 - 1;
00180 ptr1 = u0 + (j1 - 1) * width + i1 - 1;
00181
00182
00183
00184 diff = *ptr0++ - *ptr1++;
00185 dist += diff * diff;
00186 diff = *ptr0++ - *ptr1++;
00187 dist += diff * diff;
00188 diff = *ptr0 - *ptr1;
00189 dist += diff * diff;
00190
00191
00192 ptr0 += width - 2;
00193 ptr1 += width - 2;
00194
00195 diff = *ptr0++ - *ptr1++;
00196 dist += diff * diff;
00197 diff = *ptr0++ - *ptr1++;
00198 dist += diff * diff;
00199 diff = *ptr0 - *ptr1;
00200 dist += diff * diff;
00201
00202
00203 ptr0 += width - 2;
00204 ptr1 += width - 2;
00205
00206 diff = *ptr0++ - *ptr1++;
00207 dist += diff * diff;
00208 diff = *ptr0++ - *ptr1++;
00209 dist += diff * diff;
00210 diff = *ptr0 - *ptr1;
00211 dist += diff * diff;
00212
00213 return dist;
00214 }
00215
00216
00217
00218
00219
00220
00221
00237 void wxMedian(float *u,float *v, float fRadius, int inIter, int iWidth,int iHeight)
00238 {
00239
00240
00241 int iRadius = (int)(fRadius+1.0);
00242 int iNeigSize = (2*iRadius+1)*(2*iRadius+1);
00243 float fRadiusSqr = fRadius * fRadius;
00244
00245
00246
00247 float * vector = new float[iNeigSize];
00248
00249
00250 for(int n = 0; n < inIter; n++){
00251
00252
00253 for(int x=0;x < iWidth;x++)
00254 for(int y=0;y< iHeight;y++){
00255
00256
00257 int iCount=0;
00258 for(int i=-iRadius;i<=iRadius;i++)
00259 for(int j=-iRadius;j<=iRadius;j++)
00260 if ((float) (i*i + j*j) <= fRadiusSqr){
00261
00262 int x0=x+i;
00263 int y0=y+j;
00264
00265 if (x0 >= 0 && y0 >= 0 && x0 < iWidth && y0 < iHeight) {
00266
00267 vector[iCount] = u[y0*iWidth+x0];
00268 iCount++;
00269
00270 }
00271
00272 }
00273
00274
00275 QuickSortFloat(vector, iCount);
00276
00277 v[y*iWidth+x] = vector[iCount / 2];
00278
00279 }
00280
00281 wxCopy(v,u,iWidth*iHeight);
00282
00283 }
00284
00285 delete[] vector;
00286
00287 }
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 int order_float_increasing(const void *a, const void *b)
00299 {
00300 if ( *(float*)a > *(float*)b ) return 1;
00301 else if ( *(float*)a < *(float*)b ) return -1;
00302
00303 return 0;
00304 }
00305
00306
00307
00308
00320 void QuickSortFloat(float *arr, int ilength)
00321 {
00322 qsort(arr, ilength, sizeof(float), order_float_increasing);
00323
00324 }
00325
00326
00327
00328
00329
00330
00331