Changeset 28280 for trunk/ppBackground/src/ppBackgroundRestore.c
- Timestamp:
- Jun 9, 2010, 6:16:39 PM (16 years ago)
- Location:
- trunk/ppBackground
- Files:
-
- 2 edited
- 1 moved
-
. (modified) (1 prop)
-
src (modified) (1 prop)
-
src/ppBackgroundRestore.c (moved) (moved from trunk/ppBackground/src/ppBackgroundModel.c ) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppBackground
-
Property svn:ignore
set to
configure
Makefile.in
ignore
config.log
depcomp
config.status
config.guess
ltmain.sh
config.sub
autom4te.cache
libtool
missing
Makefile
aclocal.m4
install-sh
-
Property svn:ignore
set to
-
trunk/ppBackground/src
-
Property svn:ignore
set to
ppBackground
Makefile.in
config.h
ppBackgroundVersionDefinitions.h
.deps
Makefile
ppBackgroundErrorCodes.c
ppBackgroundErrorCodes.h
stamp-h1
config.h.in
-
Property svn:ignore
set to
-
trunk/ppBackground/src/ppBackgroundRestore.c
r28279 r28280 4 4 #include <psphot.h> 5 5 6 #include "ppBackground.h" 6 7 7 bool ppBackgroundModel( 8 pmReadout *ro = cell->readouts->data[0]; // Readout of interest 9 if (!ro || !ro->data_exists) { 10 psError(PS_ERR_UNKNOWN, true, "readout has no data"); 8 bool ppBackgroundRestore(pmChip *chip, const pmChip *background, const pmChip *pattern, 9 const pmFPAview *oldView, pmConfig *config) 10 { 11 PS_ASSERT_PTR_NON_NULL(chip, false); 12 PS_ASSERT_PTR_NON_NULL(oldView, false); 13 14 pmFPAview *view = pmFPAviewAlloc(0); // View to readout 15 *view = *oldView; 16 view->cell = 0; 17 view->readout = 0; 18 19 pmReadout *ro = pmFPAviewThisReadout(view, chip->parent); 20 if (!ro || !ro->data_exists) { 21 psError(PPBACKGROUND_ERR_CONFIG, true, "Readout has no data"); 22 return false; 23 } 24 psImage *image = ro->image; // Image to correct 25 int numCols = image->numCols, numRows = image->numRows; // Size of image 26 27 if (background) { 28 pmReadout *bgRO = pmFPAviewThisReadout(view, background->parent); // Readout with background 29 psImageBinning *binning = psphotBackgroundBinning(bgRO->image, config); 30 if (!binning) { 31 psError(psErrorCodeLast(), false, "Unable to find background binning"); 11 32 return false; 12 33 } 13 psImage *image = ro->image; 14 // psImage *mask = NULL; 15 // psImageMaskType maskVal = 0; 16 17 pmFPAview roView = *view; 18 roView.cell = 0; 19 roView.readout = 0; 20 pmReadout *modelRO = pmFPAviewThisReadout(&roView, backmdl->fpa); 21 if (!modelRO || !modelRO->data_exists) { 22 psError(PS_ERR_UNKNOWN, true, "model readout has no data"); 34 if (binning->nXfine != numCols || binning->nYfine != numRows) { 35 psError(PPBACKGROUND_ERR_CONFIG, true, 36 "Unbinned background model and input don't match (%dx%d vs %dx%d)", 37 binning->nXfine, binning->nYfine, numCols, numRows); 23 38 return false; 24 39 } 25 output->save = true;26 background->save = save_background;27 40 28 psImageBinning *binning = psphotBackgroundBinning(image, config); 29 if (!binning) { 30 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find background binning"); 31 return false; 32 } 33 pmReadout *backgroundRO; 34 #define USE_CELL 35 #ifdef USE_CELL 36 pmCell *backgroundCell = pmFPAviewThisCell(&roView, background->fpa); 37 backgroundRO = pmReadoutAlloc(backgroundCell); 38 #else 39 backgroundRO = pmFPAviewThisReadout(&roView, background->fpa); 40 // backgroundRO = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32); 41 #endif 42 backgroundRO->image = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32); 43 backgroundRO->data_exists = true; 44 backgroundRO->parent->data_exists = true; 45 backgroundRO->parent->parent->data_exists = true; 46 47 // linear interpolation to full-scale 48 if (!psImageUnbin (backgroundRO->image, modelRO->image, binning)) { 49 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for unbinning"); 41 psImage *bgImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Background 42 if (!psImageUnbin(bgImage, bgRO->image, binning)) { 43 psError(psErrorCodeLast(), false, "Unable to unbin background model"); 50 44 psFree(binning); 51 45 return false; 52 46 } 53 47 psFree(binning); 54 psF32 **backData = backgroundRO->image->data.F32;55 48 56 // Undo the background subtraction57 int numCols = image->numCols, numRows = image->numRows; // Size of image58 long nancount = 0;59 long naninputs = 0;60 long finitecount = 0;61 49 for (int y = 0; y < numRows; y++) { 62 50 for (int x = 0; x < numCols; x++) { 63 float imageval = image->data.F32[y][x] ; 64 float bgvalue = backData[y][x]; 65 if (!isfinite(bgvalue)) { 66 // if background is NAN leave the image unchanged 67 // According to ppImageSubtractBackground pixels where the background is not finite should be NAN 68 // experimentally 69 // for breakpoint 70 nancount++; 71 if (isfinite(imageval)) { 72 finitecount++; 73 // psWarning("unexpected finite image value %f found at %d %d background is infinite", imageval, x, y); 74 } 75 // Doing this is causes a lot of new NAN pixels to appear. 76 // NANS are appearing in the model for some reason. 77 // image->data.F32[y][x] = NAN; 78 } else if (isfinite(imageval)) { 79 // XXX: TODO:following ppImage we should not modify pixels that are masked. 80 image->data.F32[y][x] = imageval + bgvalue; 81 } else { 82 naninputs++; 83 } 51 image->data.F32[y][x] += bgImage->data.F32[y][x]; 84 52 } 85 53 } 86 if (naninputs) { 87 printf("%ld infinite pixels found in input image\n", naninputs); 54 psFree(bgImage); 55 } 56 57 if (pattern) { 58 pmReadout *patternRO = pmFPAviewThisReadout(view, pattern->parent); // Readout with pattern 59 psImage *patternImage = patternRO->image; // Image with pattern 60 for (int y = 0; y < numRows; y++) { 61 for (int x = 0; x < numCols; x++) { 62 image->data.F32[y][x] += patternImage->data.F32[y][x]; 63 } 88 64 } 89 if (nancount) { 90 psWarning("%ld infinite pixels found in background %ld pixels were finite\n", nancount, finitecount); 91 } 92 // pmFPAfileDropInternal(config->files, "PSPHOT.BACKGND"); 65 } 66 67 return true; 68 } 69 70 71
Note:
See TracChangeset
for help on using the changeset viewer.
