cv2.imwrite("ldr-Drago.jpg", ldrDrago * 255) print("saved ldr-Drago.jpg") # # Tonemap using Durand's method obtain 24-bit color image print("Tonemaping using Durand's method ... ") tonemapDurand = cv2.createTonemapDurand(1.5, 4, 1.0, 1, 1) ldrDurand = tonemapDurand.process(hdrDebevec) ldrDurand = 3 * ldrDurand cv2.imwrite("ldr-Durand.jpg", ldrDurand * 255) print("saved ldr-Durand.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") plt.figure() plt.imshow(ldrMantiuk) plt.show()
def mainfunction(): img1 = cv2.imread('processed_exposure1.tiff') img1 = cv2.resize(img1, None, fx=0.25, fy=0.25) img1 = img1.astype(np.float16) img1 = img1 / 65535 img2 = cv2.imread('processed_exposure2.tiff') img2 = cv2.resize(img2, None, fx=0.25, fy=0.25) img2 = img2.astype(np.float16) img2 = img2 / 65535 img3 = cv2.imread('processed_exposure3.tiff') img3 = cv2.resize(img3, None, fx=0.25, fy=0.25) img3 = img3.astype(np.float16) img3 = img3 / 65535 img4 = cv2.imread('processed_exposure4.tiff') img4 = cv2.resize(img4, None, fx=0.25, fy=0.25) img4 = img4.astype(np.float16) img4 = img4 / 65535 img5 = cv2.imread('processed_exposure5.tiff') img5 = cv2.resize(img5, None, fx=0.25, fy=0.25) img5 = img5.astype(np.float16) img5 = img5 / 65535 img6 = cv2.imread('processed_exposure6.tiff') img6 = cv2.resize(img6, None, fx=0.25, fy=0.25) img6 = img6.astype(np.float16) img6 = img6 / 65535 img7 = cv2.imread('processed_exposure7.tiff') img7 = cv2.resize(img7, None, fx=0.25, fy=0.25) img7 = img7.astype(np.float16) img7 = img7 / 65535 img8 = cv2.imread('processed_exposure8.tiff') img8 = cv2.resize(img8, None, fx=0.25, fy=0.25) img8 = img8.astype(np.float16) img8 = img8 / 65535 img9 = cv2.imread('processed_exposure9.tiff') img9 = cv2.resize(img9, None, fx=0.25, fy=0.25) img9 = img9.astype(np.float16) img9 = img9 / 65535 img10 = cv2.imread('processed_exposure10.tiff') img10 = cv2.resize(img10, None, fx=0.25, fy=0.25) img10 = img10.astype(np.float16) img10 = img10 / 65535 img11 = cv2.imread('processed_exposure11.tiff') img11 = cv2.resize(img11, None, fx=0.25, fy=0.25) img11 = img11.astype(np.float16) img11 = img11 / 65535 img12 = cv2.imread('processed_exposure12.tiff') img12 = cv2.resize(img12, None, fx=0.25, fy=0.25) img12 = img12.astype(np.float16) img12 = img12 / 65535 img13 = cv2.imread('processed_exposure13.tiff') img13 = cv2.resize(img13, None, fx=0.25, fy=0.25) img13 = img13.astype(np.float16) img13 = img13 / 65535 img14 = cv2.imread('processed_exposure14.tiff') img14 = cv2.resize(img14, None, fx=0.25, fy=0.25) img14 = img14.astype(np.float16) img14 = img14 / 65535 img15 = cv2.imread('processed_exposure15.tiff') img15 = cv2.resize(img15, None, fx=0.25, fy=0.25) img15 = img15.astype(np.float16) img15 = img15 / 65535 img16 = cv2.imread('processed_exposure16.tiff') img16 = cv2.resize(img16, None, fx=0.25, fy=0.25) img16 = img16.astype(np.float16) img16 = img16 / 65535 listofimages = [ img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14, img15, img16 ] #=np.zeros([4016,6016,3]) I = np.zeros([1004, 1504, 3]) #I=np.zeros([1000,1000,3]) for i in range(0, 1004): #g1.shape[0]) for j in range(0, 1504): #img1.shape[1] for c in range(0, 3): s = 0 s1 = 0 for k in range(0, 16): x = listofimages[k] #Reteiving the image from the list t = time(k + 1) #Calculating thr time value = x[i, j, c] #Storing the value weightk = weight(x[i, j, c]) #Calculating weight s = s + (weightk * value) / t s1 = s1 + weightk I[i, j, c] = s / s1 print(I[i, j, c], i, j, c) #Performing Photographic tone mapping tonemap = np.divide(I, (1 + I)) #Using the formula IHDR/1+IHDR tonemap8 = (tonemap / np.max(tonemap) * 255).astype( np.uint8) #Performing the conversion to uint8 cv2.imwrite('Photographic_tonemapping.png', tonemap8) #Displaying the image #Performing tonemapping using the opencv functions I = I.astype(np.float32) #Change to float32 tonemapMantiuk = cv2.createTonemapMantiuk( 2.2, 0.7, -0.1) #Creating object of the tonemap class ldrMantiuk = tonemapMantiuk.process( I) #Performing the process of the mapping cv2.imwrite('opencv_tonemapping2.png', ldrMantiuk)
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 Durand's method obtain 24-bit color image print("Tonemaping using Durand's method ... ") tonemapDurand = cv2.createTonemapDurand(1.5,4,1.0,1,1) ldrDurand = tonemapDurand.process(hdrDebevec) ldrDurand = 3 * ldrDurand cv2.imwrite("ldr-Durand.jpg", ldrDurand * 255) print("saved ldr-Durand.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")
def tone_mapping_Mantiuk(hdrDebevec): tonemapMantiuk = cv2.createTonemapMantiuk(2.2, 0.85, 1.2) ldrMantiuk = tonemapMantiuk.process(hdrDebevec) ldrMantiuk = 3 * ldrMantiuk return ldrMantiuk * 255