From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- noao/imred/generic/normalize.cl | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 noao/imred/generic/normalize.cl (limited to 'noao/imred/generic/normalize.cl') diff --git a/noao/imred/generic/normalize.cl b/noao/imred/generic/normalize.cl new file mode 100644 index 00000000..59290c1c --- /dev/null +++ b/noao/imred/generic/normalize.cl @@ -0,0 +1,79 @@ +# NORMALIZE -- Compute the average of a sample region and normalize. + +procedure normalize (images) + +string images {prompt="Images to be normalized"} +real norm = INDEF {prompt="Normalization value"} +string sample_section = "[]" {prompt="Sample section"} +real lower = INDEF {prompt="Lower limit of data values for sampling"} +real upper = INDEF {prompt="Upper limit of data values for sampling"} +bool keeplog = ")_.keeplog" {prompt="Keep log of processing?"} +file logfile = ")_.logfile" {prompt="Log file"} + +struct *imfd + +begin + file imlist, input, tmp + real mean + int stat + bool mef + + mef = no + + # Query parameters. + input = images + + # Set temporary files. + imlist = mktemp ("tmp$ims") + tmp = mktemp ("tmp") + + # Startup message. + if (keeplog) { + time (>> logfile) + print (" NORMALIZE: Normalize images.", >> logfile) + } + + # Generate image list. + sections (input, option="fullname", >imlist) + + # Process list. + imfd = imlist + while (fscan (imfd, input) != EOF) { + + # Determine normalization. + if (norm == INDEF) { + # Determine the mean of the sample region. + imstatistics (input // sample_section, fields="mean", + lower=lower, upper=upper, format=no) | scan (mean) + } else + mean = norm + + # Print output. + if (keeplog) { + time (>> logfile) + print (" Normalization for ", input, " = ", mean, >> logfile) + } + + if (mean != 0.) { + # Normalize the image by the mean. + if (mef) { + imarith (input, "/", mean, tmp, pixtype="real", + calctype="real") + imcopy (tmp, input//"[]", verbose-) + imdelete (tmp, verify-) + } else + imarith (input, "/", mean, input, pixtype="real", + calctype="real") + hedit (input, "ccdmean", 1., add=yes, verify=no, show=no, + update=yes) + } else + print (" WARNING: Cannot normalize ", input, ".") + } + imfd = ""; delete (imlist, verify=no) + + # Ending message. + if (keeplog) { + time (>> logfile) + print (" NORMALIZE: Done.", >> logfile) + } +end -- cgit