Newer
Older
package cz.fidentis.analyst.procrustes;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.procrustes.exceptions.ProcrustesAnalysisException;
import cz.fidentis.analyst.procrustes.utils.ProcrustesAnalysisUtils;
import java.util.List;
* @author Jakub Kolman
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
43
44
45
46
47
48
49
50
51
52
53
private final List<FeaturePoint> orderedFpList1;
private final List<FeaturePoint> orderedFpList2;
/**
*
* @param fpList1
* @param fpList2
* @throws ProcrustesAnalysisException
*/
public ProcrustesAnalysis(List<FeaturePoint> fpList1, List<FeaturePoint> fpList2) throws ProcrustesAnalysisException {
if (fpList1.size() != fpList2.size()) {
throw new ProcrustesAnalysisException("Lists of feature points do not have the same size");
}
orderedFpList1 = ProcrustesAnalysisUtils.sortByFeaturePointType(fpList1);
orderedFpList2 = ProcrustesAnalysisUtils.sortByFeaturePointType(fpList2);
if (!ProcrustesAnalysisUtils.checkfeaturePointsType(orderedFpList1, orderedFpList2)) {
throw new ProcrustesAnalysisException("Lists of feature points do not have the same feature point types");
}
}
/**
* Calculate scaling ratio of how much the appropriate object corresponding to the second feature
* point list has to be scale up or shrunk.
*
* If returned ratioValue is greater 1 then it means that the second object should be scaled up ratioValue times.
* If returned ratioValue is smaller 1 than the second object should be shrunk.
*
* @return ratioValue
*/
private double calculateScalingValue() {
double[] distancesOfList1 = ProcrustesAnalysisUtils.calculateMeanDistancesFromOrigin(orderedFpList1);
double[] distancesOfList2 = ProcrustesAnalysisUtils.calculateMeanDistancesFromOrigin(orderedFpList2);
double[] ratioArray = new double[distancesOfList1.length];
double ratioValue = 0;
for (int i = 0; i < distancesOfList1.length; i++) {
ratioArray[i] += distancesOfList1[i] / distancesOfList2[i];
}
for (double ratio: ratioArray) {
ratioValue += ratio;
}
return ratioValue / distancesOfList1.length;