Changeset 21363 for trunk/psModules/src/imcombine
- Timestamp:
- Feb 5, 2009, 4:31:25 PM (17 years ago)
- Location:
- trunk/psModules/src/imcombine
- Files:
-
- 12 edited
-
pmPSFEnvelope.c (modified) (5 diffs)
-
pmReadoutCombine.c (modified) (14 diffs)
-
pmReadoutCombine.h (modified) (4 diffs)
-
pmStack.c (modified) (8 diffs)
-
pmSubtraction.c (modified) (21 diffs)
-
pmSubtraction.h (modified) (2 diffs)
-
pmSubtractionEquation.c (modified) (25 diffs)
-
pmSubtractionMatch.c (modified) (9 diffs)
-
pmSubtractionParams.c (modified) (10 diffs)
-
pmSubtractionStamps.c (modified) (7 diffs)
-
pmSubtractionStamps.h (modified) (2 diffs)
-
pmSubtractionThreads.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmPSFEnvelope.c
r21183 r21363 36 36 #define PEAK_FLUX 1.0e4 // Peak flux for each source 37 37 #define SKY_VALUE 0.0e0 // Sky value for fake image 38 #define WEIGHT_VAL 3.0 // Weightingfor image39 #define WEIGHT_FACTOR 10.0 // Factor to multiply image by to get weighting38 #define VARIANCE_VAL 3.0 // Variance for image 39 #define VARIANCE_FACTOR 10.0 // Factor to multiply image by to get variance 40 40 #define PSF_STATS PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV // Statistics options for measuring PSF 41 41 #define SOURCE_FIT_ITERATIONS 100 // Number of iterations for source fitting … … 149 149 pmModel *model = pmModelFromPSFforXY(psf, x, y, PEAK_FLUX); // Model for source 150 150 psAssert (model, "failed to generate model: should this be an error or not?"); 151 float srcRadius = model->modelRadius(model->params, PS_SQR( WEIGHT_VAL)); // Radius for source151 float srcRadius = model->modelRadius(model->params, PS_SQR(VARIANCE_VAL)); // Radius for source 152 152 if (srcRadius > maxRadius) { 153 153 maxRadius = srcRadius; … … 216 216 psFree(envelope); 217 217 218 // XXX Setting the weightseems to be an art218 // XXX Setting the variance seems to be an art 219 219 // Can't set it too high so that pixels are rejected as insignificant 220 220 // Can't set it too low so that it's hard to get to the minimum 221 221 // Have also tried: 222 // *** readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", readout->image); 223 // *** readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", psScalarAlloc(WEIGHT_FACTOR, PS_TYPE_F32)); 224 readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(WEIGHT_VAL, PS_TYPE_F32)); 222 // *** readout->variance = (psImage*)psBinaryOp(NULL, readout->image, "*", readout->image); 223 // *** readout->variance = (psImage*)psBinaryOp(NULL, readout->image, "*", psScalarAlloc(VARIANCE_FACTOR, PS_TYPE_F32)); 224 readout->variance = (psImage*)psBinaryOp(NULL, readout->image, "+", 225 psScalarAlloc(VARIANCE_VAL, PS_TYPE_F32)); 225 226 readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 226 227 psImageInit(readout->mask, 0); … … 242 243 243 244 psFree(source->pixels); 244 psFree(source-> weight);245 psFree(source->variance); 245 246 psFree(source->maskView); 246 247 psFree(source->maskObj); 247 248 source->pixels = NULL; 248 source-> weight= NULL;249 source->variance = NULL; 249 250 source->maskView = NULL; 250 251 source->maskObj = NULL; … … 280 281 options->psfFieldYo = 0; 281 282 282 pmSourceFitModelInit(SOURCE_FIT_ITERATIONS, 0.01, WEIGHT_VAL, true);283 pmSourceFitModelInit(SOURCE_FIT_ITERATIONS, 0.01, VARIANCE_VAL, true); 283 284 284 285 pmPSFtry *try = pmPSFtryModel(fakes, modelName, options, 0, 0xff); -
trunk/psModules/src/imcombine/pmReadoutCombine.c
r21183 r21363 37 37 params->iter = 1; 38 38 params->rej = INFINITY; 39 params-> weights = false;39 params->variances = false; 40 40 41 41 return params; … … 75 75 psStringAppend(&comment, "Combining using statistic: %x", params->combine); 76 76 if (!hdu->header) { 77 hdu->header = psMetadataAlloc();77 hdu->header = psMetadataAlloc(); 78 78 } 79 79 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); … … 82 82 // note the clipping parameters, if used 83 83 if (params->combine == PS_STAT_CLIPPED_MEAN) { 84 psString comment = NULL; // Comment to add to header85 psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej);86 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");87 psFree(comment);88 } 89 90 // note the use of weights91 if (params-> weights) {84 psString comment = NULL; // Comment to add to header 85 psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej); 86 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, ""); 87 psFree(comment); 88 } 89 90 // note the use of variances 91 if (params->variances) { 92 92 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, 93 "Using input weights to combine images", "");93 "Using input variances to combine images", ""); 94 94 } 95 95 … … 121 121 122 122 // generate the required output images based on the specified sizes 123 pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params-> weights, params->blank);123 pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params->variances, params->blank); 124 124 psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0); 125 125 … … 177 177 return false; 178 178 } 179 if (params-> weights && !readout->weight) {179 if (params->variances && !readout->variance) { 180 180 psError(PS_ERR_UNEXPECTED_NULL, true, 181 "Rejection based on weights requested, but no weights supplied for image %d.\n", i);181 "Rejection based on variances requested, but no variances supplied for image %d.\n", i); 182 182 return false; 183 183 } … … 190 190 } 191 191 192 // pthread_t id = pthread_self(); 193 // char name[64]; 194 // sprintf (name, "%x", (unsigned int) id); 195 // psTimerStart (name); 196 197 psStatsOptions combineStdev = 0; // Statistics option for weights 192 #if 0 193 pthread_t id = pthread_self(); 194 char name[64]; 195 sprintf(name, "%x", (unsigned int)id); 196 psTimerStart(name); 197 #endif 198 199 psStatsOptions combineStdev = 0; // Statistics option for variances 198 200 switch (params->combine) { 199 201 case PS_STAT_SAMPLE_MEAN: … … 250 252 psVectorMaskType *maskData = mask->data.PS_TYPE_VECTOR_MASK_DATA; // Dereference mask 251 253 252 psVector * weights = NULL; // Stack of weights253 psVector *errors = NULL; // Stack of errors (sqrt of variance /weights), for psVectorStats254 psF32 * weightsData = NULL; // Dereference weights255 if (params-> weights) {256 weights = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of weights257 weightsData = weights->data.F32;254 psVector *variances = NULL; // Stack of variances 255 psVector *errors = NULL; // Stack of errors (sqrt of variance), for psVectorStats 256 psF32 *variancesData = NULL; // Dereference variances 257 if (params->variances) { 258 variances = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of variances 259 variancesData = variances->data.F32; 258 260 } 259 261 psVector *index = NULL; // The indices to sort the pixels … … 279 281 psF32 **outputImage = output->image->data.F32; // Output image 280 282 psImageMaskType **outputMask = output->mask->data.PS_TYPE_IMAGE_MASK_DATA; // Output mask 281 psF32 **output Weight = NULL; // Output weightmap282 if (output-> weight) {283 output Weight = output->weight->data.F32;283 psF32 **outputVariance = NULL; // Output variance map 284 if (output->variance) { 285 outputVariance = output->variance->data.F32; 284 286 } 285 287 … … 323 325 } 324 326 325 if (params-> weights) {326 weightsData[r] = readout->weight->data.F32[yIn][xIn];327 if (params->variances) { 328 variancesData[r] = readout->variance->data.F32[yIn][xIn]; 327 329 } 328 330 … … 332 334 if (scale) { 333 335 pixelsData[r] *= invScale->data.F32[r]; 334 if (params-> weights) {335 weightsData[r] *= invScale->data.F32[r] * invScale->data.F32[r];336 if (params->variances) { 337 variancesData[r] *= invScale->data.F32[r] * invScale->data.F32[r]; 336 338 } 337 339 } … … 376 378 377 379 // XXXXX this step probably is very expensive : convert errors to variance everywhere? 378 if (params-> weights) {379 errors = (psVector*)psUnaryOp(errors, weights, "sqrt");380 if (params->variances) { 381 errors = (psVector*)psUnaryOp(errors, variances, "sqrt"); 380 382 } 381 383 … … 386 388 outputImage[yOut][xOut] = NAN; 387 389 outputMask[yOut][xOut] = params->blank; 388 if (params-> weights) {389 output Weight[yOut][xOut] = NAN;390 if (params->variances) { 391 outputVariance[yOut][xOut] = NAN; 390 392 } 391 393 sigma->data.F32[yOut][xOut] = NAN; … … 393 395 outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine); 394 396 outputMask[yOut][xOut] = isfinite(outputImage[yOut][xOut]) ? 0 : params->blank; 395 if (params-> weights) {397 if (params->variances) { 396 398 float stdev = psStatsGetValue(stats, combineStdev); 397 output Weight[yOut][xOut] = PS_SQR(stdev); // Variance399 outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance 398 400 // XXXX this is not the correct formal error. 399 401 // also, the weighted mean is not obviously the correct thing here … … 412 414 psFree(pixels); 413 415 psFree(mask); 414 psFree( weights);416 psFree(variances); 415 417 psFree(errors); 416 418 psFree(stats); -
trunk/psModules/src/imcombine/pmReadoutCombine.h
r21183 r21363 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $8 * @date $Date: 2009-0 1-27 06:39:38$7 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2009-02-06 02:31:25 $ 9 9 * Copyright 2004-2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 22 22 typedef struct { 23 23 psStatsOptions combine; ///< Statistic to use when performing the combination 24 psImageMaskType maskVal; ///< Mask value25 psImageMaskType blank; ///< Mask value to give blank (i.e., no data) pixels24 psImageMaskType maskVal; ///< Mask value 25 psImageMaskType blank; ///< Mask value to give blank (i.e., no data) pixels 26 26 int nKeep; ///< Mimimum number of pixels to keep 27 27 float fracHigh; ///< Fraction of high pixels to immediately throw … … 29 29 int iter; ///< Number of iterations for clipping (for CLIPPED_MEAN only) 30 30 float rej; ///< Rejection threshould for clipping (for CLIPPED_MEAN only) 31 bool weights; ///< Use the supplied weights (instead of calculated stdev)?31 bool variances; ///< Use the supplied variances (instead of calculated stdev)? 32 32 } pmCombineParams; 33 33 … … 41 41 /// Combine multiple readouts, applying zero and scale, with optional minmax clipping 42 42 bool pmReadoutCombine(pmReadout *output,///< Output readout; altered and returned 43 const psArray *inputs, ///< Array of input readouts (F32 image and weight, U8 mask)43 const psArray *inputs, ///< Array of input readouts 44 44 const psVector *zero, ///< Zero corrections to subtract from input, or NULL 45 45 const psVector *scale, ///< Scale corrections to divide into input, or NULL -
trunk/psModules/src/imcombine/pmStack.c
r21183 r21363 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.4 6$ $Name: not supported by cvs2svn $11 * @date $Date: 2009-0 1-27 06:39:38$10 * @version $Revision: 1.47 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2009-02-06 02:31:25 $ 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii 13 13 * … … 30 30 #define PIXEL_LIST_BUFFER 100 // Number of entries to add to pixel list at a time 31 31 #define PIXEL_MAP_BUFFER 2 // Number of entries to add to pixel map at a time 32 //#define VARIANCE_FACTORS // Use variance factors when calculating the variances? 32 #define VARIANCE_FACTORS // Use variance factors when calculating the variances? 33 //#define ADD_VARIANCE // Allow additional variance (besides variance factor)? 33 34 #define NUM_DIRECT_STDEV 5 // For less than this number of values, measure stdev directly 34 35 … … 263 264 264 265 psImage *image = data->readout->image; // Image of interest 265 psImage *variance = data->readout-> weight; // Variance ("weight")map of interest266 psImage *variance = data->readout->variance; // Variance map of interest 266 267 pixelData->data.F32[num] = image->data.F32[yIn][xIn]; 267 268 if (variance) { … … 442 443 *numCols = data->readout->image->numCols; 443 444 *numRows = data->readout->image->numRows; 444 if (data->readout-> weight) {445 if (data->readout->variance) { 445 446 *haveVariances = true; 446 PS_ASSERT_IMAGE_NON_NULL(data->readout-> weight, false);447 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout-> weight, false);448 PS_ASSERT_IMAGE_TYPE(data->readout-> weight, PS_TYPE_F32, false);447 PS_ASSERT_IMAGE_NON_NULL(data->readout->variance, false); 448 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->variance, false); 449 PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false); 449 450 } 450 451 *haveRejects = (data->reject != NULL); … … 473 474 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->mask, false); 474 475 if (*haveVariances) { 475 PS_ASSERT_IMAGE_NON_NULL(data->readout-> weight, false);476 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout-> weight, false);477 PS_ASSERT_IMAGE_TYPE(data->readout-> weight, PS_TYPE_F32, false);476 PS_ASSERT_IMAGE_NON_NULL(data->readout->variance, false); 477 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->variance, false); 478 PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false); 478 479 } 479 480 } … … 606 607 weights->data.F32[i] = data->weight; 607 608 stack->data[i] = psMemIncrRefCounter(data->readout); 608 // Variance factor 609 float vf = psMetadataLookupF32(NULL, data->readout->parent->concepts, "CELL.VARFACTOR"); // Var factor 610 if (!isfinite(vf)) { 611 psWarning("Non-finite CELL.VARFACTOR for image %d --- setting to unity.", i); 612 vf = 1.0; 613 } 614 varFactors->data.F32[i] = vf; 609 varFactors->data.F32[i] = data->readout->covariance ? 610 psImageCovarianceFactor(data->readout->covariance) : 1.0; 611 #if 0 615 612 if (isfinite(data->addVariance)) { 616 613 varFactors->data.F32[i] *= data->addVariance; 617 614 } 615 #endif 618 616 if (!haveRejects && !data->inspect) { 619 617 data->inspect = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); … … 649 647 psImage *combinedImage = combined->image; // Combined image 650 648 psImage *combinedMask = combined->mask; // Combined mask 651 psImage *combinedVariance = combined-> weight; // Combined variance map649 psImage *combinedVariance = combined->variance; // Combined variance map 652 650 653 651 psArray *pixelMap = pixelMapGenerate(input, minInputCols, maxInputCols, … … 702 700 } 703 701 704 psImage *combinedVariance = combined-> weight; // Combined variance map702 psImage *combinedVariance = combined->variance; // Combined variance map 705 703 if (haveVariances && !combinedVariance) { 706 combined-> weight= psImageAlloc(numCols, numRows, PS_TYPE_F32);707 combinedVariance = combined-> weight;704 combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 705 combinedVariance = combined->variance; 708 706 } 709 707 -
trunk/psModules/src/imcombine/pmSubtraction.c
r21351 r21363 60 60 61 61 // Normalise so that the sum of the variance kernel is the square of the sum of the normal kernel 62 // This is required to keep the relative scaling between the image and the weightmap62 // This is required to keep the relative scaling between the image and the variance map 63 63 psBinaryOp(out->image, out->image, "*", psScalarAlloc(PS_SQR(sumNormal) / sumVariance, PS_TYPE_F32)); 64 64 … … 287 287 288 288 // Convolve an image using FFT 289 static void convolve WeightFFT(psImage *target,// Place the result in here290 psImage * weight, // Weightmap to convolve289 static void convolveVarianceFFT(psImage *target,// Place the result in here 290 psImage *variance, // Variance map to convolve 291 291 psImage *sys, // Systematic error image 292 292 psImage *mask, // Mask image … … 302 302 bool threaded = pmSubtractionThreaded(); // Are we running threaded? 303 303 304 psImage *sub Weight = convolveSubsetAlloc(weight, border, threaded); // Weightmap304 psImage *subVariance = convolveSubsetAlloc(variance, border, threaded); // Variance map 305 305 psImage *subSys = convolveSubsetAlloc(sys, border, threaded); // Systematic error image 306 306 psImage *subMask = convolveSubsetAlloc(mask, border, threaded); // Mask 307 307 308 308 // XXX Can trim this a little by combining the convolution: only have to take the FFT of the kernel once 309 psImage *conv Weight = psImageConvolveFFT(NULL, subWeight, subMask, maskVal, kernel); // Convolved weight309 psImage *convVariance = psImageConvolveFFT(NULL, subVariance, subMask, maskVal, kernel); // Convolved variance 310 310 psImage *convSys = subSys ? psImageConvolveFFT(NULL, subSys, subMask, maskVal, kernel) : NULL; // Conv sys 311 311 312 convolveSubsetFree( weight, subWeight, threaded);312 convolveSubsetFree(variance, subVariance, threaded); 313 313 convolveSubsetFree(sys, subSys, threaded); 314 314 convolveSubsetFree(mask, subMask, threaded); … … 319 319 for (int yTarget = yMin, ySource = size; yTarget < yMax; yTarget++, ySource++) { 320 320 for (int xTarget = xMin, xSource = size; xTarget < xMax; xTarget++, xSource++) { 321 target->data.F32[yTarget][xTarget] = conv Weight->data.F32[ySource][xSource] +321 target->data.F32[yTarget][xTarget] = convVariance->data.F32[ySource][xSource] + 322 322 convSys->data.F32[ySource][xSource]; 323 323 } … … 326 326 int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy 327 327 for (int yTarget = yMin, ySource = size; yTarget < yMax; yTarget++, ySource++) { 328 memcpy(&target->data.F32[yTarget][xMin], &conv Weight->data.F32[ySource][size], numBytes);329 } 330 } 331 332 psFree(conv Weight);328 memcpy(&target->data.F32[yTarget][xMin], &convVariance->data.F32[ySource][size], numBytes); 329 } 330 } 331 332 psFree(convVariance); 333 333 psFree(convSys); 334 334 … … 361 361 // Convolve a region of an image 362 362 static inline void convolveRegion(psImage *convImage, // Convolved image (output) 363 psImage *conv Weight, // Convolved weightmap (output), or NULL363 psImage *convVariance, // Convolved variance map (output), or NULL 364 364 psImage *convMask, // Convolve mask (output), or NULL 365 365 psKernel **kernelImage, // Convolution kernel for the image 366 psKernel **kernel Weight, // Convolution kernel for the weightmap, or NULL366 psKernel **kernelVariance, // Convolution kernel for the variance map, or NULL 367 367 psImage *image, // Image to convolve 368 psImage * weight, // Weightmap to convolve, or NULL368 psImage *variance, // Variance map to convolve, or NULL 369 369 psImage *sys, // Systematic error image, or NULL 370 370 psImage *subMask, // Subtraction mask … … 381 381 { 382 382 *kernelImage = solvedKernel(*kernelImage, kernels, polyValues, wantDual); 383 if ( weight|| subMask) {384 *kernel Weight = varianceKernel(*kernelWeight, *kernelImage);383 if (variance || subMask) { 384 *kernelVariance = varianceKernel(*kernelVariance, *kernelImage); 385 385 } 386 386 … … 398 398 } 399 399 400 // Convolve the image and weight400 // Convolve the image and variance 401 401 if (useFFT) { 402 402 // Use Fast Fourier Transform to do the convolution 403 403 // This provides a big speed-up for large kernels 404 404 convolveFFT(convImage, image, subMask, subBad, *kernelImage, region, background, kernels->size); 405 if ( weight) {406 convolve WeightFFT(convWeight, weight, sys, subMask, subBad, *kernelWeight, region, kernels->size);405 if (variance) { 406 convolveVarianceFFT(convVariance, variance, sys, subMask, subBad, *kernelVariance, region, kernels->size); 407 407 } 408 408 } else { 409 409 // XXX Direct convolution doesn't account for bad pixels yet 410 410 convolveDirect(convImage, image, *kernelImage, region, background, kernels->size); 411 if ( weight) {412 convolveDirect(conv Weight, weight, *kernelWeight, region, 0.0, kernels->size);411 if (variance) { 412 convolveDirect(convVariance, variance, *kernelVariance, region, 0.0, kernels->size); 413 413 } 414 414 } … … 885 885 psFree(stamp->image1); 886 886 psFree(stamp->image2); 887 psFree(stamp-> weight);888 stamp->image1 = stamp->image2 = stamp-> weight= NULL;887 psFree(stamp->variance); 888 stamp->image1 = stamp->image2 = stamp->variance = NULL; 889 889 psFree(stamp->matrix1); 890 890 psFree(stamp->matrix2); … … 915 915 } 916 916 917 ps Image *pmSubtractionKernelImage(const pmSubtractionKernels *kernels, float x, float y, bool wantDual)917 psKernel *pmSubtractionKernel(const pmSubtractionKernels *kernels, float x, float y, bool wantDual) 918 918 { 919 919 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, NULL); … … 922 922 PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, NULL); 923 923 924 // Precalulate polynomial values 925 psImage *polyValues = p_pmSubtractionPolynomial(NULL, kernels->spatialOrder, x, y); 926 927 // The appropriate kernel 928 psKernel *kernel = solvedKernel(NULL, kernels, polyValues, wantDual); 929 924 psImage *polyValues = p_pmSubtractionPolynomial(NULL, kernels->spatialOrder, x, y); // Solved polynomial 925 psKernel *kernel = solvedKernel(NULL, kernels, polyValues, wantDual); // The appropriate kernel 930 926 psFree(polyValues); 931 927 928 return kernel; 929 } 930 931 psImage *pmSubtractionKernelImage(const pmSubtractionKernels *kernels, float x, float y, bool wantDual) 932 { 933 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, NULL); 934 PM_ASSERT_SUBTRACTION_KERNELS_SOLUTION(kernels, NULL); 935 PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, NULL); 936 PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, NULL); 937 938 psKernel *kernel = pmSubtractionKernel(kernels, x, y, wantDual); // Convolution kernel 932 939 psImage *image = psMemIncrRefCounter(kernel->image); // Image of the kernel 933 940 psFree(kernel); … … 989 996 990 997 991 // XXX Put kernelImage, kernel Weightand polyValues on thread-dependent data998 // XXX Put kernelImage, kernelVariance and polyValues on thread-dependent data 992 999 static bool subtractionConvolvePatch(int numCols, int numRows, // Size of image 993 1000 int x0, int y0, // Offsets for image … … 1010 1017 1011 1018 psKernel *kernelImage = NULL; // Kernel for the images 1012 psKernel *kernel Weight = NULL; // Kernel for the weightmaps1019 psKernel *kernelVariance = NULL; // Kernel for the variance maps 1013 1020 1014 1021 // Only generate polynomial values every kernel footprint, since we have already assumed … … 1020 1027 1021 1028 if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1022 convolveRegion(out1->image, out1-> weight, convMask, &kernelImage, &kernelWeight,1023 ro1->image, ro1-> weight, sys1, subMask, kernels, polyValues, background, *region,1029 convolveRegion(out1->image, out1->variance, convMask, &kernelImage, &kernelVariance, 1030 ro1->image, ro1->variance, sys1, subMask, kernels, polyValues, background, *region, 1024 1031 maskBad, maskPoor, poorFrac, useFFT, false); 1025 1032 } 1026 1033 if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1027 convolveRegion(out2->image, out2-> weight, convMask, &kernelImage, &kernelWeight,1028 ro2->image, ro2-> weight, sys2, subMask, kernels, polyValues, background, *region,1034 convolveRegion(out2->image, out2->variance, convMask, &kernelImage, &kernelVariance, 1035 ro2->image, ro2->variance, sys2, subMask, kernels, polyValues, background, *region, 1029 1036 maskBad, maskPoor, poorFrac, useFFT, kernels->mode == PM_SUBTRACTION_MODE_DUAL); 1030 1037 } 1031 1038 1032 1039 psFree(kernelImage); 1033 psFree(kernel Weight);1040 psFree(kernelVariance); 1034 1041 psFree(polyValues); 1035 1042 … … 1148 1155 // XXX } 1149 1156 } 1150 if (ro1-> weight) {1151 if (!out1-> weight) {1152 out1-> weight= psImageAlloc(numCols, numRows, PS_TYPE_F32);1157 if (ro1->variance) { 1158 if (!out1->variance) { 1159 out1->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 1153 1160 // XXX if (threaded) { 1154 // XXX psMutexInit(out1-> weight);1161 // XXX psMutexInit(out1->variance); 1155 1162 // XXX } 1156 1163 } 1157 psImageInit(out1-> weight, 0.0);1164 psImageInit(out1->variance, 0.0); 1158 1165 } 1159 1166 } … … 1165 1172 // XXX } 1166 1173 } 1167 if (ro2-> weight) {1168 if (!out2-> weight) {1169 out2-> weight= psImageAlloc(numCols, numRows, PS_TYPE_F32);1174 if (ro2->variance) { 1175 if (!out2->variance) { 1176 out2->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 1170 1177 // XXX if (threaded) { 1171 // XXX psMutexInit(out2-> weight);1178 // XXX psMutexInit(out2->variance); 1172 1179 // XXX } 1173 1180 } 1174 psImageInit(out2-> weight, 0.0);1181 psImageInit(out2->variance, 0.0); 1175 1182 } 1176 1183 } … … 1232 1239 psImage *polyValues = NULL; // Pre-calculated polynomial values 1233 1240 psKernel *kernelImage = NULL; // Kernel for the images 1234 psKernel *kernel Weight = NULL; // Kernel for the weightmaps1241 psKernel *kernelVariance = NULL; // Kernel for the variance maps 1235 1242 #endif 1236 1243 … … 1299 1306 psFree(job); 1300 1307 } else { 1301 subtractionConvolvePatch(numCols, numRows, x0, y0, out1, out2, convMask, ro1, ro2, 1302 s ys1, sys2, subMask, maskBad, maskPoor, poorFrac, subRegion,1303 kernels, doBG,useFFT);1308 subtractionConvolvePatch(numCols, numRows, x0, y0, out1, out2, convMask, ro1, ro2, sys1, sys2, 1309 subMask, maskBad, maskPoor, poorFrac, subRegion, kernels, doBG, 1310 useFFT); 1304 1311 } 1305 1312 psFree(subRegion); … … 1334 1341 // XXX } 1335 1342 } 1336 1337 1343 psImageConvolveSetThreads(oldThreads); 1338 1344 1339 1345 psFree(sys1); 1340 1346 psFree(sys2); 1347 1348 // Calculate covariances 1349 // This can take a while, so we only do it for a single instance 1350 // XXX psImageCovarianceCalculate could be multithreaded 1351 if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1352 psKernel *kernel = pmSubtractionKernel(kernels, 0.0, 0.0, false); // Convolution kernel 1353 out1->covariance = psImageCovarianceCalculate(kernel, ro1->covariance); 1354 psFree(kernel); 1355 } 1356 if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1357 psKernel *kernel = pmSubtractionKernel(kernels, 0.0, 0.0, 1358 kernels->mode == PM_SUBTRACTION_MODE_DUAL); // Conv. kernel 1359 out2->covariance = psImageCovarianceCalculate(kernel, ro2->covariance); 1360 psFree(kernel); 1361 } 1341 1362 1342 1363 // Copy anything that wasn't convolved … … 1345 1366 if (out2) { 1346 1367 out2->image = psMemIncrRefCounter(ro2->image); 1347 out2-> weight = psMemIncrRefCounter(ro2->weight);1368 out2->variance = psMemIncrRefCounter(ro2->variance); 1348 1369 out2->mask = psMemIncrRefCounter(ro2->mask); 1370 out2->covariance = psMemIncrRefCounter(ro2->covariance); 1349 1371 } 1350 1372 break; … … 1352 1374 if (out1) { 1353 1375 out1->image = psMemIncrRefCounter(ro1->image); 1354 out1-> weight = psMemIncrRefCounter(ro1->weight);1376 out1->variance = psMemIncrRefCounter(ro1->variance); 1355 1377 out1->mask = psMemIncrRefCounter(ro1->mask); 1378 out1->covariance = psMemIncrRefCounter(ro1->covariance); 1356 1379 } 1357 1380 break; -
trunk/psModules/src/imcombine/pmSubtraction.h
r21183 r21363 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-0 1-27 06:39:38$8 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-06 02:31:25 $ 10 10 * Copyright 2004-207 Institute for Astronomy, University of Hawaii 11 11 */ … … 70 70 float sigmaRej, ///< Number of RMS deviations above zero at which to reject 71 71 int footprint ///< Half-size of stamp 72 ); 73 74 /// Generate the convolution kernel 75 psKernel *pmSubtractionKernel(const pmSubtractionKernels *kernels, ///< Kernel parameters 76 float x, float y, ///< Normalised position [-1,1] for which to generate image 77 bool wantDual ///< Calculate for the dual kernel? 72 78 ); 73 79 -
trunk/psModules/src/imcombine/pmSubtractionEquation.c
r20561 r21363 24 24 static inline double calculateSumProduct(const psKernel *image1, // First image in multiplication 25 25 const psKernel *image2, // Second image in multiplication 26 const psKernel * weight, // Weightimage26 const psKernel *variance, // Variance image 27 27 int footprint // (Half-)Size of stamp 28 28 ) … … 31 31 for (int y = - footprint; y <= footprint; y++) { 32 32 for (int x = - footprint; x <= footprint; x++) { 33 sum += image1->kernel[y][x] * image2->kernel[y][x] / 1.0; // weight->kernel[y][x];33 sum += image1->kernel[y][x] * image2->kernel[y][x] / 1.0; // variance->kernel[y][x]; 34 34 } 35 35 } … … 42 42 const psKernel *image1, // First image in multiplication 43 43 const psKernel *image2, // Second image in multiplication 44 const psKernel * weight, // Weightimage44 const psKernel *variance, // Variance image 45 45 const psImage *polyValues, // Spatial polynomial values 46 46 int numKernels, // Number of kernel basis functions … … 50 50 ) 51 51 { 52 double sum = calculateSumProduct(image1, image2, weight, footprint); // Sum of the image products52 double sum = calculateSumProduct(image1, image2, variance, footprint); // Sum of the image products 53 53 if (!isfinite(sum)) { 54 54 return false; … … 79 79 const psKernel *image1, // First image in multiplication 80 80 const psKernel *image2, // Second image in multiplication 81 const psKernel * weight, // Weightimage81 const psKernel *variance, // Variance image 82 82 const psImage *polyValues, // Spatial polynomial values 83 83 int numKernels, // Number of kernel basis functions … … 87 87 ) 88 88 { 89 double sum = calculateSumProduct(image1, image2, weight, footprint); // Sum of the image products89 double sum = calculateSumProduct(image1, image2, variance, footprint); // Sum of the image products 90 90 if (!isfinite(sum)) { 91 91 return false; … … 120 120 const psArray *convolutions1, // Convolutions for element 1 121 121 const psArray *convolutions2, // Convolutions for element 2 122 const psKernel * weight, // Weightimage122 const psKernel *variance, // Variance image 123 123 const psImage *polyValues, // Polynomial values 124 124 int numKernels, // Number of kernel basis functions … … 135 135 psKernel *jConv = convolutions2->data[j]; // Convolution for j-th element 136 136 137 if (!calculateMatrixElement2(matrix, i, j, iConv, jConv, weight, polyValues, numKernels,137 if (!calculateMatrixElement2(matrix, i, j, iConv, jConv, variance, polyValues, numKernels, 138 138 footprint, spatialOrder, symmetric)) { 139 139 psTrace("psModules.imcombine", 2, "Bad sumCC at %d, %d", i, j); … … 151 151 const psArray *convolutions, // Convolutions of source with kernels 152 152 const psKernel *input, // Input stamp, or NULL 153 const psKernel * weight, // Weightstamp153 const psKernel *variance, // Variance stamp 154 154 const psImage *polyValues, // Spatial polynomial values 155 155 int footprint, // (Half-)Size of stamp … … 171 171 172 172 // Square part of the matrix (convolution-convolution products) 173 if (!calculateMatrixSquare(matrix, convolutions, convolutions, weight, polyValues, numKernels,173 if (!calculateMatrixSquare(matrix, convolutions, convolutions, variance, polyValues, numKernels, 174 174 spatialOrder, footprint)) { 175 175 return false; … … 185 185 186 186 // Normalisation-convolution terms 187 if (!calculateMatrixElement1(matrix, i, normIndex, conv, input, weight, polyValues, numKernels,187 if (!calculateMatrixElement1(matrix, i, normIndex, conv, input, variance, polyValues, numKernels, 188 188 footprint, spatialOrder, true)) { 189 189 psTrace("psModules.imcombine", 2, "Bad sumIC at %d", i); … … 195 195 for (int y = - footprint; y <= footprint; y++) { 196 196 for (int x = - footprint; x <= footprint; x++) { 197 sumC += conv->kernel[y][x] / 1.0; // weight->kernel[y][x];197 sumC += conv->kernel[y][x] / 1.0; // variance->kernel[y][x]; 198 198 } 199 199 } … … 218 218 for (int y = - footprint; y <= footprint; y++) { 219 219 for (int x = - footprint; x <= footprint; x++) { 220 double invNoise2 = 1.0 / 1.0; // weight->kernel[y][x];220 double invNoise2 = 1.0 / 1.0; // variance->kernel[y][x]; 221 221 double value = input->kernel[y][x] * invNoise2; 222 222 sumI += value; … … 253 253 const psKernel *input, // Input stamp, or NULL if !normAndBG 254 254 const psKernel *target, // Target stamp 255 const psKernel * weight, // Weightstamp255 const psKernel *variance, // Variance stamp 256 256 const psImage *polyValues, // Spatial polynomial values 257 257 int footprint, // (Half-)Size of stamp … … 277 277 for (int y = - footprint; y <= footprint; y++) { 278 278 for (int x = - footprint; x <= footprint; x++) { 279 sumTC += target->kernel[y][x] * conv->kernel[y][x] / 1.0; // weight->kernel[y][x];279 sumTC += target->kernel[y][x] * conv->kernel[y][x] / 1.0; // variance->kernel[y][x]; 280 280 } 281 281 } … … 297 297 for (int y = - footprint; y <= footprint; y++) { 298 298 for (int x = - footprint; x <= footprint; x++) { 299 float value = target->kernel[y][x] / 1.0; // weight->kernel[y][x];299 float value = target->kernel[y][x] / 1.0; // variance->kernel[y][x]; 300 300 sumIT += value * input->kernel[y][x]; 301 301 sumT += value; … … 329 329 const psArray *convolutions2, // Convolutions of image 2 330 330 const psKernel *image1, // Image 1 stamp 331 const psKernel * weight, // Weightstamp331 const psKernel *variance, // Variance stamp 332 332 const psImage *polyValues, // Spatial polynomial values 333 333 int footprint // (Half-)Size of stamp … … 348 348 PM_SUBTRACTION_INDICES(normIndex, bgIndex, kernels); 349 349 350 if (!calculateMatrixSquare(matrix, convolutions1, convolutions2, weight, polyValues, numKernels,350 if (!calculateMatrixSquare(matrix, convolutions1, convolutions2, variance, polyValues, numKernels, 351 351 spatialOrder, footprint)) { 352 352 return false; … … 356 356 // Normalisation 357 357 psKernel *conv = convolutions2->data[i]; // Convolution 358 if (!calculateMatrixElement1(matrix, i, normIndex, conv, image1, weight, polyValues, numKernels,358 if (!calculateMatrixElement1(matrix, i, normIndex, conv, image1, variance, polyValues, numKernels, 359 359 footprint, spatialOrder, false)) { 360 360 psTrace("psModules.imcombine", 2, "Bad sumIC at %d", i); … … 366 366 for (int y = - footprint; y <= footprint; y++) { 367 367 for (int x = - footprint; x <= footprint; x++) { 368 sumC += conv->kernel[y][x] / 1.0; // weight->kernel[y][x];368 sumC += conv->kernel[y][x] / 1.0; // variance->kernel[y][x]; 369 369 } 370 370 } … … 559 559 case PM_SUBTRACTION_MODE_1: 560 560 status = calculateMatrix(stamp->matrix1, kernels, stamp->convolutions1, stamp->image1, 561 stamp-> weight, polyValues, footprint, true);561 stamp->variance, polyValues, footprint, true); 562 562 status &= calculateVector(stamp->vector1, kernels, stamp->convolutions1, stamp->image1, 563 stamp->image2, stamp-> weight, polyValues, footprint, true);563 stamp->image2, stamp->variance, polyValues, footprint, true); 564 564 break; 565 565 case PM_SUBTRACTION_MODE_2: 566 566 status = calculateMatrix(stamp->matrix1, kernels, stamp->convolutions2, stamp->image2, 567 stamp-> weight, polyValues, footprint, true);567 stamp->variance, polyValues, footprint, true); 568 568 status &= calculateVector(stamp->vector1, kernels, stamp->convolutions2, stamp->image2, 569 stamp->image1, stamp-> weight, polyValues, footprint, true);569 stamp->image1, stamp->variance, polyValues, footprint, true); 570 570 break; 571 571 case PM_SUBTRACTION_MODE_DUAL: … … 581 581 #endif 582 582 status = calculateMatrix(stamp->matrix1, kernels, stamp->convolutions1, stamp->image1, 583 stamp-> weight, polyValues, footprint, true);583 stamp->variance, polyValues, footprint, true); 584 584 status &= calculateMatrix(stamp->matrix2, kernels, stamp->convolutions2, NULL, 585 stamp-> weight, polyValues, footprint, false);585 stamp->variance, polyValues, footprint, false); 586 586 status &= calculateMatrixCross(stamp->matrixX, kernels, stamp->convolutions1, 587 stamp->convolutions2, stamp->image1, stamp-> weight, polyValues,587 stamp->convolutions2, stamp->image1, stamp->variance, polyValues, 588 588 footprint); 589 589 status &= calculateVector(stamp->vector1, kernels, stamp->convolutions1, stamp->image1, 590 stamp->image2, stamp-> weight, polyValues, footprint, true);590 stamp->image2, stamp->variance, polyValues, footprint, true); 591 591 status &= calculateVector(stamp->vector2, kernels, stamp->convolutions2, NULL, 592 stamp->image2, stamp-> weight, polyValues, footprint, false);592 stamp->image2, stamp->variance, polyValues, footprint, false); 593 593 break; 594 594 default: … … 1033 1033 1034 1034 // Calculate residuals 1035 psKernel * weight = stamp->weight; // Weightpostage stamp1035 psKernel *variance = stamp->variance; // Variance postage stamp 1036 1036 psImageInit(residual->image, 0.0); 1037 1037 if (kernels->mode != PM_SUBTRACTION_MODE_DUAL) { … … 1098 1098 for (int y = - footprint; y <= footprint; y++) { 1099 1099 for (int x = - footprint; x <= footprint; x++) { 1100 double dev = PS_SQR(residual->kernel[y][x]) / weight->kernel[y][x];1100 double dev = PS_SQR(residual->kernel[y][x]) / variance->kernel[y][x]; 1101 1101 deviation += dev; 1102 1102 #ifdef TESTING … … 1141 1141 psFitsClose(fits); 1142 1142 } 1143 if (stamp-> weight) {1143 if (stamp->variance) { 1144 1144 psString filename = NULL; 1145 psStringAppend(&filename, "stamp_ weight_%03d.fits", i);1145 psStringAppend(&filename, "stamp_variance_%03d.fits", i); 1146 1146 psFits *fits = psFitsOpen(filename, "w"); 1147 1147 psFree(filename); 1148 psFitsWriteImage(fits, NULL, stamp-> weight->image, 0, NULL);1148 psFitsWriteImage(fits, NULL, stamp->variance->image, 0, NULL); 1149 1149 psFitsClose(fits); 1150 1150 } -
trunk/psModules/src/imcombine/pmSubtractionMatch.c
r21247 r21363 60 60 const pmReadout *ro2, // Readout 2 61 61 const psImage *subMask, // Mask for subtraction, or NULL 62 psImage * weight, // Weightmap62 psImage *variance, // Variance map 63 63 const psRegion *region, // Region of interest, or NULL 64 64 float threshold, // Threshold for stamp finding … … 80 80 81 81 psTrace("psModules.imcombine", 3, "Extracting stamps...\n"); 82 if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, weight, size)) {82 if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, variance, size)) { 83 83 psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps."); 84 84 return false; … … 111 111 conv1->mask = NULL; 112 112 } 113 if (conv1-> weight) {114 psFree(conv1-> weight);115 conv1-> weight= NULL;113 if (conv1->variance) { 114 psFree(conv1->variance); 115 conv1->variance = NULL; 116 116 } 117 117 } … … 126 126 conv2->mask = NULL; 127 127 } 128 if (conv2-> weight) {129 psFree(conv2-> weight);130 conv2-> weight= NULL;128 if (conv2->variance) { 129 psFree(conv2->variance); 130 conv2->variance = NULL; 131 131 } 132 132 } … … 191 191 } 192 192 193 // Where does our weightmap come from?194 // Getting the weightexactly right is not necessary --- it's just used for weighting.195 psImage * weight = NULL; // Weightimage to use196 if (ro1-> weight && ro2->weight) {197 weight = (psImage*)psBinaryOp(NULL, ro1->weight, "+", ro2->weight);198 } else if (ro1-> weight) {199 weight = psMemIncrRefCounter(ro1->weight);200 } else if (ro2-> weight) {201 weight = psMemIncrRefCounter(ro2->weight);193 // Where does our variance map come from? 194 // Getting the variance exactly right is not necessary --- it's just used for weighting. 195 psImage *variance = NULL; // Variance image to use 196 if (ro1->variance && ro2->variance) { 197 variance = (psImage*)psBinaryOp(NULL, ro1->variance, "+", ro2->variance); 198 } else if (ro1->variance) { 199 variance = psMemIncrRefCounter(ro1->variance); 200 } else if (ro2->variance) { 201 variance = psMemIncrRefCounter(ro2->variance); 202 202 } else { 203 weight= (psImage*)psBinaryOp(NULL, ro1->image, "+", ro2->image);203 variance = (psImage*)psBinaryOp(NULL, ro1->image, "+", ro2->image); 204 204 } 205 205 … … 274 274 // We get the stamps here; we will also attempt to get stamps at the first iteration, but it 275 275 // doesn't matter. 276 if (!getStamps(&stamps, ro1, ro2, subMask, weight, NULL, threshold, stampSpacing,276 if (!getStamps(&stamps, ro1, ro2, subMask, variance, NULL, threshold, stampSpacing, 277 277 size, footprint, subMode)) { 278 278 goto MATCH_ERROR; … … 336 336 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k); 337 337 338 if (!getStamps(&stamps, ro1, ro2, subMask, weight, region, threshold, stampSpacing,338 if (!getStamps(&stamps, ro1, ro2, subMask, variance, region, threshold, stampSpacing, 339 339 size, footprint, subMode)) { 340 340 goto MATCH_ERROR; … … 439 439 psFree(subMask); 440 440 subMask = NULL; 441 psFree( weight);442 weight= NULL;443 444 if (!pmSubtractionBorder(conv1->image, conv1-> weight, conv1->mask, size, maskBad)) {441 psFree(variance); 442 variance = NULL; 443 444 if (!pmSubtractionBorder(conv1->image, conv1->variance, conv1->mask, size, maskBad)) { 445 445 psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image."); 446 446 goto MATCH_ERROR; … … 482 482 psFree(kernels); 483 483 psFree(stamps); 484 psFree( weight);484 psFree(variance); 485 485 psFree(rng); 486 486 return false; -
trunk/psModules/src/imcombine/pmSubtractionParams.c
r18287 r21363 71 71 double *sumII, // Sum of I(x)^2/sigma(x)^2 72 72 double *sumIC, // Sum of I(x)conv(x)/sigma(x)^2 73 const pmSubtractionStamp *stamp, // Stamp with weight73 const pmSubtractionStamp *stamp, // Stamp with variance 74 74 const psKernel *target, // Target stamp 75 75 int kernelIndex, // Index for kernel component … … 78 78 ) 79 79 { 80 psKernel * weight = stamp->weight; // Weight, sigma(x)^280 psKernel *variance = stamp->variance; // Variance, sigma(x)^2 81 81 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 82 82 83 83 for (int y = -footprint; y <= footprint; y++) { 84 84 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 85 psF32 *wt = & weight->kernel[y][-footprint]; // Dereference weight85 psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance 86 86 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution 87 87 for (int x = -footprint; x <= footprint; x++, in++, wt++, conv++) { … … 98 98 static void accumulateConvolutions(double *sumC, // Sum of conv(x)/sigma(x)^2 99 99 double *sumCC, // Sum of conv(x)^2/sigma(x)^2 100 const pmSubtractionStamp *stamp, // Stamp with input and weight100 const pmSubtractionStamp *stamp, // Stamp with input and variance 101 101 int kernelIndex, // Index for kernel component 102 102 int footprint, // Size of region of interest … … 104 104 ) 105 105 { 106 psKernel * weight = stamp->weight; // Weight, sigma(x)^2106 psKernel *variance = stamp->variance; // Variance, sigma(x)^2 107 107 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 108 108 109 109 for (int y = -footprint; y <= footprint; y++) { 110 psF32 *wt = & weight->kernel[y][-footprint]; // Dereference weight110 psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance 111 111 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution 112 112 for (int x = -footprint; x <= footprint; x++, wt++, conv++) { … … 120 120 121 121 static double accumulateChi2(const psKernel *target, // Target stamp 122 pmSubtractionStamp *stamp, // Stamp with weight122 pmSubtractionStamp *stamp, // Stamp with variance 123 123 int kernelIndex, // Index for kernel component 124 124 double coeff, // Coefficient of convolution … … 129 129 { 130 130 double chi2 = 0.0; 131 psKernel * weight = stamp->weight; // Weight, sigma(x)^2131 psKernel *variance = stamp->variance; // Variance, sigma(x)^2 132 132 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 133 133 134 134 for (int y = -footprint; y <= footprint; y++) { 135 135 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 136 psF32 *wt = & weight->kernel[y][-footprint]; // Dereference weight136 psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance 137 137 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution 138 138 for (int x = -footprint; x <= footprint; x++, in++, wt++, conv++) { … … 146 146 // Return the initial value of chi^2 147 147 static double initialChi2(const psKernel *target, // Target stamp 148 const pmSubtractionStamp *stamp, // Stamp with weight148 const pmSubtractionStamp *stamp, // Stamp with variance 149 149 int footprint, // Size of convolution 150 150 pmSubtractionMode mode // Mode of subtraction 151 151 ) 152 152 { 153 psKernel * weight = stamp->weight; // Weightmap153 psKernel *variance = stamp->variance; // Variance map 154 154 psKernel *source; // Source stamp 155 155 switch (mode) { … … 167 167 for (int y = -footprint; y <= footprint; y++) { 168 168 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 169 psF32 *wt = & weight->kernel[y][-footprint]; // Dereference weight169 psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance 170 170 psF32 *ref = &source->kernel[y][-footprint]; // Derference reference 171 171 for (int x = -footprint; x <= footprint; x++, in++, wt++, ref++) { … … 180 180 // Subtract a convolution from the input 181 181 static void subtractConvolution(psKernel *target, // Target stamp 182 const pmSubtractionStamp *stamp, // Stamp with weight182 const pmSubtractionStamp *stamp, // Stamp with variance 183 183 int kernelIndex, // Index for kernel component 184 184 float coeff, // Coefficient of subtraction … … 288 288 289 289 // This sum is invariant to the kernel 290 psKernel * weight = stamp->weight; // Weightmap for stamp290 psKernel *variance = stamp->variance; // Variance map for stamp 291 291 for (int v = -footprint; v <= footprint; v++) { 292 psF32 *wt = & weight->kernel[v][-footprint]; // Dereference weightmap292 psF32 *wt = &variance->kernel[v][-footprint]; // Dereference variance map 293 293 for (int u = -footprint; u <= footprint; u++, wt++) { 294 294 sum1 += 1.0 / *wt; -
trunk/psModules/src/imcombine/pmSubtractionStamps.c
r21183 r21363 54 54 psFree(stamp->image1); 55 55 psFree(stamp->image2); 56 psFree(stamp-> weight);56 psFree(stamp->variance); 57 57 psFree(stamp->convolutions1); 58 58 psFree(stamp->convolutions2); … … 211 211 stamp->image1 = NULL; 212 212 stamp->image2 = NULL; 213 stamp-> weight= NULL;213 stamp->variance = NULL; 214 214 stamp->convolutions1 = NULL; 215 215 stamp->convolutions2 = NULL; … … 333 333 psFree(stamp->image1); 334 334 psFree(stamp->image2); 335 psFree(stamp-> weight);335 psFree(stamp->variance); 336 336 psFree(stamp->convolutions1); 337 337 psFree(stamp->convolutions2); 338 stamp->image1 = stamp->image2 = stamp-> weight= NULL;338 stamp->image1 = stamp->image2 = stamp->variance = NULL; 339 339 stamp->convolutions1 = stamp->convolutions2 = NULL; 340 340 … … 480 480 481 481 bool pmSubtractionStampsExtract(pmSubtractionStampList *stamps, psImage *image1, psImage *image2, 482 psImage * weight, int kernelSize)482 psImage *variance, int kernelSize) 483 483 { 484 484 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 490 490 PS_ASSERT_IMAGE_TYPE(image2, PS_TYPE_F32, false); 491 491 } 492 PS_ASSERT_IMAGE_NON_NULL( weight, false);493 PS_ASSERT_IMAGES_SIZE_EQUAL( weight, image1, false);494 PS_ASSERT_IMAGE_TYPE( weight, PS_TYPE_F32, false);492 PS_ASSERT_IMAGE_NON_NULL(variance, false); 493 PS_ASSERT_IMAGES_SIZE_EQUAL(variance, image1, false); 494 PS_ASSERT_IMAGE_TYPE(variance, PS_TYPE_F32, false); 495 495 PS_ASSERT_INT_NONNEGATIVE(kernelSize, false); 496 496 … … 520 520 assert(stamp->image1 == NULL); 521 521 assert(stamp->image2 == NULL); 522 assert(stamp-> weight== NULL);522 assert(stamp->variance == NULL); 523 523 524 524 psRegion region = psRegionSet(x - size, x + size + 1, y - size, y + size + 1); // Region of interest … … 534 534 } 535 535 536 psImage *wtSub = psImageSubset( weight, region); // Subimage with stamp537 stamp-> weight= psKernelAllocFromImage(wtSub, size, size);536 psImage *wtSub = psImageSubset(variance, region); // Subimage with stamp 537 stamp->variance = psKernelAllocFromImage(wtSub, size, size); 538 538 psFree(wtSub); // Drop reference 539 539 -
trunk/psModules/src/imcombine/pmSubtractionStamps.h
r20465 r21363 60 60 psKernel *image1; ///< Reference image postage stamp 61 61 psKernel *image2; ///< Input image postage stamp 62 psKernel * weight; ///< Weightimage postage stamp, or NULL62 psKernel *variance; ///< Variance image postage stamp, or NULL 63 63 psArray *convolutions1; ///< Convolutions of image 1 for each kernel component, or NULL 64 64 psArray *convolutions2; ///< Convolutions of image 2 for each kernel component, or NULL … … 120 120 psImage *image1, ///< Reference image 121 121 psImage *image2, ///< Input image (or NULL) 122 psImage * weight, ///< Weight (variance)map122 psImage *variance, ///< Variance map 123 123 int kernelSize ///< Kernel half-size 124 124 ); -
trunk/psModules/src/imcombine/pmSubtractionThreads.c
r21351 r21363 27 27 // XXX psMutexInit(ro->image); 28 28 // XXX } 29 // XXX if (ro-> weight) {30 // XXX psMutexInit(ro-> weight);29 // XXX if (ro->variance) { 30 // XXX psMutexInit(ro->variance); 31 31 // XXX } 32 32 … … 43 43 // XXX psMutexDestroy(ro->image); 44 44 // XXX } 45 // XXX if (ro-> weight) {46 // XXX psMutexDestroy(ro-> weight);45 // XXX if (ro->variance) { 46 // XXX psMutexDestroy(ro->variance); 47 47 // XXX } 48 48
Note:
See TracChangeset
for help on using the changeset viewer.
