10강 HDR
HDR 기능을 활용하여 화질 개선해보자
HDR 이란
High Dynamic Range (HDR) Imaging 의 약자로 다양한 노출값 이미지들을 추출하여 보이지 않는 영역에 데이터를 선명하게 볼수 있게 만드는 기술이다.
- 이미지의 범위는 0~255 까지이고
- 밝은 값은 255에 가깝고
- 어두운 값은 0에 가깝다
1단계 여러 노출값의 이미지 가져오기
사진 정보
import cv2
import numpy as np
import matplotlib.pyplot as plt
def readImagesAndTimes():
# List of file names
filenames = ["img_0.033.jpg", "img_0.25.jpg", "img_2.5.jpg", "img_15.jpg"]
# List of exposure times
times = np.array([ 1/30.0, 0.25, 2.5, 15.0 ], dtype=np.float32)
# Read images
images = []
for filename in filenames:
im = cv2.imread(filename)
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
images.append(im)
return images, times
2단계 이미지 정렬
# Read images and exposure times
images, times = readImagesAndTimes()
# Align Images
alignMTB = cv2.createAlignMTB()
alignMTB.process(images, images)
3단계 카메라 지연 시간 측정하기
# Find Camera Response Function (CRF)
calibrateDebevec = cv2.createCalibrateDebevec()
responseDebevec = calibrateDebevec.process(images, times)
# Plot CRF
x = np.arange(256, dtype=np.uint8)
y = np.squeeze(responseDebevec)
ax = plt.figure(figsize=(30,10))
plt.title("Debevec Inverse Camera Response Function", fontsize=24)
plt.xlabel("Measured Pixel Value", fontsize=22)
plt.ylabel("Calibrated Intensity", fontsize=22)
plt.xlim([0,260])
plt.grid()
plt.plot(x, y[:,0],'r' , x, y[:,1],'g', x, y[:,2],'b');
4단계 노출된 이미지에 HDR 합치기
# Merge images into an HDR linear image
mergeDebevec = cv2.createMergeDebevec()
hdrDebevec = mergeDebevec.process(images, times, responseDebevec
5단계 Tonemapping
- ldr-Drago 방법
# Tonemap using Drago's method to obtain 24-bit color image tonemapDrago = cv2.createTonemapDrago(1.0, 0.7) ldrDrago = tonemapDrago.process(hdrDebevec) ldrDrago = 3 * ldrDrago plt.figure(figsize=(20,10)); plt.imshow(np.clip(ldrDrago,0,1)); plt.axis('off'); cv2.imwrite("ldr-Drago.jpg", ldrDrago * 255) print("saved ldr-Drago.jpg")
- ldr-Reinhard 방법
# Tonemap using Reinhard's method to obtain 24-bit color image print("Tonemaping using Reinhard's method ... ") tonemapReinhard = cv2.createTonemapReinhard(1.5, 0,0,0) ldrReinhard = tonemapReinhard.process(hdrDebevec) plt.figure(figsize=(20,10)); plt.imshow(np.clip(ldrReinhard,0,1)); plt.axis('off'); cv2.imwrite("ldr-Reinhard.jpg", ldrReinhard * 255) print("saved ldr-Reinhard.jpg")
- Mantiuk 방법
# Tonemap using Mantiuk's method to obtain 24-bit color image
print("Tonemaping using Mantiuk's method ... ")
tonemapMantiuk = cv2.createTonemapMantiuk(2.2,0.85, 1.2)
ldrMantiuk = tonemapMantiuk.process(hdrDebevec)
ldrMantiuk = 3 * ldrMantiuk
plt.figure(figsize=(20,10)); plt.imshow(np.clip(ldrMantiuk,0,1)); plt.axis('off');
cv2.imwrite("ldr-Mantiuk.jpg", ldrMantiuk * 255)
print("saved ldr-Mantiuk.jpg")
댓글남기기