Trilinear Interpolation을 이용한 Mesh Vertex Label 보간 방법

Bean·2025년 5월 11일
0

인공지능

목록 보기
23/123

3D Segmentation: Mesh Vertex에 Voxel Label을 Trilinear Interpolation으로 할당하기

3D 데이터 처리에서 voxel 기반 segmentation 결과를 mesh geometry에 매핑해야 하는 경우가 자주 발생합니다. 예를 들어, medical imaging이나 3D reconstruction에서는 voxel grid 상에 얻어진 segmentation 결과를 원래의 mesh surface에 옮겨야 할 수 있습니다.

이 글에서는 voxel segmentation label이 주어졌을 때, mesh vertex에 해당 label을 trilinear interpolation을 이용해 보간하는 방법을 설명합니다.


문제 정의

  • 주어짐:

    • 3D 공간을 나눈 voxel grid (D x H x W), 각 voxel vertex 또는 cell에는 segmentation label 정보가 있음 (예: class index, one-hot label, 또는 softmax 확률).
    • 다양한 위치에 존재하는 mesh vertex 좌표 (N x 3)
  • 목표:

    • 각 mesh vertex에 적절한 segmentation label을 voxel label로부터 interpolation을 통해 할당하기

핵심 아이디어

Trilinear interpolation은 3D 공간에서 정규격자(voxel grid) 위에 존재하는 데이터 값을 이용해, 임의 위치에서의 값을 추정하는 방법입니다.
이를 mesh vertex에 적용하면 다음과 같은 절차로 segmentation label을 보간할 수 있습니다.


보간 절차

1. Voxel label 준비

  • 입력 voxel label은 shape (C, D, H, W) 형태로 준비합니다.

    • 여기서 C는 class 수입니다 (예: 4개의 클래스라면 C=4).
    • 각 voxel point에는 soft label 또는 one-hot label이 존재합니다.

2. Mesh vertex 좌표 정규화

  • mesh_vertex는 보통 world coordinate에 있으므로, voxel grid 범위로 정규화(normalization) 합니다.

    • x_normalized = (x - min) / (max - min) * 2 - 1
      [-1, 1] 범위로 변환 (PyTorch의 grid_sample 기준)

3. Trilinear interpolation 수행

  • PyTorch의 grid_sample을 이용해 interpolation을 수행할 수 있습니다.
  • 각 mesh vertex 위치에 대해 주변 8개 voxel 값을 기반으로 보간한 soft label이 계산됩니다.

4. (선택) Class index 결정

  • Soft label 결과에서 argmax를 취해 최종 class index를 부여할 수 있습니다.

예제 코드 (PyTorch)

import torch
import torch.nn.functional as F

# voxel_labels: (1, C, D, H, W)
# mesh_vertices: (N, 3)

# 1. Normalize coordinates to [-1, 1]
coords = (mesh_vertices - min_coord) / (max_coord - min_coord) * 2 - 1
coords = coords.view(1, 1, 1, -1, 3)  # (1, D=1, H=1, W=N, 3)

# 2. Perform trilinear interpolation
sampled = F.grid_sample(voxel_labels, coords, mode='bilinear', align_corners=True)

# 3. Get class index
vertex_labels = sampled.squeeze().argmax(dim=0)  # shape: (N,)

보간 결과의 해석

  • Soft label (확률 분포): 더 부드러운 label 전이를 얻을 수 있음
  • Hard label (argmax 적용): 각 vertex에 단일 class index 부여

마무리

Trilinear interpolation은 voxel → mesh vertex로 label 정보를 매핑할 때 매우 유용한 기법입니다.
특히 voxel-based 모델의 출력을 mesh로 시각화하거나 후처리할 때 널리 활용됩니다.


profile
AI developer

0개의 댓글