This example is provided to show how to adjust the contrast of an image
import arr
def AdjustContrast(imageName,low,high):
contrast = high - low
# based on constrast a gain factor is given
# the low intensity value of the adjusted image is 40
# the high intensity value is 40 + 170 = 210
lgain = 170.0/contrast
lOffset = 40 - low * lgain
# adjust the contrast of Image
im1 = arr.toFloat(GetImageMatr(imageName))
im1 *= lgain
im1 += lOffset
SetImageMatr(imageName,im1.rangeToUint8(0,255))
|