곤약노트

이미지 변환 (Image Transformation) ⑤이미지 향상 (Image Enchantment) 3종 비교 본문

Data Science/High-Dimensional Data Analytics

이미지 변환 (Image Transformation) ⑤이미지 향상 (Image Enchantment) 3종 비교

곤약처럼 부드럽게, 쫀쫀하게 2025. 7. 8. 09:00

Gray Level Transformation은 이미지의 픽셀 값을 수학적 함수로 변환해서 밝기를 조절하거나 대비를 높이는 기법입니다.
이미지를 강조(enhancement)하거나 특정 특징을 부각할 때 자주 사용됩니다.

 

1. Linear (Negative Image)

\( g(x, y) = (L - 1) - f(x, y) \)

 

  • 밝은 부분은 어둡게, 어두운 부분은 밝게 반전 → 음화 이미지(negative image) 생성
  • 흑백 필름 느낌 표현 가능

 

2. Log Transformation

 

\( g(x, y) = c \cdot \log(f(x, y) + 1) \)
  • 어두운 영역을 강조하고 밝은 영역은 눌러줌
  • 영상에서 작은 세부사항을 살리고 싶을 때 사용

 

3. Power-Law (Gamma) Transformation

\( g(x, y) = c \cdot f(x, y)^{\gamma} \)

 

  • 감마 보정(gamma correction)이라고도 불림
  • γ<1: 이미지 밝게
  • γ>1: 이미지 어둡게
image_gray = cv2.imread('watermelon.jpg', cv2.IMREAD_GRAYSCALE)

# 1. 음화 이미지 (Negative)
negative = 255 - image_gray

# 2. 로그 변환
c = 255 / np.log(1 + np.max(image_gray))
log_transformed = c * np.log(1 + image_gray.astype(np.float32))
log_transformed = np.uint8(np.clip(log_transformed, 0, 255))

# 3. 감마 보정 (γ < 1 밝게, γ > 1 어둡게)
gamma = 0.5  # 예: 밝게
gamma_corrected = 255 * ((image_gray / 255) ** gamma)
gamma_corrected = np.uint8(np.clip(gamma_corrected, 0, 255))

plt.figure(figsize=(12, 6))

plt.subplot(1, 4, 1)
plt.imshow(image_gray, cmap='gray')
plt.title('Original')
plt.axis('off')

plt.subplot(1, 4, 2)
plt.imshow(negative, cmap='gray')
plt.title('Negative Image')
plt.axis('off')

plt.subplot(1, 4, 3)
plt.imshow(log_transformed, cmap='gray')
plt.title('Log Transform')
plt.axis('off')

plt.subplot(1, 4, 4)
plt.imshow(gamma_corrected, cmap='gray')
plt.title(f'Gamma Correction (γ={gamma})')
plt.axis('off')

plt.tight_layout()
plt.show()