File indexing completed on 2024-04-28 03:43:54

0001 /*
0002     This file is part of SEP
0003 
0004     SPDX-FileCopyrightText: 1993-2011 Emmanuel Bertin -- IAP /CNRS/UPMC
0005     SPDX-FileCopyrightText: 2014 SEP developers
0006 
0007     SPDX-License-Identifier: LGPL-3.0-or-later
0008 */
0009 
0010 
0011 #define UNKNOWN         -1    /* flag for LUTZ */
0012 #define CLEAN_ZONE      10.0  /* zone (in sigma) to consider for processing */
0013 #define CLEAN_STACKSIZE 3000  /* replaces prefs.clean_stacksize  */
0014                               /* (MEMORY_OBJSTACK in sextractor inputs) */
0015 #define CLEAN_MARGIN    0  /* replaces prefs.cleanmargin which was set based */
0016                            /* on stuff like apertures and vignet size */
0017 #define MARGIN_SCALE   2.0 /* Margin / object height */ 
0018 #define MARGIN_OFFSET  4.0 /* Margin offset (pixels) */ 
0019 #define MAXDEBAREA     3   /* max. area for deblending (must be >= 1)*/
0020 #define MAXPICSIZE     1048576 /* max. image size in any dimension */
0021 
0022 /* plist-related macros */
0023 #define PLIST(ptr, elem)    (((pbliststruct *)(ptr))->elem)
0024 #define PLISTEXIST(elem)    (plistexist_##elem)
0025 #define PLISTPIX(ptr, elem) (*((PIXTYPE *)((ptr)+plistoff_##elem)))
0026 #define PLISTFLAG(ptr, elem)    (*((FLAGTYPE *)((ptr)+plistoff_##elem)))
0027 
0028 /* Extraction status */
0029 typedef enum {COMPLETE, INCOMPLETE, NONOBJECT, OBJECT} pixstatus;
0030 
0031 /* Temporary object parameters during extraction */
0032 typedef struct structinfo
0033 {
0034   LONG  pixnb;      /* Number of pixels included */
0035   LONG  firstpix;   /* Pointer to first pixel of pixlist */
0036   LONG  lastpix;    /* Pointer to last pixel of pixlist */
0037   short flag;       /* Extraction flag */
0038 } infostruct;
0039 
0040 typedef char pliststruct;      /* Dummy type for plist */
0041 
0042 typedef struct
0043 {
0044   int     nextpix;
0045   int     x, y;
0046   PIXTYPE value;
0047 } pbliststruct;
0048 
0049 /* array buffer struct */
0050 typedef struct
0051 {
0052   BYTE *dptr;         /* pointer to original data, can be any supported type */
0053   int dtype;          /* data type of original data */
0054   int dw, dh;         /* original data width, height */
0055   PIXTYPE *bptr;      /* buffer pointer (self-managed memory) */
0056   int bw, bh;         /* buffer width, height (bufw can be larger than w due */
0057                       /* to padding). */
0058   PIXTYPE *midline;   /* "middle" line in buffer (at index bh/2) */
0059   PIXTYPE *lastline;  /* last line in buffer */
0060   array_converter readline;  /* function to read a data line into buffer */
0061   int elsize;         /* size in bytes of one element in original data */ 
0062   int yoff;           /* line index in original data corresponding to bufptr */
0063 } arraybuffer;
0064 
0065 
0066 /* globals */
0067 extern int plistexist_cdvalue, plistexist_thresh, plistexist_var;
0068 extern int plistoff_value, plistoff_cdvalue, plistoff_thresh, plistoff_var;
0069 extern int plistsize;
0070 
0071 typedef struct
0072 {
0073   /* thresholds */
0074   float    thresh;                   /* detect threshold (ADU) */
0075   float    mthresh;                  /* max. threshold (ADU) */
0076 
0077   /* # pixels */
0078   int      fdnpix;              /* nb of extracted pix */
0079   int      dnpix;               /* nb of pix above thresh  */
0080   int      npix;                /* "" in measured frame */
0081   int      nzdwpix;         /* nb of zero-dweights around */
0082   int      nzwpix;              /* nb of zero-weights inside */
0083   
0084   /* position */
0085   int      xpeak, ypeak;                     /* pos of brightest pix */
0086   int      xcpeak,ycpeak;                    /* pos of brightest pix */
0087   double   mx, my;                       /* barycenter */
0088   int      xmin,xmax,ymin,ymax,ycmin,ycmax;  /* x,y limits */
0089 
0090   /* shape */
0091   double   mx2,my2,mxy;              /* variances and covariance */
0092   float    a, b, theta, abcor;           /* moments and angle */
0093   float    cxx,cyy,cxy;              /* ellipse parameters */
0094   double   errx2, erry2, errxy;      /* Uncertainties on the variances */
0095 
0096   /* flux */
0097   float    fdflux;              /* integrated ext. flux */
0098   float    dflux;               /* integrated det. flux */
0099   float    flux;                /* integrated mes. flux */
0100   float    fluxerr;         /* integrated variance */
0101   PIXTYPE  fdpeak;              /* peak intensity (ADU) */
0102   PIXTYPE  dpeak;               /* peak intensity (ADU) */
0103   PIXTYPE  peak;                /* peak intensity (ADU) */
0104 
0105   /* flags */
0106   short    flag;                 /* extraction flags */
0107 
0108   /* accessing individual pixels in plist*/
0109   int      firstpix;                 /* ptr to first pixel */
0110   int      lastpix;              /* ptr to last pixel */
0111 } objstruct;
0112 
0113 typedef struct
0114 {
0115   int           nobj;     /* number of objects in list */
0116   objstruct     *obj;     /* pointer to the object array */
0117   int           npix;     /* number of pixels in pixel-list */
0118   pliststruct   *plist;   /* pointer to the pixel-list */
0119   PIXTYPE       thresh;   /* detection threshold */
0120 } objliststruct;
0121 
0122 
0123 int analysemthresh(int objnb, objliststruct *objlist, int minarea,
0124            PIXTYPE thresh);
0125 void preanalyse(int, objliststruct *);
0126 void analyse(int, objliststruct *, int, double);
0127 
0128 int  lutzalloc(int, int);
0129 void lutzfree(void);
0130 int  lutz(pliststruct *plistin,
0131       int *objrootsubmap, int subx, int suby, int subw,
0132       objstruct *objparent, objliststruct *objlist, int minarea);
0133 
0134 void update(infostruct *, infostruct *, pliststruct *);
0135 
0136 int  allocdeblend(int);
0137 void freedeblend(void);
0138 int  deblend(objliststruct *, int, objliststruct *, int, double, int);
0139 
0140 /*int addobjshallow(objstruct *, objliststruct *);
0141 int rmobjshallow(int, objliststruct *);
0142 void mergeobjshallow(objstruct *, objstruct *);
0143 */
0144 int addobjdeep(int, objliststruct *, objliststruct *);
0145 
0146 int convolve(arraybuffer *buf, int y, float *conv, int convw, int convh,
0147              PIXTYPE *out);
0148 int matched_filter(arraybuffer *imbuf, arraybuffer *nbuf, int y,
0149                    float *conv, int convw, int convh,
0150                    PIXTYPE *work, PIXTYPE *out, int noise_type);