Changeset 12956 for branches/eam_02_branch/psModules/src/objects/pmSource.c
- Timestamp:
- Apr 22, 2007, 5:26:23 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_02_branch/psModules/src/objects/pmSource.c
r12954 r12956 6 6 * @author EAM, IfA: significant modifications. 7 7 * 8 * @version $Revision: 1.25.4. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-04-2 2 22:23:20$8 * @version $Revision: 1.25.4.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-04-23 03:26:23 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 39 39 psFree(tmp->pixels); 40 40 psFree(tmp->weight); 41 psFree(tmp->mask); 41 psFree(tmp->maskObj); 42 psFree(tmp->maskView); 43 psFree(tmp->modelFlux); 42 44 psFree(tmp->moments); 43 45 psFree(tmp->modelPSF); … … 47 49 } 48 50 51 // free only the pixel data associated with this source 49 52 void pmSourceFreePixels(pmSource *source) 50 53 { … … 55 58 psFree (source->pixels); 56 59 psFree (source->weight); 57 psFree (source->mask); 60 psFree (source->maskObj); 61 psFree (source->maskView); 62 psFree (source->modelFlux); 58 63 59 64 source->pixels = NULL; 60 65 source->weight = NULL; 61 source->mask = NULL; 66 source->maskObj = NULL; 67 source->maskView = NULL; 68 source->modelFlux = NULL; 62 69 return; 63 70 } … … 76 83 source->pixels = NULL; 77 84 source->weight = NULL; 78 source->mask = NULL; 85 source->maskObj = NULL; 86 source->maskView = NULL; 87 source->modelFlux = NULL; 79 88 source->moments = NULL; 80 89 source->blends = NULL; … … 117 126 source->pixels = psMemIncrRefCounter (in->pixels); 118 127 source->weight = psMemIncrRefCounter (in->weight); 119 source->mask = psMemIncrRefCounter (in->mask); 128 source->maskObj = psMemIncrRefCounter (in->maskObj); 129 source->maskView = psMemIncrRefCounter (in->maskView); 120 130 source->moments = psMemIncrRefCounter (in->moments); 121 131 source->blends = NULL; 122 132 source->modelPSF = NULL; 123 133 source->modelEXT = NULL; 134 source->modelFlux = NULL; 124 135 source->type = in->type; 125 136 source->mode = in->mode; … … 151 162 srcRegion = psRegionForImage (readout->image, srcRegion); 152 163 153 mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image, srcRegion)); 154 mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, srcRegion)); 155 mySource->mask = psMemIncrRefCounter(psImageSubset(readout->mask, srcRegion)); 156 mySource->region = srcRegion; 164 // these images are subset images of the equivalent parents 165 mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image, srcRegion)); 166 mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, srcRegion)); 167 mySource->maskView = psMemIncrRefCounter(psImageSubset(readout->mask, srcRegion)); 168 mySource->region = srcRegion; 169 170 // the object mask is a copy, and used to define the source pixels 171 mySource->maskObj = psImageCopy (NULL, mySource->maskView, PS_TYPE_MASK); 157 172 158 173 return true; … … 183 198 extend |= (mySource->pixels == NULL); 184 199 extend |= (mySource->weight == NULL); 185 extend |= (mySource->mask == NULL); 200 extend |= (mySource->maskObj == NULL); 201 extend |= (mySource->maskView == NULL); 186 202 187 203 // extend = true; … … 190 206 psFree (mySource->pixels); 191 207 psFree (mySource->weight); 192 psFree (mySource->mask); 193 194 mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image, newRegion)); 195 mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, newRegion)); 196 mySource->mask = psMemIncrRefCounter(psImageSubset(readout->mask, newRegion)); 197 mySource->region = newRegion; 198 } 199 208 psFree (mySource->maskView); 209 210 mySource->pixels = psMemIncrRefCounter(psImageSubset(readout->image, newRegion)); 211 mySource->weight = psMemIncrRefCounter(psImageSubset(readout->weight, newRegion)); 212 mySource->maskView = psMemIncrRefCounter(psImageSubset(readout->mask, newRegion)); 213 mySource->region = newRegion; 214 215 // XXX how do we extend the mask? do we need to keep the old masked pixels? 216 // the object mask is a copy, and used to define the source pixels 217 psFree (mySource->maskObj); 218 mySource->maskObj = psImageCopy (NULL, mySource->maskView, PS_TYPE_MASK); 219 220 // XXX what about the modelFlux image? 221 } 200 222 return extend; 201 223 } … … 207 229 208 230 // XXX EAM include a S/N cutoff in selecting the sources? 231 // XXX this function should probably accept the values, not a recipe. wrap with a 232 // psphot-specific function which applies the recipe values 209 233 pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *recipe) 210 234 { … … 458 482 // XXX EAM : can we use the value of SATURATE if mask is NULL? 459 483 inner = psRegionForSquare (source->peak->x, source->peak->y, 2); 460 inner = psRegionForImage (source->mask , inner);461 int Nsatpix = psImageCountPixelMask (source->mask , inner, PM_MASK_SAT);484 inner = psRegionForImage (source->maskView, inner); 485 int Nsatpix = psImageCountPixelMask (source->maskView, inner, PM_MASK_SAT); 462 486 463 487 // saturated star (size consistent with PSF or larger) … … 572 596 PS_ASSERT_PTR_NON_NULL(source->peak, false); 573 597 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 574 PS_ASSERT_PTR_NON_NULL(source->mask , false);598 PS_ASSERT_PTR_NON_NULL(source->maskObj, false); 575 599 PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false); 576 600 … … 622 646 psF32 *vPix = source->pixels->data.F32[row]; 623 647 psF32 *vWgt = source->weight->data.F32[row]; 624 psU8 *vMsk = (source->mask == NULL) ? NULL : source->mask->data.U8[row];648 psU8 *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.U8[row]; 625 649 626 650 for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) { … … 751 775 // in some places (psphotEnsemble), we need a normalized version 752 776 // in others, we just want the model. which is more commonly used? 753 pmModelAdd (source->modelFlux, source->mask , model, PM_MODEL_ADD_FULL | PM_MODEL_ADD_NORM);777 pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM); 754 778 return true; 755 779 } 756 780 757 // XXX should this API take an operator (+/-)? 758 // XXX should we specify norm, etc? 759 bool pmSourceAdd (pmSource *source) { 781 // should we call pmSourceCacheModel if it does not exist? 782 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add) { 783 784 pmModel *model = pmSourceGetModel (NULL, source); 785 if (model == NULL) continue; // model must be defined 760 786 761 787 if (source->modelFlux) { 762 788 // add in the pixels from the modelFlux image 763 psImageSubsetAdd (source->pixels, source->modelFlux); 789 int dX = source->modelFlux->col0 - source->pixels->col0; 790 int dY = source->modelFlux->row0 - source->pixels->row0; 791 assert (dX >= 0); 792 assert (dY >= 0); 793 assert (dX + source->modelFlux->numCols < source->pixels->numCols); 794 assert (dY + source->modelFlux->numRows < source->pixels->numRows); 795 796 float Io = 1.0; 797 if (mode & PM_MODEL_OP_NORM) { 798 Io = 1.0 / model->params->data.F32[PM_PAR_I0]; 799 } 800 801 // XXX need to respect the source and model masks? 802 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { 803 oy = iy + dY; 804 for (int ix = 0; ix < source->modelFlux->numCols; ix++) { 805 ox = ix + dX; 806 float value = Io*source->modelFlux->data.F32[iy][ix]; 807 if (add) { 808 source->pixels->data.F32[oy][ox] -= value; 809 } else { 810 source->pixels->data.F32[oy][ox] += value; 811 } 812 } 813 } 764 814 } else { 765 pmModel *model = pmSourceGetModel (NULL, source); 766 if (model == NULL) continue; // model must be defined 767 pmModelAdd (source->pixels, source->mask, model, PM_MODEL_ADD_FULL); 815 if (add) { 816 pmModelAdd (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL); 817 } else { 818 pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL); 819 } 768 820 } 769 821 770 // we would need to save X,Y somehow (or use the peak?) 771 // psTrace ("psphot", 3, "replacing object at %f,%f\n", 772 // model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]); 822 if (add) { 823 psTrace ("psphot", 3, "replacing object at %f,%f\n", source->peak->xf, source->peak->yf); 824 } else { 825 psTrace ("psphot", 3, "removing object at %f,%f\n", source->peak->xf, source->peak->yf); 826 } 773 827 return true; 774 828 } 775 829 776 bool pmSourceSub (pmSource *source) { 777 778 if (source->modelFlux) { 779 // add in the pixels from the modelFlux image 780 psImageSubsetSub (source->pixels, source->modelFlux); 781 } else { 782 pmModel *model = pmSourceGetModel (NULL, source); 783 if (model == NULL) continue; // model must be defined 784 pmModelSub (source->pixels, source->mask, model, PM_MODEL_ADD_FULL); 785 } 786 return true; 787 } 788 789 // XXX merge this function with psImageOverlay, which is probably mid-defined 790 bool psImageSubsetAdd (psImage *input, psImage *subset) { 791 792 // col0,row0 in both images refer to parent coordinates 793 794 int dX = subset->col0 - input->col0; 795 int dY = subset->row0 - input->row0; 796 assert (dX >= 0); 797 assert (dY >= 0); 798 assert (dX + subset->numCols < input->numCols); 799 assert (dY + subset->numRows < input->numRows); 800 assert (input->type.type == PS_TYPE_F32); 801 assert (subset->type.type == PS_TYPE_F32); 802 803 for (int iy = 0; iy < subset->numRows; iy++) { 804 oy = iy + dY; 805 for (int ix = 0; ix < subset->numCols; ix++) { 806 ox = ix + dX; 807 input->data.F32[oy][ox] += subset->data.F32[iy][ix]; 808 } 809 } 810 return true; 811 } 812 813 // XXX merge this function with psImageOverlay, which is probably mid-defined 814 bool psImageSubsetSub (psImage *input, psImage *subset) { 815 816 // col0,row0 in both images refer to parent coordinates 817 818 int dX = subset->col0 - input->col0; 819 int dY = subset->row0 - input->row0; 820 assert (dX >= 0); 821 assert (dY >= 0); 822 assert (dX + subset->numCols < input->numCols); 823 assert (dY + subset->numRows < input->numRows); 824 assert (input->type.type == PS_TYPE_F32); 825 assert (subset->type.type == PS_TYPE_F32); 826 827 for (int iy = 0; iy < subset->numRows; iy++) { 828 oy = iy + dY; 829 for (int ix = 0; ix < subset->numCols; ix++) { 830 ox = ix + dX; 831 input->data.F32[oy][ox] -= subset->data.F32[iy][ix]; 832 } 833 } 834 return true; 835 } 830 bool pmSourceAdd (pmSource *source, pmSourceOpMode mode) { 831 pmSourceOp (source, mode, true); 832 } 833 834 bool pmSourceSub (pmSource *source, pmSourceOpMode mode) { 835 pmSourceOp (source, mode, false); 836 }
Note:
See TracChangeset
for help on using the changeset viewer.
