Python+OpenCV:高动态范围(High Dynamic Range, HDR)

目标

  • Learn how to generate and display HDR image from an exposure sequence.
  • Use exposure fusion to merge an exposure sequence.

理论

High-dynamic-range imaging (HDRI or HDR) is a technique used in imaging and photography to reproduce a greater dynamic range of luminosity than is possible with standard digital imaging or photographic techniques.

While the human eye can adjust to a wide range of light conditions, most imaging devices use 8-bits per channel, so we are limited to only 256 levels.

When we take photographs of a real world scene, bright regions may be overexposed, while the dark ones may be underexposed, so we can’t capture all details using a single exposure.

HDR imaging works with images that use more than 8 bits per channel (usually 32-bit float values), allowing much wider dynamic range.

There are different ways to obtain HDR images, but the most common one is to use photographs of the scene taken with different exposure values.

To combine these exposures it is useful to know your camera’s response function and there are algorithms to estimate it.

After the HDR image has been merged, it has to be converted back to 8-bit to view it on usual displays. This process is called tonemapping.

Additional complexities arise when objects of the scene or camera move between shots, since images with different exposures should be registered and aligned.

In this tutorial we show 2 algorithms (Debevec, Robertson) to generate and display HDR image from an exposure sequence, and demonstrate an alternative approach called exposure fusion (Mertens),

that produces low dynamic range image and does not need the exposure times data.

Furthermore, we estimate the camera response function (CRF) which is of great value for many computer vision algorithms.

Each step of HDR pipeline can be implemented using different algorithms and parameters, so take a look at the reference manual to see them all.

Exposure sequence HDR in OpenCV

####################################################################################################
# 图像高动态范围(High Dynamic Range, HDR)
def lmc_cv_hdr_exposure_sequence():"""函数功能: 图像高动态范围(High Dynamic Range, HDR)."""# Loading exposure images into a liststacking_images = []images = glob.glob('D:/99-Research/TestData/cv/hdr/exposures/memorial*.png')image_list = [lmc_cv.imread(image_name) for image_name in images]image_list = [lmc_cv.cvtColor(image, lmc_cv.COLOR_BGR2RGB) for image in image_list]exposure_times = np.array([1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625, 0.03125],dtype=np.float32)# exposure_times = 1.00/exposure_times# Merge exposures to HDR imagemerge_debevec = lmc_cv.createMergeDebevec()hdr_debevec = merge_debevec.process(image_list, times=exposure_times.copy())merge_robertson = lmc_cv.createMergeRobertson()hdr_robertson = merge_robertson.process(image_list, times=exposure_times.copy())# Tonemap HDR imagetonemap1 = lmc_cv.createTonemap(gamma=15.0)res_debevec = tonemap1.process(hdr_debevec.copy())tonemap2 = lmc_cv.createTonemap(gamma=15.0)res_robertson = tonemap2.process(hdr_robertson.copy())# Exposure fusion using Mertensmerge_mertens = lmc_cv.createMergeMertens()res_mertens = merge_mertens.process(image_list)# Convert datatype to 8-bit and saveres_debevec_8bit = np.clip(res_debevec * 255, 0, 255).astype('uint8')res_robertson_8bit = np.clip(res_robertson * 255, 0, 255).astype('uint8')res_mertens_8bit = np.clip(res_mertens * 255, 0, 255).astype('uint8')# 显示结果images = [image_list[0], res_debevec_8bit, res_robertson_8bit, res_mertens_8bit]titles = ['Original Image', 'Debevec', 'Robertson', 'Mertenes Fusion']pyplot.figure('Image Inpainting %d' % (0 + 1), figsize=(12, 9))for i in range(len(images)):pyplot.subplot(2, 2, i + 1)pyplot.imshow(images[i], 'gray')pyplot.title(titles[i])pyplot.xticks([])pyplot.yticks([])pyplot.savefig('High Dynamic Range.png')pyplot.show()

Estimating Camera Response Function

The camera response function (CRF) gives us the connection between the scene radiance to the measured intensity values.

The CRF if of great importance in some computer vision algorithms, including HDR algorithms. Here we estimate the inverse camera response function and use it for the HDR merge.

