-1

I have two face images and need to make sure that their eyes are aligned, so I wrote a script that allows me to get the coordinates of the eyes in the two pictures.

From there I was able to derive the rotation matrix R and translation vector T which represent the rigid planar transformation to apply to one image in order to align it to the second one.

However I don't know how can I apply the rotation and translation to the images brightness intensities and save the new version of the image.

I'm aware of these functions but can't really figure out how to use them given R and T.

I guess it should be something like this:

tform = <--- how to build this from R and T??
B = imwarp(A,tform)
Matteo
  • 7,924
  • 24
  • 84
  • 129
  • Read my answer to [this](http://stackoverflow.com/a/21819056/1586200) question. If you can't figure out the solution to your problem, please post a comment here. – Autonomous Feb 17 '14 at 01:32
  • On the other hand, if you have corresponding points (coordinates of eyes in both images), why don't you use `figeotrans` directly instead of calculating `T` and `R` and then calculating `TFORM` from that. I have explained how to use `fitgeotrans` in my above answer. Also, excellent documentation is available [here](http://www.mathworks.com/help/images/ref/fitgeotrans.html). – Autonomous Feb 17 '14 at 01:35
  • @Parag - I see, your answer seems very useful, I wasn't aware of such a function. But so what would be my moving points vector? Would you mind detailing an answer also in this post? Thanks a lot! – Matteo Feb 17 '14 at 01:40
  • Read up image stitching. – Autonomous Feb 17 '14 at 02:13

1 Answers1

2

I = imread('cameraman.tif'); tform = maketform('affine',[1 0 0; .5 1 0; 0 0 1]); J = imtransform(I,tform); imshow(I), figure, imshow(J)

you can change the 'affine' thing to projective and specify your projective transformation matrix accordingly

In your case, for a 2D image you can make the transformation as [R T; 0 0 1], where R is a 2x2 rotation matrix and T is a 2x1 translation matrix

Bharat
  • 2,139
  • 2
  • 16
  • 35
  • I tried this but for some reason if I include the translation vector the output image gets all messed up. I.e. Dimensions become `1x1x3` instead of `1080x960x3`, any clue of what's going on? – Matteo Feb 17 '14 at 01:53
  • could you upload the image and the transformation matrix you are using, you could also use [output, xdata, ydata] = imtransform(image,transform, 'XData',[1 width], 'YData',[1 height]); this would give you the output image and the position of the transformed pixels, just look into matlab help for imtransform – Bharat Feb 17 '14 at 03:44