Changeset 14983 for trunk/psLib/src/imageops/psImageMap.c
- Timestamp:
- Sep 21, 2007, 5:05:50 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageMap.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageMap.c
r14924 r14983 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-09-2 0 23:54:25$9 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-22 03:05:50 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 18 18 19 19 #include <stdio.h> 20 20 21 #include "psError.h" 21 22 #include "psAbort.h" … … 26 27 #include "psFitsImage.h" 27 28 29 #include "psMemory.h" 28 30 #include "psVector.h" 29 31 #include "psImage.h" … … 96 98 97 99 // accumulate the values for each map pixel 98 100 99 101 // we can do this by accumulating a vector of pixel indexes for each cell 100 102 psArray *pixelSets = psArrayAlloc (map->map->numCols*map->map->numRows); 101 103 for (int i = 0; i < pixelSets->n; i++) { 102 pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32);104 pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32); 103 105 } 104 106 // associate each value with a cell 105 107 for (int i = 0; i < x->n; i++) { 106 int xRuff = psImageBinningGetRuffX (map->binning, x->data.F32[i]);107 int yRuff = psImageBinningGetRuffY (map->binning, y->data.F32[i]);108 109 int bin = xRuff + yRuff*map->map->numCols;110 assert (bin >= 0);111 assert (bin < pixelSets->n);112 113 psVector *pixels = pixelSets->data[bin];114 pixels->data.S32[pixels->n] = i;115 psVectorExtend (pixels, 4, 1);108 int xRuff = psImageBinningGetRuffX (map->binning, x->data.F32[i]); 109 int yRuff = psImageBinningGetRuffY (map->binning, y->data.F32[i]); 110 111 int bin = xRuff + yRuff*map->map->numCols; 112 assert (bin >= 0); 113 assert (bin < pixelSets->n); 114 115 psVector *pixels = pixelSets->data[bin]; 116 pixels->data.S32[pixels->n] = i; 117 psVectorExtend (pixels, 4, 1); 116 118 } 117 119 … … 123 125 int Ny = map->map->numRows; 124 126 for (int iy = 0; iy < Ny; iy++) { 125 for (int ix = 0; ix < Nx; ix++) {126 127 // pixel index for this cell128 psVector *pixels = pixelSets->data[ix + iy*Nx];129 130 // storage vectors131 psVector *xCell = psVectorAlloc (pixels->n, PS_TYPE_F32);132 psVector *yCell = psVectorAlloc (pixels->n, PS_TYPE_F32);133 psVector *fCell = psVectorAlloc (pixels->n, PS_TYPE_F32);134 135 // error vector, if needed136 psVector *dfCell = NULL;137 if (df) {138 dfCell = psVectorAlloc (pixels->n, PS_TYPE_F32);139 } 140 141 // collect data for this cell142 for (int i = 0; i < pixels->n; i++) {143 int bin = pixels->data.S32[i];144 // convert x,y in the fine image to the ruff image145 xCell->data.F32[i] = psImageBinningGetRuffX (map->binning, x->data.F32[bin]);146 yCell->data.F32[i] = psImageBinningGetRuffY (map->binning, y->data.F32[bin]);147 fCell->data.F32[i] = f->data.F32[bin];148 if (df) {149 dfCell->data.F32[i] = df->data.F32[bin];150 }151 }152 153 // reset the stats to avoid contamination from the previous loop154 psStatsInit (map->stats);155 156 // get the value157 // XXX need to supply a mask and skip the masked pixels when calculating the centroid158 // this will not in general be properly weighted...159 if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {160 mask->data.U8[iy][ix] = 0;161 // XXX ensure only one option is selected, or save both position and width162 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options); 163 164 // calculate the mean position and save:165 psStatsInit (meanStat);166 psVectorStats (meanStat, xCell, NULL, NULL, 0);167 xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 168 psStatsInit (meanStat);169 psVectorStats (meanStat, yCell, NULL, NULL, 0);170 yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 171 } else {172 mask->data.U8[iy][ix] = 1;173 }174 175 psFree (xCell);176 psFree (yCell);177 psFree (fCell);178 psFree (dfCell);179 }127 for (int ix = 0; ix < Nx; ix++) { 128 129 // pixel index for this cell 130 psVector *pixels = pixelSets->data[ix + iy*Nx]; 131 132 // storage vectors 133 psVector *xCell = psVectorAlloc (pixels->n, PS_TYPE_F32); 134 psVector *yCell = psVectorAlloc (pixels->n, PS_TYPE_F32); 135 psVector *fCell = psVectorAlloc (pixels->n, PS_TYPE_F32); 136 137 // error vector, if needed 138 psVector *dfCell = NULL; 139 if (df) { 140 dfCell = psVectorAlloc (pixels->n, PS_TYPE_F32); 141 } 142 143 // collect data for this cell 144 for (int i = 0; i < pixels->n; i++) { 145 int bin = pixels->data.S32[i]; 146 // convert x,y in the fine image to the ruff image 147 xCell->data.F32[i] = psImageBinningGetRuffX (map->binning, x->data.F32[bin]); 148 yCell->data.F32[i] = psImageBinningGetRuffY (map->binning, y->data.F32[bin]); 149 fCell->data.F32[i] = f->data.F32[bin]; 150 if (df) { 151 dfCell->data.F32[i] = df->data.F32[bin]; 152 } 153 } 154 155 // reset the stats to avoid contamination from the previous loop 156 psStatsInit (map->stats); 157 158 // get the value 159 // XXX need to supply a mask and skip the masked pixels when calculating the centroid 160 // this will not in general be properly weighted... 161 if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) { 162 mask->data.U8[iy][ix] = 0; 163 // XXX ensure only one option is selected, or save both position and width 164 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options); 165 166 // calculate the mean position and save: 167 psStatsInit (meanStat); 168 psVectorStats (meanStat, xCell, NULL, NULL, 0); 169 xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 170 psStatsInit (meanStat); 171 psVectorStats (meanStat, yCell, NULL, NULL, 0); 172 yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 173 } else { 174 mask->data.U8[iy][ix] = 1; 175 } 176 177 psFree (xCell); 178 psFree (yCell); 179 psFree (fCell); 180 psFree (dfCell); 181 } 180 182 } 181 183 psFree (pixelSets); … … 193 195 map->nGood = mask->numCols * mask->numRows - map->nBad - map->nPoor; 194 196 if (map->nBad > badFrac * mask->numCols * mask->numRows) { 195 psFree (xCoord);196 psFree (yCoord);197 psFree (mask);198 return false;197 psFree (xCoord); 198 psFree (yCoord); 199 psFree (mask); 200 return false; 199 201 } 200 202 … … 222 224 // using the points given, generate a map with maximum resolution that yields only good and ok pixels 223 225 bool psImageMapGenerateScale (psImageMap *map, psVector *x, psVector *y, psVector *f, psVector *df, float badFrac) { 224 226 225 227 int nXruff, nYruff; 226 228 227 229 while (!psImageMapGenerate (map, x, y, f, df, badFrac)) { 228 // if we failed to build an acceptable map, decrease nXruff, nYruff as appropriate, and229 // try again... try to keep the aspect ratio.230 231 // if both axes are at 1, give up232 if ((map->binning->nXruff == 1) && (map->binning->nYruff == 1)) {233 return false;234 }235 236 // if one axis is at 1, decrement the other237 if (map->binning->nXruff == 1) {238 nXruff = map->binning->nXruff;239 nYruff = map->binning->nYruff - 1;240 psImageMapModifyScale (map, nXruff, nYruff);241 continue;242 }243 if (map->binning->nYruff == 1) {244 nYruff = map->binning->nYruff;245 nXruff = map->binning->nXruff - 1;246 psImageMapModifyScale (map, nXruff, nYruff);247 continue;248 }249 250 // otherwise, decrement the larger axis, and set the smaller based251 // on the aspect ratio252 float aRatio = map->binning->nXruff / map->binning->nYruff;253 if (map->binning->nXruff > map->binning->nYruff) {254 nXruff = map->binning->nXruff - 1;255 nYruff = (int)(0.5 + (nXruff / aRatio));256 } else {257 nYruff = map->binning->nYruff - 1;258 nXruff = (int)(0.5 + (nYruff * aRatio));259 }260 261 psImageMapModifyScale (map, nXruff, nYruff);230 // if we failed to build an acceptable map, decrease nXruff, nYruff as appropriate, and 231 // try again... try to keep the aspect ratio. 232 233 // if both axes are at 1, give up 234 if ((map->binning->nXruff == 1) && (map->binning->nYruff == 1)) { 235 return false; 236 } 237 238 // if one axis is at 1, decrement the other 239 if (map->binning->nXruff == 1) { 240 nXruff = map->binning->nXruff; 241 nYruff = map->binning->nYruff - 1; 242 psImageMapModifyScale (map, nXruff, nYruff); 243 continue; 244 } 245 if (map->binning->nYruff == 1) { 246 nYruff = map->binning->nYruff; 247 nXruff = map->binning->nXruff - 1; 248 psImageMapModifyScale (map, nXruff, nYruff); 249 continue; 250 } 251 252 // otherwise, decrement the larger axis, and set the smaller based 253 // on the aspect ratio 254 float aRatio = map->binning->nXruff / map->binning->nYruff; 255 if (map->binning->nXruff > map->binning->nYruff) { 256 nXruff = map->binning->nXruff - 1; 257 nYruff = (int)(0.5 + (nXruff / aRatio)); 258 } else { 259 nYruff = map->binning->nYruff - 1; 260 nXruff = (int)(0.5 + (nYruff * aRatio)); 261 } 262 263 psImageMapModifyScale (map, nXruff, nYruff); 262 264 } 263 265 return true; … … 271 273 result = psImageUnbinPixel_V2(x, y, map->map, map->binning); 272 274 273 return result; 275 return result; 274 276 } 275 277 … … 284 286 285 287 for (int i = 0; i < x->n; i++) { 286 result->data.F32[i] = psImageUnbinPixel_V2(x->data.F32[i], y->data.F32[i], map->map, map->binning);287 } 288 289 return result; 290 } 288 result->data.F32[i] = psImageUnbinPixel_V2(x->data.F32[i], y->data.F32[i], map->map, map->binning); 289 } 290 291 return result; 292 }
Note:
See TracChangeset
for help on using the changeset viewer.
