Ask Your Question
1

how to achieve Similarity Transform ?

asked 2013-09-01 10:18:35 -0600

krammer gravatar image

updated 2015-10-02 16:19:40 -0600

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-09-01 11:57:52 -0600

SR gravatar image

updated 2013-09-01 12:03:16 -0600

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.

edit flag offensive delete link more

Comments

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

krammer gravatar imagekrammer ( 2013-09-02 10:53:03 -0600 )edit
4

answered 2013-09-02 01:15:48 -0600

Michael Burdinov gravatar image

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-01 10:18:35 -0600

Seen: 4,500 times

Last updated: Sep 02 '13