shin0624 commited on
Commit
bfe81cc
ยท
verified ยท
1 Parent(s): e826484

Update utils/pointcloud_tools.py

Browse files
Files changed (1) hide show
  1. utils/pointcloud_tools.py +15 -4
utils/pointcloud_tools.py CHANGED
@@ -13,20 +13,31 @@ class PointCloudProcessor:
13
  # Z-score ์ •๊ทœํ™”
14
  mean = np.mean(points, axis=0)
15
  std = np.std(points, axis=0)
16
- return (points - mean) / (std + 1e-8)
 
 
17
 
18
  @staticmethod
19
  def filter_outliers(points: np.ndarray, z_thresh=3.0) -> np.ndarray:
20
  """์ด์ƒ์น˜ ์ œ๊ฑฐ"""
21
  if len(points) == 0:
22
  return points
 
 
 
 
 
 
 
 
 
 
23
 
24
- z_scores = np.abs(points - np.mean(points, axis=0)) / np.std(points, axis=0)
25
- return points[(z_scores < z_thresh).all(axis=1)]
26
 
27
  @staticmethod
28
  def create_mesh(points: np.ndarray) -> trimesh.Trimesh:
29
- """ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ์—์„œ ๋ฉ”์‹œ ์ƒ์„ฑ"""
30
  return trimesh.points.PointCloud(points)
31
 
32
  @staticmethod
 
13
  # Z-score ์ •๊ทœํ™”
14
  mean = np.mean(points, axis=0)
15
  std = np.std(points, axis=0)
16
+ # ํ‘œ์ค€ํŽธ์ฐจ๊ฐ€ 0์ธ ๊ฒฝ์šฐ ๋Œ€๋น„
17
+ std = np.where(std < 1e-8, 1, std)
18
+ return (points - mean) / std
19
 
20
  @staticmethod
21
  def filter_outliers(points: np.ndarray, z_thresh=3.0) -> np.ndarray:
22
  """์ด์ƒ์น˜ ์ œ๊ฑฐ"""
23
  if len(points) == 0:
24
  return points
25
+
26
+ if len(points) <= 3: # ํฌ์ธํŠธ๊ฐ€ ๋„ˆ๋ฌด ์ ์œผ๋ฉด ํ•„ํ„ฐ๋ง ์ƒ๋žต
27
+ return points
28
+
29
+ z_scores = np.abs(points - np.mean(points, axis=0)) / (np.std(points, axis=0) + 1e-8)
30
+ mask = (z_scores < z_thresh).all(axis=1)
31
+
32
+ # ๋ชจ๋“  ํฌ์ธํŠธ๊ฐ€ ํ•„ํ„ฐ๋ง๋˜์ง€ ์•Š๋„๋ก ๋ณดํ˜ธ
33
+ if not np.any(mask):
34
+ return points
35
 
36
+ return points[mask]
 
37
 
38
  @staticmethod
39
  def create_mesh(points: np.ndarray) -> trimesh.Trimesh:
40
+ """ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ์—์„œ ๋ฉ”์‰ฌ ์ƒ์„ฑ"""
41
  return trimesh.points.PointCloud(points)
42
 
43
  @staticmethod