Changeset 1076 for trunk/psLib/src/imageops/psImageStats.c
- Timestamp:
- Jun 23, 2004, 3:38:45 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageStats.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageStats.c
r1073 r1076 164 164 float *p_psCalcScaleFactorsEval(int n) 165 165 { 166 int i = 0; 167 float tmp = 0.0; 166 168 return p_psCalcScaleFactorsFit(n); 167 float tmp = 0.0; 168 int i = 0; 169 // float tmp = 0.0; 169 170 printf("Should not get here\n"); 170 171 float *scalingFactors = (float *) psAlloc(n * sizeof(float)); 171 172 for (i=0;i<n;i++) { 172 173 // scalingFactors[i] = ((2.0 * (float) i) / ((float) (n-1))) - 1.0; 173 tmp = (float) ( i + 1);174 tmp = (float) (n - i); 174 175 tmp = (M_PI * (tmp - 0.5)) / ((float) n); 175 176 scalingFactors[i] = cos(tmp); … … 224 225 psPolynomial2D *coeffs) 225 226 { 226 int k = 0;227 int l = 0;228 227 int x = 0; 229 228 int y = 0; … … 245 244 246 245 // We scale the pixel positions to values between -1.0 and 1.0 247 cScalingFactors = p_psCalcScaleFactorsFit(input->numRows);248 rScalingFactors = p_psCalcScaleFactorsFit(input->numCols);246 rScalingFactors = p_psCalcScaleFactorsFit(input->numRows); 247 cScalingFactors = p_psCalcScaleFactorsFit(input->numCols); 249 248 250 249 // Determine how many Chebyshev polynomials are needed, then create them. … … 264 263 265 264 } 266 printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp);265 //printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp); 267 266 } 268 267 } … … 282 281 } 283 282 284 // NOTE: Check the math on this at a later date.285 // coeffs->coeff[0][0] = sums[0][0] / ((float) (coeffs->nX * coeffs->nY));286 // for (i=0;i<coeffs->nX;i++) {287 // coeffs->coeff[i][0] = ((sums[i][0] * 2.0) /288 // ((float) (coeffs->nX * coeffs->nY))) -289 // coeffs->coeff[0][0];290 // }291 // for (j=0;j<coeffs->nY;j++) {292 // coeffs->coeff[0][j] =293 // ((sums[0][j] * 2.0) /294 // ((float) (coeffs->nX * coeffs->nY))) -295 // coeffs->coeff[0][0];296 // }297 298 283 for (i=0;i<coeffs->nX;i++) { 299 284 for (j=0;j<coeffs->nY;j++) { 300 285 coeffs->coeff[i][j] = sums[i][j]; 301 coeffs->coeff[i][j]/= ((float) coeffs->nX) * ((float) coeffs->nY); 286 coeffs->coeff[i][j]/= (float) (input->numRows * input->numCols); 287 302 288 if ((i != 0) && (j != 0)) { 303 289 coeffs->coeff[i][j]*= 4.0; … … 307 293 coeffs->coeff[i][j]*= 2.0; 308 294 } 309 310 // coeffs->coeff[i][j] = 311 // ((sums[i][0] * 4.0) / ((float) (coeffs->nX * coeffs->nY))) - 312 // (coeffs->coeff[0][0] + 313 // coeffs->coeff[i][0] + 314 // coeffs->coeff[0][j]); 315 } 316 } 317 318 for (k=0;k<coeffs->nX;k++) { 319 for (l=0;l<coeffs->nY;l++) { 320 tmp = 0.0; 321 for (i=0;i<coeffs->nX;i++) { 322 for (j=0;j<coeffs->nY;j++) { 323 for (x=0;x<input->numRows;x++) { 324 for (y=0;y<input->numCols;y++) { 325 tmp+= (coeffs->coeff[i][j] * 326 psEvalPolynomial1D(rScalingFactors[x], chebPolys[i]) * 327 psEvalPolynomial1D(rScalingFactors[y], chebPolys[j]) * 328 psEvalPolynomial1D(rScalingFactors[x], chebPolys[k]) * 329 psEvalPolynomial1D(rScalingFactors[y], chebPolys[l])); 330 331 } 332 } 333 } 334 } 335 } 336 } 337 295 } 296 } 338 297 339 298 // Free the Chebyshev polynomials that were created in this routine. … … 385 344 386 345 // We scale the pixel positions to values between -1.0 and 1.0 387 cScalingFactors = p_psCalcScaleFactorsEval(input->numRows);388 rScalingFactors = p_psCalcScaleFactorsEval(input->numCols);346 rScalingFactors = p_psCalcScaleFactorsEval(input->numRows); 347 cScalingFactors = p_psCalcScaleFactorsEval(input->numCols); 389 348 390 349 // Determine how many Chebyshev polynomials are needed, then create them. … … 427 386 return(0); 428 387 } 388 389 /***************************************************************************** 390 p_psImagePixelInterpolation(image, x, y): this routine takes as input an 391 image and coordinates (x, y) and produces as output the corresponding pixel 392 value at the those coordinates. For fractional corrdinates (x, y), 2-D 393 linear interpolation is performed on the image. 394 *****************************************************************************/ 395 float psImagePixelInterpolation(psImage *input, 396 float x, 397 float y) 398 { 399 float floorX = 0.0; 400 float floorY = 0.0; 401 float fracX = 0.0; 402 float fracY = 0.0; 403 int intFloorX = 0; 404 int intFloorY = 0; 405 float x1 = 0.0; 406 float x2 = 0.0; 407 float pixel = 0.0; 408 409 if ((x < 0.0) || 410 (x > ((float) input->numRows-1)) || 411 (y < 0.0) || 412 (y > ((float) input->numCols-1))) { 413 psAbort(__func__, 414 "Fractional coordinates (%f %f) outside image range.", x, y); 415 } 416 417 floorX = floorf(x); 418 intFloorX = (int) floorX; 419 fracX = x - floorX; 420 421 floorY = floorf(y); 422 intFloorY = (int) floorY; 423 fracY = y - floorY; 424 425 if (intFloorX == (input->numRows-1)) { 426 pixel = input->data.F32[intFloorX][intFloorY]; 427 if (intFloorY < (input->numCols-1)) { 428 pixel+= fracY * (input->data.F32[intFloorX][intFloorY+1] - 429 input->data.F32[intFloorX][intFloorY]); 430 } 431 return(pixel); 432 } else if (intFloorX == (input->numCols-1)) { 433 if (intFloorX < (input->numRows-1)) { 434 pixel+= fracX * (input->data.F32[intFloorX+1][intFloorY] - 435 input->data.F32[intFloorX][intFloorY]); 436 } 437 return(pixel); 438 } 439 440 441 x1 = input->data.F32[intFloorX][intFloorY]; 442 x1+= fracY * (input->data.F32[intFloorX][intFloorY+1] - 443 input->data.F32[intFloorX][intFloorY]); 444 445 x2 = input->data.F32[intFloorX+1][intFloorY]; 446 x2+= fracY * (input->data.F32[intFloorX+1][intFloorY+1] - 447 input->data.F32[intFloorX+1][intFloorY]); 448 pixel = x1; 449 pixel+= fracX * (x2 - x1); 450 451 return(pixel); 452 }
Note:
See TracChangeset
for help on using the changeset viewer.
