欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python中OpenCV?Tutorials?20??高動(dòng)態(tài)范圍成像的實(shí)現(xiàn)步驟

 更新時(shí)間:2022年06月16日 11:43:08   作者:Detection  
這篇文章主要介紹了OpenCV?Tutorials?20?-?高動(dòng)態(tài)范圍成像,本文還給大家展示了一種稱為曝光融合的替代方法,它可以產(chǎn)生低動(dòng)態(tài)范圍的圖像,需要的朋友可以參考下

高動(dòng)態(tài)范圍成像

一、引言

如今,大多數(shù)數(shù)字圖像和成像設(shè)備每通道使用 8 位整數(shù)表示灰度,因此將設(shè)備的動(dòng)態(tài)范圍限制在兩個(gè)數(shù)量級(實(shí)際上是 256 級),而人眼可以適應(yīng)變化十個(gè)數(shù)量級的照明條件。當(dāng)我們拍攝真實(shí)世界場景的照片時(shí),明亮區(qū)域可能曝光過度,而黑暗區(qū)域可能曝光不足,因此我們無法使用單次曝光捕捉所有細(xì)節(jié)。 HDR 成像適用于每通道使用超過 8 位(通常為 32 位浮點(diǎn)值)的圖像,允許更寬的動(dòng)態(tài)范圍。獲取 HDR 圖像的方法有很多種,但最常見的一種是使用以不同曝光值拍攝的場景照片。要結(jié)合這些曝光,了解相機(jī)的響應(yīng)函數(shù)以及估計(jì)它的算法很有用?;旌?HDR 圖像后,必須將其轉(zhuǎn)換回 8 位才能在普通顯示器上查看。這個(gè)過程稱為色調(diào)映射。當(dāng)場景或相機(jī)的對象在鏡頭之間移動(dòng)時(shí),會(huì)出現(xiàn)額外的復(fù)雜性,因?yàn)閼?yīng)該配準(zhǔn)和對齊具有不同曝光的圖像。在本教程中,我們將展示如何從曝光序列中生成和顯示 HDR 圖像。在我們的例子中,圖像已經(jīng)對齊并且沒有移動(dòng)對象。我們還展示了一種稱為曝光融合的替代方法,它可以產(chǎn)生低動(dòng)態(tài)范圍的圖像。 HDR 管道的每個(gè)步驟都可以使用不同的算法來實(shí)現(xiàn),因此請查看參考手冊以了解所有這些。

二、曝光序列

download.png

三、代碼演示

from __future__ import print_function
from __future__ import division
import cv2 as cv
import numpy as np
import argparse
import os
def cv_show(name, img):
    cv.imshow(name, img)
    cv.waitKey(0)
    cv.destroyAllWindows()
def compare(imgs):
  #  for i in range(len(imgs)):
 #       imgs[i][:,-3:-1,:] = [255,255,255]
    res = np.hstack(imgs)
    cv_show('Compare', res)
def loadExposureSeq(path):
    images = []
    times = []
    with open(os.path.join(path, 'list.txt')) as f:
        content = f.readlines()
    for line in content:
        tokens = line.split()
        images.append(cv.imread(os.path.join(path, tokens[0])))
        # 便于之后的逆CRF操作
        times.append(1 / float(tokens[1]))
    return images, np.asarray(times, dtype=np.float32)
# jupyter 難以手動(dòng)輸入?yún)?shù),故使用絕對路徑
#parser = argparse.ArgumentParser(description='Code for High Dynamic Range Imaging tutorial.')
# parser.add_argument('--input', type=str, help='Path to the directory that contains images and exposure times.')
# args = parser.parse_args()
# if not args.input:
#     parser.print_help()
#     exit(0)
# images, times = loadExposureSeq(args.input)
images, times = loadExposureSeq('exposures/')
calibrate = cv.createCalibrateDebevec()
response = calibrate.process(images, times)
merge_debevec = cv.createMergeDebevec()
hdr = merge_debevec.process(images, times, response)
tonemap = cv.createTonemap(2.2)
ldr = tonemap.process(hdr)
merge_mertens = cv.createMergeMertens()
fusion = merge_mertens.process(images)
cv.imwrite('fusion.png', fusion * 255)
cv.imwrite('ldr.png', ldr * 255)
cv.imwrite('hdr.hdr', hdr)
True

四、解釋

1. 加載圖像和曝光時(shí)間

images, times = loadExposureSeq('exposures/')
# 查看數(shù)據(jù)集中曝光圖像個(gè)數(shù)
len(images)
16

首先我們從用戶自定義文件夾中(此處我采用了教程提供的數(shù)據(jù)集并將其放置到了同目錄下便于載入)載入輸入圖像以及其曝光時(shí)間。文件夾中需要包含圖像和list.txt文本文件,其中包含了文件名稱和反曝光時(shí)間

提供的圖像數(shù)據(jù)集的列表如下:

memorial00.png 0.03125

memorial01.png 0.0625

...

memorial15.png 1024

