Changeset 26739
- Timestamp:
- Jan 29, 2010, 6:02:38 PM (16 years ago)
- Location:
- branches/eam_branches/20091201
- Files:
-
- 17 edited
-
ppSub/src/ppSubThreshold.c (modified) (5 diffs)
-
psModules/src/imcombine/pmStackReject.c (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtraction.c (modified) (5 diffs)
-
psModules/src/imcombine/pmSubtraction.h (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionAnalysis.c (modified) (2 diffs)
-
psModules/src/imcombine/pmSubtractionEquation.c (modified) (7 diffs)
-
psModules/src/imcombine/pmSubtractionEquation.h (modified) (4 diffs)
-
psModules/src/imcombine/pmSubtractionIO.c (modified) (4 diffs)
-
psModules/src/imcombine/pmSubtractionKernels.c (modified) (29 diffs)
-
psModules/src/imcombine/pmSubtractionKernels.h (modified) (17 diffs)
-
psModules/src/imcombine/pmSubtractionMask.c (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtractionMask.h (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionMatch.c (modified) (15 diffs)
-
psModules/src/imcombine/pmSubtractionParams.c (modified) (3 diffs)
-
psModules/src/imcombine/pmSubtractionParams.h (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionStamps.c (modified) (4 diffs)
-
psModules/src/imcombine/pmSubtractionStamps.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/ppSub/src/ppSubThreshold.c
r24862 r26739 27 27 psImageMaskType maskIgnore, // Ignore pixels with this mask 28 28 psImageMaskType maskThresh, // Give pixels this mask if below threshold 29 psRegion *region, // Region of interest 29 30 const char *description // Description of image 30 31 ) … … 37 38 psImage *image = ro->image; // Image 38 39 psImage *mask = ro->mask; // Mask 39 int numCols = ro->image->numCols, numRows = ro->image->numRows; // Size of image 40 41 psImage *subImage = psImageSubset(image, *region); // Image with region of interest 42 psImage *subMask = psImageSubset(mask, *region); // Maks with region of interest 40 43 41 44 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics 42 45 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 43 if (!psImageBackground(stats, NULL, image, mask, maskIgnore, rng)) {46 if (!psImageBackground(stats, NULL, subImage, subMask, maskIgnore, rng)) { 44 47 psError(PS_ERR_UNKNOWN, false, "Unable to determine threshold."); 45 48 psFree(rng); … … 49 52 psFree(rng); 50 53 54 psFree(subImage); 55 psFree(subMask); 56 51 57 float threshold = stats->robustMedian - thresh * stats->robustStdev; // Threshold below which to clip 52 58 psFree(stats); 53 59 psLogMsg("ppSub", PS_LOG_INFO, "Masking pixels below %f in %s", threshold, description); 54 60 55 for (int y = 0; y < numRows; y++) {56 for (int x = 0; x < numCols; x++) {61 for (int y = region->y0; y < region->y1; y++) { 62 for (int x = region->x0; x < region->x1; x++) { 57 63 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskIgnore) { 58 64 continue; … … 94 100 return false; 95 101 } 96 if (!lowThreshold(in, thresh, maskVal, maskThresh, "input convolved image")) {97 psError(PS_ERR_UNKNOWN, false, "Unable to threshold input image.");98 return false;99 }100 102 101 103 pmReadout *ref = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference image … … 104 106 return false; 105 107 } 106 if (!lowThreshold(ref, thresh, maskVal, maskThresh, "reference convolved image")) { 107 psError(PS_ERR_UNKNOWN, false, "Unable to threshold input image."); 108 return false; 108 109 psMetadataIterator *regIter = psMetadataIteratorAlloc(in->analysis, PS_LIST_HEAD, 110 "^" PM_SUBTRACTION_ANALYSIS_REGION "$"); 111 psMetadataItem *regItem; // Item with region 112 while ((regItem = psMetadataGetAndIncrement(regIter))) { 113 psAssert(regItem->type == PS_DATA_REGION && regItem->data.V, "Expect region type"); 114 psRegion *region = regItem->data.V; // Region of interest 115 if (!lowThreshold(in, thresh, maskVal, maskThresh, region, "input convolved image")) { 116 psError(PS_ERR_UNKNOWN, false, "Unable to threshold input image."); 117 return false; 118 } 119 if (!lowThreshold(ref, thresh, maskVal, maskThresh, region, "reference convolved image")) { 120 psError(PS_ERR_UNKNOWN, false, "Unable to threshold input image."); 121 return false; 122 } 109 123 } 124 psFree(regIter); 110 125 111 126 psFree(view); -
branches/eam_branches/20091201/psModules/src/imcombine/pmStackReject.c
r25468 r26739 35 35 { 36 36 int size = kernels->size; // Half-size of convolution kernel 37 psImage *polyValues = p_pmSubtractionPolynomialFromCoords(NULL, kernels, numCols, numRows,38 xMin + size + 1,yMin + size + 1); // Polynomial37 psImage *polyValues = p_pmSubtractionPolynomialFromCoords(NULL, kernels, xMin + size + 1, 38 yMin + size + 1); // Polynomial 39 39 int box = p_pmSubtractionBadRadius(NULL, kernels, polyValues, false, poorFrac); // Radius of bad box 40 40 psTrace("psModules.imcombine", 10, "Growing by %d", box); … … 165 165 166 166 // Image of the kernel at the centre of the region 167 float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - kernels->numCols/2.0) /168 (float)kernels->numCols;169 float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - kernels->numRows/2.0) /170 (float)kernels->numRows;167 float xNorm, yNorm; // Normalised coordinates 168 p_pmSubtractionPolynomialNormCoords(&xNorm, &yNorm, 0.5 * (region->x1 - region->x0), 169 0.5 * (region->y1 - region->y0), 170 kernels->xMin, kernels->xMax, kernels->yMin, kernels->yMax); 171 171 psImage *kernel = pmSubtractionKernelImage(kernels, xNorm, yNorm, false); 172 172 if (!kernel) { -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtraction.c
r26667 r26739 424 424 } else if (*source & subConvPoor) { 425 425 *target |= maskPoor; 426 } else { 427 *target &= ~maskBad & ~maskPoor; 426 428 } 427 429 } … … 574 576 } 575 577 578 void p_pmSubtractionPolynomialNormCoords(float *xOut, float *yOut, float xIn, float yIn, 579 int xMin, int xMax, int yMin, int yMax) 580 { 581 float xNormSize = xMax - xMin, yNormSize = yMax - yMin; // Size to use for normalisation 582 *xOut = 2.0 * (float)(xIn - xMin - xNormSize/2.0) / xNormSize; 583 *yOut = 2.0 * (float)(yIn - yMin - yNormSize/2.0) / yNormSize; 584 return; 585 } 586 576 587 psImage *p_pmSubtractionPolynomialFromCoords(psImage *output, const pmSubtractionKernels *kernels, 577 int numCols, int numRows, intx, int y)588 int x, int y) 578 589 { 579 590 assert(kernels); 580 assert(numCols > 0 && numRows > 0); 581 582 // Size to use when calculating normalised coordinates (different from actual size when convolving 583 // subimage) 584 int xNormSize = (kernels->numCols > 0 ? kernels->numCols : numCols); 585 int yNormSize = (kernels->numRows > 0 ? kernels->numRows : numRows); 586 587 // Normalised coordinates 588 float yNorm = 2.0 * (float)(y - yNormSize/2.0) / (float)yNormSize; 589 float xNorm = 2.0 * (float)(x - xNormSize/2.0) / (float)xNormSize; 590 591 592 float xNorm, yNorm; // Normalised coordinates 593 p_pmSubtractionPolynomialNormCoords(&xNorm, &yNorm, x, y, 594 kernels->xMin, kernels->xMax, kernels->yMin, kernels->yMax); 591 595 return p_pmSubtractionPolynomial(output, kernels->spatialOrder, xNorm, yNorm); 592 596 } … … 1072 1076 // Only generate polynomial values every kernel footprint, since we have already assumed 1073 1077 // (with the stamps) that it does not vary rapidly on this scale. 1074 psImage *polyValues = p_pmSubtractionPolynomialFromCoords(NULL, kernels, numCols, numRows, 1075 xMin + x0 + size + 1, 1076 yMin + y0 + size + 1); 1078 psImage *polyValues = p_pmSubtractionPolynomialFromCoords(NULL, kernels, xMin + x0 + size + 1, 1079 yMin + y0 + size + 1); // Polynomial 1077 1080 float background = doBG ? p_pmSubtractionSolutionBackground(kernels, polyValues) : 0.0; // Background term 1078 1081 … … 1200 1203 bool threaded = pmSubtractionThreaded(); // Running threaded? 1201 1204 1202 // Outputs1203 if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) {1204 if (!out1->image) {1205 out1->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);1206 }1207 if (ro1->variance) {1208 if (!out1->variance) {1209 out1->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);1210 }1211 psImageInit(out1->variance, 0.0);1212 }1213 }1214 if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) {1215 if (!out2->image) {1216 out2->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);1217 }1218 if (ro2->variance) {1219 if (!out2->variance) {1220 out2->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);1221 }1222 psImageInit(out2->variance, 0.0);1223 }1224 }1225 1205 psImage *convMask = NULL; // Convolved mask image (common to inputs 1 and 2) 1226 1206 if (subMask) { 1227 1207 if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1228 if (!out1->mask) {1229 out1->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);1230 }1231 psImageInit(out1->mask, 0);1232 1208 convMask = out1->mask; 1233 1209 } 1234 1210 if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1235 if (!out2->mask) {1236 out2->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);1237 }1238 psImageInit(out2->mask, 0);1239 1211 if (!convMask) { 1240 1212 convMask = out2->mask; … … 1256 1228 1257 1229 // Get region for convolution: [xMin:xMax,yMin:yMax] 1258 int xMin = size, xMax = numCols- size;1259 int yMin = size, yMax = numRows- size;1230 int xMin = kernels->xMin + size, xMax = kernels->xMax - size; 1231 int yMin = kernels->yMin + size, yMax = kernels->yMax - size; 1260 1232 if (region) { 1261 1233 xMin = PS_MAX(region->x0, xMin); -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtraction.h
r25279 r26739 127 127 ); 128 128 129 /// Return normalised coordinates 130 void p_pmSubtractionPolynomialNormCoords( 131 float *xOut, float *yOut, ///< Normalised coordinates, returned 132 float xIn, float yIn, ///< Input coordinates 133 int xMin, int xMax, int yMin, int yMax ///< Bounds of validity 134 ); 135 129 136 /// Given (normalised) coordinates (x,y), generate a matrix where the elements (i,j) are x^i * y^j 130 137 psImage *p_pmSubtractionPolynomial(psImage *output, ///< Output matrix, or NULL … … 138 145 psImage *p_pmSubtractionPolynomialFromCoords(psImage *output, ///< Output matrix, or NULL 139 146 const pmSubtractionKernels *kernels, ///< Kernel parameters 140 int numCols, int numRows, ///< Size of image of interest141 147 int x, int y ///< Position of interest 142 148 ); -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionAnalysis.c
r26593 r26739 118 118 119 119 // sample difference images 120 { 120 { 121 121 psMetadataAddArray(analysis, PS_LIST_TAIL, "SUBTRACTION.SAMPLE.STAMP.SET", PS_META_DUPLICATE_OK, "Sample Difference Stamps", kernels->sampleStamps); 122 122 } … … 273 273 // Difference in background 274 274 { 275 psImage *polyValues = p_pmSubtractionPolynomialFromCoords(NULL, kernels, numCols, numRows, 276 numCols / 2.0, numRows / 2.0); // Polynomial 275 psImage *polyValues = p_pmSubtractionPolynomial(NULL, kernels->spatialOrder, 0.0, 0.0); // Polynomial 277 276 float bg = p_pmSubtractionSolutionBackground(kernels, polyValues); // Background difference 278 277 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c
r26737 r26739 213 213 214 214 *norm = normI2 / normI1; 215 fprintf(stderr, "Sums: %f %f %f, normWindow: %d\n", normI1, normI2, *norm, normWindow);216 215 217 216 if (mode & PM_SUBTRACTION_EQUATION_NORM) { … … 522 521 523 522 *norm = normI2 / normI1; 524 fprintf(stderr, "Sums: %f %f %f - I1I1: %f\n", normI1, normI2, *norm, sumI1I1);525 523 526 524 if (mode & PM_SUBTRACTION_EQUATION_NORM) { … … 590 588 // Contribution to chi^2: a_i^2 P_i 591 589 psAssert(isfinite(penalties->data.F32[i]), "Invalid penalty"); 592 fprintf (stderr, "penalty main: %d %e vs %e x %f : %f\n",593 index,594 matrix->data.F64[index][index],595 norm, penalties->data.F32[i],596 (norm * penalties->data.F32[i]) / matrix->data.F64[index][index] );597 590 matrix->data.F64[index][index] += norm * penalties->data.F32[i]; 598 591 if (kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 599 fprintf (stderr, "penalty dual: %d %e vs %e x %f : %f\n",600 index + numParams + 2,601 matrix->data.F64[index + numParams + 2][index + numParams + 2],602 norm, penalties->data.F32[i],603 (norm * penalties->data.F32[i]) / matrix->data.F64[index + numParams + 2][index + numParams + 2] );604 592 matrix->data.F64[index + numParams + 2][index + numParams + 2] += norm * penalties->data.F32[i]; 605 593 // matrix[i][i] is ~ (k_i * I_1)(k_i * I_1) … … 997 985 // Solve normalisation and background separately 998 986 int normIndex = PM_SUBTRACTION_INDEX_NORM(kernels); // Index for normalisation 987 int bgIndex = PM_SUBTRACTION_INDEX_BG(kernels); // Index for background 999 988 1000 989 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for norm … … 1014 1003 1015 1004 fprintf(stderr, "Norm: %lf\n", normValue); 1016 // fprintf(stderr, "BG: %lf\n", bgValue);1017 1005 1018 1006 // Solve kernel components 1019 1007 for (int i = 0; i < numSolution1; i++) { 1020 sumVector->data.F64[i] -= normValue * sumMatrix->data.F64[normIndex][i]; // + bgValue * sumMatrix->data.F64[bgIndex][i];1008 sumVector->data.F64[i] -= normValue * sumMatrix->data.F64[normIndex][i]; 1021 1009 1022 1010 sumMatrix->data.F64[i][normIndex] = 0.0; 1023 1011 sumMatrix->data.F64[normIndex][i] = 0.0; 1024 1025 // sumMatrix->data.F64[i][bgIndex] = 0.0;1026 // sumMatrix->data.F64[bgIndex][i] = 0.0;1027 }1012 } 1013 sumVector->data.F64[bgIndex] -= normValue * sumMatrix->data.F64[normIndex][bgIndex]; 1014 sumMatrix->data.F64[bgIndex][normIndex] = 0.0; 1015 sumMatrix->data.F64[normIndex][bgIndex] = 0.0; 1028 1016 1029 1017 sumMatrix->data.F64[normIndex][normIndex] = 1.0; 1030 // sumMatrix->data.F64[bgIndex][bgIndex] = 1.0;1031 // sumMatrix->data.F64[normIndex][bgIndex] = sumMatrix->data.F64[bgIndex][normIndex] = 0.0;1032 1033 1018 sumVector->data.F64[normIndex] = 0.0; 1034 // sumVector->data.F64[bgIndex] = 0.0;1035 1019 1036 1020 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN); 1037 1021 1038 1022 solution->data.F64[normIndex] = normValue; 1039 // solution->data.F64[bgIndex] = bgValue;1040 1023 } 1041 1024 # endif 1042 1025 1043 1026 if (!kernels->solution1) { 1044 kernels->solution1 = psVectorAlloc (sumVector->n, PS_TYPE_F64);1045 psVectorInit (kernels->solution1, 0.0);1027 kernels->solution1 = psVectorAlloc(sumVector->n, PS_TYPE_F64); 1028 psVectorInit(kernels->solution1, 0.0); 1046 1029 } 1047 1030 … … 1126 1109 // Solve normalisation and background separately 1127 1110 int normIndex = PM_SUBTRACTION_INDEX_NORM(kernels); // Index for normalisation 1111 int bgIndex = PM_SUBTRACTION_INDEX_BG(kernels); // Index for background 1128 1112 1129 1113 #if 0 … … 1159 1143 1160 1144 double normValue = stats->robustMedian; 1161 // double bgValue = 0.0;1162 1145 1163 1146 psFree(stats); 1164 1147 1165 1148 fprintf(stderr, "Norm: %lf\n", normValue); 1166 // fprintf(stderr, "BG: %lf\n", bgValue);1167 1149 1168 1150 // Solve kernel components 1169 1151 for (int i = 0; i < numSolution2; i++) { 1170 sumVector->data.F64[i] -= normValue * sumMatrix->data.F64[normIndex][i]; // + bgValue * sumMatrix->data.F64[bgIndex][i];1171 sumVector->data.F64[i + numSolution1] -= normValue * sumMatrix->data.F64[normIndex][i + numSolution1]; // + bgValue * sumMatrix->data.F64[bgIndex][i + numSolution1];1152 sumVector->data.F64[i] -= normValue * sumMatrix->data.F64[normIndex][i]; 1153 sumVector->data.F64[i + numSolution1] -= normValue * sumMatrix->data.F64[normIndex][i + numSolution1]; 1172 1154 1173 1155 sumMatrix->data.F64[i][normIndex] = 0.0; 1174 1156 sumMatrix->data.F64[normIndex][i] = 0.0; 1175 1157 1176 // sumMatrix->data.F64[i][bgIndex] = 0.0;1177 // sumMatrix->data.F64[bgIndex][i] = 0.0;1178 1158 sumMatrix->data.F64[i + numSolution1][normIndex] = 0.0; 1179 1159 sumMatrix->data.F64[normIndex][i + numSolution1] = 0.0; 1180 // sumMatrix->data.F64[i + numSolution1][bgIndex] = 0.0; 1181 // sumMatrix->data.F64[bgIndex][i + numSolution1] = 0.0; 1182 } 1160 } 1161 sumVector->data.F64[bgIndex] -= normValue * sumMatrix->data.F64[normIndex][bgIndex]; 1162 sumMatrix->data.F64[bgIndex][normIndex] = 0.0; 1163 sumMatrix->data.F64[normIndex][bgIndex] = 0.0; 1183 1164 1184 1165 sumMatrix->data.F64[normIndex][normIndex] = 1.0; 1185 // sumMatrix->data.F64[bgIndex][bgIndex] = 1.0;1186 // sumMatrix->data.F64[normIndex][bgIndex] = sumMatrix->data.F64[bgIndex][normIndex] = 0.0;1187 1166 1188 1167 sumVector->data.F64[normIndex] = 0.0; 1189 // sumVector->data.F64[bgIndex] = 0.0;1190 1168 1191 1169 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN); 1192 1170 1193 1171 solution->data.F64[normIndex] = normValue; 1194 // solution->data.F64[bgIndex] = bgValue;1195 1172 } 1196 1173 #endif -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.h
r26577 r26739 10 10 PM_SUBTRACTION_EQUATION_BG = 0x02, 11 11 PM_SUBTRACTION_EQUATION_KERNELS = 0x04, 12 PM_SUBTRACTION_EQUATION_ALL = 0x0 5, // value should be NORM | BG | KERNELS12 PM_SUBTRACTION_EQUATION_ALL = 0x07, // value should be NORM | BG | KERNELS 13 13 } pmSubtractionEquationCalculationMode; 14 14 … … 21 21 const pmSubtractionKernels *kernels, ///< Kernel parameters 22 22 int index, ///< Index of stamp 23 const pmSubtractionEquationCalculationMode mode23 const pmSubtractionEquationCalculationMode mode 24 24 ); 25 25 … … 27 27 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, ///< Stamps 28 28 const pmSubtractionKernels *kernels, ///< Kernel parameters 29 const pmSubtractionEquationCalculationMode mode29 const pmSubtractionEquationCalculationMode mode 30 30 ); 31 31 … … 33 33 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, ///< Kernel parameters 34 34 const pmSubtractionStampList *stamps, ///< Stamps 35 const pmSubtractionEquationCalculationMode mode35 const pmSubtractionEquationCalculationMode mode 36 36 ); 37 37 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionIO.c
r23378 r26739 80 80 while ((item = psMetadataGetAndIncrement(iter))) { 81 81 assert(item->type == PS_DATA_UNKNOWN); 82 // Set the normalisation dimensions, since these will be otherwise unavailable when reading the83 // images by scans.84 82 pmSubtractionKernels *kernel = item->data.V; // Kernel used in subtraction 85 kernel->numCols = ro->image->numCols;86 kernel->numRows = ro->image->numRows;87 88 83 kernels = psArrayAdd(kernels, ARRAY_BUFFER, kernel); 89 84 } … … 126 121 kernel->bgOrder); 127 122 psMetadataAddS32(row, PS_LIST_TAIL, NAME_MODE, 0, "Matching mode (enum)", kernel->mode); 128 psMetadataAddS32(row, PS_LIST_TAIL, NAME_COLS, 0, "Number of columns", kernel->numCols);129 psMetadataAddS32(row, PS_LIST_TAIL, NAME_ROWS, 0, "Number of rows", kernel->numRows);130 123 if (kernel->mode == PM_SUBTRACTION_MODE_1 || kernel->mode == PM_SUBTRACTION_MODE_2) { 131 124 psMetadataAddVector(row, PS_LIST_TAIL, NAME_SOL1, 0, "Solution vector 1", kernel->solution1); … … 318 311 319 312 TABLE_LOOKUP(int, S32, bg, NAME_BG); 320 TABLE_LOOKUP(int, S32, numCols, NAME_COLS);321 TABLE_LOOKUP(int, S32, numRows, NAME_ROWS);322 313 323 314 TABLE_LOOKUP(float, F32, mean, NAME_MEAN); … … 325 316 TABLE_LOOKUP(int, S32, numStamps, NAME_NUMSTAMPS); 326 317 327 pmSubtractionKernels *kernels = pmSubtractionKernelsFromDescription(description, bg, mode); 328 kernels->numCols = numCols; 329 kernels->numRows = numRows; 318 pmSubtractionKernels *kernels = pmSubtractionKernelsFromDescription(description, bg, *region, mode); 330 319 kernels->mean = mean; 331 320 kernels->rms = rms; -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionKernels.c
r26734 r26739 197 197 } 198 198 199 #if 1199 #if 0 200 200 fprintf(stderr, "%d raw: %lf, null: %f, min: %lf, max: %lf, moment: %lf\n", index, sum, preCalc->kernel->kernel[0][0], min, max, penalty); 201 201 #endif … … 245 245 } 246 246 247 #if 1247 #if 0 248 248 { 249 249 double sum = 0.0; // Sum of kernel component … … 276 276 pmSubtractionKernels *p_pmSubtractionKernelsRawISIS(int size, int spatialOrder, 277 277 const psVector *fwhmsIN, const psVector *ordersIN, 278 float penalty, p mSubtractionMode mode)278 float penalty, psRegion bounds, pmSubtractionMode mode) 279 279 { 280 280 PS_ASSERT_VECTOR_NON_NULL(fwhmsIN, NULL); … … 305 305 } 306 306 307 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS, size, spatialOrder, penalty, mode); // The kernels 307 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS, size, 308 spatialOrder, penalty, bounds, mode); // Kernels 308 309 psStringAppend(&kernels->description, "ISIS(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 309 310 … … 331 332 pmSubtractionKernels *pmSubtractionKernelsISIS_RADIAL(int size, int spatialOrder, 332 333 const psVector *fwhmsIN, const psVector *ordersIN, 333 float penalty, p mSubtractionMode mode)334 float penalty, psRegion bounds, pmSubtractionMode mode) 334 335 { 335 336 PS_ASSERT_VECTOR_NON_NULL(fwhmsIN, NULL); … … 361 362 } 362 363 363 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS_RADIAL, size, spatialOrder, penalty, mode); // The kernels 364 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_ISIS_RADIAL, size, 365 spatialOrder, penalty, bounds, mode); // Kernels 364 366 psStringAppend(&kernels->description, "ISIS_RADIAL(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 365 367 … … 388 390 pmSubtractionKernels *pmSubtractionKernelsHERM(int size, int spatialOrder, 389 391 const psVector *fwhmsIN, const psVector *ordersIN, 390 float penalty, p mSubtractionMode mode)392 float penalty, psRegion bounds, pmSubtractionMode mode) 391 393 { 392 394 PS_ASSERT_VECTOR_NON_NULL(fwhmsIN, NULL); … … 417 419 } 418 420 419 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_HERM, size, spatialOrder, penalty, mode); // The kernels 421 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_HERM, size, 422 spatialOrder, penalty, bounds, mode); // Kernels 420 423 psStringAppend(&kernels->description, "HERM(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 421 424 422 psLogMsg("psModules.imcombine", PS_LOG_INFO, "HERM kernel: %s,%d --> %d elements", params, spatialOrder, num); 425 psLogMsg("psModules.imcombine", PS_LOG_INFO, "HERM kernel: %s,%d --> %d elements", 426 params, spatialOrder, num); 423 427 psFree(params); 424 428 … … 439 443 440 444 pmSubtractionKernels *pmSubtractionKernelsDECONV_HERM(int size, int spatialOrder, 441 const psVector *fwhmsIN, const psVector *ordersIN,442 float penalty, pmSubtractionMode mode)445 const psVector *fwhmsIN, const psVector *ordersIN, 446 float penalty, psRegion bounds, pmSubtractionMode mode) 443 447 { 444 448 PS_ASSERT_VECTOR_NON_NULL(fwhmsIN, NULL); … … 469 473 } 470 474 471 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_DECONV_HERM, size, spatialOrder, penalty, mode); // The kernels 475 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_DECONV_HERM, size, 476 spatialOrder, penalty, bounds, mode); // Kernels 472 477 psStringAppend(&kernels->description, "DECONV_HERM(%d,%s,%d,%.2e)", size, params, spatialOrder, penalty); 473 478 … … 544 549 545 550 pmSubtractionKernels *pmSubtractionKernelsAlloc(int numBasisFunctions, pmSubtractionKernelsType type, 546 int size, int spatialOrder, float penalty, 551 int size, int spatialOrder, float penalty, psRegion bounds, 547 552 pmSubtractionMode mode) 548 553 { … … 558 563 kernels->uStop = NULL; 559 564 kernels->vStop = NULL; 565 kernels->xMin = bounds.x0; 566 kernels->xMax = bounds.x1; 567 kernels->yMin = bounds.y0; 568 kernels->yMax = bounds.y1; 560 569 kernels->preCalc = psArrayAlloc(numBasisFunctions); 561 570 kernels->penalty = penalty; … … 566 575 kernels->bgOrder = 0; 567 576 kernels->mode = mode; 568 kernels->numCols = 0;569 kernels->numRows = 0;570 577 kernels->solution1 = NULL; 571 578 kernels->solution2 = NULL; … … 640 647 } 641 648 642 pmSubtractionKernels *pmSubtractionKernelsPOIS(int size, int spatialOrder, float penalty, 649 pmSubtractionKernels *pmSubtractionKernelsPOIS(int size, int spatialOrder, float penalty, psRegion bounds, 643 650 pmSubtractionMode mode) 644 651 { … … 649 656 650 657 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(0, PM_SUBTRACTION_KERNEL_POIS, size, 651 spatialOrder, penalty, mode); // The kernels658 spatialOrder, penalty, bounds, mode); // Kernels 652 659 psStringAppend(&kernels->description, "POIS(%d,%d,%.2e)", size, spatialOrder, penalty); 653 660 psLogMsg("psModules.imcombine", PS_LOG_INFO, "POIS kernel: %d,%d --> %d elements", … … 664 671 pmSubtractionKernels *pmSubtractionKernelsISIS(int size, int spatialOrder, 665 672 const psVector *fwhms, const psVector *orders, 666 float penalty, p mSubtractionMode mode)673 float penalty, psRegion bounds, pmSubtractionMode mode) 667 674 { 668 675 pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders, 669 penalty, mode); // Kernels676 penalty, bounds, mode); // Kernels 670 677 if (!kernels) { 671 678 return NULL; … … 676 683 677 684 pmSubtractionKernels *pmSubtractionKernelsSPAM(int size, int spatialOrder, int inner, int binning, 678 float penalty, p mSubtractionMode mode)685 float penalty, psRegion bounds, pmSubtractionMode mode) 679 686 { 680 687 PS_ASSERT_INT_POSITIVE(size, NULL); … … 697 704 698 705 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_SPAM, size, 699 spatialOrder, penalty, mode); // The kernels706 spatialOrder, penalty, bounds, mode); // Kernels 700 707 kernels->inner = inner; 701 708 psStringAppend(&kernels->description, "SPAM(%d,%d,%d,%d,%.2e)", size, inner, binning, spatialOrder, … … 768 775 769 776 pmSubtractionKernels *pmSubtractionKernelsFRIES(int size, int spatialOrder, int inner, float penalty, 770 p mSubtractionMode mode)777 psRegion bounds, pmSubtractionMode mode) 771 778 { 772 779 PS_ASSERT_INT_POSITIVE(size, NULL); … … 795 802 796 803 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_FRIES, size, 797 spatialOrder, penalty, mode); // The kernels804 spatialOrder, penalty, bounds, mode); // Kernels 798 805 kernels->inner = inner; 799 806 psStringAppend(&kernels->description, "FRIES(%d,%d,%d,%.2e)", size, inner, spatialOrder, penalty); … … 864 871 pmSubtractionKernels *pmSubtractionKernelsGUNK(int size, int spatialOrder, const psVector *fwhms, 865 872 const psVector *orders, int inner, float penalty, 866 p mSubtractionMode mode)873 psRegion bounds, pmSubtractionMode mode) 867 874 { 868 875 PS_ASSERT_INT_POSITIVE(size, NULL); … … 877 884 878 885 pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders, 879 penalty, mode); // Kernels886 penalty, bounds, mode); // Kernels 880 887 kernels->type = PM_SUBTRACTION_KERNEL_GUNK; 881 888 psStringPrepend(&kernels->description, "GUNK="); … … 893 900 // RINGS --- just what it says 894 901 pmSubtractionKernels *pmSubtractionKernelsRINGS(int size, int spatialOrder, int inner, int ringsOrder, 895 float penalty, p mSubtractionMode mode)902 float penalty, psRegion bounds, pmSubtractionMode mode) 896 903 { 897 904 PS_ASSERT_INT_POSITIVE(size, NULL); … … 924 931 925 932 pmSubtractionKernels *kernels = pmSubtractionKernelsAlloc(num, PM_SUBTRACTION_KERNEL_RINGS, size, 926 spatialOrder, penalty, mode); // The kernels933 spatialOrder, penalty, bounds, mode); // Kernels 927 934 kernels->inner = inner; 928 935 psStringAppend(&kernels->description, "RINGS(%d,%d,%d,%d,%.2e)", size, inner, ringsOrder, spatialOrder, … … 1046 1053 pmSubtractionKernels *pmSubtractionKernelsGenerate(pmSubtractionKernelsType type, int size, int spatialOrder, 1047 1054 const psVector *fwhms, const psVector *orders, int inner, 1048 int binning, int ringsOrder, float penalty, 1055 int binning, int ringsOrder, float penalty, psRegion bounds, 1049 1056 pmSubtractionMode mode) 1050 1057 { 1051 1058 switch (type) { 1052 1059 case PM_SUBTRACTION_KERNEL_POIS: 1053 return pmSubtractionKernelsPOIS(size, spatialOrder, penalty, mode);1060 return pmSubtractionKernelsPOIS(size, spatialOrder, penalty, bounds, mode); 1054 1061 case PM_SUBTRACTION_KERNEL_ISIS: 1055 return pmSubtractionKernelsISIS(size, spatialOrder, fwhms, orders, penalty, mode);1062 return pmSubtractionKernelsISIS(size, spatialOrder, fwhms, orders, penalty, bounds, mode); 1056 1063 case PM_SUBTRACTION_KERNEL_ISIS_RADIAL: 1057 return pmSubtractionKernelsISIS_RADIAL(size, spatialOrder, fwhms, orders, penalty, mode);1064 return pmSubtractionKernelsISIS_RADIAL(size, spatialOrder, fwhms, orders, penalty, bounds, mode); 1058 1065 case PM_SUBTRACTION_KERNEL_HERM: 1059 return pmSubtractionKernelsHERM(size, spatialOrder, fwhms, orders, penalty, mode);1066 return pmSubtractionKernelsHERM(size, spatialOrder, fwhms, orders, penalty, bounds, mode); 1060 1067 case PM_SUBTRACTION_KERNEL_DECONV_HERM: 1061 return pmSubtractionKernelsDECONV_HERM(size, spatialOrder, fwhms, orders, penalty, mode);1068 return pmSubtractionKernelsDECONV_HERM(size, spatialOrder, fwhms, orders, penalty, bounds, mode); 1062 1069 case PM_SUBTRACTION_KERNEL_SPAM: 1063 return pmSubtractionKernelsSPAM(size, spatialOrder, inner, binning, penalty, mode);1070 return pmSubtractionKernelsSPAM(size, spatialOrder, inner, binning, penalty, bounds, mode); 1064 1071 case PM_SUBTRACTION_KERNEL_FRIES: 1065 return pmSubtractionKernelsFRIES(size, spatialOrder, inner, penalty, mode);1072 return pmSubtractionKernelsFRIES(size, spatialOrder, inner, penalty, bounds, mode); 1066 1073 case PM_SUBTRACTION_KERNEL_GUNK: 1067 return pmSubtractionKernelsGUNK(size, spatialOrder, fwhms, orders, inner, penalty, mode);1074 return pmSubtractionKernelsGUNK(size, spatialOrder, fwhms, orders, inner, penalty, bounds, mode); 1068 1075 case PM_SUBTRACTION_KERNEL_RINGS: 1069 return pmSubtractionKernelsRINGS(size, spatialOrder, inner, ringsOrder, penalty, mode);1076 return pmSubtractionKernelsRINGS(size, spatialOrder, inner, ringsOrder, penalty, bounds, mode); 1070 1077 default: 1071 1078 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unknown kernel type: %x", type); … … 1103 1110 1104 1111 pmSubtractionKernels *pmSubtractionKernelsFromDescription(const char *description, int bgOrder, 1105 p mSubtractionMode mode)1112 psRegion bounds, pmSubtractionMode mode) 1106 1113 { 1107 1114 PS_ASSERT_STRING_NON_EMPTY(description, NULL); … … 1156 1163 PARSE_STRING_NUMBER(spatialOrder, ptr, ',', parseStringInt); 1157 1164 penalty = parseStringFloat(ptr); 1158 1159 return pmSubtractionKernelsGenerate(type, size, spatialOrder, fwhms, orders, inner, binning, ringsOrder, penalty, mode); 1160 1165 break; 1161 1166 case PM_SUBTRACTION_KERNEL_RINGS: 1162 1167 PARSE_STRING_NUMBER(size, ptr, ',', parseStringInt); … … 1165 1170 PARSE_STRING_NUMBER(spatialOrder, ptr, ',', parseStringInt); 1166 1171 PARSE_STRING_NUMBER(penalty, ptr, ')', parseStringInt); 1167 return pmSubtractionKernelsGenerate(type, size, spatialOrder, fwhms, orders, inner, binning, ringsOrder, penalty, mode);1172 break; 1168 1173 default: 1169 1174 psAbort("Deciphering kernels other than ISIS, HERM, DECONV_HERM or RINGS is not currently supported."); 1170 1175 } 1171 return NULL; 1176 1177 return pmSubtractionKernelsGenerate(type, size, spatialOrder, fwhms, orders, inner, binning, 1178 ringsOrder, penalty, bounds, mode); 1172 1179 } 1173 1180 … … 1245 1252 out->bgOrder = in->bgOrder; 1246 1253 out->mode = in->mode; 1247 out->numCols = in->numCols; 1248 out->numRows = in->numRows; 1254 out->xMin = in->xMin; 1255 out->xMax = in->xMax; 1256 out->yMin = in->yMin; 1257 out->yMax = in->yMax; 1249 1258 out->solution1 = in->solution1 ? psVectorCopy(NULL, in->solution1, PS_TYPE_F64) : NULL; 1250 1259 out->solution2 = in->solution2 ? psVectorCopy(NULL, in->solution2, PS_TYPE_F64) : NULL; -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionKernels.h
r26593 r26739 12 12 PM_SUBTRACTION_KERNEL_ISIS_RADIAL, ///< ISIS + higher-order radial Hermitians 13 13 PM_SUBTRACTION_KERNEL_HERM, ///< Hermitian polynomial kernels 14 PM_SUBTRACTION_KERNEL_DECONV_HERM, ///< Deconvolved Hermitian polynomial kernels14 PM_SUBTRACTION_KERNEL_DECONV_HERM, ///< Deconvolved Hermitian polynomial kernels 15 15 PM_SUBTRACTION_KERNEL_SPAM, ///< Summed Pixels for Advanced Matching --- summed delta functions 16 16 PM_SUBTRACTION_KERNEL_FRIES, ///< Fibonacci Radius Increases Excellence of Subtraction … … 32 32 pmSubtractionKernelsType type; ///< Type of kernels --- allowing the use of multiple kernels 33 33 psString description; ///< Description of the kernel parameters 34 int xMin, xMax, yMin, yMax; ///< Bounds of image (for normalisation) 34 35 long num; ///< Number of kernel components (not including the spatial ones) 35 36 psVector *u, *v; ///< Offset (for POIS) or polynomial order (for ISIS, HERM or DECONV_HERM) … … 44 45 int bgOrder; ///< The order for the background fitting 45 46 pmSubtractionMode mode; ///< Mode for subtraction 46 int numCols, numRows; ///< Size of image (for normalisation), or zero to use image provided47 47 psVector *solution1, *solution2; ///< Solution for the PSF matching 48 48 // Quality information 49 49 float mean, rms; ///< Mean and RMS of chi^2 from stamps 50 50 int numStamps; ///< Number of good stamps 51 float fSigResMean; ///< mean fractional stdev of residuals52 float fSigResStdev; ///< stdev of fractional stdev of residuals53 float fMaxResMean; ///< mean fractional positive swing in residuals54 float fMaxResStdev; ///< stdev of fractional positive swing in residuals55 float fMinResMean; ///< mean fractional negative swing in residuals56 float fMinResStdev; ///< stdev of fractional negative swing in residuals57 psArray *sampleStamps; ///< array of brightest set of stamps for output visualizations51 float fSigResMean; ///< mean fractional stdev of residuals 52 float fSigResStdev; ///< stdev of fractional stdev of residuals 53 float fMaxResMean; ///< mean fractional positive swing in residuals 54 float fMaxResStdev; ///< stdev of fractional positive swing in residuals 55 float fMinResMean; ///< mean fractional negative swing in residuals 56 float fMinResStdev; ///< stdev of fractional negative swing in residuals 57 psArray *sampleStamps; ///< array of brightest set of stamps for output visualizations 58 58 } pmSubtractionKernels; 59 59 60 60 // pmSubtractionKernels->preCalc is an array of pmSubtractionKernelPreCalc structures 61 61 typedef struct { 62 psVector *uCoords; // used by RINGS63 psVector *vCoords; // used by RINGS64 psVector *poly; // used by RINGS65 66 psVector *xKernel; // used by ISIS, HERM, DECONV_HERM67 psVector *yKernel; // used by ISIS, HERM, DECONV_HERM68 psKernel *kernel; // used by ISIS, HERM, DECONV_HERM62 psVector *uCoords; // used by RINGS 63 psVector *vCoords; // used by RINGS 64 psVector *poly; // used by RINGS 65 66 psVector *xKernel; // used by ISIS, HERM, DECONV_HERM 67 psVector *yKernel; // used by ISIS, HERM, DECONV_HERM 68 psKernel *kernel; // used by ISIS, HERM, DECONV_HERM 69 69 } pmSubtractionKernelPreCalc; 70 70 … … 162 162 int spatialOrder, ///< Order of spatial variations 163 163 float penalty, ///< Penalty for wideness 164 psRegion bounds, ///< Bounds for validity 164 165 pmSubtractionMode mode ///< Mode for subtraction 165 166 ); … … 168 169 pmSubtractionKernelPreCalc *pmSubtractionKernelPreCalcAlloc( 169 170 pmSubtractionKernelsType type, ///< type of kernel to allocate (not all can be pre-calculated) 170 int uOrder, ///< order in x-direction171 int vOrder, ///< order in x-direction172 int size, ///< Half-size of the kernel173 float sigma ///< sigma of gaussian kernel171 int uOrder, ///< order in x-direction 172 int vOrder, ///< order in x-direction 173 int size, ///< Half-size of the kernel 174 float sigma ///< sigma of gaussian kernel 174 175 ); 175 176 … … 179 180 int spatialOrder, ///< Order of spatial variations 180 181 float penalty, ///< Penalty for wideness 182 psRegion bounds, ///< Bounds for validity 181 183 pmSubtractionMode mode ///< Mode for subtraction 182 184 ); … … 188 190 const psVector *orders, ///< Polynomial order of gaussians 189 191 float penalty, ///< Penalty for wideness 192 psRegion bounds, ///< Bounds for validity 190 193 pmSubtractionMode mode ///< Mode for subtraction 191 194 ); … … 197 200 const psVector *orders, ///< Polynomial order of gaussians 198 201 float penalty, ///< Penalty for wideness 202 psRegion bounds, ///< Bounds for validity 199 203 pmSubtractionMode mode ///< Mode for subtraction 200 204 ); … … 202 206 /// Generate ISIS + RADIAL_HERM kernels 203 207 pmSubtractionKernels *pmSubtractionKernelsISIS_RADIAL(int size, ///< Half-size of the kernel 204 int spatialOrder, ///< Order of spatial variations 205 const psVector *fwhms, ///< Gaussian FWHMs 206 const psVector *orders, ///< Polynomial order of gaussians 207 float penalty, ///< Penalty for wideness 208 pmSubtractionMode mode ///< Mode for subtraction 208 int spatialOrder, ///< Order of spatial variations 209 const psVector *fwhms, ///< Gaussian FWHMs 210 const psVector *orders, ///< Polynomial order of gaussians 211 float penalty, ///< Penalty for wideness 212 psRegion bounds, ///< Bounds for validity 213 pmSubtractionMode mode ///< Mode for subtraction 209 214 ); 210 215 … … 215 220 const psVector *orders, ///< order of hermitian polynomials 216 221 float penalty, ///< Penalty for wideness 222 psRegion bounds, ///< Bounds for validity 217 223 pmSubtractionMode mode ///< Mode for subtraction 218 224 ); … … 220 226 /// Generate DECONV_HERM kernels 221 227 pmSubtractionKernels *pmSubtractionKernelsDECONV_HERM(int size, ///< Half-size of the kernel 222 int spatialOrder, ///< Order of spatial variations 223 const psVector *fwhms, ///< Gaussian FWHMs 224 const psVector *orders, ///< order of hermitian polynomials 225 float penalty, ///< Penalty for wideness 226 pmSubtractionMode mode ///< Mode for subtraction 228 int spatialOrder, ///< Order of spatial variations 229 const psVector *fwhms, ///< Gaussian FWHMs 230 const psVector *orders, ///< order of hermitian polynomials 231 float penalty, ///< Penalty for wideness 232 psRegion bounds, ///< Bounds for validity 233 pmSubtractionMode mode ///< Mode for subtraction 227 234 ); 228 235 … … 233 240 int binning, ///< Kernel binning factor 234 241 float penalty, ///< Penalty for wideness 242 psRegion bounds, ///< Bounds for validity 235 243 pmSubtractionMode mode ///< Mode for subtraction 236 244 ); … … 241 249 int inner, ///< Inner radius to preserve unbinned 242 250 float penalty, ///< Penalty for wideness 251 psRegion bounds, ///< Bounds for validity 243 252 pmSubtractionMode mode ///< Mode for subtraction 244 253 ); … … 251 260 int inner, ///< Inner radius containing grid of delta functions 252 261 float penalty, ///< Penalty for wideness 262 psRegion bounds, ///< Bounds for validity 253 263 pmSubtractionMode mode ///< Mode for subtraction 254 264 ); … … 260 270 int ringsOrder, ///< Polynomial order 261 271 float penalty, ///< Penalty for wideness 272 psRegion bounds, ///< Bounds for validity 262 273 pmSubtractionMode mode ///< Mode for subtraction 263 274 ); … … 274 285 int ringsOrder, ///< Polynomial order for RINGS 275 286 float penalty, ///< Penalty for wideness 287 psRegion bounds, ///< Bounds for validity 276 288 pmSubtractionMode mode ///< Mode for subtraction 277 289 ); … … 281 293 const char *description, ///< Description of kernel 282 294 int bgOrder, ///< Polynomial order for background fitting 295 psRegion bounds, ///< Bounds for validity 283 296 pmSubtractionMode mode ///< Mode for subtraction 284 297 ); -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMask.c
r24257 r26739 38 38 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 39 39 40 psImage *pmSubtractionMask(const psImage *mask1, const psImage *mask2, psImageMaskType maskVal, 41 int size, int footprint, float badFrac, pmSubtractionMode mode) 42 { 43 PS_ASSERT_IMAGE_NON_NULL(mask1, NULL); 44 PS_ASSERT_IMAGE_TYPE(mask1, PS_TYPE_IMAGE_MASK, NULL); 45 if (mask2) { 46 PS_ASSERT_IMAGE_NON_NULL(mask2, NULL); 47 PS_ASSERT_IMAGE_TYPE(mask2, PS_TYPE_IMAGE_MASK, NULL); 48 PS_ASSERT_IMAGES_SIZE_EQUAL(mask2, mask1, NULL); 49 } 40 psImage *pmSubtractionMask(psRegion *bounds, const pmReadout *ro1, const pmReadout *ro2, 41 psImageMaskType maskVal, int size, int footprint, float badFrac, 42 pmSubtractionMode mode) 43 { 44 PM_ASSERT_READOUT_NON_NULL(ro1, NULL); 45 PM_ASSERT_READOUT_IMAGE(ro1, NULL); 46 PM_ASSERT_READOUT_MASK(ro1, NULL); 47 PM_ASSERT_READOUT_NON_NULL(ro2, NULL); 48 PM_ASSERT_READOUT_IMAGE(ro2, NULL); 49 PM_ASSERT_READOUT_MASK(ro2, NULL); 50 PS_ASSERT_IMAGES_SIZE_EQUAL(ro1->image, ro2->image, NULL); 50 51 PS_ASSERT_INT_NONNEGATIVE(size, NULL); 51 52 PS_ASSERT_INT_NONNEGATIVE(footprint, NULL); … … 55 56 } 56 57 57 int numCols = mask1->numCols, numRows = mask1->numRows; // Size of the images58 int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Size of the images 58 59 59 60 // Dereference inputs for convenience 60 psImageMaskType **data1 = mask1->data.PS_TYPE_IMAGE_MASK_DATA; 61 psImageMaskType **data2 = NULL; 62 if (mask2) { 63 data2 = mask2->data.PS_TYPE_IMAGE_MASK_DATA; 64 } 61 psF32 **imageData1 = ro1->image->data.F32, **imageData2 = ro2->image->data.F32; 62 psImageMaskType **maskData1 = ro1->mask->data.PS_TYPE_IMAGE_MASK_DATA, 63 **maskData2 = ro2->mask->data.PS_TYPE_IMAGE_MASK_DATA; 65 64 66 65 // First, a pass through to determine the fraction of bad pixels 67 if (isfinite(badFrac) && badFrac != 1.0) { 66 if (bounds || (isfinite(badFrac) && badFrac != 1.0)) { 67 int xMin = numCols, xMax = 0, yMin = numRows, yMax = 0; // Bounds of good pixels 68 68 int numBad = 0; // Number of bad pixels 69 69 for (int y = 0; y < numRows; y++) { 70 70 for (int x = 0; x < numCols; x++) { 71 if ( data1[y][x] & maskVal) {71 if ((maskData1[y][x] & maskVal) || !isfinite(imageData1[y][x])) { 72 72 numBad++; 73 73 continue; 74 74 } 75 if ( data2 && data2[y][x] & maskVal) {75 if ((maskData2[y][x] & maskVal) || !isfinite(imageData2[y][x])) { 76 76 numBad++; 77 continue; 77 78 } 78 } 79 } 80 if (numBad > badFrac * numCols * numRows) { 79 xMin = PS_MIN(xMin, x); 80 xMax = PS_MAX(xMax, x); 81 yMin = PS_MIN(yMin, y); 82 yMax = PS_MAX(yMax, y); 83 } 84 } 85 if (bounds) { 86 bounds->x0 = xMin; 87 bounds->x1 = xMax; 88 bounds->y0 = yMin; 89 bounds->y1 = yMax; 90 } 91 if (isfinite(badFrac) && badFrac != 1.0 && numBad > badFrac * numCols * numRows) { 81 92 psError(PM_ERR_SMALL_AREA, true, 82 93 "Fraction of bad pixels (%d/%d=%f) exceeds limit (%f)\n", … … 117 128 for (int y = 0; y < numRows; y++) { 118 129 for (int x = 0; x < numCols; x++) { 119 if ( data1[y][x] & maskVal) {130 if (maskData1[y][x] & maskVal) { 120 131 maskData[y][x] |= PM_SUBTRACTION_MASK_BAD_1; 121 132 } 122 if ( data2 && data2[y][x] & maskVal) {133 if (maskData2[y][x] & maskVal) { 123 134 maskData[y][x] |= PM_SUBTRACTION_MASK_BAD_2; 124 135 } -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMask.h
r23851 r26739 5 5 6 6 /// Generate a mask for use in the subtraction process 7 psImage *pmSubtractionMask(const psImage *refMask, ///< Mask for the reference image (will be convolved) 8 const psImage *inMask, ///< Mask for the input image, or NULL 9 psImageMaskType maskVal, ///< Value to mask out 10 int size, ///< Half-size of the kernel (pmSubtractionKernels.size) 11 int footprint, ///< Half-size of the kernel footprint 12 float badFrac, ///< Maximum fraction of bad input pixels to accept 13 pmSubtractionMode mode ///< Subtraction mode 7 psImage *pmSubtractionMask( 8 psRegion *bounds, ///< Bounds of valid pixels (or NULL), returned 9 const pmReadout *ro1, ///< Readout 1 10 const pmReadout *ro2, ///< Readout 2 11 psImageMaskType maskVal, ///< Value to mask out 12 int size, ///< Half-size of the kernel (pmSubtractionKernels.size) 13 int footprint, ///< Half-size of the kernel footprint 14 float badFrac, ///< Maximum fraction of bad input pixels to accept 15 pmSubtractionMode mode ///< Subtraction mode 14 16 ); 15 17 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMatch.c
r26733 r26739 70 70 const psImage *subMask, // Mask for subtraction, or NULL 71 71 psImage *variance, // Variance map 72 const psRegion *region, // Region of interest , or NULL72 const psRegion *region, // Region of interest 73 73 float thresh1, // Threshold for stamp finding on readout 1 74 74 float thresh2, // Threshold for stamp finding on readout 2 … … 82 82 ) 83 83 { 84 PS_ASSERT_PTR_NON_NULL(stamps, false); 85 PM_ASSERT_READOUT_NON_NULL(ro1, false); 86 PM_ASSERT_READOUT_NON_NULL(ro2, false); 87 PS_ASSERT_IMAGE_NON_NULL(subMask, false); 88 PS_ASSERT_IMAGE_NON_NULL(variance, false); 89 PS_ASSERT_PTR_NON_NULL(region, false); 90 84 91 psTrace("psModules.imcombine", 3, "Finding stamps...\n"); 85 92 … … 96 103 97 104 psTrace("psModules.imcombine", 3, "Extracting stamps...\n"); 98 if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, variance, size)) {105 if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2->image, variance, size, *region)) { 99 106 psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps."); 100 107 return false; … … 319 326 pmSubtractionMaskInvalid(ro2, maskVal); 320 327 321 psImage *subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskVal, size, 0, 328 psRegion bounds = psRegionSet(NAN, NAN, NAN, NAN); // Bounds of valid pixels 329 330 psImage *subMask = pmSubtractionMask(&bounds, ro1, ro2, maskVal, size, 0, 322 331 badFrac, mode); // Subtraction mask 323 332 if (!subMask) { … … 441 450 // Putting important variable declarations here, since they are freed after a "goto" if there is an error. 442 451 psImage *subMask = NULL; // Mask for subtraction 443 psRegion *region = NULL;// Iso-kernel region452 psRegion *region = psRegionAlloc(NAN, NAN, NAN, NAN); // Iso-kernel region 444 453 psString regionString = NULL; // String for region 445 454 pmSubtractionStampList *stamps = NULL; // Stamps for matching PSF … … 457 466 pmSubtractionMaskInvalid(ro2, maskVal); 458 467 459 subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskVal, size, footprint, 460 badFrac, subMode); 468 psRegion bounds = psRegionSet(NAN, NAN, NAN, NAN); // Bounds of valid pixels 469 470 subMask = pmSubtractionMask(&bounds, ro1, ro2, maskVal, size, footprint, badFrac, subMode); 461 471 if (!subMask) { 462 472 psError(psErrorCodeLast(), false, "Unable to generate subtraction mask."); … … 468 478 // Get region of interest 469 479 int xRegions = 1, yRegions = 1; // Number of iso-kernel regions 470 float xRegionSize = 0, yRegionSize = 0; // Size of iso-kernel regions480 float xRegionSize = NAN, yRegionSize = NAN; // Size of iso-kernel regions 471 481 if (isfinite(regionSize) && regionSize != 0.0) { 472 xRegions = numCols / regionSize + 1; 473 yRegions = numRows / regionSize + 1; 474 xRegionSize = (float)numCols / (float)xRegions; 475 yRegionSize = (float)numRows / (float)yRegions; 476 region = psRegionAlloc(NAN, NAN, NAN, NAN); 482 xRegions = (bounds.x1 - bounds.x0) / regionSize + 1; 483 yRegions = (bounds.y1 - bounds.y0) / regionSize + 1; 484 xRegionSize = (float)(bounds.x1 - bounds.x0) / (float)xRegions; 485 yRegionSize = (float)(bounds.y1 - bounds.y0) / (float)yRegions; 486 } else { 487 xRegionSize = bounds.x1 - bounds.x0; 488 yRegionSize = bounds.y1 - bounds.y0; 477 489 } 478 490 … … 480 492 float stampThresh1 = NAN, stampThresh2 = NAN; // Stamp thresholds for images 481 493 { 482 psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for backgroun 494 psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for background 483 495 if (ro1) { 484 496 psStatsInit(bg); … … 504 516 } 505 517 518 // Just in case the iso-kernel region doesn't cover the entire image... 519 if (subMode == PM_SUBTRACTION_MODE_1 || subMode == PM_SUBTRACTION_MODE_UNSURE || 520 subMode == PM_SUBTRACTION_MODE_DUAL) { 521 if (!conv1->image) { 522 conv1->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 523 } 524 psImageInit(conv1->image, NAN); 525 if (ro1->variance) { 526 if (!conv1->variance) { 527 conv1->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 528 } 529 psImageInit(conv1->variance, NAN); 530 } 531 if (subMask) { 532 if (!conv1->mask) { 533 conv1->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 534 } 535 psImageInit(conv1->mask, maskBad); 536 } 537 } 538 if (subMode == PM_SUBTRACTION_MODE_1 || subMode == PM_SUBTRACTION_MODE_UNSURE || 539 subMode == PM_SUBTRACTION_MODE_DUAL) { 540 if (!conv2->image) { 541 conv2->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 542 } 543 psImageInit(conv2->image, NAN); 544 if (ro2->variance) { 545 if (!conv2->variance) { 546 conv2->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 547 } 548 psImageInit(conv2->variance, NAN); 549 } 550 if (subMask) { 551 if (!conv2->mask) { 552 conv2->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 553 } 554 psImageInit(conv2->mask, maskBad); 555 } 556 } 557 558 506 559 // Iterate over iso-kernel regions 507 560 for (int j = 0; j < yRegions; j++) { … … 509 562 psTrace("psModules.imcombine", 1, "Subtracting region %d of %d...\n", 510 563 j * xRegions + i + 1, xRegions * yRegions); 511 if (region) {512 *region = psRegionSet((int)(i * xRegionSize),(int)((i + 1) * xRegionSize),513 (int)(j * yRegionSize), (int)((j + 1) * yRegionSize));514 psFree(regionString);515 regionString = psRegionToString(*region);516 psTrace("psModules.imcombine", 3, "Iso-kernel region: %s out of %d,%d\n",517 regionString, numCols, numRows);518 }564 *region = psRegionSet(bounds.x0 + (int)(i * xRegionSize), 565 bounds.x0 + (int)((i + 1) * xRegionSize), 566 bounds.y0 + (int)(j * yRegionSize), 567 bounds.y0 + (int)((j + 1) * yRegionSize)); 568 psFree(regionString); 569 regionString = psRegionToString(*region); 570 psLogMsg("psModules.imcombine", PS_LOG_DETAIL, "Iso-kernel region: %s out of %d,%d\n", 571 regionString, numCols, numRows); 519 572 520 573 if (stampsName && strlen(stampsName) > 0) { … … 530 583 // We get the stamps here; we will also attempt to get stamps at the first iteration, but it 531 584 // doesn't matter. 532 if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, NULL, stampThresh1, stampThresh2,585 if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, region, stampThresh1, stampThresh2, 533 586 stampSpacing, normFrac, sysError, skyError, size, footprint, subMode)) { 534 587 goto MATCH_ERROR; … … 544 597 // Define kernel basis functions 545 598 if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) { 546 kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, optFWHMs, optOrder, 547 stamps, footprint, optThreshold, penalty, subMode); 599 kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, 600 optFWHMs, optOrder, stamps, footprint, 601 optThreshold, penalty, bounds, subMode); 548 602 if (!kernels) { 549 603 psErrorClear(); … … 554 608 // Not an ISIS/GUNK kernel, or the optimum kernel search failed 555 609 kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders, 556 inner, binning, ringsOrder, penalty, subMode);610 inner, binning, ringsOrder, penalty, bounds, subMode); 557 611 // pmSubtractionVisualShowKernels(kernels); 558 612 } … … 603 657 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k); 604 658 605 #if 0606 659 if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, region, 607 660 stampThresh1, stampThresh2, stampSpacing, normFrac, … … 609 662 goto MATCH_ERROR; 610 663 } 611 #endif612 664 613 665 // generate the window function from the set of stamps -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionParams.c
r26491 r26739 204 204 int spatialOrder, const psVector *fwhms, int maxOrder, 205 205 const pmSubtractionStampList *stamps, int footprint, 206 float tolerance, float penalty, pmSubtractionMode mode) 206 float tolerance, float penalty, psRegion bounds, 207 pmSubtractionMode mode) 207 208 { 208 209 if (type != PM_SUBTRACTION_KERNEL_ISIS && type != PM_SUBTRACTION_KERNEL_GUNK) { … … 232 233 psVectorInit(orders, maxOrder); 233 234 pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders, 234 penalty, mode); // Kernels235 penalty, bounds, mode); // Kernels 235 236 psFree(orders); 236 237 psFree(kernels->description); … … 483 484 if (type == PM_SUBTRACTION_KERNEL_ISIS) { 484 485 485 // XXX in r26035, this code was just wrong. we had:486 487 // psKernel *subtract = kernels->preCalc->data[0]488 489 // but, kernels->preCalc was an array of psArray, not an array of kernels. It is now490 // an array of pmSubtractionKernelPreCalc.486 // XXX in r26035, this code was just wrong. we had: 487 488 // psKernel *subtract = kernels->preCalc->data[0] 489 490 // but, kernels->preCalc was an array of psArray, not an array of kernels. It is now 491 // an array of pmSubtractionKernelPreCalc. 491 492 492 493 pmSubtractionKernelPreCalc *subtract = kernels->preCalc->data[0]; // Kernel to subtract from the rest -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionParams.h
r18287 r26739 17 17 float tolerance, ///< Maximum difference in chi^2 18 18 float penalty, ///< Penalty for wideness 19 pmSubtractionMode mode // Mode for subtraction 19 psRegion bounds, ///< Bounds of validity 20 pmSubtractionMode mode ///< Mode for subtraction 20 21 ); 21 22 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionStamps.c
r26735 r26739 709 709 } 710 710 } 711 fprintf(stderr, "Normalization window radius: %d\n", stamps->normWindow);712 711 713 712 psTrace("psModules.imcombine", 3, "Normalisation window radius set to %d\n", stamps->normWindow); … … 741 740 742 741 bool pmSubtractionStampsExtract(pmSubtractionStampList *stamps, psImage *image1, psImage *image2, 743 psImage *variance, int kernelSize )742 psImage *variance, int kernelSize, psRegion bounds) 744 743 { 745 744 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 758 757 } 759 758 760 int numCols = image1->numCols, numRows = image1->numRows; // Size of images761 759 int size = kernelSize + stamps->footprint; // Size of postage stamps 762 760 … … 767 765 } 768 766 769 if (isnan(stamp->xNorm)) { 770 stamp->xNorm = 2.0 * (stamp->x - (float)numCols/2.0) / (float)numCols; 771 } 772 if (isnan(stamp->yNorm)) { 773 stamp->yNorm = 2.0 * (stamp->y - (float)numRows/2.0) / (float)numRows; 774 } 767 p_pmSubtractionPolynomialNormCoords(&stamp->xNorm, &stamp->yNorm, stamp->x, stamp->y, 768 bounds.x0, bounds.x1, bounds.y0, bounds.y1); 775 769 776 770 int x = stamp->x + 0.5, y = stamp->y + 0.5; // Stamp coordinates 777 if (x < size || x > numCols - size || y < size || y > numRows- size) {778 psError(PS_ERR_UNKNOWN, false, "Stamp %d (%d,%d) is within the imageborder.\n", i, x, y);771 if (x < bounds.x0 + size || x > bounds.x1 - size || y < bounds.y0 + size || y > bounds.y1 - size) { 772 psError(PS_ERR_UNKNOWN, false, "Stamp %d (%d,%d) is within the region border.\n", i, x, y); 779 773 return false; 780 774 } -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionStamps.h
r26703 r26739 164 164 psImage *image2, ///< Input image (or NULL) 165 165 psImage *variance, ///< Variance map 166 int kernelSize ///< Kernel half-size 166 int kernelSize, ///< Kernel half-size 167 psRegion bounds ///< Bounds of validity 167 168 ); 168 169
Note:
See TracChangeset
for help on using the changeset viewer.
