| Line 7... |
Line 7... |
*
|
*
|
* Author: E.BERTIN (IAP)
|
* Author: E.BERTIN (IAP)
|
*
|
*
|
* Contents: functions dealing with background computation.
|
* Contents: functions dealing with background computation.
|
*
|
*
|
* Last modify: 16/08/2006
|
* Last modify: 27/10/2008
|
*
|
*
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
*/
|
*/
|
|
|
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
| Line 127... |
Line 127... |
if (!nlines)
|
if (!nlines)
|
{
|
{
|
/*---- The image is small enough so that we can make exhaustive stats */
|
/*---- The image is small enough so that we can make exhaustive stats */
|
if (j == ny-1 && field->npix%bufsize)
|
if (j == ny-1 && field->npix%bufsize)
|
bufsize = field->npix%bufsize;
|
bufsize = field->npix%bufsize;
|
readdata(field, buf, bufsize);
|
read_body(field->tab, buf, bufsize);
|
if (wfield)
|
if (wfield)
|
{
|
{
|
readdata(wfield, wbuf, bufsize);
|
read_body(wfield->tab, wbuf, bufsize);
|
weight_to_var(wfield, wbuf, bufsize);
|
weight_to_var(wfield, wbuf, bufsize);
|
}
|
}
|
/*---- Build the histograms */
|
/*---- Build the histograms */
|
backstat(backmesh, wbackmesh, buf, wbuf, bufsize,nx, w, bw,
|
backstat(backmesh, wbackmesh, buf, wbuf, bufsize,nx, w, bw,
|
wfield?wfield->weight_thresh:0.0);
|
wfield?wfield->weight_thresh:0.0);
|
| Line 183... |
Line 183... |
QFSEEK(field->file, bufshift*(OFF_T)field->bytepix, SEEK_CUR,
|
QFSEEK(field->file, bufshift*(OFF_T)field->bytepix, SEEK_CUR,
|
field->filename);
|
field->filename);
|
buft = buf;
|
buft = buf;
|
for (i=nlines; i--; buft += w)
|
for (i=nlines; i--; buft += w)
|
{
|
{
|
readdata(field, buft, w);
|
read_body(field->tab, buft, w);
|
if (i)
|
if (i)
|
QFSEEK(field->file, jumpsize*(OFF_T)field->bytepix, SEEK_CUR,
|
QFSEEK(field->file, jumpsize*(OFF_T)field->bytepix, SEEK_CUR,
|
field->filename);
|
field->filename);
|
}
|
}
|
|
|
| Line 197... |
Line 197... |
QFSEEK(wfield->file, bufshift*(OFF_T)wfield->bytepix, SEEK_CUR,
|
QFSEEK(wfield->file, bufshift*(OFF_T)wfield->bytepix, SEEK_CUR,
|
wfield->filename);
|
wfield->filename);
|
wbuft = wbuf;
|
wbuft = wbuf;
|
for (i=nlines; i--; wbuft += w)
|
for (i=nlines; i--; wbuft += w)
|
{
|
{
|
readdata(wfield, wbuft, w);
|
read_body(wfield->tab, wbuft, w);
|
weight_to_var(wfield, wbuft, w);
|
weight_to_var(wfield, wbuft, w);
|
if (i)
|
if (i)
|
QFSEEK(wfield->file, jumpsize*(OFF_T)wfield->bytepix, SEEK_CUR,
|
QFSEEK(wfield->file, jumpsize*(OFF_T)wfield->bytepix, SEEK_CUR,
|
wfield->filename);
|
wfield->filename);
|
}
|
}
|
| Line 228... |
Line 228... |
/*---- Build (progressively this time) the histograms */
|
/*---- Build (progressively this time) the histograms */
|
for(size=meshsize, bufsize2=bufsize; size>0; size -= bufsize2)
|
for(size=meshsize, bufsize2=bufsize; size>0; size -= bufsize2)
|
{
|
{
|
if (bufsize2>size)
|
if (bufsize2>size)
|
bufsize2 = size;
|
bufsize2 = size;
|
readdata(field, buf, bufsize2);
|
read_body(field->tab, buf, bufsize2);
|
if (wfield)
|
if (wfield)
|
{
|
{
|
readdata(wfield, wbuf, bufsize2);
|
read_body(wfield->tab, wbuf, bufsize2);
|
weight_to_var(wfield, wbuf, bufsize2);
|
weight_to_var(wfield, wbuf, bufsize2);
|
}
|
}
|
backhisto(backmesh, wbackmesh, buf, wbuf, bufsize2, nx, w, bw,
|
backhisto(backmesh, wbackmesh, buf, wbuf, bufsize2, nx, w, bw,
|
wfield?wfield->weight_thresh:0.0);
|
wfield?wfield->weight_thresh:0.0);
|
}
|
}
|
| Line 674... |
Line 674... |
void filterback(picstruct *field)
|
void filterback(picstruct *field)
|
|
|
{
|
{
|
float *back,*sigma, *back2,*sigma2, *bmask,*smask, *sigmat,
|
float *back,*sigma, *back2,*sigma2, *bmask,*smask, *sigmat,
|
d2,d2min, fthresh, med, val,sval;
|
d2,d2min, fthresh, med, val,sval;
|
int i,j,px,py, np, nx,ny, npxm,npxp, npym,npyp, dpx,dpy, x,y, nmin;
|
int i,j,px,py, np, nx,ny, npx,npx2, npy,npy2, dpx,dpy, x,y, nmin;
|
|
|
fthresh = prefs.backfthresh;
|
fthresh = prefs.backfthresh;
|
nx = field->nbackx;
|
nx = field->nbackx;
|
ny = field->nbacky;
|
ny = field->nbacky;
|
np = field->nback;
|
np = field->nback;
|
npxm = field->nbackfx/2;
|
npx = field->nbackfx/2;
|
npxp = field->nbackfx - npxm;
|
npy = field->nbackfy/2;
|
npym = field->nbackfy/2;
|
npy *= nx;
|
npyp = field->nbackfy - npym;
|
|
npym *= nx;
|
|
npyp *= nx;
|
|
|
|
QMALLOC(bmask, float, field->nbackfx*field->nbackfy);
|
QMALLOC(bmask, float, (2*npx+1)*(2*npy+1));
|
QMALLOC(smask, float, field->nbackfx*field->nbackfy);
|
QMALLOC(smask, float, (2*npx+1)*(2*npy+1));
|
QMALLOC(back2, float, np);
|
QMALLOC(back2, float, np);
|
QMALLOC(sigma2, float, np);
|
QMALLOC(sigma2, float, np);
|
|
|
back = field->back;
|
back = field->back;
|
sigma = field->sigma;
|
sigma = field->sigma;
|
| Line 730... |
Line 727... |
}
|
}
|
memcpy(back, back2, (size_t)np*sizeof(float));
|
memcpy(back, back2, (size_t)np*sizeof(float));
|
|
|
/* Do the actual filtering */
|
/* Do the actual filtering */
|
for (py=0; py<np; py+=nx)
|
for (py=0; py<np; py+=nx)
|
|
{
|
|
npy2 = np - py - nx;
|
|
if (npy2>npy)
|
|
npy2 = npy;
|
|
if (npy2>py)
|
|
npy2 = py;
|
for (px=0; px<nx; px++)
|
for (px=0; px<nx; px++)
|
{
|
{
|
|
npx2 = nx - px - 1;
|
|
if (npx2>npx)
|
|
npx2 = npx;
|
|
if (npx2>px)
|
|
npx2 = px;
|
i=0;
|
i=0;
|
for (dpy = -npym; dpy< npyp; dpy+=nx)
|
for (dpy = -npy2; dpy<=npy2; dpy+=nx)
|
for (dpx = -npxm; dpx < npxp; dpx++)
|
|
{
|
{
|
y = py+dpy;
|
y = py+dpy;
|
x = px+dpx;
|
for (dpx = -npx2; dpx <= npx2; dpx++)
|
if (y>=0 && y<np && x>=0 && x<nx)
|
|
{
|
{
|
|
x = px+dpx;
|
bmask[i] = back[x+y];
|
bmask[i] = back[x+y];
|
smask[i++] = sigma[x+y];
|
smask[i++] = sigma[x+y];
|
}
|
}
|
}
|
}
|
if (fabs((med=hmedian(bmask, i))-back[px+py])>=fthresh)
|
if (fabs((med=hmedian(bmask, i))-back[px+py])>=fthresh)
|
| Line 755... |
Line 762... |
{
|
{
|
back2[px+py] = back[px+py];
|
back2[px+py] = back[px+py];
|
sigma2[px+py] = sigma[px+py];
|
sigma2[px+py] = sigma[px+py];
|
}
|
}
|
}
|
}
|
|
}
|
|
|
free(bmask);
|
free(bmask);
|
free(smask);
|
free(smask);
|
memcpy(back, back2, np*sizeof(float));
|
memcpy(back, back2, np*sizeof(float));
|
field->backmean = hmedian(back2, np);
|
field->backmean = hmedian(back2, np);
|