Previous topic

Create Split Image

Next topic

View phase difference

Modulate Image by Python FunctionΒΆ

This snippet shows how to define a python algorithm that modulates an image by a sine. Note the explicit call of ConstModIPAlgorithm.__init__ in the modulator class.

from math import sin

class SinusModulator(img.ConstModIPAlgorithm):
        def __init__(self,v):
                img.ConstModIPAlgorithm.__init__(self,"SinusModulator")
                self.v_=v

        def VisitImage(self,image):
                for point in image:
                        image.SetReal(point,sin(point[0]*self.v_))

image = img.CreateImage(img.Size(400,200))
sin_modulator=SinusModulator(5.3)
image.ApplyIP(sin_modulator)
v=Viewer(image)