Files
2nd/10_Wiki/Topics/AI_and_ML/Shape-Feature-Extraction.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

5.1 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-shape-feature-extraction Shape Feature Extraction 10_Wiki/Topics verified self
Shape Descriptors
HOG
SIFT
Contour Features
none A 0.9 applied
computer-vision
feature-extraction
image-processing
2026-05-10 pending
language framework
python OpenCV / scikit-image / PyTorch

Shape Feature Extraction

매 한 줄

"매 image / object 에서 numerical descriptor 뽑기 — boundary, region, gradient". 매 classical (HOG, SIFT, Hu moments, Fourier descriptors) 부터 매 deep features (CNN backbone, DINOv2/v3, SAM2 mask embedding) 까지의 spectrum. 매 2026 default: deep features for recognition, classical for low-data / explainable / edge.

매 핵심

매 분류

  • Boundary-based: contour chain code, Fourier descriptors, polygon approx.
  • Region-based: area, perimeter, eccentricity, Hu moments (rotation/scale invariant).
  • Gradient-based: HOG (Dalal 2005), SIFT (Lowe 2004), SURF, ORB.
  • Texture+shape: LBP, GLCM.
  • Deep: CNN penultimate layer, ViT [CLS] token, DINOv3 patch features.

매 Invariance 요구

  • Translation: 매 거의 모든 method.
  • Rotation: Hu moments, SIFT, RIFT.
  • Scale: SIFT, multi-scale CNN.
  • Illumination: HOG (gradient), normalized embeddings.
  • Affine: ASIFT.

매 응용

  1. Object recognition (legacy + edge).
  2. Image retrieval / re-id (deep embeddings).
  3. OCR pre-processing (contour).
  4. Medical imaging (lesion shape descriptors).
  5. Industrial defect inspection.
  6. Robot grasp planning (object silhouette).

💻 패턴

Contour features (OpenCV)

import cv2, numpy as np
gray = cv2.imread("obj.png", 0)
_, bw = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)
contours, _ = cv2.findContours(bw, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
c = max(contours, key=cv2.contourArea)
area = cv2.contourArea(c)
peri = cv2.arcLength(c, True)
circ = 4 * np.pi * area / (peri ** 2)
hu = cv2.HuMoments(cv2.moments(c)).flatten()

HOG

from skimage.feature import hog
feat, vis = hog(gray, orientations=9, pixels_per_cell=(8,8),
                cells_per_block=(2,2), visualize=True)

SIFT (OpenCV)

sift = cv2.SIFT_create()
kp, desc = sift.detectAndCompute(gray, None)  # desc: (N, 128)

Fourier descriptors

def fourier_descriptors(contour, k=20):
    pts = contour[:, 0, 0] + 1j * contour[:, 0, 1]
    fd = np.fft.fft(pts)
    fd[0] = 0                    # translation invariant
    fd /= np.abs(fd[1])          # scale invariant
    return np.abs(fd[1:k+1])     # rotation invariant (magnitude)

Deep feature (DINOv3)

import torch
from transformers import AutoModel, AutoImageProcessor
proc = AutoImageProcessor.from_pretrained("facebook/dinov3-base")
model = AutoModel.from_pretrained("facebook/dinov3-base").eval().cuda()
inp = proc(img, return_tensors="pt").to("cuda")
with torch.no_grad():
    feats = model(**inp).last_hidden_state  # (1, N+1, D)
    cls_emb = feats[:, 0]                   # global shape/appearance

SAM2 mask + descriptor pipeline

from sam2.build_sam import build_sam2
from sam2.sam2_image_predictor import SAM2ImagePredictor
sam = build_sam2("sam2_hiera_l.yaml", "sam2_l.pt")
pred = SAM2ImagePredictor(sam)
pred.set_image(img)
masks, _, _ = pred.predict(point_coords=pts, point_labels=lbl)
# 매 mask 내부 영역만 dino feature 뽑기 → object-centric descriptor

Image retrieval pipeline

emb = []
for p in paths:
    e = dino_embed(load(p))
    emb.append(e / e.norm())
emb = torch.stack(emb)
# query
q = dino_embed(load(query))
q /= q.norm()
sims = (emb @ q.T).flatten()
topk = sims.topk(10).indices

매 결정 기준

상황 Approach
Modern recognition / retrieval DINOv3 / CLIP embedding
Explainable / regulatory Hu moments, contour
Real-time embedded ORB or tiny CNN
Robust to occlusion local features (SIFT/SuperPoint)
Mask 필요 + descriptor SAM2 + DINO

기본값: DINOv3 embedding for general purpose.

🔗 Graph

🤖 LLM 활용

언제: dataset 작거나 explainability 요구 → classical. Otherwise deep. 언제 X: 매 generic image classification — end-to-end deep model 가 매 simpler.

안티패턴

  • HOG + SVM in 2026: deep baseline 보다 명확히 약함 unless tiny data.
  • Hand-crafted features then deep classifier: 매 mismatch — pick one paradigm.
  • No normalization: scale/illumination drift → 매 retrieval 실패.
  • SIFT 특허 우려: 2020+ 매 expired, 그래도 license 확인.

🧪 검증 / 중복

  • Verified (Lowe 2004 SIFT, Dalal 2005 HOG, OpenCV docs, DINOv3 paper).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — classical + DINOv3/SAM2 2026