| 1 |
|
#ifndef lint |
| 2 |
< |
static const char RCSid[] = "$Id$"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
|
/* |
| 5 |
|
* pf3.c - routines for gaussian and box filtering |
| 9 |
|
|
| 10 |
|
#include "standard.h" |
| 11 |
|
|
| 12 |
+ |
#include <string.h> |
| 13 |
+ |
|
| 14 |
|
#include "color.h" |
| 15 |
+ |
#include "pfilt.h" |
| 16 |
|
|
| 17 |
|
#define RSCA 1.13 /* square-radius multiplier: sqrt(4/PI) */ |
| 18 |
|
#define TEPS 0.2 /* threshold proximity goal */ |
| 19 |
|
#define REPS 0.1 /* radius proximity goal */ |
| 20 |
|
|
| 18 |
– |
extern double CHECKRAD; /* radius over which gaussian is summed */ |
| 19 |
– |
|
| 20 |
– |
extern double rad; /* output pixel radius for filtering */ |
| 21 |
– |
|
| 22 |
– |
extern double thresh; /* maximum contribution for subpixel */ |
| 23 |
– |
|
| 24 |
– |
extern int nrows; /* number of rows for output */ |
| 25 |
– |
extern int ncols; /* number of columns for output */ |
| 26 |
– |
|
| 27 |
– |
extern int xres, yres; /* resolution of input */ |
| 28 |
– |
|
| 29 |
– |
extern double x_c, y_r; /* conversion factors */ |
| 30 |
– |
|
| 31 |
– |
extern int xrad; /* x search radius */ |
| 32 |
– |
extern int yrad; /* y search radius */ |
| 33 |
– |
extern int xbrad; /* x box size */ |
| 34 |
– |
extern int ybrad; /* y box size */ |
| 35 |
– |
|
| 36 |
– |
extern int barsize; /* size of input scan bar */ |
| 37 |
– |
extern COLOR **scanin; /* input scan bar */ |
| 38 |
– |
extern COLOR *scanout; /* output scan line */ |
| 39 |
– |
extern COLOR **scoutbar; /* output scan bar (if thresh > 0) */ |
| 40 |
– |
extern float **greybar; /* grey-averaged input values */ |
| 41 |
– |
extern int obarsize; /* size of output scan bar */ |
| 42 |
– |
extern int orad; /* output window radius */ |
| 43 |
– |
|
| 44 |
– |
extern int wrapfilt; /* wrap filter horizontally? */ |
| 45 |
– |
|
| 46 |
– |
extern char *progname; |
| 47 |
– |
|
| 21 |
|
float *gausstable; /* gauss lookup table */ |
| 22 |
|
|
| 23 |
|
float *ringsum; /* sum of ring values */ |
| 25 |
|
short *ringndx; /* ring index table */ |
| 26 |
|
float *warr; /* array of pixel weights */ |
| 27 |
|
|
| 28 |
< |
extern double (*ourbright)(); /* brightness computation function */ |
| 28 |
> |
#define lookgauss(x) gausstable[(int)(20.*(x)+.5)] |
| 29 |
|
|
| 30 |
< |
double pickfilt(); |
| 30 |
> |
static double pickfilt(double p0); |
| 31 |
> |
static void sumans(int px, int py, int rcent, int ccent, double m); |
| 32 |
|
|
| 59 |
– |
#define lookgauss(x) gausstable[(int)(10.*(x)+.5)] |
| 33 |
|
|
| 34 |
< |
|
| 35 |
< |
initmask() /* initialize gaussian lookup table */ |
| 34 |
> |
void |
| 35 |
> |
initmask(void) /* initialize gaussian lookup table */ |
| 36 |
|
{ |
| 37 |
|
int gtabsiz; |
| 38 |
|
double gaussN; |
| 39 |
|
double d; |
| 40 |
< |
register int x; |
| 40 |
> |
int x; |
| 41 |
|
|
| 42 |
< |
gtabsiz = 111*CHECKRAD*CHECKRAD/(rad*rad); |
| 42 |
> |
gtabsiz = 444*CHECKRAD*CHECKRAD; |
| 43 |
|
gausstable = (float *)malloc(gtabsiz*sizeof(float)); |
| 44 |
|
if (gausstable == NULL) |
| 45 |
|
goto memerr; |
| 46 |
|
d = x_c*y_r*0.25/(rad*rad); |
| 47 |
|
gausstable[0] = exp(-d); |
| 48 |
|
for (x = 1; x < gtabsiz; x++) |
| 49 |
< |
if (x*0.1 <= d) |
| 49 |
> |
if (x*0.05 <= d) |
| 50 |
|
gausstable[x] = gausstable[0]; |
| 51 |
|
else |
| 52 |
< |
gausstable[x] = exp(-x*0.1); |
| 52 |
> |
gausstable[x] = exp(-x*0.05); |
| 53 |
|
if (obarsize == 0) |
| 54 |
|
return; |
| 55 |
|
/* compute integral of filter */ |
| 72 |
|
ringsum = (float *)malloc((orad+1)*sizeof(float)); |
| 73 |
|
ringwt = (short *)malloc((orad+1)*sizeof(short)); |
| 74 |
|
warr = (float *)malloc(obarsize*obarsize*sizeof(float)); |
| 75 |
< |
if (ringsum == NULL | ringwt == 0 | warr == NULL) |
| 75 |
> |
if ((ringsum == NULL) | (ringwt == 0) | (warr == NULL)) |
| 76 |
|
goto memerr; |
| 77 |
|
return; |
| 78 |
|
memerr: |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
|
| 84 |
< |
dobox(csum, xcent, ycent, c, r) /* simple box filter */ |
| 85 |
< |
COLOR csum; |
| 86 |
< |
int xcent, ycent; |
| 87 |
< |
int c, r; |
| 84 |
> |
void |
| 85 |
> |
dobox( /* simple box filter */ |
| 86 |
> |
COLOR csum, |
| 87 |
> |
int xcent, |
| 88 |
> |
int ycent, |
| 89 |
> |
int c, |
| 90 |
> |
int r |
| 91 |
> |
) |
| 92 |
|
{ |
| 93 |
|
int wsum; |
| 94 |
|
double d; |
| 95 |
|
int y; |
| 96 |
< |
register int x, offs; |
| 97 |
< |
register COLOR *scan; |
| 96 |
> |
int x, offs; |
| 97 |
> |
COLOR *scan; |
| 98 |
|
|
| 99 |
|
wsum = 0; |
| 100 |
|
setcolor(csum, 0.0, 0.0, 0.0); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
< |
dogauss(csum, xcent, ycent, c, r) /* gaussian filter */ |
| 127 |
< |
COLOR csum; |
| 128 |
< |
int xcent, ycent; |
| 129 |
< |
int c, r; |
| 126 |
> |
void |
| 127 |
> |
dogauss( /* gaussian filter */ |
| 128 |
> |
COLOR csum, |
| 129 |
> |
int xcent, |
| 130 |
> |
int ycent, |
| 131 |
> |
int c, |
| 132 |
> |
int r |
| 133 |
> |
) |
| 134 |
|
{ |
| 135 |
|
double dy, dx, weight, wsum; |
| 136 |
|
COLOR ctmp; |
| 137 |
|
int y; |
| 138 |
< |
register int x, offs; |
| 139 |
< |
register COLOR *scan; |
| 138 |
> |
int x, offs; |
| 139 |
> |
COLOR *scan; |
| 140 |
|
|
| 141 |
|
wsum = FTINY; |
| 142 |
|
setcolor(csum, 0.0, 0.0, 0.0); |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
|
| 165 |
< |
dothresh(xcent, ycent, ccent, rcent) /* gaussian threshold filter */ |
| 166 |
< |
int xcent, ycent; |
| 167 |
< |
int ccent, rcent; |
| 165 |
> |
void |
| 166 |
> |
dothresh( /* gaussian threshold filter */ |
| 167 |
> |
int xcent, |
| 168 |
> |
int ycent, |
| 169 |
> |
int ccent, |
| 170 |
> |
int rcent |
| 171 |
> |
) |
| 172 |
|
{ |
| 173 |
|
double d; |
| 174 |
|
int r, y, offs; |
| 175 |
< |
register int c, x; |
| 176 |
< |
register float *gscan; |
| 175 |
> |
int c, x; |
| 176 |
> |
float *gscan; |
| 177 |
|
/* compute ring sums */ |
| 178 |
< |
bzero((char *)ringsum, (orad+1)*sizeof(float)); |
| 179 |
< |
bzero((char *)ringwt, (orad+1)*sizeof(short)); |
| 178 |
> |
memset((char *)ringsum, '\0', (orad+1)*sizeof(float)); |
| 179 |
> |
memset((char *)ringwt, '\0', (orad+1)*sizeof(short)); |
| 180 |
|
for (r = -orad; r <= orad; r++) { |
| 181 |
|
if (rcent+r < 0) continue; |
| 182 |
|
if (rcent+r >= nrows) break; |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
|
| 216 |
< |
double |
| 217 |
< |
pickfilt(p0) /* find filter multiplier for p0 */ |
| 218 |
< |
double p0; |
| 216 |
> |
static double |
| 217 |
> |
pickfilt( /* find filter multiplier for p0 */ |
| 218 |
> |
double p0 |
| 219 |
> |
) |
| 220 |
|
{ |
| 221 |
|
double m = 1.0; |
| 222 |
|
double t, num, denom, avg, wsum; |
| 223 |
|
double mlimit[2]; |
| 224 |
|
int ilimit = 4.0/TEPS; |
| 225 |
< |
register int i; |
| 225 |
> |
int i; |
| 226 |
|
/* iterative search for m */ |
| 227 |
|
mlimit[0] = 1.0; mlimit[1] = orad/rad/CHECKRAD; |
| 228 |
|
do { |
| 274 |
|
} |
| 275 |
|
|
| 276 |
|
|
| 277 |
< |
sumans(px, py, rcent, ccent, m) /* sum input pixel to output */ |
| 278 |
< |
int px, py; |
| 279 |
< |
int rcent, ccent; |
| 280 |
< |
double m; |
| 277 |
> |
static void |
| 278 |
> |
sumans( /* sum input pixel to output */ |
| 279 |
> |
int px, |
| 280 |
> |
int py, |
| 281 |
> |
int rcent, |
| 282 |
> |
int ccent, |
| 283 |
> |
double m |
| 284 |
> |
) |
| 285 |
|
{ |
| 286 |
|
double dy2, dx; |
| 287 |
|
COLOR pval, ctmp; |
| 288 |
|
int ksiz, r, offs; |
| 289 |
|
double pc, pr, norm; |
| 290 |
< |
register int i, c; |
| 291 |
< |
register COLOR *scan; |
| 290 |
> |
int i, c; |
| 291 |
> |
COLOR *scan; |
| 292 |
|
/* |
| 293 |
|
* This normalization method fails at the picture borders because |
| 294 |
|
* a different number of input pixels contribute there. |
| 327 |
|
scan = scoutbar[r%obarsize]; |
| 328 |
|
for (c = ccent-ksiz; c <= ccent+ksiz; c++) { |
| 329 |
|
offs = c < 0 ? ncols : c >= ncols ? -ncols : 0; |
| 330 |
< |
if (offs && !wrapfilt) |
| 330 |
> |
if ((offs != 0) & !wrapfilt) |
| 331 |
|
continue; |
| 332 |
|
copycolor(ctmp, pval); |
| 333 |
|
dx = norm*warr[i++]; |