Files
x04sa-es3/script/spec/image.py
gac-x04sa 2ed890b76b Startup
2018-10-18 17:36:39 +02:00

757 lines
25 KiB
Python

#==============================================================================
# Macroname: image.mac
# =========
#+
# $Date: 2008/03/20 13:36:14 $
# $Author: schlepuetz $
# $Source: /cvs/G/SPEC/local/X04SA/ES3/image.mac,v $
# $Revision: 1.11 $
# $Tag: $
#
# Description: This macro file provides a set of macro definitions which are
# used to analyze images (taken by any sort of imaging device)
# on-line during data acquisition and return a set of charac-
# teristic values to SPEC.
# It is thus possible to plot results of a scan (usually an
# intensity value) during data acquisition with the imaging
# device, just like one would with a point detector.
# Furthermore, the image information can be used to automate
# filter transmission and exposure time settings during a scan
# (refer to auto.mac for more information on automated scans).
#
# Note: This macro is based on an earlier version by O. Bunk
# and R. Herger
#
# Author: C. M. Schlepuetz (CS)
# Co-author(s): R. Herger (RH), P. R. Willmott (PW)
# Address: Surface Diffraction Station
# Materials Science Beamline X04SA
# Swiss Light Source (SLS)
# Paul Scherrer Institute
# CH - 5232 Villigen PSI
# Created: 2005/07/12
#
#-
# Chained macro definitions affected by this macro:
# -------------------------------------------------
# - user_getcounts
#
# Change Log:
# -----------
#
# 2005/07/12 (CS):
# - created first version of this file.
#
# 2005/12/10 (CS):
# - fixed bug in imageGetInt: background region area was not correctly
# calculated in the c-routine and consequently all intensities were wrong.
# (also changed the c-routine, of course)
#
# 2005/12/11 (CS):
# - attempt to generalize the image_get_int routine to images of different
# sizes and color-depths, and possibly header lengths.
# Introduced new globals variables:
# IMAGE_INFO_FILENAME
# IMAGE_HEADER_LENGTH (in bytes)
# IMAGE_COLOR_DEPTH (in number of bits, e.g. 16 or 32)
# - write an info-file with information about each image in imageUserGetcounts
# which can be accessed by all external programs which want to look at the
# images.
# - Increase the number of threshold levels for image analysis to 4. That way,
# the thresholds for adjusting the exposure time automatically (see also
# auto.mac) and the filter transmission are independent of each other.
# Introduced new global variables:
# IMAGE_THRESH4
# IMAGE_THRESH4_COUNT
#
# 2006/01/27 (CS):
# - fixed typo in imageCheckRoi
#
# 2006/06/23 (CS):
# - retrieve IMAGE_PATH from IMAGE_FILENAME with unix command DIRNAME.
# - copy image information file into IMAGE_PATH such that it is accessible
# to all applications which have access to the image path.
#
# 2006/08/09 (CS):
# - input to 'imgeSetRoi' is now possible in several ways, including user
# interaction.
# - removed old commented out workarounds.
#
# 2006/09/21 (CS):
# - added new functionality to the image_get_int.c routine for selectively
# median filtering only those pixels where the measured intensity differs
# from the mean of the surrounding pixels by more than N times the standard
# deviation of these neighbours. N is presently set to 30 in imageGetInt.
#
# 2006/11/29 (CS):
# - include wait loop in imageUserGetcounts to make sure the image file is
# available an non-empty in order to do statistical analysis with
# image_get_int.c.
#
# 2007/04/05 (CS):
# - new error message if image file to be analyzed is not found.
#
# 2007/04/22 (CS):
# - changed imageCheckROI to allow for ROIs of 1 pixel width/height (used to
# be at least 2 pixels).
#
# 2008/03/19 (CS):
# - removed quotation marks around argument variables $1,$2 in imageSetRoi,
# allowing one to also pass the arguments via variables.
# - added imageShowRoi.
#
#==============================================================================
#
global IMAGE_MAC
#
IMAGE_MAC = DOFILE # Save the name of this macro file.
# (Used for the help function).
#+
#==============================================================================
# This macro file contains the following commands:
#-
#
#+
#------------------------------------------------------------------------------
# imagehelp - generates this help text. This is obtained by
# displaying the file image.txt, which should sit in the
# same directory as this macro file.
#-
# allow for misspelled help commands
def helpimage 'imagehelp'
def helpImage 'imagehelp'
def imageHelp 'imagehelp'
def imagehelp '{
# =========
unix (sprintf ("dirname %s", IMAGE_MAC), _1)
ll = length (_1)
if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
file = sprintf ("%s/image.txt", _1)
if (file_info (file, "-e")) {
unix (sprintf ("cat %s | less", file))
} else {
printf("\n Macros available in file image.mac ($Revision: 1.11 $):\n")
printf( " ========="\n)
printf("\n")
printf(" imagehelp - creates this help text\n")
printf(" imageOn - turn on image analysis functionality\n")
printf(" imageOff - turn off image analysis functionality\n")
printf(" imageShow - show current image analysis setup.\n")
printf(" imageShowRoi - show current region of interest info.\n")
printf(" imageSetRoi - define a signal and background region-\n")
printf(" of-interest (ROI).")
printf(" imageCheckRoi - checks whether ROI is valid and within\n")
printf(" image bounds.
printf(" imageGetInt - description\n")
}
}'
#+
#------------------------------------------------------------------------------
# imageInit - initializes all global variables used by image.mac
#-
def imageInit '{
# =========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
}'
#+
#------------------------------------------------------------------------------
# imageOn - turn on macro functionality to analyze images acquired by
# an area detector on-line and return the results to SPEC.
#-
def imageon 'imageOn'
def imageOn '{
# =======
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
#--------------------------------------------
# include necessary chained macro definitions
#---------------------
def imageUserGetcounts \'
# ==================
if (IMAGE_IS_ON) {
# update IMAGE_PATH variable
unix(sprintf("dirname %s",IMAGE_FILENAME), IMAGE_PATH)
# write important image information to file so image_get_int.c and other
# possible helper applications can read it.
local ux_cmd
ux_cmd = ""
IMAGE_INFO_FILENAME = "/tmp/spec_image_info.dat"
ux_cmd = sprintf("echo \"%s\" > %s",\\
IMAGE_FILENAME, IMAGE_INFO_FILENAME)
if (unix(ux_cmd) != 0) {
eprint ">> Cannot store image information file <<"
} else {
ux_cmd = sprintf("echo \"%.6f\" >> %s",\\
time(), IMAGE_INFO_FILENAME)
if (unix(ux_cmd) != 0) {
eprint ">> Cannot store image information file <<"
}
unix(sprintf("echo \"%d\" >> %s",\\
IMAGE_HEADER_LENGTH,IMAGE_INFO_FILENAME))
unix(sprintf("echo \"%d %d %d\" >> %s",\\
IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH,\\
IMAGE_INFO_FILENAME))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2, \\
IMAGE_INFO_FILENAME))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2, \\
IMAGE_INFO_FILENAME))
}
# copy information file into image path
unix(sprintf("cp -f %s %s", IMAGE_INFO_FILENAME, IMAGE_PATH))
# get the AUTO_THRESH2 value if auto levels are enabled
if ((whatis("AUTO_THRESH2") & 0x08000000) == 0) {
IMAGE_THRESH2=AUTO_THRESH2
}
# check whether image file is ready to be read (size > 0 bytes)
retry = 0
_tmp_filename = IMAGE_FILENAME
while((!(file_info(_tmp_filename,"-s"))) & (retry<3000)){
printf("waiting for image file %s\n",IMAGE_FILENAME)
printf("retry %d of 3000\n",retry)
retry++
if (retry%100 == 0) {
unix(sprintf("head -n 1 %f", IMAGE_FILENAME))
}
sleep(0.01)
}
# get the integrated intensity in the intensity and background boxes
imageGetInt IMAGE_THRESH1 IMAGE_THRESH2 IMAGE_THRESH3 IMAGE_THRESH4
# update the auto-level threshold count values if auto-level support
# is available
if ((whatis("AUTO_THRESH1_COUNT") & 0x08000000) == 0) {
AUTO_THRESH1_COUNT=IMAGE_THRESH1_COUNT
AUTO_THRESH2_COUNT=IMAGE_THRESH2_COUNT
AUTO_THRESH3_COUNT=IMAGE_THRESH3_COUNT
AUTO_THRESH4_COUNT=IMAGE_THRESH4_COUNT
}
# return the background corrected intensity
if (IMAGE_AREA_BG > 0){
S[2] = (IMAGE_I_SUM - IMAGE_I_BG/IMAGE_AREA_BG*IMAGE_AREA_SIG)
} else{
S[2] = IMAGE_I_SUM
}
# correct for filter transmission and exposure time
# p epics_get("X04SA-ES2-FI:TRANSM")
S[3] = S[2] / COUNT_TIME / epics_get("X04SA-ES2-FI:TRANSM")
# write plot information for Matlab
local ux_cmd, comFile, tmpFile
ux_cmd = ""
tmpFile = "/tmp/spec_image_temp.dat"
comFile = "/tmp/spec_matlab_image.dat"
ux_cmd = sprintf("echo \"%s\" > %s",\\
IMAGE_FILENAME, tmpFile)
if (unix(ux_cmd) != 0) {
eprint ">> Can not store Matlab plot information <<"
} else {
ux_cmd = sprintf("echo \"%.6f\" >> %s",\\
time(), tmpFile)
if (unix(ux_cmd) != 0) {
eprint ">> Can not store Matlab plot information <<"
}
unix(sprintf("echo \"%d %d\" >> %s",\\
IMAGE_XDIM, IMAGE_YDIM, tmpFile))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2, tmpFile))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2, tmpFile))
# overwrite the last file
unix(sprintf("mv -f %s %s",tmpFile,comFile))
}
}
\'
# add imageUserGetcounts to middle of user_getcounts
cdef("user_getcounts","imageUserGetcounts; ","image_user_getcounts_key")
#---------------------------------------------------
# update the global variables for auto-level support
if ((whatis("AUTO_THRESH1") & 0x08000000) == 0) {
AUTO_THRESH1 = IMAGE_THRESH1
AUTO_THRESH2 = IMAGE_THRESH2
AUTO_THRESH3 = IMAGE_THRESH3
AUTO_THRESH4 = IMAGE_THRESH4
}
IMAGE_IS_ON=1
imageShow
}'
#+
#------------------------------------------------------------------------------
# imageOff - turn off macro functionality to analyze images acquired by
# an area detector on-line and return the results to SPEC.
#-
def imageoff 'imageOff'
def imageOff '{
# ========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
#---------------------------------------------
# remove unnecessary chained macro definitions
# remove imageUserGetcounts from user_getcounts
cdef("user_getcounts","imageUserGetcounts; ","image_user_getcounts_key",\\
"delete")
IMAGE_IS_ON=0
imageShow
}'
#+
#------------------------------------------------------------------------------
# imageShow - show whether image analysis is currently enabled and
# display the region-of-interest (ROI) settings.
#-
def imageshow 'imageShow'
def imageInfo 'imageShow'
def imageinfo 'imageShow'
def imageShow '{
# =========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
if(IMAGE_IS_ON==1){
printf("\nImage analysis is currently enabled.\n")
printf("The active imaging device name is: %s\n", IMAGE_DEVICE)
imageShowRoi
} else{
printf("Image analysis is disabled.\n")
}
}'
#+
#------------------------------------------------------------------------------
# imageShowRoi - show information on the currently active region of interest
#-
def imageshowroi 'imageShowRoi'
def imageshowROI 'imageShowRoi'
def imageShowROI 'imageShowRoi'
def imageShowRoi '{
# ============
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
imageCheckRoi
}'
#+
#------------------------------------------------------------------------------
# imageSetRoi - set the region-of-interest for intensity and background
# integration.
#
# Usage : imageSetRoi
# prompts user for roi coordinates
# or imageSetRoi <Sx1> <Sy1> <Sx2> <Sy2>
# set signal roi to <Sx1> <Sy1> <Sx2> <Sy2> and use same
# coordinates for background roi
# (as a result, no background is subtracted)
# or imageSetRoi <Sx1> <Sy1> <Sx2> <Sy2> <Bx1> <By1> <Bx2> <By2>
# set signal roi to <Sx1> <Sy1> <Sx2> <Sy2> and background
# roi to <Bx1> <By1> <Bx2> <By2>.
#-
def imagesetroi 'imageSetRoi'
def imageSetROI 'imageSetRoi'
def imageSetRoi '{
# ===========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
if ($# == 8) {
IMAGE_SX1 = $1
IMAGE_SY1 = $2
IMAGE_SX2 = $3
IMAGE_SY2 = $4
IMAGE_BX1 = $5
IMAGE_BY1 = $6
IMAGE_BX2 = $7
IMAGE_BY2 = $8
} else if($# == 4){
IMAGE_SX1 = $1
IMAGE_SY1 = $2
IMAGE_SX2 = $3
IMAGE_SY2 = $4
IMAGE_BX1 = $1
IMAGE_BY1 = $2
IMAGE_BX2 = $3
IMAGE_BY2 = $4
} else if($# == 0){
sig_roi = getval("Signal Roi (sx1 sy1 sx2 sy2):",sprintf("%d %d %d %d",\
IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2))
sscanf(sig_roi,"%d %d %d %d",IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2)
bg_roi = getval("Background Roi (bx1 by1 bx2 by2):",sprintf("%d %d %d %d",\
IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2))
sscanf(bg_roi,"%d %d %d %d",IMAGE_BX1,IMAGE_BY1,IMAGE_BX2,IMAGE_BY2)
} else{
eprint "Wrong number of arguments in \'imageSetRoi\'"
eprint "Usage:"
eprint " imageSetRoi"
eprint " prompts the user for input"
eprint " imageSetRoi <sx1> <sy1> <sx2> <sy2>"
eprint " set background roi = signal roi (no background subtraction)"
eprint " imageSetRoi <sx1> <sy1> <sx2> <sy2> <bx1> <by1> <bx2> <by2>"
eprint " sets signal and background roi individually"
exit
}
imageCheckRoi
}'
#+
#------------------------------------------------------------------------------
# imageCheckRoi - Check the region of interest for intensity and background
# integration for consistency with the image dimensions, etc.
#
# Usage : imageCheckRoi # no arguments needed
#-
def imageCheckRoi '{
# =============
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
local coordAdjusted
coordAdjusted = 0
#-----------------
# check signal box
if (IMAGE_SX1 < 1) {
IMAGE_SX1 = 1
coordAdjusted = 1
}
if (IMAGE_SY1 < 1) {
IMAGE_SY1 = 1
coordAdjusted = 1
}
if (IMAGE_SX1 > IMAGE_XDIM-1) {
IMAGE_SX1 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_SY1 > IMAGE_YDIM-1) {
IMAGE_SY1 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_SX2 > IMAGE_XDIM-1) {
IMAGE_SX2 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_SY2 > IMAGE_YDIM-1) {
IMAGE_SY2 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_SX2 < IMAGE_SX1) {
IMAGE_SX2 = IMAGE_SX1
coordAdjusted = 1
}
if (IMAGE_SY2 < IMAGE_SY1) {
IMAGE_SY2 = IMAGE_SY1
coordAdjusted = 1
}
#---------------------
# check background box
if (IMAGE_BX1 < 1) {
IMAGE_BX1 = 1
coordAdjusted = 1
}
if (IMAGE_BY1 < 1) {
IMAGE_BY1 = 1
coordAdjusted = 1
}
if (IMAGE_BX1 > IMAGE_XDIM-1) {
IMAGE_BX1 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_BY1 > IMAGE_YDIM-1) {
IMAGE_BY1 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_BX2 > IMAGE_XDIM-1) {
IMAGE_BX2 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_BY2 > IMAGE_YDIM-1) {
IMAGE_BY2 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_BX2 < IMAGE_BX1) {
IMAGE_BX2 = IMAGE_BX1
coordAdjusted = 1
}
if (IMAGE_BY2 < IMAGE_BY1) {
IMAGE_BY2 = IMAGE_BY1
coordAdjusted = 1
}
if (coordAdjusted != 0) {
eprint">> Coordinates out of range - automatically adjusted. <<"
}
printf("signal region of interest : (%3d,%3d) (%3d,%3d)\n",\\
IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2)
printf("background region of interest: (%3d,%3d) (%3d,%3d)\n",\\
IMAGE_BX1,IMAGE_BY1,IMAGE_BX2,IMAGE_BY2)
printf("image dimensions (x*y) : %3d * %3d pixels\n",\\
IMAGE_XDIM,IMAGE_YDIM)
}'
#+
#------------------------------------------------------------------------------
# imageGetInt - This macro analyzes the last image taken by the active area
# detector. It checks the region-of-interest defined via
# imageSetRoi and sets some global variables to the intensity
# values determined. Calling parameters are the three threshold
# values (no. of pixels with intensity above these values is
# returned).
#-
def imagegetint 'imageGetInt'
def imageGetInt '{
# ===========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
local unixCommand, unixReturn
if ($# != 4) {
eprint "Wrong number of arguments in \'imageGetInt\'"
eprint "Usage:"
eprint "imageGetInt <threshold1> <threshold2> <threshold3> <threshold4>"
exit
}
commandDir = ""
unix(sprintf("dirname %s", IMAGE_MAC),commandDir)
if(index(commandDir,"\n") != 0){
commandDir = substr(commandDir,0,length(commandDir)-1)
}
unixCommand = sprintf("%s%s %s %d %d %d %d -median 30",\\
commandDir,\\
"/bin/image_get_int.py",\\
"/tmp/spec_image_info.dat",\\
$1, $2, $3, $4)
if(IMAGE_DEBUG){
printf("unix command: %s\n", unixCommand)
}
unixReturn = ""
unix(unixCommand,unixReturn)
if(IMAGE_DEBUG){
printf("unix return: %s\n", unixReturn)
}
IMAGE_I_SUM = ""
IMAGE_AREA_SIG = ""
IMAGE_THRESH1_COUNT = ""
IMAGE_THRESH2_COUNT = ""
IMAGE_THRESH3_COUNT = ""
IMAGE_I_BG = ""
IMAGE_AREA_BG = ""
if (sscanf(unixReturn,"I_sum %d area_I %d Threshold1 %d Threshold2 %d Threshold3 %d Threshold4 %d I_bgr %d area_bgr %d",\\
IMAGE_I_SUM, IMAGE_AREA_SIG,\\
IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT, IMAGE_THRESH3_COUNT,\\
IMAGE_THRESH4_COUNT, IMAGE_I_BG, IMAGE_AREA_BG) != 8) {
printf("Couldn\'t get intensity data\n")
exit
}
if (IMAGE_AREA_BG > 0){
IMAGE_I_SIG = IMAGE_I_SUM - ((IMAGE_I_BG / IMAGE_AREA_BG) * IMAGE_AREA_SIG)
} else {
IMAGE_I_SIG = IMAGE_I_SUM
}
if (IMAGE_DEBUG){
printf("I_sum: %d, area_I: %d\nthresh1: %d, thresh2: %d, thresh3: %d, thresh4: %d\n",\\
IMAGE_I_SUM, IMAGE_AREA_SIG,\\
IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT,\\
IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT)
printf("I_bgr: %d, area_bgr: %d\n",IMAGE_I_BG,IMAGE_AREA_BG)
}
}'
#+
#------------------------------------------------------------------------------
#-
#==============================================================================
#
#####################################################
# emacs setup: force text mode to get no help with #
# indentation and force use of spaces #
# when tabbing. #
# Local Variables: #
# mode:text #
# indent-tabs-mode:nil #
# End: #
#####################################################
#
# $Log: image.mac,v $
# Revision 1.11 2008/03/20 13:36:14 schlepuetz
# removed quotation marks around argument variables ,,... in imageSetRoi, added imageShowRoi.
#
# Revision 1.10 2007/04/22 15:42:11 schlepuetz
# changed imageCheckROI to allow for ROIs of 1 pixel width/height.
#
# Revision 1.9 2007/04/05 09:57:21 schlepuetz
# new error message if image file to be analyzed is not found
#
# Revision 1.8 2006/12/01 08:28:52 schlepuetz
# include wait loop in imageUserGetcounts to make sure the image file is available and non-empty
#
# Revision 1.7 2006/09/21 11:49:43 schlepuetz
# added new feature in imageGetInt to selectively median filter hot and dead pixels
#
# Revision 1.6 2006/08/09 13:44:38 schlepuetz
# added more input options for imageSetRoi.
#
# Revision 1.5 2006/06/23 16:26:52 schlepuetz
# missing bracket...
#
# Revision 1.4 2006/06/23 08:07:32 schlepuetz
# copy image info file also into image directory for accessibility
#
# Revision 1.3 2006/03/01 13:02:47 maden
# Check-in newer version from /work ...
#
# Revision 1.2 2005/12/10 16:32:57 schlepuetz
# fixed bug in imageGetInt.
#
# Revision 1.1 2005/11/10 11:01:21 schlepuetz
# first tested version of this file
#
#
#============================= End of $RCSfile: image.mac,v $ ===