IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 12, 2005, 3:49:21 PM (21 years ago)
Author:
eugene
Message:

rework with masks and noise array

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/setup.c

    r4215 r4216  
    11# 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
    28
    39psImageData *setup (psMetadata *config)
    410{
     11    psMetadata *header = NULL;
     12    psImage *image = NULL;
     13    psImage *noise = NULL;
     14    psImage *mask = NULL;
     15
    516    psRegion  region = {0,0,0,0};       // a region representing the entire array
    617
    718    psTimerStart ("psphot");
    819
     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
    926    char *input = psMetadataLookupSTR (&status, config, "INPUT");
    1027    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);
    1628    header = psFitsReadHeader (header, file);
    17     psImage *image = psFitsReadImage (NULL, file, region, 0);
     29    image = psFitsReadImage (NULL, file, region, 0);
    1830    psFree (file);
    1931
     
    2537    psMetadataAdd (config, PS_LIST_TAIL, "GAIN",    PS_META_F32 | PS_META_REPLACE, "gain value used", GAIN);
    2638
    27     imdata->image = image;
    28     imdata->header = header;
    29 
    3039    // load the noise image if it is supplied, otherwise build from input
    3140    char *noiseName = psMetadataLookupSTR (&status, config, "NOISE");
    3241    if (status == true) {
    3342      file = psFitsAlloc (noiseName);
    34       imdata->noise = psFitsReadImage  (NULL, file, region, 0);
     43      noise = psFitsReadImage  (NULL, file, region, 0);
    3544      psFree (file);
    3645    } else {
    3746      psScalar *value = psScalarAlloc (1.0 / GAIN, PS_TYPE_F64);
    38       imdata->noise = BinaryOp (NULL, imdata->image, '/', value);
     47      noise = BinaryOp (NULL, image, '/', value);
    3948      psFree (value);
    4049
    4150      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);
    4352      psFree (value);
    4453    }
     
    4756    if (status == true) {
    4857      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
    5160      psFree (file);
    5261    } else {
    53       imdata->mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8);
     62      mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8);
    5463    }
    5564
     
    5867    psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
    5968    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    }
    6180
    6281    psLogMsg ("psphot", 3, "load data: %f sec\n", psTimerMark ("psphot"));
    6382
     83    psImageData *imdata = psAlloc(sizeof(psImageData));
     84    imdata->image = image;
     85    imdata->header = header;
     86    imdata->noise = noise;
     87    imdata->mask = mask;
     88
    6489    return (true);
    6590}
Note: See TracChangeset for help on using the changeset viewer.