Changeset 20207
- Timestamp:
- Oct 16, 2008, 12:55:45 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageInterpolate.c (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageInterpolate.c
r20104 r20207 7 7 * @author Paul Price, IfA 8 8 * 9 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2008-10-1 3 21:47:41$9 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-10-16 22:55:45 $ 11 11 * 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 166 166 // No need to normalise to unity 167 167 static inline void interpolateKernelGenerate(int xNum, int yNum, // Size of interpolation kernel 168 doublekernel[xNum][yNum], // Kernel, to be set168 float kernel[xNum][yNum], // Kernel, to be set 169 169 bool *xExact, bool *yExact, // Exact shift? 170 170 int xCentral, int yCentral, // Central pixel of convolution … … 174 174 ) 175 175 { 176 doublexFrac = x - 0.5 - xCentral; // Fraction of pixel in x177 doubleyFrac = y - 0.5 - yCentral; // Fraction of pixel in y176 float xFrac = x - 0.5 - xCentral; // Fraction of pixel in x 177 float yFrac = y - 0.5 - yCentral; // Fraction of pixel in y 178 178 *xExact = (allowExact && fabs(xFrac) < DBL_EPSILON); 179 179 *yExact = (allowExact && fabs(yFrac) < DBL_EPSILON); … … 188 188 } 189 189 case PS_INTERPOLATE_BICUBE: { 190 doublexFrac = x - 0.5 - xCentral; // Fraction of pixel in x191 doubleyFrac = y - 0.5 - yCentral; // Fraction of pixel in y190 float xFrac = x - 0.5 - xCentral; // Fraction of pixel in x 191 float yFrac = y - 0.5 - yCentral; // Fraction of pixel in y 192 192 // Calculation variables 193 193 double xxFrac = xFrac * xFrac / 6.0; … … 208 208 } 209 209 case PS_INTERPOLATE_GAUSS: { 210 doublexFrac = x - xCentral - 0.5; // Fraction of pixel in x211 doubleyFrac = y - yCentral - 0.5; // Fraction of pixel in y212 doublesigma = 0.5; // Gaussian sigma210 float xFrac = x - xCentral - 0.5; // Fraction of pixel in x 211 float yFrac = y - yCentral - 0.5; // Fraction of pixel in y 212 float sigma = 0.5; // Gaussian sigma 213 213 for (int j = 0, yPos = - (yNum - 1) / 2; j < yNum; j++, yPos++) { 214 214 for (int i = 0, xPos = - (xNum - 1) / 2; i < xNum; i++, xPos++) { 215 kernel[j][i] = exp (-0.5 / PS_SQR(sigma) * (PS_SQR(xPos - xFrac) +216 PS_SQR(yPos - yFrac)));215 kernel[j][i] = expf(-0.5 / PS_SQR(sigma) * (PS_SQR(xPos - xFrac) + 216 PS_SQR(yPos - yFrac))); 217 217 } 218 218 } … … 326 326 INTERPOLATE_BOUNDS(); 327 327 328 double kernel[yNum][xNum];// Interpolation kernel for straight interpolation328 float kernel[yNum][xNum]; // Interpolation kernel for straight interpolation 329 329 bool xExact, yExact; // Exact shifts? 330 330 interpolateKernelGenerate(xNum, yNum, kernel, &xExact, &yExact, xCentral, yCentral, … … 345 345 // Add contributions in an area outside the image 346 346 #define INTERPOLATE_KERNEL_ADD_OFFIMAGE() { \ 347 float kernelValue = kernel[j][i]; /* Value of kernel */ \ 348 double kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \ 349 sumBad += kernelValue2; \ 350 sumKernel2 += kernelValue2; \ 347 sumBad += PS_SQR(kernel[j][i]); \ 351 348 } 352 349 … … 390 387 for (int i = iMin, xPix = xMin; i < iMax; i++, xPix++) { \ 391 388 float kernelValue = kernel[j][i]; /* Value of kernel */ \ 392 doublekernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \389 float kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \ 393 390 if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { \ 394 391 sumBad += kernelValue2; \ … … 397 394 sumVariance += kernelValue2 * variance->data.TYPE[yPix][xPix]; \ 398 395 sumKernel += kernelValue; \ 396 sumKernel2 += kernelValue2; \ 399 397 } \ 400 sumKernel2 += PS_SQR(kernelValue); \401 398 } \ 402 399 } \ … … 407 404 for (int i = iMin, xPix = xMin; i < iMax; i++, xPix++) { \ 408 405 float kernelValue = kernel[j][i]; /* Value of kernel */ \ 409 doublekernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \406 float kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \ 410 407 sumImage += kernelValue * image->data.TYPE[yPix][xPix]; \ 411 408 sumVariance += kernelValue2 * variance->data.TYPE[yPix][xPix]; \ … … 420 417 for (int i = iMin, xPix = xMin; i < iMax; i++, xPix++) { \ 421 418 float kernelValue = kernel[j][i]; /* Value of kernel */ \ 419 float kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \ 422 420 if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { \ 423 sumBad += PS_SQR(kernelValue); \421 sumBad += kernelValue2; \ 424 422 } else { \ 425 423 sumImage += kernelValue * image->data.TYPE[yPix][xPix]; \ 426 424 sumKernel += kernelValue; \ 425 sumKernel2 += kernelValue2; \ 427 426 } \ 428 sumKernel2 += PS_SQR(kernelValue); \429 427 } \ 430 428 } \ … … 463 461 *imageValue = sumImage / sumKernel; 464 462 if (wantVariance) { 465 *varianceValue = sumVariance * PS_SQR(sumKernel)/ sumKernel2;463 *varianceValue = sumVariance / sumKernel2; 466 464 } 467 465 if (sumBad == 0) { 468 466 // Completely good pixel 469 467 status = PS_INTERPOLATE_STATUS_GOOD; 470 } else if (sumBad / sumKernel2 < PS_SQR(options->poorFrac)) {468 } else if (sumBad < PS_SQR(options->poorFrac) * (sumBad + sumKernel2)) { 471 469 // Some pixels masked: poor pixel 472 470 if (haveMask && maskValue) { … … 487 485 488 486 // Generate Lanczos interpolation kernels 489 static void lanczos( doublevalues[], // Interpolation kernel to generate487 static void lanczos(float values[], // Interpolation kernel to generate 490 488 bool *exact, // Exact shift? 491 489 int num, // Number of values in the kernel … … 506 504 } else { 507 505 *exact = false; 508 doublenorm1 = 2.0 / PS_SQR(M_PI); // Normalisation for laczos509 doublenorm2 = M_PI * 4.0 / (float)num; // Normalisation for sinc function 1510 double norm3 =M_PI_2 * 4.0 / (float)num; // Normalisation for sinc function 2511 doublepos = - (num - 1)/2 - frac; // Position of interest506 float norm1 = 2.0 / PS_SQR(M_PI); // Normalisation for laczos 507 float norm2 = M_PI * 4.0 / (float)num; // Normalisation for sinc function 1 508 float norm3 = M_PI_2 * 4.0 / (float)num; // Normalisation for sinc function 2 509 float pos = - (num - 1)/2 - frac; // Position of interest 512 510 for (int i = 0; i < num; i++, pos += 1.0) { 513 511 if (fabs(pos) < DBL_EPSILON) { 514 512 values[i] = 1.0; 515 513 } else { 516 values[i] = norm1 * sin (pos * norm2) * sin(pos * norm3) / PS_SQR(pos);514 values[i] = norm1 * sinf(pos * norm2) * sinf(pos * norm3) / PS_SQR(pos); 517 515 } 518 516 } … … 553 551 // Generate the interpolation kernels for separable case; they should be normalised to unity 554 552 static inline void interpolateSeparateGenerate(int xNum, int yNum, // Size of interpolation kernel 555 double xKernel[xNum], doubleyKernel[yNum], // Kernels553 float xKernel[xNum], float yKernel[yNum], // Kernels 556 554 bool *xExact, bool *yExact, // Exact shifts? 557 555 int xCentral, int yCentral, // Central pixel of convolution … … 566 564 case PS_INTERPOLATE_LANCZOS3: 567 565 case PS_INTERPOLATE_LANCZOS4: { 568 doublexFrac = x - xCentral - 0.5; // Fraction of pixel in x566 float xFrac = x - xCentral - 0.5; // Fraction of pixel in x 569 567 lanczos(xKernel, xExact, xNum, xFrac, allowExact); 570 doubleyFrac = y - yCentral - 0.5; // Fraction of pixel in y568 float yFrac = y - yCentral - 0.5; // Fraction of pixel in y 571 569 lanczos(yKernel, yExact, yNum, yFrac, allowExact); 572 570 break; … … 598 596 INTERPOLATE_BOUNDS(); 599 597 600 doublexKernel[xNum], yKernel[yNum]; // Interpolation kernels598 float xKernel[xNum], yKernel[yNum]; // Interpolation kernels 601 599 bool xExact, yExact; // Exact shift? 602 600 interpolateSeparateGenerate(xNum, yNum, xKernel, yKernel, &xExact, &yExact, … … 605 603 float sumKernel = 0.0; // Sum of the kernel 606 604 double sumKernel2 = 0.0; // Sum of the kernel-squared 607 float sumBad = 0.0;// Sum of bad kernel-squared contributions605 double sumBad = 0.0; // Sum of bad kernel-squared contributions 608 606 psMaskType maskVal = options->maskVal; // Value to mask 609 607 double sumImage = 0.0; // Sum of image multiplied by kernel … … 617 615 // Add contributions in an area outside the image 618 616 #define INTERPOLATE_SEPARATE_SETUP_OFFIMAGE_COL() \ 619 float xSumBad = 0.0; \620 double xSumKernel2 = 0.0; 617 float xSumBad = 0.0; 618 621 619 #define INTERPOLATE_SEPARATE_ADD_OFFIMAGE_COL() { \ 622 float kernelValue = xKernel[i]; /* Value of kernel */ \ 623 double kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \ 624 xSumBad += kernelValue2; \ 625 xSumKernel2 += kernelValue2; \ 626 } 620 xSumBad += PS_SQR(xKernel[i]); \ 621 } 622 627 623 #define INTERPOLATE_SEPARATE_ADD_OFFIMAGE_ROW() { \ 628 float kernelValue = yKernel[j]; /* Value of kernel */ \ 629 double kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \ 630 sumBad += kernelValue2 * xSumBad; \ 631 sumKernel2 += kernelValue2 * xSumKernel2; \ 624 sumBad += PS_SQR(yKernel[j]) * xSumBad; \ 632 625 } 633 626 … … 696 689 xSumVariance += kernelValue2 * *varianceData; \ 697 690 xSumKernel += kernelValue; \ 691 xSumKernel2 += kernelValue2; \ 698 692 } \ 699 xSumKernel2 += kernelValue2; \700 693 } \ 701 694 float kernelValue = yKernel[j]; /* Value of kernel in y */ \ … … 745 738 xSumImage += kernelValue * image->data.TYPE[yPix][xPix]; \ 746 739 xSumKernel += kernelValue; \ 740 xSumKernel2 += kernelValue2; \ 747 741 } \ 748 xSumKernel2 += kernelValue2; \749 742 } \ 750 743 float kernelValue = yKernel[j]; /* Value of kernel in y */ \ … … 794 787 *imageValue = sumImage / sumKernel; 795 788 if (wantVariance) { 796 *varianceValue = sumVariance * PS_SQR(sumKernel)/ sumKernel2;789 *varianceValue = sumVariance / sumKernel2; 797 790 } 798 791 if (sumBad == 0) { 799 792 // Completely good pixel 800 793 status = PS_INTERPOLATE_STATUS_GOOD; 801 } else if (sumBad / sumKernel2 < PS_SQR(options->poorFrac)) {794 } else if (sumBad < PS_SQR(options->poorFrac) * (sumBad + sumKernel2) ) { 802 795 // Some pixels masked: poor pixel 803 796 if (haveMask && maskValue) { … … 888 881 } 889 882 890 doublekernel[yNum][xNum]; // Interpolation kernel for straight interpolation883 float kernel[yNum][xNum]; // Interpolation kernel for straight interpolation 891 884 bool xExact, yExact; // Exact shift? 892 885 // Pretend we're not shifting pixels (i.e., we don't care about any exact shifting) because on the off … … 896 889 x, y, options->mode, false); 897 890 898 doublesumKernel = 0.0; // Sum of kernel891 float sumKernel = 0.0; // Sum of kernel 899 892 double sumKernel2 = 0.0; // Sum of kernel squares 900 893 for (int j = 0; j < yNum; j++) { … … 925 918 } 926 919 927 doublexKernel[xNum], yKernel[yNum]; // Interpolation kernels for separable interpolation920 float xKernel[xNum], yKernel[yNum]; // Interpolation kernels for separable interpolation 928 921 bool xExact, yExact; // Exact shift? 929 922 // Pretend we're not shifting pixels (i.e., we don't care about any exact shifting) because on the off … … 933 926 xCentral, yCentral, x, y, options->mode, false); 934 927 935 doubleySumKernel = 0.0; // Sum of kernel in y928 float ySumKernel = 0.0; // Sum of kernel in y 936 929 double ySumKernel2 = 0.0; // Sum of kernel squared in y 937 930 for (int j = 0; j < yNum; j++) { 938 doublexSumKernel = 0.0; // Sum of kernel in x931 float xSumKernel = 0.0; // Sum of kernel in x 939 932 double xSumKernel2 = 0.0; // Sum of kernel squared in x 940 933 for (int i = 0; i < xNum; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.
