public software.sextractor

[/] [trunk/] [src/] [retina.c] - Blame information for rev 233

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 233 bertin
/*
2
*                               retina.c
3 2 bertin
*
4 233 bertin
* Filter the image raster using a "retina" (convolution neural network).
5 2 bertin
*
6 233 bertin
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 2 bertin
*
8 233 bertin
*       This file part of:      SExtractor
9 2 bertin
*
10 233 bertin
*       Copyright:              (C) 1998-2010 IAP/CNRS/UPMC
11
*                               (C) 1997 ESO
12
*                               (C) 1995,1996 Sterrewacht Leiden
13 2 bertin
*
14 233 bertin
*       Author:                 Emmanuel Bertin (IAP)
15
*
16
*       License:                GNU General Public License
17
*
18
*       SExtractor is free software: you can redistribute it and/or modify
19
*       it under the terms of the GNU General Public License as published by
20
*       the Free Software Foundation, either version 3 of the License, or
21
*       (at your option) any later version.
22
*       SExtractor is distributed in the hope that it will be useful,
23
*       but WITHOUT ANY WARRANTY; without even the implied warranty of
24
*       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
*       GNU General Public License for more details.
26
*       You should have received a copy of the GNU General Public License
27
*       along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
28
*
29
*       Last modified:          11/10/2010
30
*
31
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32 2 bertin
 
33
#ifdef HAVE_CONFIG_H
34
#include        "config.h"
35
#endif
36
 
37
#include        <math.h>
38
#include        <stdio.h>
39
#include        <stdlib.h>
40
#include        <string.h>
41
 
42
#include        "define.h"
43
#include        "globals.h"
44
#include        "fits/fitscat.h"
45
#include        "bpro.h"
46
#include        "image.h"
47
#include        "retina.h"
48
 
49
 
50
/******************************** readretina *********************************/
51
/*
52
Return the response of the retina at a given image position.
53
*/
54
float    readretina(picstruct *field, retistruct *retina, float x, float y)
55
  {
56
   float        *pix, resp, norm;
57
   int          i, ix,iy;
58
 
59
  ix = (int)(x+0.499999);
60
  iy = (int)(y+0.499999);
61
  if (ix>=0 && ix<field->width && iy>=field->ymin && iy<field->ymax)
62
    norm = field->strip[ix+(iy%field->stripheight)*field->width];
63
  else
64
    norm = retina->minnorm;
65
  if (norm<retina->minnorm)
66
    norm = retina->minnorm;
67
/* Copy the right pixels to the retina */
68
  pix = retina->pix;
69
  copyimage(field, pix, retina->width, retina->height, ix,iy);
70
  for (i=retina->npix; i--;)
71
    *(pix++) /= norm;
72
  *pix = -2.5*log10(norm/retina->minnorm);
73
  play_bpann(retina->bpann, retina->pix, &resp);
74
 
75
  return resp;
76
  }
77
 
78
 
79
/********************************** getretina ********************************/
80
/*
81
Read an ANN retina file.
82
*/
83
retistruct      *getretina(char *filename)
84
 
85
  {
86
#define FILTEST(x) \
87
        if (x != RETURN_OK) \
88
          error(EXIT_FAILURE, "*Error*: RETINA header in ", filename)
89
 
90
   retistruct   *retina;
91
   catstruct    *fcat;
92
   tabstruct    *ftab;
93
   int          ival;
94
 
95
  QMALLOC(retina, retistruct, 1);
96
/* We first map the catalog */
97
  if (!(fcat = read_cat(filename)))
98
    error(EXIT_FAILURE, "*Error*: retina file not found: ", filename);
99
/* Test if the requested table is present */
100
  if (!(ftab = name_to_tab(fcat, "BP-ANN", 0)))
101
    error(EXIT_FAILURE, "*Error*: no BP-ANN info found in ", filename);
102
  FILTEST(fitsread(ftab->headbuf, "BPTYPE  ", gstr,H_STRING,T_STRING));
103
  if (strcmp(gstr, "RETINA_2D"))
104
    error(EXIT_FAILURE, "*Error*: not a suitable retina in ", filename);
105
  FILTEST(fitsread(ftab->headbuf, "RENAXIS ", &ival ,H_INT, T_LONG));
106
  if (ival != 2)
107
    error(EXIT_FAILURE, "*Error*: not a 2D retina in ", filename);
108
  FILTEST(fitsread(ftab->headbuf, "RENAXIS1", &retina->width ,H_INT, T_LONG));
109
  FILTEST(fitsread(ftab->headbuf, "RENAXIS2", &retina->height ,H_INT, T_LONG));
110
  retina->npix = retina->width*retina->height;
111
  FILTEST(fitsread(ftab->headbuf, "RENORM  ",&retina->minnorm,H_FLOAT,T_FLOAT));
112
  retina->bpann = loadtab_bpann(ftab, filename);
113
  QMALLOC(retina->pix, float, retina->bpann->nn[0]);
114
 
115
  close_cat(fcat);
116
  free_cat(&fcat,1);
117
 
118
  return retina;
119
  }
120
 
121
 
122
/********************************** endretina ********************************/
123
/*
124
Free a retina structure.
125
*/
126
void    endretina(retistruct *retina)
127
 
128
  {
129
  free(retina->pix);
130
  free_bpann(retina->bpann);
131
  free(retina);
132
 
133
  return;
134
  }
135