Start up giplt and enter the following lines:
from ost.img import *
This will import the basic image processing classes.
im=CreateImage(Size(200,200))
This will create an empty, 2D image, with a height and width of 200 pixels, whose origin (ie the pixel with the coordinates <0,0>) is in the top-left corner.
v=Viewer(im)
A viewer window will pop up (see below), showing a white frame on a black background. The inner area of the white frame is the image, which is empty. Let us fill this with random values.
rand_alg = alg.Randomize() # create algorithm object
im.ApplyIP( rand_alg ) # apply algorithm object in-place
As you can see, applying an algorithm is conceptually a two-step process. First, an instance of an algorithm class is created, yielding an algorithm object (in this case rand_alg). In a second step, the algorithm object is applied to an image, either in-place, modifying the image, or out-of-place, leaving the original image untouched, and returning the result as a new image. Note that the in-place/out-of-place logic is decoupled from the algorithm object.
Now that we have some (noisy) data present, let us run another algorithm, this time a gaussian filter with a sigma of 4 pixel.
im.ApplyIP( alg.GaussianFilter(4.0) ) # apply temporary algorithm object in-place
As you can see, it is not always necessary to create an independent algorithm instance first, in many cases a temporary object will suffice (this applies to the randomization algorithm as well, im.ApplyIP(alg.Randomize()) would have been fine).
Having algorithms as instances is very useful, however, since it makes the algorithm stateful, meaning the algorithm can “remember” values prior to and after applying itself to an image. For example, to gather statistics about the image, the Stat algorithm can be employed as follows:
stat=alg.Stat()
im.ApplyIP(stat)
print stat.GetMean()
Here, the algorithm object is required to live beyond the ApplyIP call, in order for the results to be retrieved from it.