博主实现

来自wolf96的测试

未矫正的模糊颜色不准确,而且丢失了大量细节

正文

One mistake most of us have done at some point is to do perform an image bluring downsizeing (or other linear pixel operation) on photographs without taking gamma into account. And that's because photographs are encoded in gamma space for best display quality. Ideally your image blurring algorithm should preserve the image brightness intact and only blur the detail in it, or in other words, if the blur kernel is going to be energy conserving, it will have to operate in linear space rather than gamma space. So, when blurring an photograph, one should degamma the image pixels before accumulating them, and then probably apply gamma back to the result after averaging for display. This, of course, is something we now always do, because it's a pain and most of the times slow if done by hand (thankfully most GPU hardware these days can do this for you if you choose the correct internal format for your textures).

This observation applies to box lurring, gaussian blurring, image downsampling, sobel filters, and basically anything that is a linear combination of pixel values, but it can probably be best illustrated with this simple box blur pseudocode below.

Wrong way to do a box blur:

vec3 col = vec3(0.0);
for( int j=-w; j<=w; j++ )
for( int i=-w; i<=w; i++ )
{col += src[x+i,y+j];
}
dst[x,y] = col / ((2*w+1)*(2*w+1));
  Correct way to do a box blur:

vec3 col = vec3(0.0);
for( int j=-w; j<=w; j++ )
for( int i=-w; i<=w; i++ )
{col += DeGamma( src[x+i,y+j] );
}
dst[x,y] = Gamma( col / ((2*w+1)*(2*w+1)) );

Here Gamma() and DeGamma() are the gamma correction function and its inverse. These can probably be just approximations, such as Gamma(x) = pow( x, 1.0/2.2 ) and DeGamma(x) = pow( x, 2.2 ), or even Gamma(x) = sqrt(x) and DeGamma(x) = x*x if you really want to safe some cycles.

The image bellow shows on the left side the wrong (and most common) way to blur an image, and the right side shows the result of correct blurring. Note how the correct version does not get darker but retains the original overall intensity after blurring, unlike the one in the left. The effect is pretty obvious in the area where the bus is in the picture. The effect would be even more obvious if the correct and incorrect images were overlapping.


Left, gamma unaware blurring (too dark). Right, gamma correct blurring (correct brightness)

So, remember. If you are in the GPU, use sRGB for textures that containt photographics material and are ready to be displayed as they are. If you are in the CPU, remember to apply the inverse gamma correction. You probably want to do with a LUT with 256 entries that stores 16 bit integers with the fixed point representation of the de-gammaed value (mapping 8 bit to 8 bit would give you a lose of quality, for that point of storing images in gamma space is exatcly to improve perceptual quantification quality).

http://iquilezles.org/www/articles/gamma/gamma.htm

gamma correct blurring相关推荐

  1. 图像的Gamma变换

    什么是Gamma变换 Gamma变换是对输入图像灰度值进行的非线性操作,使输出图像灰度值与输入图像灰度值呈指数关系: Vout=AVinγV_{out}=AV_{in}^{\gamma}Vout​=A ...

  2. 图像滤镜的一些加速和改进--笔记

    原文:http://blog.csdn.net/zwlq1314521/article/details/50455782 滤镜有很多开源代码包,imageshop,tinyimage,还有安卓的源码包 ...

  3. Rendering Linear lighting and color

    Overview Working with "linear color" means lighting and rendering in a color space where t ...

  4. Removing-Camera-Shake-from-a-Single-Photograph图像去模糊读书笔记

    图片模型 模糊图B.潜在图L与模糊核K的关系为: B=K⊗L+NB = K ⊗ L + N B=K⊗L+N 其中,⊗代表卷积(非周期边界条件),N表示每个像素上的传感器噪声. 我们假设图像的像素值与传 ...

  5. PBR中引入IBL——镜面反射篇

    文章目录 PBR中引入IBL--镜面反射篇 回顾上一篇:漫反射 镜面反射的计算思路 镜面反射部分方程的分解 生成预计算纹理 必要的预备知识 镜面波瓣 蒙特卡洛积分(Monte Carlo Integr ...

  6. 嵌入式Linux小项目之图片编解码播放器(6)

    目录 一.解码显示png图片 1.思路分析 2.libpng移植 3.zlib移植 4.参考源码包自带的资料 5.学习了解示例代码 6.完整移植好的代码 一.解码显示png图片 1.思路分析 (1)p ...

  7. Skia深入分析6——skia中图像编解码代码概述

    1.API和自注册机制 Skia中编码解码图片都只需要一行代码: SkBitmap bitmap; SkImageDecoder::DecodeFile("test.xxx", & ...

  8. OpenCV基础入门系列基本操作——贰

    系列博文第二篇,关于OpenCV4的一些基本操作和使用. 博文主要以实例展示不同的函数使用方法. OpenCV基础入门系列基本操作--壹 前言 下述为本博文需要用到的各类头文件以及全局变量等 读者可根 ...

  9. 在android中替换整个相机管道

    Computational photography has been at the forefront of smartphone camera innovation (e.g. Google's H ...

最新文章

  1. 5个找出Linux中“二进制命令”描述和系统中位置的方法
  2. FTP软件VSFTP配置文件详解
  3. 存储过程与事务应用两三事
  4. Trie UVALive 7192 Chip Factory (15长春J)
  5. 2018,人工智能在清算中落地
  6. MySQL速忆笔记(更新中)
  7. React中refs的理解
  8. android runnable内存泄漏,这个Runnable可以防止内存泄漏吗?
  9. 各种音频视频编解码详细介绍
  10. 华佳慧科技:OSN500设备ERPS相切环组网介绍
  11. 图层蒙版和图层剪贴路径_剪贴蒙版,PS选择蒙版技巧都在这了
  12. pandas之美国2012年总统候选人政治献金数据分析
  13. SAP MM 事务代码MI31之思考
  14. 当前线程运行完毕,再运行后续逻辑
  15. web项目经理手册-项目经理需要铭记在心的话
  16. 【CF1646D】D. Weight the Tree(树形dp、贪心)
  17. python发明小故事简写_科学发明小故事20字
  18. 先收藏! 立体库的维护保养规范
  19. ACIS,Parasolid两种CAD几何内核的优劣势对比
  20. mysql压缩包5.7.20安装_Mysql 5.7.20压缩版下载和安装简易教程

热门文章

  1. RAKsmart:美国服务器租用对建站有哪些帮助?
  2. MaskNet 这个CTR模型,有点意思
  3. 微信小程序如何隐藏右上角分享按钮
  4. arch模型 python_【时间序列】波动率建模之ARCH模型
  5. IntelliJ IDEA 还能画思维导图,果然最强 IDE!
  6. 华为荣耀20s云服务_华为荣耀20s云服务_华为荣耀20和20s的区别
  7. golang下文件锁的使用
  8. 阿里天池—2022江苏气象预测AI算法挑战赛
  9. Flink SQL xxx is not serializable. The object probably contains or references non serializable field
  10. 华三防火墙web端口_HCL模拟器防火墙WEB方式登录配置