IPMATH Function
Performs mathematical and logical operations on a single image or between two images.
Usage
result = IPMATH(image, operation[, operand])
Input Parameters
image—A 3D array containing image, row, or pixel-interleaved images. This parameter is the first operand for the mathematical operation.
operation—A scalar string specifying the mathematical or logical operation to perform (see Discussion section).
operand—(optional) The second operand for the mathematical operation. This parameter may be a scalar or an array exactly the same size as image.
Returned Value
result—An array or scalar value which is the result of the mathematical or logical operation performed.
Keywords
Intleave—A scalar string indicating the type of interleaving of 3D input image arrays. When both image and operand are used, Intleave specifies the interleaving method for both parameters. Valid strings and the corresponding interleaving methods are:
*'pixel'—The input array arrangement is (pxy) for p  pixel-interleaved images of x-by-y.
*'row'—The 3D image array arrangement is (xpy) for p  row-interleaved images of x-by-y.
*'image'—The 3D image array arrangement is (xyp) for p  image-interleaved images of x-by-y.
No_Clip—If set, the result data type is larger than the input image data type.
 
note
The No_Clip  keyword prevents underflow or overflow conditions from occurring.
Plane_Num—Specifies a single plane number for the function operation, where 0 Plane_Num < the number of planes in either image or operand arrays. This keyword is valid when image and/or operand are 3D arrays.
Zero_Negatives—If set, all negative values in result are set to zero.
Discussion
The operation parameter specifies the logical or mathematical operation to apply to one or two operands. The following two tables contain the lists of valid scalar strings for the operation parameter: Table 10-3: Operators for the Operation Parameter contains the list of strings which apply existing PV-WAVE operators; Table 10-4: Routines for the Operation Parameter contains a list of the existing PV-WAVE routines which can be applied to the operands.
 
Operators for the Operation Parameter
Operation
Operands Required
Operation Performed
'+'
2
image + operand, (addition)
'-'
2
imageoperand, (subtraction)
'*'
2
image x operand, (multiplication)
'/'
2
image ÷ operand, (division)
'#'
2
[image] x [operand], (matrix multiplication)
'^'
2
(image)operand , (exponentiation)
'<'
2
comparison of image and operand to find minimum
'>'
2
comparison of image and operand to find maximum
'AND'
2
image AND operand, (Boolean AND)
'MOD'
2
image MOD operand, (modulo operator)
'NOT'
1
compliment of image, (Boolean compliment)
'OR'
2
image OR operand, (Boolean inclusive OR)
'XOR'
2
image XOR operand, (Boolean exclusive OR)
 
Routines for the Operation Parameter
operation
Operands Required
Operation Performed
'ABS'
1
| image |, (absolute value)
'ALOG'
1
ln image, (natural logarithm)
'ALOG10'
1
log10 image, (logarithm to base 10)
'COS'
1
cos(image), (cosine)
'EXP'
1
eimage , (natural exponential function)
'MAX'
1
maximum value of image
'MEDIAN'
1
statistical median of the image values
'MIN'
1
minimum value of image
'MODE'
1
statistical mode of image
'RANGE'
1
range of values in image
'SIN'
1
sin(image), (sine)
'SQRT'
1
(image)1/2 , (square root)
'STDEV'
1
statistical standard deviation of image
'TAN'
1
tan(image), (tangent)
'VARIANCE'
1
statistical variance of image
Example 1
In this example, a portion of an existing image is masked using the Boolean AND operator. To do this, the mask image is first created, and then specified in the IPMATH calling sequence.
image = BYTARR(512,512)
OPENR, unit, !Data_Dir + 'mandril.img', /Stream, /Get_Lun
READU, unit, image
CLOSE, 1
FREE_LUN, unit
mask = BYTARR(512, 512)
mask(100:300, 250:300) = 255
result = IPMATH(image, 'AND', mask)
TVSCL, result
Example 2
In this example, the IPMATH calling sequence is used to improve the brightness of an image by adding a scalar value.
result = IPMATH(image, '+', 50, /No_Clip)
TVSCL, result
Example 3
In this example, a common background is subtracted from several images to reveal a moving object. Any negative values in the result are set to 0.
background = IMAGE_READ(!IP_Data + 'frame.tif')
result1 = IPMATH(image1, '-', background('pixels'), $
/Zero_Negatives)
result2 = IPMATH(image2, '-', background('pixels'), $
/Zero_Negatives)
result3 = IPMATH(image3, '-', background('pixels'), $
/Zero_Negatives)
; Display each image to see the object without the background.
TVSCL, result1
TVSCL, result2
TVSCL, result3
Example 4
In this example, a 24-bit color image is “tinted” red.
image = IMAGE_READ(!IP_Data + 'boulder_image.tif')
red_image = IPMATH(image('pixels'), '+', 10, Plane_Num = 0, $
Intleave = 'image')
; Display the “tinted” image.
TV, red_image, True = 3
See Also
Operators—PV‑WAVE Programmer’s Guide.
Routines—PV‑WAVE Reference.