-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimizeFrames.m
86 lines (64 loc) · 2.56 KB
/
optimizeFrames.m
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function [bestx, bestf] = optimizeFrames(tiepts, frameStart, frameEnd)
% Winnow tie points table to only include the specified range
north = frameStart:frameEnd;
tiepts(~ismember(tiepts.northidx, north), :) = [];
frames = cell(size(north));
for i = 1:numel(frames)
frames{i} = unique(tiepts.file(tiepts.northidx==north(i)));
end
% Calculate a time range and number of instances for each geographic point
upoints = unique(tiepts.point);
timeRange = zeros(size(upoints));
pointFreq = zeros(size(upoints));
for i = 1:numel(upoints)
timeRange(i) = range(tiepts.flightTime(tiepts.point==upoints(i)));
pointFreq(i) = sum(tiepts.point==upoints(i));
end
clear i
% Eliminate all points appearing in only one image
idx = pointFreq < 2;
tiepts(ismember(tiepts.point, upoints(idx)), :) = [];
upoints(idx) = [];
pointFreq(idx) = [];
timeRange(idx) = [];
% For each frame, select (up to) thirty points with the greatest time range
selection = false(size(upoints));
[~,iTime] = sort(timeRange, 'descend');
upoints = upoints(iTime);
pointFreq = pointFreq(iTime);
for i = 1:numel(frames)
frameidx = strcmp(tiepts.file, frames{i});
pointidx = find(ismember(upoints, tiepts.point(frameidx)));
for j = 1:min([numel(pointidx) 30])
selection(pointidx(j)) = true;
end
end
clear iTime i frameidx pointidx j
% Create a table extracting intensity from each high point instance
hiPoints = upoints(selection);
highpts = tiepts(ismember(tiepts.point, hiPoints), :);
% Prepare objective function to be passed to SCEUA
idximage = false(size(highpts,1), numel(frames));
idxpoint = false(size(highpts,1), numel(hiPoints));
hiPtFreq = pointFreq(selection);
for j = 1:numel(frames)
idximage(:,j) = strcmp(frames{j}, highpts.file); end
for j = 1:numel(hiPoints)
idxpoint(:,j) = highpts.point == hiPoints(j); end
functn = @(nopt, b)sceuaObjective(highpts.rawIntensity, ...
idxpoint, idximage, hiPtFreq, nopt, b);
clear j idximage idxpoint
% Set up and run shuffled complex algorithm
x0 = [ones(1, numel(frames)) zeros(1, numel(frames))];
lb = [1 0.8*ones(1, numel(frames)-1) 0 -40*ones(1, numel(frames)-1)];
ub = [ 1.2*ones(1, numel(frames)) 40*ones(1, numel(frames))];
ngs = 4;
maxn = 5e5;
kstop = 20;
pcento = 0.01;
peps = 1e-4;
iseed = 1;
iniflg = 1;
[bestx, bestf] = sceua(x0, lb, ub, maxn, kstop, pcento, peps, ngs, ...
iseed, iniflg, functn);
end