-
Notifications
You must be signed in to change notification settings - Fork 3
/
outliers.py
80 lines (68 loc) · 2.31 KB
/
outliers.py
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
#
# This file is part of wganvo.
#
# Copyright (C) 2019 Javier Cremona (CIFASIS-CONICET)
# For more information see <https://github.com/CIFASIS/wganvo>
#
# wganvo 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, either version 3 of the License, or
# (at your option) any later version.
#
# wganvo 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 wganvo. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
import matplotlib.pyplot as plt
def reject_outliers(data, m=2.):
mask = mask_outliers(data, m)
return data[mask]
def mask_outliers(data, m):
d = np.abs(data - np.median(data))
mdev = np.median(d)
s = d / mdev if mdev else 0.
return s < m
# data: Nx3xP
def print_points(data):
plt.subplot(131)
plt.plot(data[:, 0, :])
plt.subplot(132)
plt.plot(data[:, 1, :])
plt.subplot(133)
plt.plot(data[:, 2, :])
plt.show()
def load(path):
return np.load(path)
# def fix_array(m, K, N):
# new_m = np.empty((m.shape[0], m.shape[1], 25))
# for idx, points in enumerate(m):
# points_h = np.ones((4, 150))
# points_h[0:3, :] = points
# x1 = np.matmul(K, points_h)
# x1 /= x1[2]
# c_mask = center_crop_mask(x1)
# points = points[:, c_mask]
# front_mask = in_front_of_cam_mask(points, 0.)
# points = points[:, front_mask]
# replace = points.shape[1] <= N
# random_selection = np.random.choice(points.shape[1], N, replace=replace)
# points = points[:3, random_selection]
# new_m[idx] = points
# return new_m
if __name__ == "__main__":
m = load('/home/jcremona/output/02/points.npy')
print_points(m)
# m.shape -> Nx3xP
# new_m = fix_array(m, K, N)
#np.save('/home/jcremona/output/09/points.npy', new_m)
# Take some example
X = m[432]
for i in range(3):
# Each axis (X,Y,Z) is filtered by mask_outliers
mask = mask_outliers(X[i], 1000)
X = X[:, mask]
print(X.shape)