0001
0002
0003
0004
0005 function [R,S,E] = xSuperimposeCandidates(Model,Cand,LocationWeight,AngleWeight)
0006
0007 L = length(Model);
0008
0009 if nargin < 5,
0010 LocationWeight = ones(1,length(Model));
0011 AngleWeight = ones(1,length(Model));
0012 else
0013 LocationWeight = L * LocationWeight / sum(LocationWeight);
0014 end
0015
0016 if length(Model) ~= length(Cand),
0017 R = [];
0018 S = [];
0019 E = [];
0020 else
0021
0022
0023
0024 ModelCenters = cat(1,Model.Center);
0025 ModelWeightedCenter = LocationWeight * ModelCenters / L;
0026 MCC = ModelCenters-ones(L,1)*ModelWeightedCenter;
0027
0028 CandCenters = cat(1,Cand.Center);
0029 CandWeightedCenter = LocationWeight * CandCenters / L;
0030 CC = CandCenters - ones(L,1) * CandWeightedCenter;
0031
0032 if (L == 2),
0033
0034 R = Model(1).Rot * Cand(1).Rot';
0035 S = Cand(1).Center;
0036 E = [];
0037
0038 else
0039
0040 R = zBestRotation(CC, diag(LocationWeight)*MCC);
0041 S = CandWeightedCenter;
0042 E = LocationWeight * sum(((MCC - CC*R').^2)')';
0043
0044 end
0045 end