[DIP] Hu Moment

2024. 9. 10. 16:57·Programming/DIP
728x90
728x90

Hu moment

Hu 모멘트(Hu Moment)는 이미지의 형태적 특성을 수학적으로 분석하기 위해 사용되는 지표임.

 

1962년 중국 수학자인 Hu Ming-Kei가 제안한 불변 모멘트(invariant moments)로, 이미지의 크기, 회전, 그리고 이동 변환에 대해 불변.

  • Hu 모멘트를 이용하면 이미지가 회전하거나 크기가 변경되어도 동일한 형태적 특성을 추출할 수 있음.
  • 주로 binary image나 gray-scale image에 많이 사용됨.

ref. Hu. Visual Pattern Recognition by Moment Invariants, IRE Transactions on Information Theory, 8:2, pp. 179-187, 1962.

 

Hu Moment는 고전적인 패턴 인식(pattern recognition), 물체 인식(object recognition) 및 영상처리(image processing) 분야에서 물체의 형상을 분석하거나 분류할 때 널리 사용된 일종의 feature라고 봐도 됨. 이를 통해, 이미지를 회전, 이동, 크기 변화에 관계없이 인식하거나 비교할 수 있음.

 

https://dsaint31.me/mkdocs_site/DIP/cv2/ch02/dip_contour_features/#moment

 

BME228

Contour Features Moment Image moments은 물체의 중심, 물체의 면적 등을 계산하는데 이용되는 quantity(양)임. pixel intensity(←물리에서 force, mass등)의 정량적 크기 와 함께 분포 (어떤 기준에 대한) 를 고려한

dsaint31.me


1. Hu moment의 특징

  • Hu 모멘트는 7개의 invariant moment로 구성
  • 이들 각각은 이미지의 normalized central moments를 기반으로 계산됨.
  • 이 7개의 모멘트는 각각 이미지의 다양한 특성을 설명하는 값으로, 이미지가 회전하거나, 크기가 변하거나, 이동하더라도 동일한 값을 유지함: invariant moment
  • 이 invariant 덕분에 Hu moment는 다양한 상황에서 image recognition 에 강력한 feature로 사용됨.

2. Hu moment의 계산 과정

Hu moment는 normalized central moment를 이용해 계산됨.

2-1. 영역 모멘트(spatial moment):

이미지의 각 좌표 값과 그에 해당하는 픽셀 값을 이용하여 구함.

$$m_{pq} = \sum_{x} \sum_{y} x^p y^q I(x, y)$$
여기서 $I(x, y))는 좌표 ((x, y))에 있는 픽셀 값임.


2-2. 중심 모멘트(central moment):

이미지의 중심을 기준으로 픽셀 값들이 어떻게 분포되어 있는지를 나타내며, 이미지를 이동해도 변하지 않음: translational invariant

$$\mu_{pq} = \sum_{x} \sum_{y} (x - \bar{x})^p (y - \bar{y})^q I(x, y)$$

  • 여기서 (\bar{x}, \bar{y})는 이미지의 무게중심(centroid)을 나타냄.

2-3. Normalized Central Moment

Object의 전체 크기 ($\mu_{00}$)를 기반으로 normalization을 한 central moment로 좀더 robust함.

이미지의 확대(축소)와 이동에  invariant: Transaltional and Scale Invairiant

$$\nu_{pq} = \frac{\mu_{pq}}{\mu_{00}^{\left(1+\frac{p+q}{w}\right)}}$$

Hu moment는 이 중심 모멘트들를 normalization을 한 다음의 normalized central moment를 조합하여 이미지의 형태적 특성을 표현하고, 7개의 값으로 나타냄.


2-4. Hu moment 의 7가지 invariant moments

Hu는 다음과 같은 7개의 invariant moments를 제안했음.

  1. $\phi_1 = \nu_{20} + \nu_{02}$
  2. $\phi_2 = (\nu_{20} - \nu_{02})^2 + 4\nu_{11}^2$
  3. $\phi_3 = (\nu_{30} - 3\nu_{12})^2 + (3\nu_{21} - \nu_{03})^2$
  4. $\phi_4 = (\nu_{30} + \nu_{12})^2 + (\nu_{21} + \nu_{03})^2$
  5. $\phi_5 = (\nu_{30} - 3\nu_{12})(\nu_{30} + \nu_{12})[(\nu_{30} + \nu_{12})^2 - 3(\nu_{21} + \nu_{03})^2] + (3\nu_{21} - \nu_{03})(\nu_{21} + \nu_{03})[3(\nu_{30} + \nu_{12})^2 - (\nu_{21} + \nu_{03})^2]$
  6. $\phi_6 = (\nu_{20} - \nu_{02})[(\nu_{30} + \nu_{12})^2 - (\nu_{21} + \nu_{03})^2] + 4\nu_{11}(\nu_{30} + \nu_{12})(\nu_{21} + \nu_{03})$
  7. $\phi_7 = (3\nu_{21} - \nu_{03})(\nu_{30} + \nu_{12})[(\nu_{30} + \nu_{12})^2 - 3(\nu_{21} + \nu_{03})^2] - (\nu_{30} - 3\nu_{12})(\nu_{21} + \nu_{03})[3(\nu_{30} + \nu_{12})^2 - (\nu_{21} + \nu_{03})^2]$

