Changeset 34848
- Timestamp:
- Dec 18, 2012, 2:12:42 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/ppStack/src/ppStackCombineAlternate.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackCombineAlternate.c
r34800 r34848 23 23 pmFPAfileClose(file,view); 24 24 } 25 26 // Scaling block 27 if (!ppStackLinearScale(inputs, config)) { 28 psFree(inputs); 29 return(false); 30 } 31 25 32 if (!pmStackSimpleMedianCombine(outRO,inputs)) { 26 33 psFree(inputs); 27 34 return(false); 28 35 } 36 29 37 #if 0 30 38 if (!ppStackWriteImage("/tmp/test_forced.median.fits", … … 79 87 pmFPAfileClose(file,view); 80 88 } 89 90 91 // Do combination 81 92 if (!pmStackSimpleMedianCombine(bkgRO,inputs)) { 82 93 psFree(inputs); … … 113 124 return(true); 114 125 } 115 126 127 bool ppStackLinearScale (psArray *inputs, pmConfig *config) { 128 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); 129 bool doLinearScaling = psMetadataLookupBool(NULL, recipe, "DO.LINEAR.INPUT.SCALING"); 130 if (doLinearScaling) { 131 int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine 132 int xSize, ySize; // Size of the output image 133 134 if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize,inputs)) { 135 psError(psErrorCodeLast(), false, "Input stack is not valid."); 136 psFree(inputs); 137 return false; 138 } 139 140 // Determine best input. 141 int ref = 0; 142 int Nref = 0; 143 double refScale = 0; 144 145 for (int i = 0; i < inputs->n; i++) { 146 pmReadout *ro = inputs->data[i]; 147 psImage *roImage = ro->image; 148 int Nvalid = 0; 149 double scale = 0; 150 151 for (int y = minInputRows; y < maxInputRows; y++) { 152 for (int x = minInputCols; x < maxInputCols; x++) { 153 if ((isfinite(roImage->data.F32[y][x]))) { 154 Nvalid += 1; 155 scale += roImage->data.F32[y][x]; 156 } 157 } 158 } 159 if ((scale > refScale)&&(Nvalid > 0.9 * Nref)) { 160 ref = i; 161 refScale = scale; 162 Nref = Nvalid; 163 } 164 } 165 fprintf(stderr,"ref: %d %d %f\n",ref,Nref,refScale); 166 // Calculate scaling factors 167 pmReadout *refReadout = inputs->data[ref]; 168 psImage *refImage = refReadout->image; 169 for (int i = 0; i < inputs->n; i++) { 170 pmReadout *ro = inputs->data[i]; 171 psImage *roImage = ro->image; 172 double S = 0.0; 173 double Sx = 0.0; 174 double Sy = 0.0; 175 double Sxx = 0.0; 176 double Syy = 0.0; 177 double Sxy = 0.0; 178 double D = 0.0; 179 double offset = 0.0; 180 double scale = 0.0; 181 182 for (int y = minInputRows; y < maxInputRows; y++) { 183 for (int x = minInputCols; x < maxInputCols; x++) { 184 if ((isfinite(refImage->data.F32[y][x]))&& 185 (isfinite(roImage->data.F32[y][x]))) { 186 S += 1.0; 187 Sx += roImage->data.F32[y][x]; 188 Sy += refImage->data.F32[y][x]; 189 190 Sxx += pow(roImage->data.F32[y][x],2); 191 Syy += pow(refImage->data.F32[y][x],2); 192 Sxy += roImage->data.F32[y][x] * refImage->data.F32[y][x]; 193 } 194 } 195 } 196 197 D = S * Sxx - Sx * Sx; 198 offset = (Sy * Sxx - Sx * Sxy) / D; 199 scale = (S * Sxy - Sx * Sy) / D; 200 fprintf(stderr,"Scales: %d %g %g\n",i,offset,scale); 201 // Apply scaling factors 202 for (int y = minInputRows; y < maxInputRows; y++) { 203 for (int x = minInputCols; x < maxInputCols; x++) { 204 roImage->data.F32[y][x] = offset + scale * roImage->data.F32[y][x]; 205 } 206 } 207 } 208 } 209 return(true); 210 } 211 212
Note:
See TracChangeset
for help on using the changeset viewer.
