diff --git a/06-Image-Thresholding/cv2_thresholding.py b/06-Image-Thresholding/cv2_thresholding.py index 746947f..fce9689 100644 --- a/06-Image-Thresholding/cv2_thresholding.py +++ b/06-Image-Thresholding/cv2_thresholding.py @@ -1,5 +1,7 @@ import cv2 import matplotlib.pyplot as plt +import numpy as np + # 灰度图读入 img = cv2.imread('gradient.jpg', 0) @@ -30,6 +32,51 @@ # 自适应阈值对比固定阈值 img = cv2.imread('sudoku.jpg', 0) + print("Aligning images ... ") + alignMTB = cv2.createAlignMTB() + alignMTB.process(images, images) + + # Obtain Camera Response Function (CRF) + print("Calculating Camera Response Function (CRF) ... ") + calibrateDebevec = cv2.createCalibrateDebevec() + responseDebevec = calibrateDebevec.process(images, times) + + # Merge images into an HDR linear image + print("Merging images into one HDR image ... ") + mergeDebevec = cv2.createMergeDebevec() + hdrDebevec = mergeDebevec.process(images, times, responseDebevec) + # Save HDR image. + cv2.imwrite("hdrDebevec.hdr", hdrDebevec) + print("saved hdrDebevec.hdr ") + + # # Tonemap using Drago's method to obtain 24-bit color image + print("Tonemaping using Drago's method ... ") + tonemapDrago = cv2.createTonemapDrago(1.0, 0.7) + ldrDrago = tonemapDrago.process(hdrDebevec) + ldrDrago = 3 * ldrDrago + cv2.imwrite("ldr-Drago.jpg", ldrDrago * 255) + print("saved ldr-Drago.jpg") + + + # # 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) + cv2.imwrite("ldr-Reinhard.jpg", ldrReinhard * 255) + print("saved ldr-Reinhard.jpg") + + # # 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 + cv2.imwrite("ldr-Mantiuk.jpg", ldrMantiuk * 255) + print("saved ldr-Mantiuk.jpg") + + + + + # 固定阈值 ret, th1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY) # 自适应阈值