Changeset 12776 for trunk/psLib/src/imageops/psImageInterpolate.c
- Timestamp:
- Apr 9, 2007, 5:59:13 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageInterpolate.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageInterpolate.c
r12756 r12776 7 7 * @author Paul Price, IfA 8 8 * 9 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-04- 05 23:57:42$9 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-04-10 03:59:13 $ 11 11 * 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 132 132 133 133 int xNum, yNum; // Number of interpolation kernel pixels 134 int xCentral, yCentral; // Central pixel of the convolution 134 135 switch (options->mode) { 135 136 case PS_INTERPOLATE_BILINEAR: 136 137 xNum = yNum = 2; 138 // Central pixel is the pixel below the point of interest 139 xCentral = floor(x - 0.5 + FLT_EPSILON); 140 yCentral = floor(y - 0.5 + FLT_EPSILON); 137 141 break; 138 142 case PS_INTERPOLATE_BICUBE: 139 143 case PS_INTERPOLATE_GAUSS: 140 144 xNum = yNum = 3; 145 // Central pixel is the closest pixel to the point of interest 146 xCentral = x; 147 yCentral = y; 141 148 break; 142 149 case PS_INTERPOLATE_FLAT: … … 149 156 150 157 const psImage *image = options->image; // Image of interest 151 int xFloor = floor(x - 0.5 + FLT_EPSILON); // Pixel below point of interest in x152 int yFloor = floor(y - 0.5 + FLT_EPSILON); // Pixel below point of interest in y153 158 int xLast = image->numCols - 1; // Last pixel in x 154 159 int yLast = image->numRows - 1; // Last pixel in y 155 160 156 if (x Floor - (xNum - 1) / 2 < 0 || xFloor+ xNum / 2 > xLast ||157 y Floor - (yNum - 1) / 2 < 0 || yFloor+ yNum / 2 > yLast) {161 if (xCentral - (xNum - 1) / 2 < 0 || xCentral + xNum / 2 > xLast || 162 yCentral - (yNum - 1) / 2 < 0 || yCentral + yNum / 2 > yLast) { 158 163 // At least one pixel of the interpolation kernel is off the image 159 164 if (imageValue) { … … 171 176 switch (options->mode) { 172 177 case PS_INTERPOLATE_BILINEAR: { 173 double xFrac = x - 0.5 - x Floor; // Fraction of pixel in x174 double yFrac = y - 0.5 - y Floor; // Fraction of pixel in y178 double xFrac = x - 0.5 - xCentral; // Fraction of pixel in x 179 double yFrac = y - 0.5 - yCentral; // Fraction of pixel in y 175 180 kernel[0][0] = (1.0 - xFrac) * (1.0 - yFrac); 176 181 kernel[0][1] = xFrac * (1.0 - yFrac); … … 180 185 } 181 186 case PS_INTERPOLATE_BICUBE: { 182 double xFrac = x - 0.5 - x Floor; // Fraction of pixel in x183 double yFrac = y - 0.5 - y Floor; // Fraction of pixel in y187 double xFrac = x - 0.5 - xCentral; // Fraction of pixel in x 188 double yFrac = y - 0.5 - yCentral; // Fraction of pixel in y 184 189 // Calculation variables 185 190 double xxFrac = xFrac * xFrac / 6.0; … … 200 205 } 201 206 case PS_INTERPOLATE_GAUSS: { 202 double xFrac = x - 0.5 - xFloor; // Fraction of pixel in x 203 double yFrac = y - 0.5 - yFloor; // Fraction of pixel in y 204 double xGaussFrac = 2.0 * erf((double)xNum / 4.0) - 1.0; // Fraction of Gaussian in x 205 double yGaussFrac = 2.0 * erf((double)yNum / 4.0) - 1.0; // Fraction of Gaussian in x 206 double norm = 1.0 / (double)xNum / (double)yNum * 207 (1.0 - xGaussFrac) / xGaussFrac * (1.0 - yGaussFrac) / yGaussFrac; // Normalisation 207 double xFrac = x - xCentral - 0.5; // Fraction of pixel in x 208 double yFrac = y - yCentral - 0.5; // Fraction of pixel in y 209 double sigma = 0.5; // Gaussian sigma 210 double norm = 0.0; // Normalisation 208 211 for (int j = 0, yPos = - (yNum - 1) / 2; j < yNum; j++, yPos++) { 209 212 for (int i = 0, xPos = - (xNum - 1) / 2; i < xNum; i++, xPos++) { 210 kernel[j][i] = norm * exp(-0.5 * (PS_SQR(xPos - xFrac) + PS_SQR(yPos - yFrac))); 213 norm += kernel[j][i] = exp(-0.5 / PS_SQR(sigma) * (PS_SQR(xPos - xFrac) + 214 PS_SQR(yPos - yFrac))); 215 } 216 } 217 norm = 1.0 / norm; 218 for (int j = 0; j < yNum; j++) { 219 for (int i = 0; i < xNum; i++) { 220 kernel[j][i] *= norm; 211 221 } 212 222 } … … 224 234 #define KERNEL_IMAGE_CASE(TYPE) \ 225 235 case PS_TYPE_##TYPE: { \ 226 for (int j = 0, yPix = y Floor- (yNum - 1) / 2; j < yNum; j++, yPix++) { \227 for (int i = 0, xPix = x Floor- (xNum - 1) / 2; i < xNum; i++, xPix++) { \236 for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \ 237 for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \ 228 238 value += values[j][i] = kernel[j][i] * image->data.TYPE[yPix][xPix]; \ 229 239 } \ … … 262 272 int badPix = 0; // Number of bad pixels 263 273 *maskValue = 0; 264 for (int j = 0, yPix = y Floor- (yNum - 1) / 2; j < yNum; j++, yPix++) {265 for (int i = 0, xPix = x Floor- (xNum - 1) / 2; i < xNum; i++, xPix++) {274 for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { 275 for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { 266 276 if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { 267 277 badValue += values[j][i]; … … 289 299 #define KERNEL_VARIANCE_CASE(TYPE) \ 290 300 case PS_TYPE_##TYPE: { \ 291 for (int j = 0, yPix = y Floor- (yNum - 1) / 2; j < yNum; j++, yPix++) { \292 for (int i = 0, xPix = x Floor- (xNum - 1) / 2; i < xNum; i++, xPix++) { \301 for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \ 302 for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \ 293 303 *varianceValue += PS_SQR(kernel[j][i]) * variance->data.TYPE[yPix][xPix]; \ 294 304 } \ … … 337 347 } 338 348 } else { 349 double norm3 = 0.0; // Normalisation 339 350 double norm1 = 2.0 / PS_SQR(M_PI); // Normalisation for laczos 340 double norm2 = 2.0 / (num / 2); // Normalisation for sinc functions341 double pos = frac - (num - 1)/2; // Position of interest351 double norm2 = 4.0 / (float)num; // 2.0 / (num / 2); // Normalisation for sinc functions 352 double pos = - (num - 1)/2 - frac; // Position of interest 342 353 for (int i = 0; i < num; i++, pos += 1.0) { 343 values[i] = norm1 * sin(M_PI * pos * norm2) * sin(M_PI_2 * pos * norm2) / PS_SQR(pos); 354 norm3 += values[i] = norm1 * sin(M_PI * pos * norm2) * sin(M_PI_2 * pos * norm2) / PS_SQR(pos); 355 } 356 norm3 = 1.0 / norm3; 357 for (int i = 0; i < num; i++, pos += 1.0) { 358 values[i] *= norm3; 344 359 } 345 360 } … … 373 388 } 374 389 390 // Central pixel is the pixel below the point of interest 391 int xCentral = floor(x - 0.5), yCentral = floor(y - 0.5); // Central pixel of the convolution 375 392 const psImage *image = options->image; // Image of interest 376 int xFloor = floor(x - 0.5 + FLT_EPSILON); // Pixel below point of interest in x377 int yFloor = floor(y - 0.5 + FLT_EPSILON); // Pixel below point of interest in y378 393 int xLast = image->numCols - 1; // Last pixel in x 379 394 int yLast = image->numRows - 1; // Last pixel in y 380 395 381 if (x Floor - (xNum - 1) / 2 < 0 || xFloor+ xNum / 2 > xLast ||382 y Floor - (yNum - 1) / 2 < 0 || yFloor+ yNum / 2 > yLast) {396 if (xCentral - (xNum - 1) / 2 < 0 || xCentral + xNum / 2 > xLast || 397 yCentral - (yNum - 1) / 2 < 0 || yCentral + yNum / 2 > yLast) { 383 398 // At least one pixel of the interpolation kernel is off the image 384 399 if (imageValue) { … … 400 415 case PS_INTERPOLATE_LANCZOS3: 401 416 case PS_INTERPOLATE_LANCZOS4: { 402 double xFrac = x - 0.5 - xFloor; // Fraction of pixel in x417 double xFrac = x - xCentral - 0.5; // Fraction of pixel in x 403 418 #if 0 404 419 if (fabs(xFrac) < DBL_EPSILON) { … … 411 426 } 412 427 #endif 413 double yFrac = y - 0.5 - yFloor; // Fraction of pixel in y428 double yFrac = y - yCentral - 0.5; // Fraction of pixel in y 414 429 #if 0 415 430 if (fabs(yFrac) < DBL_EPSILON) { … … 435 450 #define SEPARATE_IMAGE_CASE(TYPE) \ 436 451 case PS_TYPE_##TYPE: { \ 437 for (int j = 0, yPix = y Floor- (yNum - 1) / 2; j < yNum; j++, yPix++) { \452 for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \ 438 453 double xInterpValue = 0.0; /* Interpolation in x */ \ 439 for (int i = 0, xPix = x Floor- (xNum - 1) / 2; i < xNum; i++, xPix++) { \454 for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \ 440 455 xInterpValue += values[j][i] = xKernel[i] * image->data.TYPE[yPix][xPix]; \ 441 456 } \ … … 475 490 int badPix = 0; // Number of bad pixels 476 491 *maskValue = 0; 477 for (int j = 0, yPix = y Floor- (yNum - 1) / 2; j < yNum; j++, yPix++) {492 for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { 478 493 // Interpolation in x 479 494 double xInterpValue = 0.0; 480 for (int i = 0, xPix = x Floor- (xNum - 1) / 2; i < xNum; i++, xPix++) {495 for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { 481 496 if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { 482 497 xInterpValue += values[j][i]; … … 506 521 #define SEPARATE_VARIANCE_CASE(TYPE) \ 507 522 case PS_TYPE_##TYPE: { \ 508 for (int j = 0, yPix = y Floor- (yNum - 1) / 2; j < yNum; j++, yPix++) { \523 for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \ 509 524 double xInterpValue = 0.0; /* Interpolation in x */ \ 510 for (int i = 0, xPix = x Floor- (xNum - 1) / 2; i < xNum; i++, xPix++) { \525 for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \ 511 526 xInterpValue += PS_SQR(xKernel[i]) * variance->data.TYPE[yPix][xPix]; \ 512 527 } \
Note:
See TracChangeset
for help on using the changeset viewer.
