Question

I have images of faces in different positions. I want to rotate them, to make the line connecting the eyes always be horizontal. But I don't know how to do this in MATLAB.

And how can I calculate the angle of rotation?

Descriptive drawing of problem:

enter image description here

Was it helpful?

Solution

If you already have the locations of the eyes, then it's easy :) Here's an outline:

%//    left eye - right eye
pos = [  30          90    %// X
         80          40];  %// Y 

%// The angle equals the arctangent of dy/dx
angle = atan2(diff(pos(2,:)), diff(pos(1,:)));

%// Rotate in the opposite direction 
img = imrotate(img, -angle);

OTHER TIPS

Since you seem to have the Image Processing Toolbox, you can also look into the built-in landmark-based registration functions (especially if your transform is not limited to pure rotation), in particular cpselect with a syntax like:

cpselect(moving,fixed)

And then use fitgeotrans to construct the geometrical transform and imwarp to warp the moving image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top