1

There are many functions in Mathematica, which return expressions with TransformationFunction head, for example RotationTransform. Unfortunately, there is no PerspectiveTransform amongst them.

How to create custom transformation functions in general? There is no explanation in docs. It is only said that "TransformationFunction works like Function." what does it mean? That writing TransformationFunction is just writing a Function?

Also it is said that when possible "matrix forms for transformations can be obtained from TransformationFunction objects using TransformationMatrix."

Can I have some samples of custom TransformationFunction with and without matrix?

UPDATE

If I provide my transformation (homogenous) matrix it produces "nonaffine" error:

enter image description here

enter image description here

enter image description here

UPDATE 2

Now trying to form transformation via LinearFractionalTransform and effect ios the same

enter image description here

Suzan Cioc
  • 2,023
  • 1
  • 16
  • 21
  • 1
    have a look at FindGeometricTransform and the Transformation options – Stefan Jun 18 '13 at 08:21
  • Ok, FindGeometricTransform can return perspective transform. But what about generating custom one? – Suzan Cioc Jun 18 '13 at 08:31
  • Just provide the transformation matrix as an argument, e.g. custom = TransformationFunction[Array[Plus,{4,4}]] – Simon Woods Jun 18 '13 at 09:13
  • @SimonWoods does not work; see my update – Suzan Cioc Jun 18 '13 at 09:40
  • The problem in your update is with GeometricTransformation, which can only deal with affine transformations. – Simon Woods Jun 18 '13 at 10:33
  • @SimonWoods where is it written? – Suzan Cioc Jun 18 '13 at 10:50
  • I inferred it from the error message - it appears to be missing from the documentation. – Simon Woods Jun 18 '13 at 11:06
  • It is in the documentation: "GeometricTransformation[g,{m,v}] effectively applies an affine transform to g." – bill s Jun 18 '13 at 11:07
  • @bills, I see what you mean, but Suzan is using the first form: GeometricTransformation[g, tfun] and it isn't clear that tfun must be affine. – Simon Woods Jun 18 '13 at 11:20
  • Also it is not clear if it is an error or a warning, since some drawing is produced nevertheless – Suzan Cioc Jun 18 '13 at 11:21
  • Yes, it effectively sets the bottom row of the matrix to {0,0,1} to make the transformation affine. It would be better if the message explained that, so you know that what you get out is not what you asked for. – Simon Woods Jun 18 '13 at 11:26
  • @Simon Woods -- I have updated my answer to reflect the current state of the discussion -- if you put up an answer I will happily delete mine. – bill s Jun 18 '13 at 13:09
  • @bills, I think your latest edit sums up the situation nicely. I see no reason to replace it with one of mine that would just say the same thing :-) – Simon Woods Jun 18 '13 at 13:45

1 Answers1

3

You can define any matrix as a transformation in LinearFractionalTransform:

t = LinearFractionalTransform[{{1, 2, 1}, {4, 5, 3}, {1, 1, 9}}]

However, this can only be applied to a geometric object using

 Graphics[GeometricTransformation[Rectangle[], t]]

if the matrix is affine.

The subtlety is that the TransformationFunction itself need not be affine, but that GeometricTransformation requires an affine transformation. In 2D, the distinction is that an affine transformation represents a mapping A.x+b where A is a 2 by 2 matrix and b is a 2 by 1 vector. These six numbers become the top two rows of the Transformation matrix, and the bottom row is {0,0,1}. GeometricTransformation gives an error if this is not the case. In the comments, Simon Woods points out that after issuing the error, GeometricTransformation then calculates the output as if the bottom row were {0,0,1}, effectively truncating the bottom row. This behavior is alluded to in the help file, which says: GeometricTransformation[g,{m,v}] effectively applies an affine transform to g." Apparently, this same restriction applies to the form `GeometricTransformation[g, tfn] as well.

If you wish to transform images through your non-affine mapping, there is the function ImagePerspectiveTransformation which allows application of any matrix transformation to a 2D image. The first example in the help file shows a transformation with a matrix that is clearly non-affine. So if you have an image to manipulate, or if you are willing to rasterize your current object, this can be done straightforwardly.

bill s
  • 68,936
  • 4
  • 101
  • 191