Changeset 37680
- Timestamp:
- Nov 27, 2014, 5:06:54 AM (12 years ago)
- Location:
- branches/eam_branches/ipp-20140904/Ohana/src/libdvo
- Files:
-
- 4 edited
-
include/libdvo_astro.h (modified) (2 diffs)
-
src/AstromOffsetMapIO.c (modified) (2 diffs)
-
src/AstromOffsetMapOps.c (modified) (2 diffs)
-
src/AstromOffsetMapUtils.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h
r37664 r37680 64 64 int Nmap; 65 65 AstromOffsetMap **map; 66 int *IDtoSeq;66 int *imageIDtoTableSeq; 67 67 int MaxImageID; 68 68 int MaxTableID; … … 174 174 void AstromOffsetTableFree(AstromOffsetTable *table); 175 175 int AstromOffsetTableAddMapFromImage (AstromOffsetTable *table, Image *image); 176 void AstromOffsetMapPrint (AstromOffsetMap *map, char *filename); 177 int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir); 176 178 177 179 # endif -
branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapIO.c
r37575 r37680 116 116 117 117 // generate the index and init values to -1 118 ALLOCATE (table-> IDtoSeq, int, MaxImageID + 1);118 ALLOCATE (table->imageIDtoTableSeq, int, MaxImageID + 1); 119 119 for (i = 0; i <= MaxImageID; i++) { 120 table-> IDtoSeq[i] = -1;120 table->imageIDtoTableSeq[i] = -1; 121 121 } 122 122 … … 124 124 for (i = 0; i < Nmap; i++) { 125 125 int ImageID = map_disk[i].imageID; 126 myAssert (table-> IDtoSeq[ImageID] == -1, "oops, duplicate image IDs");127 table-> IDtoSeq[ImageID] = i;126 myAssert (table->imageIDtoTableSeq[ImageID] == -1, "oops, duplicate image IDs"); 127 table->imageIDtoTableSeq[ImageID] = i; 128 128 } 129 129 -
branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapOps.c
r37674 r37680 295 295 ALLOCATE (Empty, int, Nx*Ny); 296 296 297 // find the max value 298 double MaxPivot = 0.0; 299 for (i = 0; i < Nx*Ny; i++) { 300 MaxPivot = MAX(A[i][i], MaxPivot); 301 } 302 303 // elements of A[i][j] are just the fractional weight of the number of input points to the pixel. 304 // any pixels which have < 5% contribution are not very well constrained. NAN them for now... 305 double MinPivot = 0.05 * MaxPivot; 297 306 for (i = 0; i < Nx*Ny; i++) { 298 307 Empty[i] = 0; 299 if (fabs(A[i][i]) < 1.e-2) {308 if (fabs(A[i][i]) < MinPivot) { 300 309 Empty[i] = 1; 301 310 for (j = 0; j < Nx*Ny; j++) { … … 352 361 } 353 362 363 // this function repairs an image with NAN pixels (only valid for a small-scale map -- no robust mean) 364 int AstromOffsetMapRepair (AstromOffsetMap *map, int xdir) { 365 366 // we are going to repair the image by: 367 // 1) finding NAN pixels 368 // 2) if any of the neighbors are valid, 369 // replace with the mean of the neighbors 370 // 3) otherwise, replace with the image mean 371 372 int Nx = map->Nx; 373 int Ny = map->Ny; 374 375 int ix, iy; 376 377 float **Vfix = NULL; 378 ALLOCATE (Vfix, float *, Nx); 379 for (ix = 0; ix < Nx; ix++) { 380 ALLOCATE (Vfix[ix], float, Ny); 381 for (iy = 0; iy < Ny; iy++) { 382 Vfix[ix][iy] = NAN; 383 } 384 } 385 386 // find the global mean 387 float mean = 0.0; 388 float npix = 0.0; 389 390 for (ix = 0; ix < Nx; ix++) { 391 for (iy = 0; iy < Ny; iy++) { 392 float value = xdir ? map->dXv[ix][iy] : map->dYv[ix][iy]; 393 if (isnan(value)) continue; 394 mean += value; 395 npix += 1.0; 396 } 397 } 398 mean /= npix; 399 400 // find the NAN pixels: 401 for (ix = 0; ix < Nx; ix++) { 402 for (iy = 0; iy < Ny; iy++) { 403 404 float value = xdir ? map->dXv[ix][iy] : map->dYv[ix][iy]; 405 if (!isnan(value)) { 406 Vfix[ix][iy] = value; 407 continue; 408 } 409 410 // find mean of all possible neighbors 411 float meanLocal = 0.0; 412 float npixLocal = 0.0; 413 414 int jx, jy; 415 for (jx = -1; jx <= +1; jx++) { 416 int nx = ix + jx; 417 if (nx < 0) continue; 418 if (nx >= Nx) continue; 419 for (jy = -1; jy <= +1; jy++) { 420 int ny = iy + jy; 421 if (ny < 0) continue; 422 if (ny >= Ny) continue; 423 float value = xdir ? map->dXv[nx][ny] : map->dYv[nx][ny]; 424 if (isnan(value)) continue; 425 426 meanLocal += value; 427 npixLocal += 1.0; 428 } 429 } 430 // if there are no valid (non-NAN) local pixels, use global mean 431 meanLocal = (npixLocal > 0.0) ? meanLocal / npixLocal : mean; 432 Vfix[ix][iy] = meanLocal; 433 } 434 } 435 436 // replace the bad pixels: 437 for (ix = 0; ix < Ny; ix++) { 438 for (iy = 0; iy < Ny; iy++) { 439 if (xdir) { 440 map->dXv[ix][iy] = Vfix[ix][iy]; 441 } else { 442 map->dYv[ix][iy] = Vfix[ix][iy]; 443 } 444 } 445 } 446 for (ix = 0; ix < Nx; ix++) { 447 free (Vfix[ix]); 448 } 449 free (Vfix); 450 451 return TRUE; 452 } 453 354 454 int dump_map_data (float *x, float *y, float *f, int Npts, char *filename) { 355 455 -
branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/AstromOffsetMapUtils.c
r37664 r37680 6 6 // each of the maps so we can assign the map to the image.coords.offsetMap entry 7 7 8 // we have the lookup table of table-> IDtoSeq to find the match by imageID9 10 // we are just going to assume that table-> IDtoSeq is correct and complete8 // we have the lookup table of table->imageIDtoTableSeq to find the match by imageID 9 10 // we are just going to assume that table->imageIDtoTableSeq is correct and complete 11 11 off_t i; 12 12 for (i = 0; i < Nimages; i++) { … … 15 15 if (imageID > table->MaxImageID) continue; 16 16 17 int seq = table-> IDtoSeq[imageID];17 int seq = table->imageIDtoTableSeq[imageID]; 18 18 if (seq < 0) continue; 19 19 if (seq >= table->Nmap) continue; // this one is probably not valid, right? … … 83 83 FREE (table->map[i][0].dYv); 84 84 } 85 FREE (table-> IDtoSeq);85 FREE (table->imageIDtoTableSeq); 86 86 FREE (table->map); 87 87 } … … 101 101 int oldMaxID = table->MaxImageID; 102 102 table->MaxImageID = image->imageID; 103 REALLOCATE (table-> IDtoSeq, int, table->MaxImageID + 1);103 REALLOCATE (table->imageIDtoTableSeq, int, table->MaxImageID + 1); 104 104 for (i = oldMaxID + 1; i < table->MaxImageID + 1; i++) { 105 table->IDtoSeq[i] = -1; 106 } 107 } 108 myAssert (table->IDtoSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision"); 109 table->IDtoSeq[image->imageID] = Nmap; 105 table->imageIDtoTableSeq[i] = -1; 106 } 107 } 108 int seq = table->imageIDtoTableSeq[image->imageID]; 109 if (seq != -1) { 110 // already assigned (but not used) 111 // XXX this is probably wrong : I need to mark failed maps so they are not saved. 112 image[0].coords.offsetMap = table->map[seq]; 113 return TRUE; 114 } 115 116 myAssert (table->imageIDtoTableSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision"); 117 table->imageIDtoTableSeq[image->imageID] = Nmap; 110 118 111 119 table->map[Nmap] = AstromOffsetMapInit (Nx, Ny); … … 129 137 REALLOCATE (table->map, AstromOffsetMap *, table->Nmap); 130 138 131 // find the imageID and update the IDtoSeq allocation if needed139 // find the imageID and update the imageIDtoTableSeq allocation if needed 132 140 off_t i; 133 141 if (image->imageID > table->MaxImageID) { 134 142 int oldMaxID = table->MaxImageID; 135 143 table->MaxImageID = image->imageID; 136 REALLOCATE (table-> IDtoSeq, int, table->MaxImageID + 1);144 REALLOCATE (table->imageIDtoTableSeq, int, table->MaxImageID + 1); 137 145 for (i = oldMaxID + 1; i < table->MaxImageID + 1; i++) { 138 table-> IDtoSeq[i] = -1;139 } 140 } 141 myAssert (table-> IDtoSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision");142 table-> IDtoSeq[image->imageID] = Nmap;146 table->imageIDtoTableSeq[i] = -1; 147 } 148 } 149 myAssert (table->imageIDtoTableSeq[image->imageID] == -1, "table IDtoSeq not initiazed or image collision"); 150 table->imageIDtoTableSeq[image->imageID] = Nmap; 143 151 144 152 table->map[Nmap] = image[0].coords.offsetMap; … … 158 166 159 167 // generate the index and init values to -1 160 ALLOCATE (table-> IDtoSeq, int, 1);161 table-> IDtoSeq[0] = -1;168 ALLOCATE (table->imageIDtoTableSeq, int, 1); 169 table->imageIDtoTableSeq[0] = -1; 162 170 163 171 return table; 164 172 } 173 174 void AstromOffsetMapPrint (AstromOffsetMap *map, char *filename) { 175 176 FILE *f = stderr; 177 if (strcasecmp(filename, "stderr") && strcasecmp(filename, "stdout")) { 178 f = fopen (filename, "w"); 179 if (!f) { 180 fprintf (stderr, "failed to open output file %s\n", filename); 181 } 182 } 183 184 fprintf (f, "imageID: %d, tableID: %d (dX: %f, dY: %f)\n", map->imageID, map->tableID, map->dX, map->dY); 185 int ix, iy; 186 fprintf (f, "dXv map:\n"); 187 for (ix = 0; ix < map->Nx; ix++) { 188 for (iy = 0; iy < map->Ny; iy++) { 189 fprintf (f, "%9.5f ", map->dXv[ix][iy]); 190 } 191 fprintf (f, "\n"); 192 } 193 fprintf (f, "dYv map:\n"); 194 for (ix = 0; ix < map->Nx; ix++) { 195 for (iy = 0; iy < map->Ny; iy++) { 196 fprintf (f, "%9.5f ", map->dYv[ix][iy]); 197 } 198 fprintf (f, "\n"); 199 } 200 if (f != stderr) fclose (f); 201 return; 202 }
Note:
See TracChangeset
for help on using the changeset viewer.
