Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- high-dimensional data analysis
- simulation
- big data
- bitdepth
- gray level resolution
- 이미지스트레칭
- 스플라인
- 데이터분석
- OpenCV
- 미국온라인석사
- data science
- functional data analysis
- 빅데이터
- datascience
- 이미지처리
- 이미지대비
- 이미지프로세싱
- 이미지변환
- 이미지향상
- Data Analysis
- 이미지분석
- 고차원데이터
- 데이터사이언스
- 함수형데이터분석
- 이미지콘볼루션
- 고차원데이터분석
- 시뮬레이션
- 모델링
- high dimensional data analysis
- OMSA
Archives
- Today
- Total
곤약노트
이미지 변환 (Image Transformation) ②밝기 조절하기 – 히스토그램 이동 (Histogram Shifting) 본문
Data Science/High-Dimensional Data Analytics
이미지 변환 (Image Transformation) ②밝기 조절하기 – 히스토그램 이동 (Histogram Shifting)
곤약처럼 부드럽게, 쫀쫀하게 2025. 6. 29. 07:00이미지의 밝기(brightness)를 조절하고 싶을 때 어떻게 해야 할까요? 가장 직관적이고 쉬운 방법 중 하나가 바로 히스토그램 이동(Histogram Shifting)입니다.
앞선 포스팅에서 설명 드린대로 이미지의 히스토그램이란, 각 밝기 값(0~255)이 이미지에 얼마나 자주 등장하는지를 막대 그래프로 표현한 것이에요.
- 왼쪽: 어두운 픽셀 많음
- 오른쪽: 밝은 픽셀 많음
픽셀 값을 전체적으로 상수 S만큼 더하거나 빼면, 이미지가 밝아지거나 어두워집니다.
$$ g(x, y) = T(f(x, y)) = \begin{cases} U & \text{if } f(x, y) > U - S \\ f(x, y) + S & \text{otherwise} \\ L & \text{if } f(x, y) \leq L - S \end{cases} $$
- f(x,y): 원본 이미지에서의 밝기 값
- g(x,y): 밝기 조절된 결과 이미지
- S: 밝기 변화 정도 (양수 = 밝게, 음수 = 어둡게)
- L=0, : 픽셀 값의 최소, 최대
import numpy as np
import matplotlib.pyplot as plt
import cv2
# 이미지 불러오기 및 Grayscale 변환
image = cv2.imread('watermelon.jpg', cv2.IMREAD_GRAYSCALE)
# 밝기 이동: [25, 225] 범위 내 픽셀만 +50
shifted = image.copy().astype(np.int32)
mask = (shifted >= 25) & (shifted <= 225)
shifted[mask] += 50
shifted = np.clip(shifted, 0, 255).astype(np.uint8)
# 이미지 및 히스토그램 시각화
plt.figure(figsize=(12, 5))
# 1. 원본 그레이스케일 이미지
plt.subplot(1, 3, 1)
plt.imshow(image, cmap='gray')
plt.title('Original Grayscale')
plt.axis('off')
# 2. 밝기 이동된 이미지
plt.subplot(1, 3, 2)
plt.imshow(shifted, cmap='gray')
plt.title('Histogram Shifted (+50)')
plt.axis('off')
# 3. 히스토그램
plt.subplot(1, 3, 3)
plt.hist(shifted.ravel(), bins=256, range=[0, 256], color='gray')
plt.title('Histogram (Shifted)')
plt.xlabel('Pixel Intensity (0–255)')
plt.ylabel('Frequency')
plt.tight_layout()
plt.show()

