Get Teem at SourceForge.net. Fast, secure and Free Open Source software downloads
teem / bin

  ilk: Composition of transformations

Composition of transformations

Most of the examples so far gave only one transformation to the "-t" option, but you can string together as many as you want. The transformations are concatenated (post-multiplied) into one transform, which is then applied to the image, so that the image is resampled once. This allows us, for instance, to demonstrate the factorization of an image rotation into three shears ("A Fast Algorithm for General Raster Rotation", Alan Paeth, Graphics Interface '86).

Following along with a page about this method, if you want to rotate by 30 degrees, then we need to shear by -tan(30/2)=-0.26795 in X, sin(30)=0.5 in Y, and tan(30/2) in X again. However, because of my funny basis, I need to flip the sign of the Y shear. First, doing these as seperate samplings, in order to color each differently:

ilk -i init.ppm -0 u:0.5,0.5 -b pad -t shear:0,-0.26795 -bg 255 80 80 | tojpg > sh1.jpg
ilk -i init.ppm -0 u:0.5,0.5 -b pad -t shear:0,-0.26795 -bg 255 80 80 \
  | ilk -0 u:0.5,0.5 -b pad -t shear:90,-0.5 -bg 80 255 80 \
  | tojpg > sh2.jpg
ilk -i init.ppm -0 u:0.5,0.5 -b pad -t shear:0,-0.26795 -bg 255 80 80 \
  | ilk -0 u:0.5,0.5 -b pad -t shear:90,-0.5 -bg 80 255 80 \
  | ilk -0 u:0.5,0.5 -b pad -t shear:0,-0.26795 -bg 80 80 255 \
  | tojpg > sh3.jpg
And now, putting all the transformations together in one resampling (demonstrating that the post-multiplying done by ilk really is tantamount to running the individual transforms in that order):
ilk -i init.ppm -0 u:0.5,0.5 -b pad \
  -t shear:0,-0.26795 shear:90,-0.5 shear:0,-0.26795 | tojpg > sh4.jpg
And as a rotation:
ilk -i init.ppm -0 u:0.5,0.5 -b pad \
  -t rotate:30 | tojpg > sh5.jpg