Changeset 4216 for trunk/psphot/src/setup.c
- Timestamp:
- Jun 12, 2005, 3:49:21 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/setup.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/setup.c
r4215 r4216 1 1 # include "psphot.h" 2 3 // load the image 4 // load or construct the mask 5 // apply X/Y border info 6 // apply the SATURATE mask? 7 // load or construct the noise 2 8 3 9 psImageData *setup (psMetadata *config) 4 10 { 11 psMetadata *header = NULL; 12 psImage *image = NULL; 13 psImage *noise = NULL; 14 psImage *mask = NULL; 15 5 16 psRegion region = {0,0,0,0}; // a region representing the entire array 6 17 7 18 psTimerStart ("psphot"); 8 19 20 // setup header template, specify COMMENT and HISTORY as multis 21 header = psMetadataAlloc (); 22 psMetadataAdd (header, PS_LIST_HEAD, "COMMENT", PS_META_MULTI, "folder for comment", NULL); 23 psMetadataAdd (header, PS_LIST_HEAD, "HISTORY", PS_META_MULTI, "folder for history", NULL); 24 25 // read header and image data from INPUT 9 26 char *input = psMetadataLookupSTR (&status, config, "INPUT"); 10 27 psFits *file = psFitsAlloc (input); 11 12 psImageData *imdata = psAlloc(sizeof(psImageData));13 psMetadata *header = psMetadataAlloc ();14 psMetadataAdd (header, PS_LIST_HEAD, "COMMENT", PS_META_MULTI, "folder for comment", NULL);15 psMetadataAdd (header, PS_LIST_HEAD, "HISTORY", PS_META_MULTI, "folder for history", NULL);16 28 header = psFitsReadHeader (header, file); 17 psImage *image = psFitsReadImage (NULL, file, region, 0);29 image = psFitsReadImage (NULL, file, region, 0); 18 30 psFree (file); 19 31 … … 25 37 psMetadataAdd (config, PS_LIST_TAIL, "GAIN", PS_META_F32 | PS_META_REPLACE, "gain value used", GAIN); 26 38 27 imdata->image = image;28 imdata->header = header;29 30 39 // load the noise image if it is supplied, otherwise build from input 31 40 char *noiseName = psMetadataLookupSTR (&status, config, "NOISE"); 32 41 if (status == true) { 33 42 file = psFitsAlloc (noiseName); 34 imdata->noise = psFitsReadImage (NULL, file, region, 0);43 noise = psFitsReadImage (NULL, file, region, 0); 35 44 psFree (file); 36 45 } else { 37 46 psScalar *value = psScalarAlloc (1.0 / GAIN, PS_TYPE_F64); 38 imdata->noise = BinaryOp (NULL, imdata->image, '/', value);47 noise = BinaryOp (NULL, image, '/', value); 39 48 psFree (value); 40 49 41 50 psScalar *value = psScalarAlloc (PS_SQR(RDNOISE/GAIN), PS_TYPE_F64); 42 imdata->noise = BinaryOp (imdata->noise, imdata->noise, '+', value);51 noise = BinaryOp (noise, noise, '+', value); 43 52 psFree (value); 44 53 } … … 47 56 if (status == true) { 48 57 file = psFitsAlloc (maskName); 49 imdata->mask = psFitsReadImage (NULL, file, region, 0);50 // check if U8 & force?58 mask = psFitsReadImage (NULL, file, region, 0); 59 // require U8 51 60 psFree (file); 52 61 } else { 53 imdata->mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8);62 mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8); 54 63 } 55 64 … … 58 67 psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER); 59 68 keep = psRegionForImage (keep, image, keep); 60 psImageKeepRegion (imdata->mask, keep, 0x01); 69 psImageKeepRegion (mask, keep, 0x01); 70 71 // mask the saturated pixels 72 float SATURATE = psMetadataLookupF32 (&status, config, "SATURATE"); 73 for (int i = 0; i < image->numRows; i++) { 74 for (int j = 0; j < image->numCols; j++) { 75 if (image->data.F32[i][j] >= SATURATE) { 76 mask->data.U8[i][j] |= 0x02; 77 } 78 } 79 } 61 80 62 81 psLogMsg ("psphot", 3, "load data: %f sec\n", psTimerMark ("psphot")); 63 82 83 psImageData *imdata = psAlloc(sizeof(psImageData)); 84 imdata->image = image; 85 imdata->header = header; 86 imdata->noise = noise; 87 imdata->mask = mask; 88 64 89 return (true); 65 90 }
Note:
See TracChangeset
for help on using the changeset viewer.
