Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
1  
have a look at FindGeometricTransform and the Transformation options –  Stefan Jun 18 '13 at 8:21
    
Ok, FindGeometricTransform can return perspective transform. But what about generating custom one? –  Suzan Cioc Jun 18 '13 at 8:31
    
Just provide the transformation matrix as an argument, e.g. custom = TransformationFunction[Array[Plus,{4,4}]] –  Simon Woods Jun 18 '13 at 9:13
    
@SimonWoods does not work; see my update –  Suzan Cioc Jun 18 '13 at 9:40
    
The problem in your update is with GeometricTransformation, which can only deal with affine transformations. –  Simon Woods Jun 18 '13 at 10:33
show 8 more comments

1 Answer 1

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.

share|improve this answer
    
You used different values and I don't understand how this relates with my case. –  Suzan Cioc Jun 18 '13 at 10:22
    
Ah, you meant that to get transformation represented by arbitrary homogenous matrix it should be passed to LinearFractionalTransform, not to TransformationFunction? –  Suzan Cioc Jun 18 '13 at 10:24
    
@Suzan, yes. ${}$ –  J. M. Jun 18 '13 at 10:44
    
@0x4A4D it also does not work –  Suzan Cioc Jun 18 '13 at 10:54
    
@0x4A4D, LinearFractionalTransform just passes the matrix through to TransformationFunction. The real issue here is that GeometricTransformation can't handle non-affine transformations. –  Simon Woods Jun 18 '13 at 11:04
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.