2. 估計(jì)相機(jī)響應(yīng)

calibrate = cv.createCalibrateDebevec()
response = calibrate.process(images, times)
  • 用法如下:

cv.createCalibrateDebevec( [, samples[, lambda_[, random]]] ) -> retval

  • 參數(shù)含義:
  • samples :number of pixel locations to use
  • lambda :smoothness term weight. Greater values produce smoother results, but can alter the response.
  • random :if true sample pixel locations are chosen at random, otherwise they form a rectangular grid.

很多 HDR 構(gòu)建算法都需要了解相機(jī)響應(yīng)函數(shù)(CRF)。 我們使用一種校準(zhǔn)算法來估計(jì)所有 256 個(gè)像素值的逆 CRF

3. 形成HDR圖像

merge_debevec = cv.createMergeDebevec()
# 利用逆CRF形成HDR圖像
hdr = merge_debevec.process(images, times, response)
  • 用法如下:

cv.createMergeMertens( [, contrast_weight[, saturation_weight[, exposure_weight]]] ) -> retval

  • 參數(shù)含義:
  • contrast_weight :contrast measure weight. See MergeMertens.
  • saturation_weight: saturation measure weight
  • exposure_weight :well-exposedness measure weight

我們使用 Debevec 的加權(quán)方案,使用上一項(xiàng)中計(jì)算的響應(yīng)來構(gòu)建 HDR 圖像。

4. 對 HDR 圖像進(jìn)行色調(diào)映射

tonemap = cv.createTonemap(2.2)
ldr = tonemap.process(hdr)
cv_show('Result', ldr)
  • 用法如下: cv.createTonemap( [, gamma] ) -> retval
  • 參數(shù)含義:
  • gamma :positive value for gamma correction. Gamma value of 1.0 implies no correction, gamma equal to 2.2f is suitable for most displays. Generally gamma > 1 brightens the image and gamma < 1 darkens it.

由于我們想在普通 LDR 顯示器上看到我們的結(jié)果,我們必須將 HDR 圖像映射到 8 位范圍,保留大部分細(xì)節(jié)。 這是色調(diào)映射方法的主要目標(biāo)。 我們使用帶有雙邊濾波的色調(diào)映射器,并將 2.2 設(shè)置為 gamma 校正的值。

5. 實(shí)現(xiàn)曝光融合

merge_mertens = cv.createMergeMertens()
fusion = merge_mertens.process(images)

如果我們不需要 HDR 圖像,還有另一種方法可以合并我們的曝光。 這個(gè)過程稱為曝光融合,并產(chǎn)生不需要伽馬校正的 LDR 圖像。 它也不使用照片的曝光值。

compare([ldr,fusion])

download.png

左邊是對HDR圖像直接進(jìn)行色調(diào)映射的結(jié)果,只會(huì)保留大部分細(xì)節(jié),右邊圖像是使用所有輸入圖像序列進(jìn)行圖像曝光融合的結(jié)果

請注意,HDR 圖像不能以一種常見的圖像格式存儲(chǔ),因此我們將其保存為 Radiance 圖像 (.hdr)。 此外,所有 HDR 成像函數(shù)都返回 [0, 1] 范圍內(nèi)的結(jié)果,因此我們應(yīng)該將結(jié)果乘以 255。您可以嘗試其他色調(diào)映射算法:cv::TonemapDrago、cv::TonemapMantiuk 和 cv::TonemapReinhard 您還可以調(diào)整 您自己的照片的 HDR 校準(zhǔn)和色調(diào)映射方法參數(shù)。

# 修改gamma使整幅圖像變亮
tonemap = cv.createTonemap(10)
ldr = tonemap.process(hdr)
cv_show('Result', ldr)

download.png

五、補(bǔ)充資源

  • Paul E Debevec and Jitendra Malik. Recovering high dynamic range radiance maps from photographs. In ACM SIGGRAPH 2008 classes, page 31. ACM, 2008. [57]
  • Mark A Robertson, Sean Borman, and Robert L Stevenson. Dynamic range improvement through multiple exposures. In Image Processing, 1999. ICIP 99. Proceedings. 1999 International Conference on, volume 3, pages 159–163. IEEE, 1999. [207]
  • Tom Mertens, Jan Kautz, and Frank Van Reeth. Exposure fusion. In Computer Graphics and Applications, 2007. PG'07. 15th Pacific Conference on, pages 382–390. IEEE, 2007. [170]-range_imaging
  • Recovering High Dynamic Range Radiance Maps from Photographs (webpage) www.pauldebevec.com/Research/HD…

到此這篇關(guān)于Python中OpenCV Tutorials 20  高動(dòng)態(tài)范圍成像的文章就介紹到這了,更多相關(guān)OpenCV高動(dòng)態(tài)范圍成像內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python生成tensorflow輸入輸出的圖像格式的方法

    python生成tensorflow輸入輸出的圖像格式的方法

    本篇文章主要介紹了python生成tensorflow輸入輸出的圖像格式的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-02-02
  • 最新評論