This example is provided to show how to do image averaging using python
and the arr module.
#------------------------------------------------------
# An example that is part of a PythonScript tool
#------------------------------------------------------
import arr
global image # contains the averaged image data
global counter # counter is set to zero in the Central Start Script
# increment image counter
counter += 1
# read 'Intensity' image data
img = GetImageMatr('Intensity')
if counter == 1:
image=img # initial value
else:
# --------------------------------------------------
# an exponential image average is calculated
#
# image = image * 10/11 + img * 1/11
#
# --------------------------------------------------
image=arr.toUint8(arr.toInt(image)*(10,11)+arr.toInt(img)*(1,11)) #
note special fraction multiplication syntax
if counter > 2:
# the Mean Image is set
SetImageMatr('Mean',image)
#
------------------------------------------------------------------------------------------
# image substraction
# convert images to float - the rangeToUnit8
function
# scales and handles image overflow to an 8 bit
image with values from 0 to 255
#--------------------------------------------------------------------------------------------
image1 = arr.toFloat(image)-arr.toFloat(img)
img = image1.rangeToUint8(-128,128)
# set Subtract image
SetImageMatr('Subtract',img)
|