# how to achieve Similarity Transform ?

Hi

I have been able to transform an image using affine transform and perspective transform using the affine transformation tutorial. I have also been able to rotate an image using getRotationMatrix2D. But how can I translate an image ?

edit retag close merge delete

Sort by » oldest newest most voted

You need to create a 2x3 (sic!) transformation matrix suited for cv::warpAffine():

| 1 0 tx |
| 0 1 ty |


You translation is then given as by the vector (tx, ty).

Note: warpAffine requires a 2x3 matrix although technically it is better to think in 3x3 matrices for 2-D homogenous coordinates (the third row would be set implicitly to 0 0 1 in this case).

Alternatively: If you only want a pure shift and nothing else you may simply shift the image within the corresponding cv::Mat object. Which is certainly faster but constrained to pure translations.

more

thanks. I have tried getAffineTransform(). Is it possible to get homogenous matrix from it ?

( 2013-09-02 10:53:03 -0500 )edit

krammer, SR already gave a good answer to your question. I just want to add couple of small corrections to the question itself.

First, Similarity transform is not just translation. Usually it means scale + rotation + translation. Its difference from Affine transform is absence of shear.

Second, you can approximate certain perspective transforms by affine transforms (which is called sometimes 'weak perspective transform'), but in general you need 3x3 matrix to define perspective transformation. So you can't perform all perspective transforms if you only use affine transforms from the tutorial you mentioned.

more

Official site

GitHub

Wiki

Documentation