여기서 $\nu_{pq}$는 normalized central moments임.

translation, scale, rotation에 invariant.


Hu moment 의 응용

Hu moment 는 다음과 같은 다양한 영상처리 및 패턴 인식 응용에 사용됨:

  • 패턴 인식(pattern recognition): 물체의 회전이나 크기 변환에 관계없이 물체를 인식하는 데 사용됨.
  • 물체 검출(object detection): 이미지 내 특정 물체를 검출하고 추적하는 작업에서 활용됨.
  • 문자 인식(optical character recognition, OCR): 글자가 회전하거나 크기가 변해도 동일한 글자임을 인식하는 데 유용함.
  • 의료 영상 분석(medical image analysis): 다양한 각도에서 촬영된 의료 영상을 분석하는 데 도움을 줌.

Example: OpenCV

관련 코드는 다음과 같음.

import cv2
import numpy as np

# 이미지 읽기 (grayscale로)
image = cv2.imread('image_path.jpg', cv2.IMREAD_GRAYSCALE)

# 이진화 (thresholding) - 배경과 객체를 분리하기 위해
_, thresholded_image = cv2.threshold(image, 128, 255, cv2.THRESH_BINARY)

# 모멘트 계산
moments = cv2.moments(thresholded_image)

# Hu 모멘트 계산
hu_moments = cv2.HuMoments(moments)

# Hu 모멘트를 로그 스케일로 변환 (더 보기 쉽게)
log_hu_moments = -np.sign(hu_moments) * np.log10(np.abs(hu_moments))

# Hu 모멘트 출력
print("Hu Moments:")
for i, hu_moment in enumerate(log_hu_moments):
    print(f"Hu Moment {i+1}: {hu_moment[0]}")

 

실행 방법:

  • image_path.jpg 부분을 분석하려는 이미지 경로로 변경하여 사용함.
  • 이 코드를 실행하면 이미지에 대한 7개의 Hu 모멘트 값이 출력됨.

같이 보면 좋은 자료들

https://docs.opencv.org/4.10.0/d3/dc0/group__imgproc__shape.html#gab001db45c1f1af6cbdbe64df04c4e944

 

OpenCV: Structural Analysis and Shape Descriptors

lineOutput line parameters. In case of 2D fitting, it should be a vector of 4 elements (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and (x0, y0) is a point on the line. In case of 3D fitting, it should be a v

docs.opencv.org

https://en.wikipedia.org/wiki/Image_moment

 

Image moment - Wikipedia

From Wikipedia, the free encyclopedia Weighted average/moment of some pixel intensities In image processing, computer vision and related fields, an image moment is a certain particular weighted average (moment) of the image pixels' intensities, or a functi

en.wikipedia.org

 

'Programming > DIP' 카테고리의 다른 글

[OpenCV] VideoCapture 사용법.  (0) 2024.09.11
[OpenCV] API Backend for VideoCapture  (0) 2024.09.11
[DIP] Tangential Distortion (접선왜곡)  (0) 2024.09.10
[CV] Sharpness (선예도)  (0) 2024.09.05
[CV] Brightness vs. Intensity  (0) 2024.09.05
'Programming/DIP' 카테고리의 다른 글
  • [OpenCV] VideoCapture 사용법.
  • [OpenCV] API Backend for VideoCapture
  • [DIP] Tangential Distortion (접선왜곡)
  • [CV] Sharpness (선예도)
dsaint31x
dsaint31x
    반응형
    250x250
  • dsaint31x
    Dsaint31's blog
    dsaint31x
  • 전체
    오늘
    어제
    • 분류 전체보기 (740)
      • Private Life (13)
      • Programming (56)
        • DIP (104)
        • ML (26)
      • Computer (119)
        • CE (53)
        • ETC (33)
        • CUDA (3)
        • Blog, Markdown, Latex (4)
        • Linux (9)
      • ... (351)
        • Signals and Systems (103)
        • Math (172)
        • Linear Algebra (33)
        • Physics (42)
        • 인성세미나 (1)
      • 정리필요. (54)
        • 의료기기의 이해 (6)
        • PET, MRI and so on. (1)
        • PET Study 2009 (1)
        • 방사선 장해방호 (4)
        • 방사선 생물학 (3)
        • 방사선 계측 (9)
        • 기타 방사능관련 (3)
        • 고시 (9)
        • 정리 (18)
      • RI (0)
      • 원자력,방사능 관련법 (2)
  • 블로그 메뉴

    • Math
    • Programming
    • SS
    • DIP
  • 링크

    • Convex Optimization For All
  • 공지사항

    • Test
    • PET Study 2009
    • 기타 방사능관련.
  • 인기 글

  • 태그

    Convolution
    math
    SS
    SIGNAL
    random
    Programming
    인허가제도
    Python
    fourier transform
    Term
    numpy
    opencv
    function
    linear algebra
    Optimization
    signals_and_systems
    Vector
    Probability
    검사
    signal_and_system
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
dsaint31x
[DIP] Hu Moment
상단으로

티스토리툴바