diff options
Diffstat (limited to 'noao/imred/bias')
-rw-r--r-- | noao/imred/bias/Revisions | 97 | ||||
-rw-r--r-- | noao/imred/bias/bias.cl | 8 | ||||
-rw-r--r-- | noao/imred/bias/bias.hd | 7 | ||||
-rw-r--r-- | noao/imred/bias/bias.men | 2 | ||||
-rw-r--r-- | noao/imred/bias/bias.par | 3 | ||||
-rw-r--r-- | noao/imred/bias/colbias.par | 16 | ||||
-rw-r--r-- | noao/imred/bias/colbias.x | 308 | ||||
-rw-r--r-- | noao/imred/bias/doc/colbias.hlp | 113 | ||||
-rw-r--r-- | noao/imred/bias/doc/linebias.hlp | 115 | ||||
-rw-r--r-- | noao/imred/bias/linebias.par | 16 | ||||
-rw-r--r-- | noao/imred/bias/linebias.x | 330 | ||||
-rw-r--r-- | noao/imred/bias/mkpkg | 30 | ||||
-rw-r--r-- | noao/imred/bias/x_bias.x | 2 |
13 files changed, 1047 insertions, 0 deletions
diff --git a/noao/imred/bias/Revisions b/noao/imred/bias/Revisions new file mode 100644 index 00000000..6c67e622 --- /dev/null +++ b/noao/imred/bias/Revisions @@ -0,0 +1,97 @@ +.help revisions Jun88 noao.imred.bias +.nf +noao$imred/bias/colbias.x +noao$imred/bias/linebias.x +noao$imred/bias/doc/colbias.hlp +noao$imred/bias/doc/linebias.hlp + The output pixel type is now changed to real rather than preserving + the input pixel type. (3/2/93, Valdes) + +======= +V2.10.2 +======= + +noao$imred/bias/colbias.x + Valdes, January 6, 1990 + The graphics device parameter was being ignored and "stdgraph" always + opened. + +=== +V2.8 +==== + +noao$imred/bias/colbias.x,linebias.x,colbias.par,linebias.par + Davis, October 4, 1988 + 1. The parameters low_reject, high_reject and niterate have been added + to the linebias and colbias tasks which then pass them to the icfit + package. + +noao$imred/bias/linebias.x + Valdes, May, 1, 1987 + 1. The fix of December 3 was slightly wrong. + 296: ...Memr[buf2+(k-1)*n+i-1] ==> ...Memr[buf2+k*n+i-j] + 2. Increased the maximum buffer MAXPIX from 10000 to 100000. + +noao$imred/bias/colbias.x +noao$imred/bias/linebias.x + Valdes, January 15, 1986 + 1. When the bias section consists of just one column or line the + dimensionality of the mapped bias decreases. The code had to be + modified to recognize and work properly in this case. + +noao$imred/bias/linebias.x + Valdes, December, 3, 1986 + 1. There was a bug in using the median option which gave incorrect + results for the bias vector. + 291: n = min (nx - j - 1, maxn) ==> n = min (nx - j + 1, maxn) + 296: ...Memr[buf2+(k-1)*n+i-1] ==> ...Memr[buf2+(k-1)*n+i-j] + +noao$imred/bias/linebias.x + Valdes, October 29, 1986 + 1. The log information for LINEBIAS identified itself as COLBIAS. + +==================================== +Version 2.3 Release, August 18, 1986 +==================================== + +noao$imred/bias/colbias.x +noao$imred/bias/linebias.x + Valdes, July 3, 1986 + 1. COLBIAS and LINEBIAS modified to use new ICFIT package. + +========================================= +STScI Pre-release and 1st SUN 2.3 Release +========================================= + +=========== +Release 2.2 +=========== + +From Valdes Dec 12, 1985: + +1. COLBIAS and LINEBIAS changes to allow taking a median instead of an +average when generating the 1D bias data. +------ +From Valdes Dec 11, 1985: + +1. COLBIAS and LINEBIAS changed to use image templates instead of filename +templates. This allows use of the concatenation function even though the +images should not have images sections. + +2. REVS task removed. +------ +From Valdes Oct 4, 1985: + +1. Colbais and linebias recompiled because of the change in the icfit package +for low and high rejection and rejection iteration. +------ +From Valdes Aug 7, 1985: + +1. The task revisions has been added to page package revisions. +To get the system revisions type system.revisions. + +2. The parameters to linebias and colbias now include control over +the graphics output device, the graphics input cursor, and multiple logfiles. + +3. Changes have been made to use the "improved" icfit and gtools packages. +.endhelp diff --git a/noao/imred/bias/bias.cl b/noao/imred/bias/bias.cl new file mode 100644 index 00000000..18624a2c --- /dev/null +++ b/noao/imred/bias/bias.cl @@ -0,0 +1,8 @@ +#{ BIAS -- Bias Package + +package bias + +task colbias, + linebias = biasdir$x_bias.e + +clbye diff --git a/noao/imred/bias/bias.hd b/noao/imred/bias/bias.hd new file mode 100644 index 00000000..b55e1b6c --- /dev/null +++ b/noao/imred/bias/bias.hd @@ -0,0 +1,7 @@ +# Help directory for the BIAS package. + +$doc = "./doc/" + +colbias hlp=doc$colbias.hlp, src=colbias.x +linebias hlp=doc$linebias.hlp, src=linebias.x +revisions sys=Revisions diff --git a/noao/imred/bias/bias.men b/noao/imred/bias/bias.men new file mode 100644 index 00000000..7bf225d4 --- /dev/null +++ b/noao/imred/bias/bias.men @@ -0,0 +1,2 @@ + colbias - Fit and subtract an average column bias + linebias - Fit and subtract an average line bias diff --git a/noao/imred/bias/bias.par b/noao/imred/bias/bias.par new file mode 100644 index 00000000..4bdb4e20 --- /dev/null +++ b/noao/imred/bias/bias.par @@ -0,0 +1,3 @@ +# BIAS package parameter file. + +version,s,h,"May 1985" diff --git a/noao/imred/bias/colbias.par b/noao/imred/bias/colbias.par new file mode 100644 index 00000000..8c3ba4b3 --- /dev/null +++ b/noao/imred/bias/colbias.par @@ -0,0 +1,16 @@ +# COLBIAS -- Subtract a column bias + +input,s,a,,,,Input images +output,s,a,,,,Output images +bias,s,h,"[]",,,Bias section +trim,s,h,"[]",,,Trim section +median,b,h,no,,,Use median instead of average in column bias? +interactive,b,h,yes,,,Interactive? +function,s,h,"spline3","spline3|legendre|chebyshev|spline1",,Fitting function +order,i,h,1,1,,Order of fitting function +low_reject,r,h,3.0,,,Low sigma rejection factor +high_reject,r,h,3.0,,,High sigma rejection factor +niterate,i,h,1,,,Number of rejection iterations +logfiles,s,h,"",,,Log files +graphics,s,h,"stdgraph",,,Graphics output device +cursor,*gcur,h,"",,,Graphics cursor input diff --git a/noao/imred/bias/colbias.x b/noao/imred/bias/colbias.x new file mode 100644 index 00000000..f7aac840 --- /dev/null +++ b/noao/imred/bias/colbias.x @@ -0,0 +1,308 @@ +include <imhdr.h> +include <imio.h> +include <pkg/gtools.h> +include <pkg/xtanswer.h> + +# COLBIAS -- Remove line by line bias from images. +# +# A one dimensional bias vector is extracted from the bias columns. +# A function is fit to the bias vector and the function is subtracted +# from the image lines. A trim section may be specified to output +# only a part of the bias subtracted image. + +# Control procedure for mapping the images. +# +# The input and output images are given by image templates. The +# number of output images must match the number of input images. Image +# sections are not allowed. The output image may be the same as the input +# image. + +procedure colbias () + +int listin # List of input images +int listout # List of output images +int logfiles # List of log files +char biassec[SZ_FNAME] # Bias section +char trimsec[SZ_FNAME] # Trim section +int median # Use median of bias section? +int interactive # Interactive? + +char function[SZ_LINE] # Curve fitting function +int order # Order of curve fitting function + +char image[SZ_FNAME] +char input[SZ_FNAME] +char biasimage[SZ_FNAME] +char output[SZ_FNAME] +char logfile[SZ_FNAME] +char original[SZ_FNAME] +char title[SZ_LINE] + +int logfd +pointer in, bias, out, ic, gt + +int clgeti(), clpopnu(), clgfil(), open(), gt_init(), nowhite() +int imtopen(), imtlen(), imtgetim(), btoi() +bool clgetb() +long clktime() +pointer immap() +real clgetr() + +begin + # Get input and output lists and check that the number of images + # are the same. + + call clgstr ("input", title, SZ_LINE) + listin = imtopen (title) + call clgstr ("output", title, SZ_LINE) + listout = imtopen (title) + if (imtlen (listin) != imtlen (listout)) { + call imtclose (listin) + call imtclose (listout) + call error (0, "Input and output image lists do not match") + } + + # Get the bias and trim sections. + + call clgstr ("bias", biassec, SZ_FNAME) + call clgstr ("trim", trimsec, SZ_FNAME) + if (nowhite (biassec, biassec, SZ_FNAME) == 0) + ; + if (nowhite (trimsec, trimsec, SZ_FNAME) == 0) + ; + median = btoi (clgetb ("median")) + + # Determine if the task is interactive. If not set the interactive + # flag to always no. + + if (clgetb ("interactive")) + interactive = YES + else + interactive = ALWAYSNO + + # Initialize the curve fitting package. + + call ic_open (ic) + call clgstr ("function", function, SZ_LINE) + call ic_pstr (ic, "function", function) + order = clgeti ("order") + call ic_puti (ic, "order", order) + call ic_putr (ic, "low", clgetr ("low_reject")) + call ic_putr (ic, "high", clgetr ("high_reject")) + call ic_puti (ic, "niterate", clgeti ("niterate")) + call ic_pstr (ic, "xlabel", "Line") + call ic_pstr (ic, "ylabel", "Bias") + + gt = gt_init () + call gt_sets (gt, GTTYPE, "line") + + # Get the log files. + + logfiles = clpopnu ("logfiles") + + # For each input and output image map the bias image, the + # trimmed input image, and the output image. Use a temporary + # image header for overwritting the input image. + + while ((imtgetim (listin, image, SZ_FNAME) != EOF) && + (imtgetim (listout, output, SZ_FNAME) != EOF)) { + + call sprintf (biasimage, SZ_FNAME, "%s%s") + call pargstr (image) + call pargstr (biassec) + call sprintf (input, SZ_FNAME, "%s%s") + call pargstr (image) + call pargstr (trimsec) + + in = immap (input, READ_ONLY, 0) + bias = immap (biasimage, READ_ONLY, 0) + call xt_mkimtemp (image, output, original, SZ_FNAME) + out = immap (output, NEW_COPY, in) + IM_PIXTYPE(out) = TY_REAL + + call sprintf (title, SZ_LINE, "colbias %s") + call pargstr (image) + call xt_answer (title, interactive) + call gt_sets (gt, GTTITLE, title) + + # Enter log header. + + while (clgfil (logfiles, logfile, SZ_FNAME) != EOF) { + logfd = open (logfile, APPEND, TEXT_FILE) + call cnvtime (clktime (0), title, SZ_LINE) + call fprintf (logfd, "\nCOLBIAS: %s\n") + call pargstr (title) + call fprintf (logfd, "input = %s\noutput = %s\nbias = %s\n") + call pargstr (input) + call pargstr (output) + call pargstr (biasimage) + if (median == YES) + call fprintf (logfd, "Median of bias section used.\n") + call close (logfd) + } + call clprew (logfiles) + + call cb_colbias (in, bias, out, ic, gt, median, logfiles, + interactive) + + call imunmap (in) + call imunmap (bias) + call imunmap (out) + call xt_delimtemp (output, original) + } + + call ic_closer (ic) + call gt_free (gt) + call clpcls (logfiles) + call imtclose (listin) + call imtclose (listout) +end + + +# CB_COLBIAS -- Get an average column bias vector from the bias image. +# Fit a function to the bias vector and subtract it from the input image +# to form the output image. Line coordinates are in terms of the full +# input image. + +procedure cb_colbias (in, bias, out, ic, gt, median, logfiles, interactive) + +pointer in # Input image pointer +pointer bias # Bias image pointer +pointer out # Output image pointer +pointer ic # ICFIT pointer +pointer gt # GTOOLS pointer +int median # Median of bias section? +int logfiles # List of log files +int interactive # Interactive curve fitting? + +char graphics[SZ_FNAME] # Graphics output device +char logfile[SZ_FNAME] +int i, nbias, nx, ny, ydim, yoff, ystep, ylen +real y, z +pointer cv, gp, sp, ybias, zbias, wts + +int clgfil() +real cveval() +pointer gopen(), imgl2r(), impl2r() + +begin + # The bias coordinates are in terms of the full input image because + # the input and bias images may have different sections. + + nx = IM_LEN(in, 1) + ny = IM_LEN(in, 2) + + ydim = IM_VMAP(in, 2) + yoff = IM_VOFF(in, ydim) + ystep = IM_VSTEP(in, ydim) + ylen = IM_SVLEN(in, ydim) + + # Get the bias vector and set the weights. + + call cb_getcolbias (bias, ybias, zbias, nbias, median) + call smark (sp) + call salloc (wts, nbias, TY_REAL) + call amovkr (1., Memr[wts], nbias) + + # Do the curve fitting using the interactive curve fitting package. + # Free memory when the fit is complete. + + call ic_putr (ic, "xmin", 1.) + call ic_putr (ic, "xmax", real (ylen)) + if ((interactive == YES) || (interactive == ALWAYSYES)) { + call clgstr ("graphics", graphics, SZ_FNAME) + gp = gopen (graphics, NEW_FILE, STDGRAPH) + call gt_setr (gt, GTXMIN, 1.) + call gt_setr (gt, GTXMAX, real (ylen)) + call icg_fit (ic, gp, "cursor", gt, cv, Memr[ybias], Memr[zbias], + Memr[wts], nbias) + call gclose (gp) + } else { + call ic_fit (ic, cv, Memr[ybias], Memr[zbias], Memr[wts], nbias, + YES, YES, YES, YES) + } + + # Log the fitting information. + + while (clgfil (logfiles, logfile, SZ_FNAME) != EOF) { + call ic_show (ic, logfile, gt) + call ic_errors (ic, logfile, cv, Memr[ybias], Memr[zbias], + Memr[wts], nbias) + } + call clprew (logfiles) + + call mfree (ybias, TY_REAL) + call mfree (zbias, TY_REAL) + call sfree (sp) + + # Subtract the bias function from the input image. + + do i = 1, ny { + y = yoff + i * ystep + z = cveval (cv, y) + call asubkr (Memr[imgl2r(in,i)], z, Memr[impl2r(out,i)], nx) + } + + # Free curve fitting memory. + + call cvfree (cv) +end + + +# CB_GETCOLBIAS -- Get the column bias vector. +# The ybias line values are in terms of the full image. + +procedure cb_getcolbias (bias, ybias, zbias, nbias, median) + +pointer bias # Bias image pointer +pointer ybias, zbias # Bias vector +int nbias # Number of bias points +int median # Median of bias section? + +int i, nx, ny, ydim, yoff, ystep + +real amedr(), asumr() +pointer imgl1r(), imgl2r() + +begin + # Check for a bias consisting of a single column which is turned + # into a 1D image by IMIO. + if (IM_NDIM(bias) == 1) { + ny = IM_LEN(bias, 1) + ydim = IM_VMAP(bias, 1) + yoff = IM_VOFF(bias, ydim) + ystep = IM_VSTEP(bias, ydim) + + nbias = ny + call malloc (ybias, nbias, TY_REAL) + call malloc (zbias, nbias, TY_REAL) + + do i = 1, nbias + Memr[ybias+i-1] = yoff + i * ystep + call amovr (Memr[imgl1r(bias)], Memr[zbias], nbias) + + return + } + + nx = IM_LEN(bias, 1) + ny = IM_LEN(bias, 2) + ydim = IM_VMAP(bias, 2) + yoff = IM_VOFF(bias, ydim) + ystep = IM_VSTEP(bias, ydim) + + nbias = ny + call malloc (ybias, nbias, TY_REAL) + call malloc (zbias, nbias, TY_REAL) + + if (median == YES) { + do i = 1, ny { + Memr[ybias+i-1] = yoff + i * ystep + Memr[zbias+i-1] = amedr (Memr[imgl2r(bias,i)], nx) + } + } else { + do i = 1, ny { + Memr[ybias+i-1] = yoff + i * ystep + Memr[zbias+i-1] = asumr (Memr[imgl2r(bias,i)], nx) / nx + } + } +end diff --git a/noao/imred/bias/doc/colbias.hlp b/noao/imred/bias/doc/colbias.hlp new file mode 100644 index 00000000..a95e4694 --- /dev/null +++ b/noao/imred/bias/doc/colbias.hlp @@ -0,0 +1,113 @@ +.help colbias Mar93 noao.imred.bias +.ih +NAME +colbias -- Fit and subtract an average column bias +.ih +USAGE +.nf +colbias input output +.fi +.ih +PARAMETERS +.ls input +Images to be bias subtracted. The images may not contain image sections. +.le +.ls output +Output bias subtracted images. An output images may be the same as its +matching input image. The output pixel type will be real regardless +of the input pixel type. +.le +.ls bias = "[]" +Bias section appended to the input image to define the bias region. +The default section or an empty string will use the full image. +.le +.ls trim = "[]" +Trim section appended to the input image to define the region to be +bias subtracted and output. The default section or an empty string +will use the full image. +.le +.ls median = no +Take the median of the bias columns? If no then the bias +columns are averaged. +.le +.ls function = "spline3" +The function fit to the average bias line. The functions are "legendre", +"chebyshev", "spline1", or "spline3". Abbreviations are allowed. +.le +.ls order +The order (number of terms or number of spline pieces) in the function. +.le +.ls low_reject = 3.0 +The low sigma rejection factor. +.le +.ls high_reject = 3.0 +The high sigma rejection factor. +.le +.ls niterate = 1 +The maximum number of rejection iterations. +.le +.ls interactive = yes +Fit the average bias line interactively? +.le +.ls logfiles = "" +List of log files. If no file name is given then no log file is kept. +.le +.ls graphics = "stdgraph" +Graphics output device for interactive graphics. +.le +.ls cursor = "" +Graphics cursor input +.le +.ih +DESCRIPTION +For each input image in the input image list an average or median bias +column is determined from the bias region. The bias region is defined by +the bias section applied to the input image. A function of the image lines +is fit to the average bias column. This function is subtracted from each +image column in the trim region. The trim region is defined by the trim +section applied to the input image. The bias subtracted and trimmed image +is output to the output image. The input and output images may not contain +sections and the number of images in each list must be the same. + +If the interactive flag is set then the user may interactively examine +and fit the average bias column. The interactive fitting is done using the +interactive curve fitting routine (see icfit). Before each image is +processed a prompt of the form "colbias image (yes)? " is given. +A response of yes allows interactive fitting for the specified image +while a response of no uses the last defined fitting parameters. +The default value is accepted with a carriage return. The possible +responses are "yes", "no", "YES", or "NO". The capitalized responses +permanently set the response to yes or no and the prompt is not +issued again for the remaining images. Thus, a response of NO processes +the remaining images non-interactively while a response of YES processes +the remaining image interactively without prompting. +.ih +EXAMPLES +The bias region for a set of images occupies columns 801 to 832 and lines +1 to 800. To subtract the bias and remove the bias region: + +.nf + cl> colbias.bias = "[801:832,*]" + cl> colbias.trim = "[1:800,*]" + cl> colbias ccd* ccd* + colbias ccd001 (yes)? yes + colbias ccd002 (yes)? + colbias ccd003 (no)? NO +.fi + +The first two lines set the bias and trim parameters. These parameters +could be temporarily set on the command line but generally these parameters +are only changed when new instruments are used. The first image +is interactively fit and the fitting order is change to 2. The +second image is examined and the fit found to be acceptable. All remaining +image are then fit non-interactively using the same fitting parameters. +.ih +REVISIONS +.ls COLBIAS V2.10.3 +The output pixel type is now real instead of preserving the pixel type +of the input image. +.le +.ih +SEE ALSO +icfit +.endhelp diff --git a/noao/imred/bias/doc/linebias.hlp b/noao/imred/bias/doc/linebias.hlp new file mode 100644 index 00000000..6c5d73a5 --- /dev/null +++ b/noao/imred/bias/doc/linebias.hlp @@ -0,0 +1,115 @@ +.help linebias Mar93 noao.imred.bias +.ih +NAME +linebias -- Fit and subtract an average line bias +.ih +USAGE +.nf +linebias input output +.fi +.ih +PARAMETERS +.ls input +Images to be bias subtracted. The images may not contain image sections. +.le +.ls output +Output bias subtracted images. An output images may be the same as its +matching input image. The output image pixel type will real regardless +of the input image pixel type. +.le +.ls bias = "[]" +Bias section appended to the input image to define the bias region. +The default section or an empty string will use the full image. +.le +.ls trim = "[]" +Trim section appended to the input image to define the region to be +bias subtracted and output. The default section or an empty string +will use the full image. +.le +.ls median = no +Take the median of the bias lines? If no then the bias lines are averaged. +.le +.ls function = "spline3" +The function fit to the average bias line. The functions are "legendre", +"chebyshev", "spline1", or "spline3". Abbreviations are allowed. +.le +.ls order +The order (number of terms or number of spline pieces) in the function. +.le +.ls low_reject = 3.0 +The low sigma rejection factor. +.le +.ls high_reject = 3.0 +The high sigma rejection factor. +.le +.ls niterate = 1 +The maximum number of rejection iterations. +.le +.ls interactive = yes +Fit the average bias line interactively? +.le +.ls logfile = "" +Name of a log file. If no file name is given then no log file is kept. +.le +.ls logfiles = "" +List of log files. If no file name is given then no log file is kept. +.le +.ls graphics = "stdgraph" +Graphics output device for interactive graphics. +.le +.ls cursor = "" +Graphics cursor input +.le +.ih +DESCRIPTION +For each input image in the input image list an average or median bias line +is determined from the bias region. The bias region +is defined by the bias section applied to the input image. A function of +the image columns is fit to the average bias line. This function is subtracted +from each image line in the trim region. The trim region is defined by the +trim section applied to the input image. The bias subtracted and trimmed +image is output to the output image. The input and output images may not +contain sections and the number of images in each list must be the same. + +If the interactive flag is set then the user may interactively examine +and fit the average bias line. The interactive fitting is done using the +interactive curve fitting routine (see icfit). Before each image is +processed a prompt of the form "linebias image (yes)? " is given. +A response of yes allows interactive fitting for the specified image +while a response of no uses the last defined fitting parameters. +The default value is accepted with a carriage return. The possible +responses are "yes", "no", "YES", or "NO". The capitalized responses +permanently set the response to yes or no and the prompt is not +issued again for the remaining images. Thus, a response of NO processes +the remaining images non-interactively while a response of YES processes +the remaining image interactively without prompting. +.ih +EXAMPLES +The bias region for a set of images occupies columns 1 to 800 and lines +801 to 832. To subtract the bias and remove the bias region: + +.nf + cl> linebias.bias = "[*, 801:832]" + cl> linebias.trim = "[*, 1:800]" + cl> linebias ccd* ccd* + linebias ccd001 (yes)? yes + linebias ccd002 (yes)? + linebias ccd003 (no)? NO +.fi + +The first two lines set the bias and trim parameters. These parameters +could be temporarily set on the command line but generally these parameters +are only changed when new instruments are used. The first image +is interactively fit and the fitting order is change to 2. The +second image is examined and the fit found to be acceptable. All remaining +image are then fit non-interactively using the same fitting parameters. +.ih +REVISIONS +.ls LINEBIAS V2.10.3 +The output pixel type is now real instead of preserving the pixel type +of the input image. +.le +.ih +SEE ALSO +icfit +.endhelp diff --git a/noao/imred/bias/linebias.par b/noao/imred/bias/linebias.par new file mode 100644 index 00000000..a056f02d --- /dev/null +++ b/noao/imred/bias/linebias.par @@ -0,0 +1,16 @@ +# LINEBIAS -- Subtract a line bias + +input,s,a,,,,Input images +output,s,a,,,,Output images +bias,s,h,"[]",,,Bias section +trim,s,h,"[]",,,Trim section +median,b,h,no,,,Use median instead of average in line bias? +interactive,b,h,yes,,,Interactive? +function,s,h,"spline3","spline3|legendre|chebyshev|spline1",,Fitting function +order,i,h,1,1,,Order of fitting function +low_reject,r,h,3.0,,,Low sigma rejection factor +high_reject,r,h,3.0,,,High sigma rejection factor +niterate,i,h,1,,,Number of rejection iterations +logfiles,s,h,"",,,Log files +graphics,s,h,"stdgraph",,,Graphics output device +cursor,*gcur,h,"",,,Graphics cursor input diff --git a/noao/imred/bias/linebias.x b/noao/imred/bias/linebias.x new file mode 100644 index 00000000..91d789af --- /dev/null +++ b/noao/imred/bias/linebias.x @@ -0,0 +1,330 @@ +include <imhdr.h> +include <imio.h> +include <pkg/gtools.h> +include <pkg/xtanswer.h> + +# LINEBIAS -- Remove column by column bias from images. +# +# A one dimensional bias vector is extracted from the bias lines. +# A function is fit to the bias vector and the function is subtracted +# from the image columns. A trim section may be specified to output +# only a part of the bias subtracted image. + +# Control procedure for mapping the images. +# +# The input and output images are given by image templates. The +# number of output images must match the number of input images. Image +# sections are not allowed. The output image may be the same as the input +# image. + +procedure linebias () + +int listin # List of input images +int listout # List of output images +int logfiles # List of log files +char biassec[SZ_FNAME] # Bias section +char trimsec[SZ_FNAME] # Trim section +int median # Median of bias section? +int interactive # Interactive? + +char function[SZ_LINE] # Curve fitting function +int order # Order of curve fitting function + +char image[SZ_FNAME] +char input[SZ_FNAME] +char biasimage[SZ_FNAME] +char output[SZ_FNAME] +char logfile[SZ_FNAME] +char original[SZ_FNAME] +char title[SZ_LINE] + +int logfd +pointer in, bias, out, ic, gt + +int clgeti(), clpopnu(), clgfil(), open(), gt_init(), nowhite() +int imtopen(), imtlen(), imtgetim(), btoi() +bool clgetb() +long clktime() +pointer immap() +real clgetr() + +begin + # Get input and output lists and check that the number of images + # are the same. + + call clgstr ("input", title, SZ_LINE) + listin = imtopen (title) + call clgstr ("output", title, SZ_LINE) + listout = imtopen (title) + if (imtlen (listin) != imtlen (listout)) { + call imtclose (listin) + call imtclose (listout) + call error (0, "Input and output image lists do not match") + } + + # Get the bias and trim sections. + + call clgstr ("bias", biassec, SZ_FNAME) + call clgstr ("trim", trimsec, SZ_FNAME) + if (nowhite (biassec, biassec, SZ_FNAME) == 0) + ; + if (nowhite (trimsec, trimsec, SZ_FNAME) == 0) + ; + median = btoi (clgetb ("median")) + + # Determine if the task is interactive. If not set the interactive + # flag to always no. + + if (clgetb ("interactive")) + interactive = YES + else + interactive = ALWAYSNO + + # Initialize the curve fitting package. + + call ic_open (ic) + call clgstr ("function", function, SZ_LINE) + call ic_pstr (ic, "function", function) + order = clgeti ("order") + call ic_puti (ic, "order", order) + call ic_putr (ic, "low", clgetr ("low_reject")) + call ic_putr (ic, "high", clgetr ("high_reject")) + call ic_puti (ic, "niterate", clgeti ("niterate")) + call ic_pstr (ic, "xlabel", "Column") + call ic_pstr (ic, "ylabel", "Bias") + + gt = gt_init() + call gt_sets (gt, GTTYPE, "line") + + # Get the list of log files. + + logfiles = clpopnu ("logfiles") + + # For each input and output image map the bias image, the + # trimmed input image, and the output image. Use a temporary + # image header for overwritting the input image. + + while ((imtgetim (listin, image, SZ_FNAME) != EOF) && + (imtgetim (listout, output, SZ_FNAME) != EOF)) { + + call sprintf (biasimage, SZ_FNAME, "%s%s") + call pargstr (image) + call pargstr (biassec) + call sprintf (input, SZ_FNAME, "%s%s") + call pargstr (image) + call pargstr (trimsec) + + in = immap (input, READ_ONLY, 0) + bias = immap (biasimage, READ_ONLY, 0) + call xt_mkimtemp (image, output, original, SZ_FNAME) + out = immap (output, NEW_COPY, in) + IM_PIXTYPE(out) = TY_REAL + + call sprintf (title, SZ_LINE, "linebias %s") + call pargstr (image) + call xt_answer (title, interactive) + call gt_sets (gt, GTTITLE, title) + + # Enter a header in the log file. + + while (clgfil (logfiles, logfile, SZ_FNAME) != EOF) { + logfd = open (logfile, APPEND, TEXT_FILE) + call cnvtime (clktime (0), title, SZ_LINE) + call fprintf (logfd, "\nLINEBIAS: %s\n") + call pargstr (title) + call fprintf (logfd, "input = %s\noutput = %s\nbias = %s\n") + call pargstr (input) + call pargstr (output) + call pargstr (biasimage) + if (median == YES) + call fprintf (logfd, "Median of bias section used.\n") + call close (logfd) + } + call clprew (logfiles) + + call lb_linebias (in, bias, out, ic, gt, median, logfiles, + interactive) + + call imunmap (in) + call imunmap (bias) + call imunmap (out) + call xt_delimtemp (output, original) + } + + call ic_closer (ic) + call gt_free (gt) + call clpcls (logfiles) + call imtclose (listin) + call imtclose (listout) +end + + +# LB_LINEBIAS -- Get an average line bias vector from the bias image. +# Fit a function to the bias vector and subtract it from the input image +# to form the output image. Column coordinates are in terms of the full +# input image. + +procedure lb_linebias (in, bias, out, ic, gt, median, logfiles, interactive) + +pointer in # Input image pointer +pointer bias # Bias image pointer +pointer out # Output image pointer +pointer ic # ICFIT pointer +pointer gt # GTOOLS pointer +int median # Median of bias section? +int logfiles # List of log files +int interactive # Interactive curve fitting? + +char graphics[SZ_FNAME] # Graphics output device +char logfile[SZ_FNAME] +int i, nbias, nx, ny, xdim, xoff, xstep, xlen +real x +pointer cv, gp, sp, xbias, zbias, wts, z + +int clgfil() +real cveval() +pointer gopen(), imgl2r(), impl2r() + +begin + # The bias coordinates are in terms of the full input image because + # the input and bias images may have different sections. + + nx = IM_LEN(in, 1) + ny = IM_LEN(in, 2) + + xdim = IM_VMAP(in, 1) + xoff = IM_VOFF(in, xdim) + xstep = IM_VSTEP(in, xdim) + xlen = IM_SVLEN(in, xdim) + + # Get the bias vector and set the weights. + + call lb_getlinebias (bias, xbias, zbias, nbias, median) + call smark (sp) + call salloc (wts, nbias, TY_REAL) + call amovkr (1., Memr[wts], nbias) + + # Do the curve fitting using the interactive curve fitting package. + # Free memory when the fit is complete. + + call ic_putr (ic, "xmin", 1.) + call ic_putr (ic, "xmax", real (xlen)) + if ((interactive == YES) || (interactive == ALWAYSYES)) { + call clgstr ("graphics", graphics, SZ_FNAME) + gp = gopen (graphics, NEW_FILE, STDGRAPH) + call gt_setr (gt, GTXMIN, 1.) + call gt_setr (gt, GTXMAX, real (xlen)) + call icg_fit (ic, gp, "cursor", gt, cv, Memr[xbias], Memr[zbias], + Memr[wts], nbias) + call gclose (gp) + } else { + call ic_fit (ic, cv, Memr[xbias], Memr[zbias], Memr[wts], nbias, + YES, YES, YES, YES) + } + + # Log the fitting information. + + while (clgfil (logfiles, logfile, SZ_FNAME) != EOF) { + call ic_show (ic, logfile, gt) + call ic_errors (ic, logfile, cv, Memr[xbias], Memr[zbias], + Memr[wts], nbias) + } + call clprew (logfiles) + + call mfree (xbias, TY_REAL) + call mfree (zbias, TY_REAL) + call sfree (sp) + + # Subtract the bias function from the input image.. + + call smark (sp) + call salloc (z, nx, TY_REAL) + do i = 1, nx { + x = xoff + i * xstep + Memr[z+i-1] = cveval (cv, x) + } + + do i = 1, ny + call asubr (Memr[imgl2r(in,i)], Memr[z], Memr[impl2r(out,i)], nx) + + # Free allocated memory. + + call cvfree (cv) + call sfree (sp) +end + + +# LB_GETLINEBIAS -- Get the line bias vector. +# The xbias column values are in terms of the full image. + +define MAXPIX 100000 # Maximum number of pixels to buffer + +procedure lb_getlinebias (bias, xbias, zbias, nbias, median) + +pointer bias # Bias image pointer +pointer xbias, zbias # Bias vector +int nbias # Number of bias points +int median # Median of bias section? + +int i, j, k, n, nx, ny, xdim, xoff, xstep, maxn +pointer buf1, buf2 + +real amedr() +pointer imgl1r(), imgl2r(), imgs2r() + +begin + # Check for a bias consisting of a single line which is turned + # into a 1D image by IMIO. + if (IM_NDIM(bias) == 1) { + nx = IM_LEN(bias, 1) + xdim = IM_VMAP(bias, 1) + xoff = IM_VOFF(bias, xdim) + xstep = IM_VSTEP(bias, xdim) + + nbias = nx + call malloc (xbias, nbias, TY_REAL) + call malloc (zbias, nbias, TY_REAL) + + do i = 1, nbias + Memr[xbias+i-1] = xoff + i * xstep + call amovr (Memr[imgl1r(bias)], Memr[zbias], nbias) + + return + } + + nx = IM_LEN(bias, 1) + ny = IM_LEN(bias, 2) + xdim = IM_VMAP(bias, 1) + xoff = IM_VOFF(bias, xdim) + xstep = IM_VSTEP(bias, xdim) + + nbias = nx + call malloc (xbias, nbias, TY_REAL) + call calloc (zbias, nbias, TY_REAL) + + if (median == NO) { + do i = 1, ny + call aaddr (Memr[imgl2r(bias,i)], Memr[zbias], Memr[zbias], nx) + call adivkr (Memr[zbias], real (ny), Memr[zbias], nx) + } else { + call malloc (buf1, ny, TY_REAL) + + maxn = MAXPIX / ny + j = 1 + do i = 1, nx { + if (i == j) { + n = min (nx - j + 1, maxn) + buf2 = imgs2r (bias, j, j + n - 1, 1, ny) + j = j + n + } + do k = 1, ny + Memr[buf1+k-1] = Memr[buf2+k*n+i-j] + Memr[zbias+i-1] = amedr (Memr[buf1], ny) + } + + call mfree (buf1, TY_REAL) + } + + do i = 1, nx + Memr[xbias+i-1] = xoff + i * xstep +end diff --git a/noao/imred/bias/mkpkg b/noao/imred/bias/mkpkg new file mode 100644 index 00000000..fefd744a --- /dev/null +++ b/noao/imred/bias/mkpkg @@ -0,0 +1,30 @@ +# Make the BIAS package. + +$call relink +$exit + +update: + $call relink + $call install + ; + +relink: + $update libpkg.a + $call bias + ; + +install: + $move x_bias1.e noaobin$x_bias.e + ; + +bias: + $omake x_bias.x + $link x_bias.o libpkg.a -lxtools -lcurfit -o x_bias1.e + ; + +libpkg.a: + colbias.x <imhdr.h> <imio.h> <pkg/xtanswer.h>\ + <pkg/gtools.h> + linebias.x <imhdr.h> <imio.h> <pkg/xtanswer.h>\ + <pkg/gtools.h> + ; diff --git a/noao/imred/bias/x_bias.x b/noao/imred/bias/x_bias.x new file mode 100644 index 00000000..e0ade131 --- /dev/null +++ b/noao/imred/bias/x_bias.x @@ -0,0 +1,2 @@ +task colbias, + linebias |