문제

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

도움이 되었습니까?

해결책

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);

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top