| 1 |
283 |
bertin |
/*
|
| 2 |
|
|
* subimage.c
|
| 3 |
|
|
*
|
| 4 |
|
|
* Manage subimage structures.
|
| 5 |
|
|
*
|
| 6 |
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 7 |
|
|
*
|
| 8 |
|
|
* This file part of: SExtractor
|
| 9 |
|
|
*
|
| 10 |
|
|
* Copyright: (C) 1993-2012 Emmanuel Bertin -- IAP/CNRS/UPMC
|
| 11 |
|
|
*
|
| 12 |
|
|
* License: GNU General Public License
|
| 13 |
|
|
*
|
| 14 |
|
|
* SExtractor is free software: you can redistribute it and/or modify
|
| 15 |
|
|
* it under the terms of the GNU General Public License as published by
|
| 16 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
| 17 |
|
|
* (at your option) any later version.
|
| 18 |
|
|
* SExtractor is distributed in the hope that it will be useful,
|
| 19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
* GNU General Public License for more details.
|
| 22 |
|
|
* You should have received a copy of the GNU General Public License
|
| 23 |
|
|
* along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
|
| 24 |
|
|
*
|
| 25 |
285 |
bertin |
* Last modified: 06/05/2012
|
| 26 |
283 |
bertin |
*
|
| 27 |
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
| 28 |
|
|
|
| 29 |
|
|
#ifdef HAVE_CONFIG_H
|
| 30 |
|
|
#include "config.h"
|
| 31 |
|
|
#endif
|
| 32 |
|
|
|
| 33 |
|
|
#include <math.h>
|
| 34 |
|
|
#include <stdio.h>
|
| 35 |
|
|
#include <stdlib.h>
|
| 36 |
|
|
#include <string.h>
|
| 37 |
|
|
|
| 38 |
|
|
#include "define.h"
|
| 39 |
|
|
#include "globals.h"
|
| 40 |
|
|
#include "prefs.h"
|
| 41 |
|
|
#include "fits/fitscat.h"
|
| 42 |
|
|
#include "field.h"
|
| 43 |
|
|
#include "fitswcs.h"
|
| 44 |
|
|
#include "image.h"
|
| 45 |
|
|
#include "subimage.h"
|
| 46 |
|
|
|
| 47 |
|
|
/****** subimage_getall ******************************************************
|
| 48 |
|
|
PROTO subimagestruct *subimage_getall(fieldstruct **fields,
|
| 49 |
|
|
fieldstruct **wfields, int nfield, obj2struct *obj2)
|
| 50 |
|
|
PURPOSE Create array of object sub-images (copy of local image data).
|
| 51 |
|
|
INPUT Pointer to an array of image fields,
|
| 52 |
|
|
pointer to an array of weight-map fields,
|
| 53 |
|
|
number of fields,
|
| 54 |
|
|
pointer to obj2 "object",
|
| 55 |
|
|
OUTPUT Pointer to a new malloc'ed subimage structure.
|
| 56 |
|
|
NOTES Global preferences are used. Input fields must have been through
|
| 57 |
|
|
frame_wcs() with detection field as a reference.
|
| 58 |
|
|
AUTHOR E. Bertin (IAP)
|
| 59 |
285 |
bertin |
VERSION 02/05/2012
|
| 60 |
283 |
bertin |
***/
|
| 61 |
|
|
subimagestruct *subimage_getall(fieldstruct **fields, fieldstruct **wfields,
|
| 62 |
|
|
int nfield, obj2struct *obj2)
|
| 63 |
|
|
|
| 64 |
|
|
{
|
| 65 |
|
|
subimagestruct *subimage;
|
| 66 |
|
|
fieldstruct *field,*wfield;
|
| 67 |
|
|
int f,s, nsubimage;
|
| 68 |
|
|
|
| 69 |
|
|
if (prefs.multigrids_flag)
|
| 70 |
|
|
{
|
| 71 |
|
|
nsubimage = 0;
|
| 72 |
|
|
for (f=0; f<nfield; f++)
|
| 73 |
|
|
{
|
| 74 |
|
|
field = fields[f];
|
| 75 |
|
|
if (!(field->flags&MULTIGRID_FIELD)
|
| 76 |
|
|
|| (field->wcs->outmin[0] <= obj2->xmax
|
| 77 |
|
|
&& field->wcs->outmax[0] >= obj2->xmin
|
| 78 |
|
|
&& field->wcs->outmin[1] <= obj2->ymax
|
| 79 |
|
|
&& field->wcs->outmax[1] >= obj2->ymin))
|
| 80 |
|
|
nsubimage++;
|
| 81 |
|
|
}
|
| 82 |
|
|
obj2->nsubimage = nsubimage;
|
| 83 |
|
|
}
|
| 84 |
|
|
else
|
| 85 |
|
|
obj2->nsubimage = nsubimage = nfield;
|
| 86 |
|
|
|
| 87 |
|
|
QMALLOC(obj2->subimage, subimagestruct, obj2->nsubimage);
|
| 88 |
|
|
|
| 89 |
|
|
subimage = obj2->subimage;
|
| 90 |
|
|
/* Initialize first (detection) sub-image */
|
| 91 |
|
|
subimage_init(subimage, fields[0], wfields? wfields[0]:NULL, obj2, NULL);
|
| 92 |
|
|
/* Initialize remaining sub-images */
|
| 93 |
|
|
for (f=1; f<nfield; f++)
|
| 94 |
|
|
{
|
| 95 |
|
|
field = fields[f];
|
| 96 |
|
|
wfield = wfields? wfields[f] : NULL;
|
| 97 |
|
|
if (field->flags&MULTIGRID_FIELD
|
| 98 |
|
|
&& (field->wcs->outmin[0] > obj2->xmax
|
| 99 |
|
|
|| field->wcs->outmax[0] < obj2->xmin
|
| 100 |
|
|
|| field->wcs->outmin[1] > obj2->ymax
|
| 101 |
|
|
|| field->wcs->outmax[1] < obj2->ymin))
|
| 102 |
|
|
continue;
|
| 103 |
|
|
subimage_init(++subimage, field, wfield, obj2, obj2->subimage);
|
| 104 |
|
|
}
|
| 105 |
|
|
|
| 106 |
|
|
subimage = obj2->subimage;
|
| 107 |
285 |
bertin |
for (s=0; s<nsubimage; s++, subimage++)
|
| 108 |
283 |
bertin |
{
|
| 109 |
|
|
QMALLOC(subimage->image, PIXTYPE, subimage->imsize[0]*subimage->imsize[1]);
|
| 110 |
|
|
copyimage(subimage->field, subimage->image,
|
| 111 |
|
|
subimage->imsize[0],subimage->imsize[1],
|
| 112 |
|
|
subimage->ipos[0],subimage->ipos[1]);
|
| 113 |
|
|
if (subimage->wfield)
|
| 114 |
|
|
{
|
| 115 |
|
|
QMALLOC(subimage->weight, PIXTYPE,
|
| 116 |
|
|
subimage->imsize[0]*subimage->imsize[1]);
|
| 117 |
|
|
copyimage(subimage->wfield, subimage->weight,
|
| 118 |
|
|
subimage->imsize[0],subimage->imsize[1],
|
| 119 |
|
|
subimage->ipos[0],subimage->ipos[1]);
|
| 120 |
|
|
}
|
| 121 |
|
|
else
|
| 122 |
|
|
subimage->weight = NULL;
|
| 123 |
285 |
bertin |
subimage->bkg = obj2->bkg[s];
|
| 124 |
283 |
bertin |
}
|
| 125 |
|
|
|
| 126 |
|
|
return obj2->subimage;
|
| 127 |
|
|
}
|
| 128 |
|
|
|
| 129 |
|
|
|
| 130 |
|
|
/****** subimage_init ********************************************************
|
| 131 |
|
|
PROTO void subimage_init(subimagestruct *subimage,
|
| 132 |
|
|
fieldstruct *field, fieldstruct *wfield,
|
| 133 |
|
|
obj2struct *obj2, subimagestruct *dsubimage)
|
| 134 |
|
|
PURPOSE Initialize a new sub-image (copy of local image data).
|
| 135 |
|
|
INPUT Pointer to subimage,
|
| 136 |
|
|
pointer to current image field,
|
| 137 |
|
|
pointer to current weight-map field (or NULL if no weighting),
|
| 138 |
|
|
pointer to obj2 "object",
|
| 139 |
|
|
pointer to reference sub-image (or NULL to make one).
|
| 140 |
|
|
OUTPUT -.
|
| 141 |
|
|
NOTES -.
|
| 142 |
|
|
AUTHOR E. Bertin (IAP)
|
| 143 |
285 |
bertin |
VERSION 06/05/2012
|
| 144 |
283 |
bertin |
***/
|
| 145 |
|
|
void subimage_init(subimagestruct *subimage,
|
| 146 |
|
|
fieldstruct *field, fieldstruct *wfield,
|
| 147 |
|
|
obj2struct *obj2, subimagestruct *dsubimage)
|
| 148 |
|
|
|
| 149 |
|
|
{
|
| 150 |
|
|
fieldstruct *dfield;
|
| 151 |
|
|
double dval,dmax, det;
|
| 152 |
|
|
|
| 153 |
|
|
if (dsubimage)
|
| 154 |
|
|
{
|
| 155 |
|
|
dfield = dsubimage->field;
|
| 156 |
|
|
if (field->flags&MULTIGRID_FIELD)
|
| 157 |
|
|
{
|
| 158 |
|
|
det = wcs_rawtoraw(field->wcs, dfield->wcs,
|
| 159 |
|
|
dsubimage->dpos, subimage->dpos, subimage->djacob);
|
| 160 |
|
|
subimage->dscale = sqrt(det);
|
| 161 |
|
|
if (fabs(det) > 0.0 )
|
| 162 |
|
|
det = 1.0/det;
|
| 163 |
|
|
subimage->dinvjacob[0] = det*subimage->djacob[3];
|
| 164 |
|
|
subimage->dinvjacob[1] = -det*subimage->djacob[1];
|
| 165 |
|
|
subimage->dinvjacob[2] = -det*subimage->djacob[2];
|
| 166 |
|
|
subimage->dinvjacob[3] = det*subimage->djacob[0];
|
| 167 |
|
|
subimage->ipos[0] = (int)(subimage->dpos[0]-0.50001);/* Integer coords */
|
| 168 |
|
|
subimage->ipos[1] = (int)(subimage->dpos[1]-0.50001);/* Integer coords */
|
| 169 |
|
|
dmax = fabs(subimage->djacob[0]*dsubimage->imsize[0]);
|
| 170 |
|
|
if ((dval=fabs(subimage->djacob[1]*dsubimage->imsize[1]))>dmax)
|
| 171 |
|
|
dmax = dval;
|
| 172 |
|
|
subimage->imsize[0] = (int)(dmax+0.49999);
|
| 173 |
|
|
dmax = fabs(subimage->djacob[2]*dsubimage->imsize[0]);
|
| 174 |
|
|
if ((dval=fabs(subimage->djacob[3]*dsubimage->imsize[1]))>dmax)
|
| 175 |
|
|
dmax = dval;
|
| 176 |
|
|
subimage->imsize[1] = (int)(dmax+0.49999);
|
| 177 |
|
|
subimage->immin[0] = subimage->ipos[0] - subimage->imsize[0]/2;
|
| 178 |
|
|
subimage->immin[1] = subimage->ipos[1] - subimage->imsize[1]/2;
|
| 179 |
|
|
subimage->immax[0] = subimage->immin[0] + subimage->imsize[0];
|
| 180 |
|
|
subimage->immax[1] = subimage->immin[1] + subimage->imsize[1];
|
| 181 |
|
|
}
|
| 182 |
|
|
else
|
| 183 |
|
|
*subimage = *dsubimage;
|
| 184 |
|
|
}
|
| 185 |
|
|
else
|
| 186 |
|
|
{
|
| 187 |
|
|
subimage->dscale = 1.0;
|
| 188 |
|
|
subimage->dpos[0] = obj2->mx + 1.0;
|
| 189 |
|
|
subimage->dpos[1] = obj2->my + 1.0;
|
| 190 |
|
|
subimage->ipos[0] = (int)(subimage->dpos[0]-0.50001); /* Integer coords */
|
| 191 |
|
|
subimage->ipos[1] = (int)(subimage->dpos[1]-0.50001); /* Integer coords */
|
| 192 |
|
|
subimage->djacob[0] = subimage->djacob[2]
|
| 193 |
285 |
bertin |
= subimage->dinvjacob[0] = subimage->dinvjacob[3] = 1.0;
|
| 194 |
|
|
subimage->djacob[1] = subimage->djacob[2]
|
| 195 |
|
|
= subimage->dinvjacob[1] = subimage->dinvjacob[2] = 0.0;
|
| 196 |
283 |
bertin |
subimage->imsize[0] = 2.0*(obj2->xmax-obj2->xmin)+1+2*field->stripmargin;
|
| 197 |
|
|
subimage->imsize[1] = 2.0*(obj2->ymax-obj2->ymin)+1+2*field->stripmargin;
|
| 198 |
|
|
subimage->immin[0] = subimage->ipos[0] - subimage->imsize[0]/2;
|
| 199 |
|
|
subimage->immin[1] = subimage->ipos[1] - subimage->imsize[1]/2;
|
| 200 |
|
|
subimage->immax[0] = subimage->immin[0] + subimage->imsize[0];
|
| 201 |
|
|
subimage->immax[1] = subimage->immin[1] + subimage->imsize[1];
|
| 202 |
|
|
}
|
| 203 |
|
|
|
| 204 |
|
|
subimage->field = field;
|
| 205 |
|
|
subimage->wfield = wfield;
|
| 206 |
|
|
|
| 207 |
|
|
return;
|
| 208 |
|
|
}
|
| 209 |
|
|
|
| 210 |
|
|
|
| 211 |
|
|
/****** subimage_endall ******************************************************
|
| 212 |
|
|
PROTO void subimage_endall(obj2struct *obj2)
|
| 213 |
|
|
PURPOSE Free resources related to an array of sub-images.
|
| 214 |
|
|
INPUT Pointer to an obj2 "object" structure.
|
| 215 |
|
|
NOTES -.
|
| 216 |
|
|
AUTHOR E. Bertin (IAP)
|
| 217 |
|
|
VERSION 29/03/2012
|
| 218 |
|
|
***/
|
| 219 |
|
|
void subimage_endall(obj2struct *obj2)
|
| 220 |
|
|
|
| 221 |
|
|
{
|
| 222 |
|
|
subimagestruct *subimage;
|
| 223 |
|
|
int s;
|
| 224 |
|
|
|
| 225 |
|
|
subimage = obj2->subimage;
|
| 226 |
|
|
for (s=obj2->nsubimage; s--; subimage++)
|
| 227 |
|
|
{
|
| 228 |
|
|
free(subimage->image);
|
| 229 |
|
|
free(subimage->weight);
|
| 230 |
|
|
}
|
| 231 |
|
|
|
| 232 |
|
|
QFREE(obj2->subimage);
|
| 233 |
|
|
obj2->nsubimage = 0;
|
| 234 |
|
|
|
| 235 |
|
|
return;
|
| 236 |
|
|
}
|
| 237 |
|
|
|
| 238 |
|
|
|
| 239 |
|
|
|