####################################################################################################
# 图像高动态范围(High Dynamic Range, HDR)
def lmc_cv_hdr_exposure_sequence():"""函数功能: 图像高动态范围(High Dynamic Range, HDR)."""# Loading exposure images into a liststacking_images = []images = glob.glob('D:/99-Research/TestData/cv/hdr/exposures/memorial*.png')image_list = [lmc_cv.imread(image_name) for image_name in images]image_list = [lmc_cv.cvtColor(image, lmc_cv.COLOR_BGR2RGB) for image in image_list]exposure_times = np.array([1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625, 0.03125],dtype=np.float32)# exposure_times = 1.00/exposure_times# Merge exposures to HDR imagemerge_debevec = lmc_cv.createMergeDebevec()hdr_debevec = merge_debevec.process(image_list, times=exposure_times.copy())merge_robertson = lmc_cv.createMergeRobertson()hdr_robertson = merge_robertson.process(image_list, times=exposure_times.copy())# Tonemap HDR imagetonemap1 = lmc_cv.createTonemap(gamma=15.0)res_debevec = tonemap1.process(hdr_debevec.copy())tonemap2 = lmc_cv.createTonemap(gamma=15.0)res_robertson = tonemap2.process(hdr_robertson.copy())# Exposure fusion using Mertensmerge_mertens = lmc_cv.createMergeMertens()res_mertens = merge_mertens.process(image_list)# Convert datatype to 8-bit and saveres_debevec_8bit = np.clip(res_debevec * 255, 0, 255).astype('uint8')res_robertson_8bit = np.clip(res_robertson * 255, 0, 255).astype('uint8')res_mertens_8bit = np.clip(res_mertens * 255, 0, 255).astype('uint8')# 显示结果images = [image_list[0], res_debevec_8bit, res_robertson_8bit, res_mertens_8bit]titles = ['Original Image', 'Debevec', 'Robertson', 'Mertenes Fusion']pyplot.figure('Image Inpainting %d' % (0 + 1), figsize=(12, 9))for i in range(len(images)):pyplot.subplot(2, 2, i + 1)pyplot.imshow(images[i], 'gray')pyplot.title(titles[i])pyplot.xticks([])pyplot.yticks([])pyplot.savefig('E:/WHL/High Dynamic Range.png')pyplot.show()# Estimate camera response function (CRF)cal_debevec = lmc_cv.createCalibrateDebevec()crf_debevec = cal_debevec.process(image_list, times=exposure_times)hdr_debevec = merge_debevec.process(image_list, times=exposure_times.copy(), response=crf_debevec.copy())cal_robertson = lmc_cv.createCalibrateRobertson()crf_robertson = cal_robertson.process(image_list, times=exposure_times)hdr_robertson = merge_robertson.process(image_list, times=exposure_times.copy(), response=crf_robertson.copy())# 创建窗口pyplot.figure('Inverse Camera Response Function')# 显示直方图x1 = range(254)x2 = range(254)pyplot.subplot(1, 2, 1)# pyplot.plot(x1, crf_debevec[:, :, 0], 'go-', x1, crf_debevec[:, :, 1], 'rx-', x1, crf_debevec[:, :, 2], 'b*-')pyplot.plot(x1, crf_debevec[x1, :, 0], 'r', x1, crf_debevec[x1, :, 1], 'g', x1, crf_debevec[x1, :, 2], 'b')pyplot.xlabel('Measured Intensity')pyplot.ylabel('Calibrated Intensity')pyplot.title('Debevec Inverse Camera Response Function')pyplot.subplot(1, 2, 2)pyplot.plot(x2, crf_robertson[x2, :, 0], 'r', x2, crf_robertson[x2, :, 1], 'g', x2, crf_robertson[x2, :, 2], 'b')pyplot.xlabel('Measured Intensity')pyplot.ylabel('Calibrated Intensity')pyplot.title('Robertson Inverse Camera Response Function')

