용화.las(기복 251.9m) 전처리에서 지면점이 0.06%까지 사라졌다. 원인은 현장 하나에
맞춰 박아둔 상수였다.
- CSF 하강 예산이 0.3185m x 150회 = 47.8m로 고정돼, 기복이 그보다 큰 산악지에서
천이 지면에 닿지 못했다. 반복 수를 collision_grid 기준 필요 하강량에서 뽑고
SURFACE_CSF_MAX_ITERATIONS로 상한만 둔다.
- CSF 6단계 수목 필터는 비교 피연산자가 뒤집혀 조건이 항상 참이었다. 셀 지면
후보 대비 높이를 보도록 순서를 바로잡는다.
- grid_min_z의 3x3 minimum_filter가 급경사에서 기준면을 경사만큼 파고들어
(중앙 1.88m > 임계 1.5m) 지면점을 떨궜다. 제거한다.
- 기준면 배열이 float32라 셀 최저점이 반올림으로 자기 기준면보다 낮아져
탈락했다. 원본 좌표와 같은 float64로 둔다.
- LAS가 지면분류(class 2)를 싣고 오면 filter_classification을 자동으로 붙인다.
미분류 LAS에서는 조용히 빠진다.
- 필터별 ground_ratio를 로그에 남기고, 하한 미만이면 WARNING을 띄운다.
지금까지는 0.06%가 나와도 "계산 완료"로만 보였다.
실측 (build_ground_masks 재계산):
용화 grid_min_z 0.52% -> 4.91% (class2 회수율 17.9% -> 93.3%)
csf 0.06% -> 1.57% (class2 회수율 1.3% -> 55.1%)
cloud_merged grid_min_z 11.60% -> 17.51%
csf 8.84% -> 10.68%
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
85 lines
3.0 KiB
Python
85 lines
3.0 KiB
Python
"""B04 지면 필터 오케스트레이션.
|
|
|
|
구조화된 포인트클라우드(structured.npz)에 대해 grid_min_z/csf/pmf/ransac
|
|
필터를 실행하여 지면 마스크 딕셔너리를 만든다. 필터 선택은 config의
|
|
source_filters를 따른다.
|
|
"""
|
|
|
|
from typing import Any
|
|
|
|
import numpy as np
|
|
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_Classification import (
|
|
filter_classification,
|
|
has_classified_ground,
|
|
)
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_CSF import filter_csf
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_Grid import filter_grid_min_z
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_PMF import filter_pmf
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_RANSAC import filter_ransac
|
|
|
|
# 필터 키 → 함수 매핑
|
|
_FILTERS = {
|
|
"grid_min_z": filter_grid_min_z,
|
|
"csf": filter_csf,
|
|
"pmf": filter_pmf,
|
|
"ransac": filter_ransac,
|
|
"classification": filter_classification,
|
|
}
|
|
|
|
# LAS에 지면분류가 실제로 들어 있을 때만 쓰는 필터 (미분류 LAS에서는 마스크가 빈다)
|
|
_CONDITIONAL_FILTERS = {"classification": has_classified_ground}
|
|
|
|
|
|
def available_filters() -> tuple[str, ...]:
|
|
return tuple(_FILTERS.keys())
|
|
|
|
|
|
def detect_extra_filters(
|
|
structured_data: dict[str, Any] | np.lib.npyio.NpzFile,
|
|
filter_keys: tuple[str, ...] | list[str],
|
|
) -> list[str]:
|
|
"""이 LAS에서만 쓸 수 있는 조건부 필터 중 아직 목록에 없는 것을 고른다."""
|
|
return [
|
|
key
|
|
for key, is_usable in _CONDITIONAL_FILTERS.items()
|
|
if key not in filter_keys and is_usable(structured_data)
|
|
]
|
|
|
|
|
|
def run_ground_filter(
|
|
filter_key: str, structured_data: dict[str, Any] | np.lib.npyio.NpzFile
|
|
) -> np.ndarray:
|
|
"""단일 지면 필터를 실행해 불리언 마스크를 반환한다."""
|
|
if filter_key not in _FILTERS:
|
|
raise ValueError(f"알 수 없는 지면 필터입니다: {filter_key}")
|
|
return np.asarray(_FILTERS[filter_key](structured_data), dtype=bool)
|
|
|
|
|
|
def build_ground_masks(
|
|
structured_data: dict[str, Any] | np.lib.npyio.NpzFile,
|
|
filter_keys: tuple[str, ...] | list[str],
|
|
) -> dict[str, np.ndarray]:
|
|
"""지정한 필터들을 실행해 {filter_key: mask} 딕셔너리를 만든다."""
|
|
masks: dict[str, np.ndarray] = {}
|
|
for filter_key in filter_keys:
|
|
masks[filter_key] = run_ground_filter(filter_key, structured_data)
|
|
return masks
|
|
|
|
|
|
def summarize_masks(
|
|
structured_data: dict[str, Any] | np.lib.npyio.NpzFile,
|
|
masks: dict[str, np.ndarray],
|
|
) -> dict[str, dict[str, Any]]:
|
|
"""각 필터 마스크의 지면 포인트 수·비율 요약을 만든다."""
|
|
total = int(len(structured_data["xyz"]))
|
|
summary: dict[str, dict[str, Any]] = {}
|
|
for filter_key, mask in masks.items():
|
|
ground = int(np.count_nonzero(mask))
|
|
summary[filter_key] = {
|
|
"ground_point_count": ground,
|
|
"total_point_count": total,
|
|
"ground_ratio": round(ground / total, 4) if total else 0.0,
|
|
}
|
|
return summary
|