Changeset 14775
- Timestamp:
- Sep 7, 2007, 10:19:48 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20070830/psLib/test/imageops/tap_psImageMap.c
r14726 r14775 26 26 27 27 // make a model for a well-sampled field of a simple function (f = ax + by + c) 28 # if (0) 28 29 { 29 30 // function is defined over the range 0-1000, 0-1000 … … 39 40 psVector *f = psVectorAllocEmpty (100, PS_TYPE_F32); 40 41 41 for (int ix = 0; ix < 1000; ix += 10) {42 for (int iy = 0; iy < 1000; iy += 10) {42 for (int ix = 0; ix < 1000; ix += 20) { 43 for (int iy = 0; iy < 1000; iy += 20) { 43 44 x->data.F32[x->n] = ix; 44 45 y->data.F32[y->n] = iy; … … 78 79 for (int ix = 0; ix < map->map->numCols; ix++) { 79 80 for (int iy = 0; iy < map->map->numRows; iy++) { 80 81 int xo = (ix + 0.5)*map->binning->nXbin; 82 int yo = (iy + 0.5)*map->binning->nYbin; 81 int xo = psImageBinningGetFineX(map->binning, ix + 0.5); 82 int yo = psImageBinningGetFineY(map->binning, iy + 0.5); 83 83 float df = field->data.F32[yo][xo] - map->map->data.F32[iy][ix]; 84 84 fprintf (stderr, "%d %d -> %d %d : %f = %f - %f\n", ix, iy, xo, yo, df, field->data.F32[yo][xo], map->map->data.F32[iy][ix]); 85 85 } 86 86 } 87 88 psImage *model = psImageAlloc(1000, 1000, PS_TYPE_F32); 89 for (int ix = 0; ix < 1000; ix++) { 90 for (int iy = 0; iy < 1000; iy++) { 91 model->data.F32[iy][ix] = psImageUnbinPixel (ix + 0.5, iy + 0.5, map->map, map->binning); 92 } 93 } 94 SaveImage (NULL, model, "model.fits"); 87 95 } 96 # endif 88 97 89 98 // make a model for a poorly-sampled field of a simple function (f = ax + by + c) … … 91 100 // choose a model scale for a poorly-sampled field of a simple function (f = ax + by + c) 92 101 93 // make a model for a well-sampled field of a non-polynomial function (f = (a(x-xo)^2 + b(y-yo)^2)^-1) 102 // make a model for a well-sampled field of a high-order polynomial function (f = (a(x-xo)^2 + b(y-yo)^2) + c) 103 # if (0) 94 104 { 95 105 // function is defined over the range 0-1000, 0-1000 … … 105 115 psVector *f = psVectorAllocEmpty (100, PS_TYPE_F32); 106 116 107 for (int ix = 0; ix < 1000; ix += 10) {108 for (int iy = 0; iy < 1000; iy += 10) {117 for (int ix = 0; ix < 1000; ix += 20) { 118 for (int iy = 0; iy < 1000; iy += 20) { 109 119 x->data.F32[x->n] = ix; 110 120 y->data.F32[y->n] = iy; 111 f->data.F32[f->n] = C 00 / (C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500) + 0.1);121 f->data.F32[f->n] = C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500); 112 122 psVectorExtend (x, 100, 1); 113 123 psVectorExtend (y, 100, 1); … … 136 146 for (int ix = 0; ix < 1000; ix++) { 137 147 for (int iy = 0; iy < 1000; iy++) { 138 field->data.F32[iy][ix] = C 00 / (C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500) + 0.1);148 field->data.F32[iy][ix] = C10*PS_SQR(ix-500) + C01*PS_SQR(iy-500); 139 149 } 140 150 } … … 144 154 for (int ix = 0; ix < map->map->numCols; ix++) { 145 155 for (int iy = 0; iy < map->map->numRows; iy++) { 146 147 int xo = (ix + 0.5)*map->binning->nXbin; 148 int yo = (iy + 0.5)*map->binning->nYbin; 156 int xo = psImageBinningGetFineX(map->binning, ix + 0.5); 157 int yo = psImageBinningGetFineY(map->binning, iy + 0.5); 149 158 float df = field->data.F32[yo][xo] - map->map->data.F32[iy][ix]; 150 159 fprintf (stderr, "%d %d -> %d %d : %f = %f - %f\n", ix, iy, xo, yo, df, field->data.F32[yo][xo], map->map->data.F32[iy][ix]); … … 152 161 } 153 162 } 163 # endif 164 165 // make a model for a well-sampled field of a high-order polynomial function (f = (a(x-xo)^2 + b(y-yo)^2) + c) 166 # if (1) 167 { 168 // function is defined over the range 0-1000, 0-1000 169 psImageBinning *binning = psImageBinningAlloc(); 170 binning->nXfine = 1000; 171 binning->nYfine = 1000; 172 binning->nXruff = 5; 173 binning->nYruff = 5; 174 175 // generate a grid of test data points 176 psVector *x = psVectorAllocEmpty (100, PS_TYPE_F32); 177 psVector *y = psVectorAllocEmpty (100, PS_TYPE_F32); 178 psVector *f = psVectorAllocEmpty (100, PS_TYPE_F32); 179 180 for (int ix = 0; ix < 1000; ix += 20) { 181 for (int iy = 0; iy < 1000; iy += 20) { 182 x->data.F32[x->n] = ix; 183 y->data.F32[y->n] = iy; 184 f->data.F32[f->n] = C10*(ix-500) + PS_SQR(C01*(iy-500)); 185 psVectorExtend (x, 100, 1); 186 psVectorExtend (y, 100, 1); 187 psVectorExtend (f, 100, 1); 188 } 189 } 190 191 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); 192 193 // scale defines both field and map image sizes (nXfine, nXruff) 194 psImageMap *map = psImageMapAlloc (NULL, binning, stats); 195 196 // allocate a map, but we have no field image to supply 197 // XXX this function needs to correct for the mean superpixel position 198 // which is sampled... 199 psImageMapGenerate (map, x, y, f, 0.1); 200 psFree (binning); 201 202 fprintf (stderr, "nGood: %d\n", map->nGood); 203 fprintf (stderr, "nPoor: %d\n", map->nPoor); 204 fprintf (stderr, "nBad: %d\n", map->nBad); 205 206 SaveImage (NULL, map->map, "map.fits"); 207 208 psImage *field = psImageAlloc(1000, 1000, PS_TYPE_F32); 209 for (int ix = 0; ix < 1000; ix++) { 210 for (int iy = 0; iy < 1000; iy++) { 211 field->data.F32[iy][ix] = C10*(ix-500) + PS_SQR(C01*(iy-500)); 212 } 213 } 214 SaveImage (NULL, field, "field.fits"); 215 216 // measure difference between model (map) and data (field) 217 for (int ix = 0; ix < map->map->numCols; ix++) { 218 for (int iy = 0; iy < map->map->numRows; iy++) { 219 int xo = psImageBinningGetFineX(map->binning, ix + 0.5); 220 int yo = psImageBinningGetFineY(map->binning, iy + 0.5); 221 float df = field->data.F32[yo][xo] - map->map->data.F32[iy][ix]; 222 fprintf (stderr, "%d %d -> %d %d : %f = %f - %f\n", ix, iy, xo, yo, df, field->data.F32[yo][xo], map->map->data.F32[iy][ix]); 223 } 224 } 225 226 227 psImage *model = psImageAlloc(1000, 1000, PS_TYPE_F32); 228 for (int ix = 0; ix < 1000; ix++) { 229 for (int iy = 0; iy < 1000; iy++) { 230 // XXX the binned coordinates are probably off by 0.5 pix, or we are interpolating 231 // to the wrong binned coordinate. 232 // XXX fix edge cases 233 model->data.F32[iy][ix] = psImageUnbinPixel (ix + 0.5, iy + 0.5, map->map, map->binning); 234 } 235 } 236 SaveImage (NULL, model, "model.fits"); 237 } 238 # endif 154 239 155 240 // make a model for a poorly-sampled field of a non-polynomial function (f = (a(x-xo)^2 + b(y-yo)^2)^-1)
Note:
See TracChangeset
for help on using the changeset viewer.
