-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuildShapeModel.m
More file actions
42 lines (38 loc) · 1.2 KB
/
buildShapeModel.m
File metadata and controls
42 lines (38 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function shapeModel = buildShapeModel(unalignedShapes,pathToTrainingImages)
% BUILDSHAPEMODEL performs PCA on a set of aligned shapes to create an active shape
% model.
%
% INPUT
% unalignedLandmarks: Unaligned shapes, placed on training images [2*n_landmarks x n_shapes]
%
% OUTPUT
% ShapeModel (struct)
% xBar: Mean shape [2*n_landmarks x 1]
% V: Eigenvectors (decreasing energy)
% D: Eigenvalues (decreasing energy)
%
% TODO: Do I need to account for resolution somehow with the eigenvectors and values?
%
% John W. Miller
% 25-Apr-2017
% Align shapes from training images using Procrustes
scaling = 0; % Almost always best to set scaling to 0
x = alignShapes(unalignedShapes,scaling);
% Use PCA to create model
xBar = mean(x,2); % Mean shape
S = cov(x'); % Covariance matrix
[V,D] = eig(S); % Eigenvectors
D = sort(diag(D),'descend');
V = fliplr(V);
% Store model as a struct
shapeModel = struct();
shapeModel.meanShape = xBar;
shapeModel.eVectors = V;
shapeModel.eValues = D;
shapeModel.alignedShapes = x;
shapeModel.unalignedShapes = unalignedShapes;
if nargin > 1
shapeModel.trainingImages = pathToTrainingImages;
end
shapeModel.n_shapes = size(x,2);
end % End of main