forked from Coastal-Imaging-Research-Network/cBathy-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspatialLimitBathy.m
85 lines (65 loc) · 2.66 KB
/
spatialLimitBathy.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
function [subG, subXYZ, camUsed] = spatialLimitBathy(G, xyz, cam, xm, ym, params, kappa )
%% spatialLimitBathy -- extract appropriate data from stack for
% processing in the vicinity of xm, ym.
%
% [subG, subXYZ, camUsed] = spatialLimitBathy( G, xyz, cam, xm, ym, params, kappa )
%
% these are the indices of xy data that are within our box
idUse = find( (xyz(:,1) >= xm-params.Lx*kappa) ...
& (xyz(:,1) <= xm+params.Lx*kappa) ...
& (xyz(:,2) >= ym-params.Ly*kappa) ...
& (xyz(:,2) <= ym+params.Ly*kappa) );
% first decimate to maxNPix per tile, then drop minority cameras at seams.
% Otherwise you end up limited only by maxNPix and the weightings get funny
% for tiles with partial coverage.
del = max(1, length(idUse)/params.maxNPix);
idUse = idUse(round(1: del: length(idUse)));
subG = G(:,idUse);
subXYZ = xyz(idUse,:);
cams = cam(idUse);
% if on seam, limit to the dominant camera bypixel count
uniqueCams = unique(cams);
for i = 1: length(uniqueCams)
N(i) = length(find(cams==uniqueCams(i)));
end
pick = [];
camUsed = -1;
if exist('N')
[~,pickCam] = max(N);
pick = find(cams==uniqueCams(pickCam));
camUsed = uniqueCams(pickCam);
end
subG = subG(:,pick); % keep only those for the majority camera
subXYZ = subXYZ(pick,:);
% problem: we've started getting subG's that came from missing data.
% they are Inf because of the normalization in prepBathyInput, and they
% mess up the EIG function in csmInvertKAlpha. Let's throw those columns
% away. We may have no data (handled in subBathyProcess, or too little
% data (handled in csmInvertKAlpha).
% first, do we still have any data?
if ~isempty(subG)
[ugly, bad] = find(isnan(subG));
all = 1:size(subG,2);
good = setxor( all, unique(bad) );
subG = subG(:,good);
subXYZ = subXYZ(good,:);
end
%
% Copyright (C) 2017 Coastal Imaging Research Network
% and Oregon State University
% This program is free software: you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation, version 3 of the
% License.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program. If not, see
% <http://www.gnu.org/licenses/>.
% CIRN: https://coastal-imaging-research-network.github.io/
% CIL: http://cil-www.coas.oregonstate.edu
%
%key cBathy
%