- Timestamp:
- Sep 3, 2007, 10:29:07 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20070830/psLib/src/imageops/psImageMap.c
r14725 r14726 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1.1.2. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-09-0 2 20:29:50$9 * @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-03 20:29:07 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 63 63 64 64 psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_MASK); 65 psImage *xCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32); 66 psImage *yCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32); 65 67 66 68 // accumulate the values for each map pixel 67 69 68 // we can do this by accumulating a sub-vectorfor each cell69 psArray * vectors = psArrayAlloc (map->map->numCols*map->map->numRows);70 for (int i = 0; i < vectors->n; i++) {71 vectors->data[i] = psVectorAllocEmpty (4, PS_TYPE_F32);70 // we can do this by accumulating a vector of pixel indexes for each cell 71 psArray *pixelSets = psArrayAlloc (map->map->numCols*map->map->numRows); 72 for (int i = 0; i < pixelsSets->n; i++) { 73 pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32); 72 74 } 73 75 // associate each value with a cell 74 76 for (int i = 0; i < x->n; i++) { 75 77 // XXX use the psImageUnbin command to convert from x,y, to xRuff,yRuff? 76 78 int xRuff = x->data.F32[i] / map->binning->nXbin; 77 79 int yRuff = y->data.F32[i] / map->binning->nYbin; … … 79 81 int bin = xRuff + yRuff*map->map->numCols; 80 82 81 psVector * vector = vectors->data[bin];82 vector->data.F32[vector->n] = f->data.F32[i];83 psVector *pixels = pixelSets->data[bin]; 84 pixels->data.S32[pixels->n] = i; 83 85 psVectorExtend (vector, 4, 1); 84 86 } 85 87 88 // accumulate the x,y coords for each point to calculate the mean position. 86 89 int Nx = map->map->numCols; 87 90 int Ny = map->map->numRows; … … 89 92 for (int ix = 0; ix < Nx; ix++) { 90 93 91 // select the vector 92 psVector *vector = vectors->data[ix + iy*Nx]; 94 // select the vector. use psImageUnbin command to convert xRuff,yRuff to 95 // xFine,yFine 96 psVector *pixels = pixelSets->data[ix + iy*Nx]; 97 98 psVector xCell = psVectorAlloc (pixels->n, PS_TYPE_F32); 99 psVector yCell = psVectorAlloc (pixels->n, PS_TYPE_F32); 100 psVector fCell = psVectorAlloc (pixels->n, PS_TYPE_F32); 101 102 for (int i = 0; i < pixels->n; i++) { 103 bin = pixels->data.S32[i]; 104 xCell->data.F32[i] = x->data.F32[bin]; 105 yCell->data.F32[i] = y->data.F32[bin]; 106 fCell->data.F32[i] = f->data.F32[bin]; 107 } 93 108 94 109 // reset the stats to avoid contamination from the previous loop … … 96 111 97 112 // get the value 98 if (psVectorStats (map->stats, vector, NULL, NULL, 0)) { 113 // XXX need to supply a mask and skip the masked pixels when calculating the centroid 114 // this will not in general be properly weighted... 115 if (psVectorStats (map->stats, fCell, NULL, NULL, 0)) { 99 116 mask->data.U8[iy][ix] = 0; 100 117 // XXX ensure only one option is selected, or save both position and width 101 118 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options); 119 120 // calculate the mean position and save: 121 psVectorStats (meanStat, xCell, NULL, NULL, 0); 122 xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 123 psVectorStats (meanStat, yCell, NULL, NULL, 0); 124 yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 102 125 } else { 103 126 mask->data.U8[iy][ix] = 1; 104 127 } 128 129 psFree (xCell); 130 psFree (yCell); 131 psFree (fCell); 105 132 } 106 133 } 134 135 // at this point, for each map pixel, we have (f,x,y), or the pixel is masked. 107 136 108 137 psImage *state = psImagePixelInterpolateState (&map->nBad, &map->nPoor, mask, 0xff); … … 112 141 } 113 142 143 // fit the valid pixels to (0,1,2) order polynomials, interpolate values to the pixel center 144 // XXX I need to be careful about the pixel coordinates: center is 0,0 or 0.5, 0.5? 145 psImagePixelInterpolateCenters (map->map, xCoord, yCoord, state, mask, 0xff); 146 psFree (xCoord); 147 psFree (yCoord); 148 114 149 psImagePixelInterpolatePoor (map->map, state, mask, 0xff); 150 115 151 return true; 116 152 }
Note:
See TracChangeset
for help on using the changeset viewer.
