-- New Image Expression Evaluation Task

New Image Expression Evaluation Task

A new task for evaluating general image expressions, imexpr, has been released with IRAF 2.10.3BETA. imexpr evaluates an arbitrary input image expression and writes the results to an output image. imexpr can be used for a wide variety of applications including, but not limited to, simple image arithmetic, image editing, image combining, function evaluation, and artificial image and pixel mask generation. The input images may be any dimension or size and any datatype. Expressions can combine images of different dimensions or datatypes. Image expressions may be read from the command line or from a file and may consist of one or more operands, operators, builtin functions, and user defined macros.

imexpr supports three types of operands: images and image sections, image header parameters, and numeric constants. Operands are represented symbolically in the expression by the letters a-z. Use of the symbolic operands permits the same expression to be used with different data sets, simplifies the expression syntax, and allows a single input image to be used several times in the same expression. The operands a-z are implemented as imexpr task parameters. The following examples show how imexpr can be used to compute the weighted sum of three images or to add two images together after normalizing by their respective exposure times.

        cl> imexpr "x*a+y*b+z*c" ave a=im1 b=im2 c=im3 x=.25 y=.50 z=.25

or equivalently
	cl> imexpr "0.25*a+0.50*b+0.25*c" ave a=im1 b=im2 c=im3
	cl> imexpr "a/c+b/d" norm a=im1 b=im2 c=a.exptime d=b.exptime
or equivalently
	cl> imexpr "a/a.exptime+b/b.exptime" norm a=im1 b=im2
where ``exptime'' is an image header parameter of images A and B.

In simple expressions like the above the same expression is evaluated at every point in the image, with only the input pixel values changing. It is also possible to implement space-variant functions by including the image pixel coordinates in the expression, using a special builtin set of operands. These operands have the names I, J, K, and so on, up to the dimensions of the image (upper case is required to avoid confusion with the input operand names i, j, k, etc.). This capability is especially useful for generating functions and test patterns.

The following example shows how this feature of imexpr can be used to create two artificial images, one a 2D test image where the pixel value gives the coordinates of each pixel, and the other a sampled 1D Gaussian.

	cl> imexpr "I+J*512" coordsim dim=512,512 outtype=int
	cl> imexpr "a*exp(-((I-b)/c)** 2/2.)" gauss \
	>>>\0\f(CBa=1000. b=255 c=3.5 dim=512 outtype=real
The imexpr expression syntax supports all the standard arithmetic and logical operators. Of special note is the conditional expression which permits pixel-dependent operations such as checking for and editing special pixel values. The following example replaces all the negative pixels in an image by the corresponding pixels from a second image "b". The two branches of a conditional expression may be arbitrary expressions.

	cl> imexpr "(a < 0) ? b : a" image.noneg a=image
String and vector concatenation operators and a substring equality operator are also provided.

imexpr supports all the standard mathematics and type conversion scalar functions including conversion from degrees to radians and vice versa. In addition some special functions which accept both scalar and vector arguments are provided. Functions which operate on vectors are applied to the lines of an image. When applied to an image of dimension 2 or greater these functions are evaluated separately for each line of the multidimensional image. The following two examples show 1) how imexpr can be used to compute the square root of an image and 2) how to subtract the median of a section of each image line from each image line using the scalar function sqrt and the vector projection function median.

	cl> imexpr "sqrt(a)" image.sqrt a=image
	cl> imexpr "a - median(b)" image.lmedsub a=image b=image[513:530,*]
The imexpr expression database provides a macro facility which can be used to create custom libraries of functions for specific applications. For example users may create their own ``what to do if dividing by a small number function'' by defining a simple macro like the following and entering it in a text file.

	divz(a,b)   (abs(b) < .000001) ? 0.0 : a/b)
Macros can be nested and are indistinguishable from intrinsic functions in expressions. Expression databases are particularly useful for expressions which are too large or too cumbersome to enter on the command line.

imexpr can also be used to create image masks. The following examples show how to create boolean mask images using 1) an input image and a conditional expression, and 2) a generating function defining a circular mask. The output mask is written to a compressed ".pl" pixel list image.

	cl> imexpr "a >= 0.0 && a <=10000.0" mask.pl a=image
	cl> imexpr "(((I-255.0)**2+(J-255.0)**2) < 150.0)" circle.pl \
	>>> dim=512,512
imexpr is available in the images package.

Doug Tody, Lindsey Davis


This document was translated by ms2html v1.8 on 21Jan95.