IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4215


Ignore:
Timestamp:
Jun 11, 2005, 5:43:47 AM (21 years ago)
Author:
eugene
Message:

adding mask & noise images

Location:
trunk/psphot/src
Files:
1 added
8 edited

Legend:

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

    r4129 r4215  
    2626    float RADIUS   = psMetadataLookupF32 (&status, config, "FIT_RADIUS");
    2727
    28     float XBORDER  = psMetadataLookupF32 (&status, config, "XBORDER");
    29     float YBORDER  = psMetadataLookupF32 (&status, config, "YBORDER");
    30     psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
    31     keep           = psRegionForImage (keep, image, keep);
    32 
    3328    for (int i = 0; i < stars->n; i++) {
    3429        psSource *source = stars->data[i];
    3530        pmSourceSetPixelCircle (source, image, RADIUS);
    36         pmSourceMaskRegion (source, keep);
    37         // XXX EAM - this is silly: reconsider how we use the masks
    38         // XXX - we are needlessly re-defining the pixels here
    3931    }
    4032
  • trunk/psphot/src/find_peaks.c

    r4189 r4215  
    11# include "psphot.h"
    22
    3 psArray *find_peaks (psImage *image, psMetadata *config, psStats *sky)
     3psArray *find_peaks (psImageData *imdata, psMetadata *config, psStats *sky)
    44{
    55    bool  status = false;
     
    1616    NSIGMA = psMetadataLookupF32 (&status, config, "SMOOTH_NSIGMA");
    1717
     18    psImage *image  = imdata->image;
    1819    psImage *smooth = psImageCopy (NULL, image, PS_TYPE_F32);
    1920    psImageSmooth (smooth, SIGMA, NSIGMA);
  • trunk/psphot/src/image_stats.c

    r4115 r4215  
    11# include "psphot.h"
    22
    3 psStats *image_stats (psImage *image, psMetadata *config)
     3psStats *image_stats (psImageData *imdata, psMetadata *config)
    44{
    55    psStats *stats = NULL;
    66    psStats *sky   = NULL;
     7
     8    psImage *image = imdata->image;
    79
    810    // get image stats on a subset of the image (random 1e5 pts)
  • trunk/psphot/src/psphot-utils.c

    r4114 r4215  
    160160}
    161161
     162// mask the area contained by the region
     163void psImageMaskRegion (psImage *image, psRegion *region, int maskValue) {
     164
     165    for (int iy = 0; iy < image->numRows; iy++) {
     166        for (int ix = 0; ix < image->numCols; ix++) {
     167            if (ix + image->col0 <  region->x0) continue;
     168            if (ix + image->col0 >= region->x1) continue;
     169            if (iy + image->row0 <  region->y0) continue;
     170            if (iy + image->row0 >= region->y1) continue;
     171            image->data.U8[iy][ix] |= maskValue;
     172        }
     173    }
     174}
     175
     176// mask the area not contained by the region
     177void psImageKeepRegion (psImage *image, psRegion *region, int maskValue) {
     178
     179    for (int iy = 0; iy < image->numRows; iy++) {
     180        for (int ix = 0; ix < image->numCols; ix++) {
     181            if (ix + image->col0 <  region->x0) goto maskit;
     182            if (ix + image->col0 >= region->x1) goto maskit;
     183            if (iy + image->row0 <  region->y0) goto maskit;
     184            if (iy + image->row0 >= region->y1) goto maskit;
     185            continue;
     186        maskit:
     187            image->data.U8[iy][ix] |= maskValue;
     188        }
     189    }
     190}
     191
    162192// create a subset of sources for the PS_SOURCE_PSFSTAR entries
    163193// XXX deprecated
  • trunk/psphot/src/psphot.c

    r4189 r4215  
    44int main (int argc, char **argv) {
    55
    6     psMetadata *config  = NULL;         // user-provided configuration information
    7     psMetadata *header  = NULL;         // input image header
    8     psImage    *image   = NULL;         // input image data
    9     psImage    *noise   = NULL;         // input image data
    10     psImage    *mask    = NULL;         // input image data
    11     psArray    *sources = NULL;
    12     psArray    *peaks   = NULL;         // a list of pmPeaks
    13     pmPSF      *psf     = NULL;
    14     psStats    *sky     = NULL;
     6    psMetadata  *config  = NULL;                // user-provided configuration information
     7    psImageData *imdata  = NULL;
     8    psArray     *sources = NULL;
     9    psArray     *peaks   = NULL;                // a list of pmPeaks
     10    pmPSF       *psf     = NULL;
     11    psStats     *sky     = NULL;
    1512
    1613    psLogArguments (&argc, argv);
     
    2017    // load input data (image and config)
    2118    // create or load mask and noise images
    22     setup (&image, &mask, &noise, &header, config);
     19    imdata = setup (config);
    2320
    2421    // measure image stats for initial guess
    25     sky = image_stats (image, config);
     22    sky = image_stats (imdata, config);
    2623
    2724    // find the peaks in the image
    28     peaks = find_peaks (image, config, sky);
     25    peaks = find_peaks (imdata, config, sky);
    2926
    3027    // construct sources and measure basic stats
    31     sources = source_moments (image, config, peaks);
     28    sources = source_moments (imdata, config, peaks);
    3229
    3330    // source analysis is done in S/N order (brightest first)
  • trunk/psphot/src/psphot.h

    r4129 r4215  
    55# include <unistd.h>
    66# include <stdlib.h>
     7
     8typedef struct {
     9  psImage *image;
     10  psImage *mask;
     11  psImage *noise;
     12  psMetadata *header;
     13} psImageData;
    714
    815// data to test a given PSF model type
  • trunk/psphot/src/setup.c

    r4189 r4215  
    11# include "psphot.h"
    22
    3 bool setup (psImage **image, psImage **mask, psImage **noise, psMetadata **header, psMetadata **config)
     3psImageData *setup (psMetadata *config)
    44{
    5     int       Nfail;
    6     psFits   *file = NULL;              // FITS pointer to input image
    75    psRegion  region = {0,0,0,0};       // a region representing the entire array
    86
    97    psTimerStart ("psphot");
    108
    11     char *input = pmConfigLookupSTR (&status, *config, *header, "INPUT");
    12     file = psFitsAlloc (input);
     9    char *input = psMetadataLookupSTR (&status, config, "INPUT");
     10    psFits *file = psFitsAlloc (input);
    1311
    14     *header = psMetadataAlloc ();
    15     psMetadataAdd (*header, PS_LIST_HEAD, "COMMENT", PS_META_MULTI, "folder for comment", NULL);
    16     psMetadataAdd (*header, PS_LIST_HEAD, "HISTORY", PS_META_MULTI, "folder for history", NULL);
    17     *header = psFitsReadHeader (*header, file);
    18     *image  = psFitsReadImage  (*image,  file, region, 0);
     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    header = psFitsReadHeader (header, file);
     17    psImage *image = psFitsReadImage (NULL, file, region, 0);
    1918    psFree (file);
    2019
    2120    // grab these values from the approrpiate location (image header if necessary)
    2221    bool  status   = false;
    23     float RDNOISE  = pmConfigLookupF32 (&status, *config, *header, "RDNOISE");
    24     float GAIN     = pmConfigLookupF32 (&status, *config, *header, "GAIN");
    25     psMetadataAdd (*config, PS_LIST_TAIL, "RDNOISE", PS_META_F32 | PS_META_REPLACE, "read noise value used", RDNOISE);
    26     psMetadataAdd (*config, PS_LIST_TAIL, "GAIN",    PS_META_F32 | PS_META_REPLACE, "gain value used", GAIN);
     22    float RDNOISE  = pmConfigLookupF32 (&status, config, header, "RDNOISE");
     23    float GAIN     = pmConfigLookupF32 (&status, config, header, "GAIN");
     24    psMetadataAdd (config, PS_LIST_TAIL, "RDNOISE", PS_META_F32 | PS_META_REPLACE, "read noise value used", RDNOISE);
     25    psMetadataAdd (config, PS_LIST_TAIL, "GAIN",    PS_META_F32 | PS_META_REPLACE, "gain value used", GAIN);
    2726
    28     // load the noise image if it exists, otherwise build from input
    29     char *noiseName = pmConfigLookupSTR (&status, *config, *header, "NOISE");
     27    imdata->image = image;
     28    imdata->header = header;
     29
     30    // load the noise image if it is supplied, otherwise build from input
     31    char *noiseName = psMetadataLookupSTR (&status, config, "NOISE");
    3032    if (status == true) {
    3133      file = psFitsAlloc (noiseName);
    32       *noise  = psFitsReadImage  (*noise, file, region, 0);
     34      imdata->noise = psFitsReadImage  (NULL, file, region, 0);
    3335      psFree (file);
    3436    } else {
    35       *value = psScalar (1.0 / GAIN);
    36       *noise = BinaryOp (NULL, *image, '/', value);
     37      psScalar *value = psScalarAlloc (1.0 / GAIN, PS_TYPE_F64);
     38      imdata->noise = BinaryOp (NULL, imdata->image, '/', value);
    3739      psFree (value);
    3840
    39       *value = psScalar (PS_SQR(RDNOISE/GAIN));
    40       *noise = BinaryOp (*noise, *noise, '+', value);
     41      psScalar *value = psScalarAlloc (PS_SQR(RDNOISE/GAIN), PS_TYPE_F64);
     42      imdata->noise = BinaryOp (imdata->noise, imdata->noise, '+', value);
    4143      psFree (value);
    4244    }
    4345
    44     char *maskName = pmConfigLookupSTR (&status, *config, *header, "MASK");
     46    char *maskName = psMetadataLookupSTR (&status, config, "MASK");
    4547    if (status == true) {
    4648      file = psFitsAlloc (maskName);
    47       *mask  = psFitsReadImage  (*mask, file, region, 0);
     49      imdata->mask  = psFitsReadImage  (NULL, file, region, 0);
     50      // check if U8 & force?
    4851      psFree (file);
    4952    } else {
    50       *mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8);
     53      imdata->mask = psImageAlloc (image->numCols, image->numRows, PS_TYPE_U8);
    5154    }
     55
     56    float XBORDER  = psMetadataLookupF32 (&status, config, "XBORDER");
     57    float YBORDER  = psMetadataLookupF32 (&status, config, "YBORDER");
     58    psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
     59    keep           = psRegionForImage (keep, image, keep);
     60    psImageKeepRegion (imdata->mask, keep, 0x01);
    5261
    5362    psLogMsg ("psphot", 3, "load data: %f sec\n", psTimerMark ("psphot"));
  • trunk/psphot/src/source_moments.c

    r4129 r4215  
    11# include "psphot.h"
    22
    3 psArray *source_moments (psImage *image, psMetadata *config, psArray *allpeaks)
     3psArray *source_moments (psImageData *imdata, psMetadata *config, psArray *allpeaks)
    44{
    55    bool     status  = false;
     
    88
    99    psTimerStart ("psphot");
    10 
    11     // reduce the initial peaks to a subset of the better peaks
    12     // is this the appropriate place for this culling?
    13 
    14     float XBORDER  = psMetadataLookupF32 (&status, config, "XBORDER");
    15     float YBORDER  = psMetadataLookupF32 (&status, config, "YBORDER");
    16     float SATURATE = psMetadataLookupF32 (&status, config, "SATURATE");
    17 
    18     psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
    19     keep           = psRegionForImage (keep, image, keep);
    20     // I need to exclude the saturated objects here, but include them again later...?
    21     peaks          = pmPeaksSubset (allpeaks, 100000, keep);
    2210
    2311    // determine properties (sky, moments) of initial sources
     
    3220    for (int i = 0; i < peaks->n; i++) {
    3321        // provide the user arguments as metadata?
    34         psSource *source  = pmSourceLocalSky (image, (psPeak *)peaks->data[i], PS_STAT_SAMPLE_MEDIAN, INNER, OUTER);
     22        psSource *source  = pmSourceDefinePixels (imdata, (psPeak *)peaks->data[i], OUTER);
    3523        if (source == NULL) continue;
    36         pmSourceMaskRegion (source, keep);
     24
     25        pmSourceLocalSky_EAM (source, PS_STAT_SAMPLE_MEDIAN, INNER);
    3726        pmSourceMoments (source, RADIUS);
    3827        psArrayAdd (sources, 100, source);
Note: See TracChangeset for help on using the changeset viewer.