Python+OpenCV:高动态范围(High Dynamic Range, HDR)相关推荐

  1. wide dynamic range - WDR - 宽动态范围 - high dynamic range - HDR - 高动态范围

    wide dynamic range - WDR - 宽动态范围 - high dynamic range - HDR - 高动态范围 高动态范围 (high dynamic range,HDR) 图 ...

  2. High Dynamic Range(HDR)图像介绍(一)

    在工程技术领域,有许多涉及数字图像的应用程序.用它们创建的现代数码相机和扫描仪,采用先进的计算机图形处理技术,或用绘图程序制作.目前,大多数应用程序依赖在某种形式的图形表示上.数字图像在其生命周期中经 ...

  3. 高动态范围光照(High Dynamic Range Imaging,简称HDRI或HDR)

    1  HDR基本概念 高动态范围光照(High Dynamic Range Imaging,简称HDRI或HDR),是一种表达超过了显示器所能表现的亮度范围的图像映射技术,已成为目前游戏应用不可或缺的 ...

  4. visualmap超过范围改变颜色_高动态范围(High-Dynamic Range,简称HDR)

    高动态范围(High-Dynamic Range,简称HDR) 一.HDR介绍 高动态范围(High-Dynamic Range,简称HDR),又称宽动态范围技术,是在非常强烈的对比下让摄像机看到影像 ...

  5. 3.2.3 Quantization Techniques(HDR量化)(Advanced High Dynamic Range Imaging)Schlick TMO

    3.2.3 Quantization Techniques(HDR量化)(Advanced High Dynamic Range Imaging)Schlick TMO Schlick [341]提出 ...

  6. 2.1.2 Capturing HDR Videos(Advanced High Dynamic Range Imaging )

    2.1.2 Capturing HDR Videos(Advanced High Dynamic Range Imaging ) 目录 2.1.2 Capturing HDR Videos(Advan ...

  7. A comparative review of tone-mapping algorithms for high dynamic range video(高动态范围视频色调映射算法的比较研究)(二)

    研读论文A comparative review of tone-mapping algorithms for high dynamic range video(高动态范围视频色调映射算法的比较研究) ...

  8. python opencv imwrite()方法 cv :: ImwriteFlags (写入图片、保存图片)

    from init.py: opencv版本4.1.0,不同版本也许doc稍有不同 def imwrite(filename, img, params=None): # real signature ...

  9. 【图像处理】一种低光照图像的亮度提升方法(Adaptive Local Tone Mapping Based on Retinex for High Dynamic Range Images)

    [fishing-pan:https://blog.csdn.net/u013921430 转载请注明出处] 前言   在实际的拍照过程中,常常会遇到,光线不足的情况.这时候单反用户一般会调大感光度, ...

最新文章

  1. Firefox下http协议监测工具LiveHttpHeaders
  2. HDU 1225 覆盖的面积
  3. linux p 参数,tar的-p参数解决方案
  4. 计算机应用基础 东师 离线,奥鹏东师秋季计算机应用基础离线作业答案
  5. 洛谷 P1168 中位数 堆
  6. 《请君入瓮——APT攻防指南之兵不厌诈》目录—导读
  7. 九款实用的在线画图工具(那些可以替代Visio的应用)
  8. 数字式PID控制MATLAB仿真
  9. background详解
  10. android实时投屏软件下载,安卓投屏助手
  11. Java计算时间差、日期差总结
  12. python中mapping_python-学习-ORM中遇到的 mapping 详解并再总结字典dict
  13. LruCache源码的理解
  14. 逆滤波和维纳滤波(附Matlab完整代码)
  15. 【欧几里得扩展欧几里得】
  16. 解决印象笔记无法搜索到对应标题或内容笔记的问题
  17. 基于ssm医药药品管理系统
  18. 微信公众号文章怎么加入文件下载
  19. (20)打鸡儿教你Vue.js
  20. 自媒体时代如何营销?自媒体推广投放新趋势

热门文章

  1. Linux 命令(74)—— top 命令
  2. GridView网格控件
  3. Js跨域解决方法总结
  4. C# Socket 简易的图片传输
  5. IDEA下项目打包成jar,并通过cmd命令调用
  6. Java内存溢出OOM使用Mat分析
  7. SOFABoot 扩展点初体验 | SOFALab 实践系列
  8. Spring Boot2.0 整合mybatis、分页插件、druid
  9. Web服务器Nginx多方位优化策略
  10. 【译】Spring 4.0带来的@Conditional注解