forked from jakobkarlstrand/tnm034-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crop_face.asv
24 lines (15 loc) · 1.17 KB
/
crop_face.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
%%This function crops the rotated image. The cropped image should only
%%contain the face of the image
function [croppedImage] = crop_face(currentImage, lEye, rEye)
distance_between_eyes = abs(lEye - rEye); %%Distance between eyes
point_between_eyes = (distance_between_eyes / 2) + lEye; %%The point between the eyes
[height, width, chans] = size(currentImage); %%Get image size.
centerOfImage = [width/2, height/2]; %%Calculate center of x in image.
distance = centerOfImage - point_between_eyes; %%Distance between point between eyes and center.
move_point = point_between_eyes + distance; %%move the point between eyes to the center of the image
left_top_corner = move_point + [-130, -100]; %%Define top left corner of cropped image.
translatedImage = imtranslate(currentImage, [distance(1), distance(2)]); %%Translate image
space_above_eye = 1;
%%croppedImage = imcrop(translatedImage, [left_top_corner(1) left_top_corner(2) 260 300]); %%Crop the image.
croppedImage = imcrop(translatedImage, [centerOfImage(1) - distance_between_eyes(1), centerOfImage(2) - space_above_eye*distance_between_eyes(1), 2*distance_between_eyes(1), 3*distance_between_eyes(1)] )
end