在tone mapping过程中,通常经过统计之后得到一条mapping曲线,记这条曲线为 f ( x ) f(x) f(x),mapping过程中,对于给定的点,假定其亮度为 x x x,映射后为 f ( x ) f(x) f(x),信号的放大增益为 k = f ( x ) x k=\frac{f(x)}{x} k=xf(x),上述放大增益的过程在luma平面上进行,若tone mapping在raw图像上,且像素值为 x r a w x_{raw} xraw,则经过tone mapping后的像素值为 k ⋅ x r a w = x r a w ⋅ f ( x ) x k\cdot x_{raw}=x_{raw}\cdot\frac{f(x)}{x} k⋅xraw=xraw⋅xf(x);为了方便讨论,我们仅讨论在luma平面进行tone mapping,那么tone mapping后的像素计算公式为 k ⋅ x = x ⋅ f ( x ) x = f ( x ) k\cdot x=x\cdot\frac{f(x)}{x}=f(x) k⋅x=x⋅xf(x)=f(x);
经过上面的背景介绍和铺垫,下面讨论在tone mapping过程中,对于luma平面进行降噪滤波之后再计算放大增益,对于噪声放大、边缘增强及对比度增强现象的内在原理。
对于图像中的 x 1 x_1 x1, x 2 x_2 x2,映射曲线为 f ( x ) f(x) f(x),那么 x 1 x_1 x1点映射为 f ( x 1 ) f(x_1) f(x1), x 2 x_2 x2点映射为 f ( x 2 ) f(x_2) f(x2),先分析极端情况, x 1 , x 2 x_1,x_2 x1,x2经过滤波的像素值均变为 x 0 x_0 x0,映射之后为 f ( x 0 ) f(x_0) f(x0),上述数量关系如图2所示,于是
k 1 = f ( x 1 ) x 1 , k 2 = f ( x 2 ) x 2 , k 0 = f ( x 0 ) x 0 k_1=\frac{f(x_1)}{x_1},k_2=\frac{f(x_2)}{x_2},k_0=\frac{f(x_0)}{x_0} k1=x1f(x1),k2=x2f(x2),k0=x0f(x0)
于是,在没有开NR时,其tone mapping后 x 1 x_1 x1与 x 2 x_2 x2的差异为:
Δ 0 = k 2 x 2 − k 1 x 1 \Delta_0=k_2x_2-k_1x_1 Δ0=k2x2−k1x1
开NR后,其tone mapping后 x 1 x_1 x1与 x 2 x_2 x2的差异为:
Δ 1 = k 0 x 2 − k 0 x 1 \Delta_1=k_0x_2-k_0x_1 Δ1=k0x2−k0x1
比较 Δ 0 \Delta_0 Δ0与 Δ 1 \Delta_1 Δ1的大小:
Δ 1 − Δ 0 = f ( x 0 ) x 0 ( x 2 − x 1 ) − f ( x 2 ) − f ( x 1 ) x 2 − x 1 ( x 2 − x 1 ) = [ f ( x 0 ) x 0 − f ( x 2 ) − f ( x 1 ) x 2 − x 1 ] ( x 2 − x 1 ) \Delta_1-\Delta_0=\frac{f(x_0)}{x_0}(x_2-x_1)-\frac{f(x_2)-f(x_1)}{x_2-x_1}(x_2-x_1)=[\frac{f(x_0)}{x_0}-\frac{f(x_2)-f(x_1)}{x_2-x_1}](x_2-x_1) Δ1−Δ0=x0f(x0)(x2−x1)−x2−x1f(x2)−f(x1)(x2−x1)=[x0f(x0)−x2−x1f(x2)−f(x1)](x2−x1)
由于 x 2 − x 1 > 0 x_2-x_1>0 x2−x1>0,于是只需要讨论 f ( x 0 ) x 0 − f ( x 2 ) − f ( x 1 ) x 2 − x 1 \frac{f(x_0)}{x_0}-\frac{f(x_2)-f(x_1)}{x_2-x_1} x0f(x0)−x2−x1f(x2)−f(x1)的符号即可,令
m ( x ) = f ( x 0 ) x 0 − f ( x 2 ) − f ( x 1 ) x 2 − x 1 m(x)=\frac{f(x_0)}{x_0}-\frac{f(x_2)-f(x_1)}{x_2-x_1} m(x)=x0f(x0)−x2−x1f(x2)−f(x1)
为了分析 Δ 1 − Δ 0 \Delta_1-\Delta_0 Δ1−Δ0的符号,我们回过头来对mapping曲线 f ( x ) f(x) f(x)做一些数学层面的条件归纳:首先 f ( x ) f(x) f(x)为单调函数,其一阶导数 f ′ ( x ) > 0 f^{'}(x)>0 f′(x)>0,其次曲线 f ( x ) f(x) f(x)的斜率在不断减小,即其一阶导数为减函数,于是 f ′ ′ ( x ) < 0 f^{''}(x)<0 f′′(x)<0,此外还有 f ( 0 ) = 0 f(0)=0 f(0)=0,于是问题简化为一个简单的数学问题:
对于 f ( x ) f(x) f(x),有 f ( 0 ) = 0 , f ′ ( x ) > 0 , f ′ ′ < 0 f(0)=0,f^{'}(x)>0,f^{''}<0 f(0)=0,f′(x)>0,f′′<0,当 x ∈ ( x 1 , x 2 ) x\in(x_1,x_2) x∈(x1,x2)时,讨论 m ( x ) m(x) m(x)与0的大小
针对这个问题,我们先直观判断一下 m ( x ) m(x) m(x)的符号, f ( x 2 ) − f ( x 1 ) x 2 − x 1 \frac{f(x_2)-f(x_1)}{x_2-x_1} x2−x1f(x2)−f(x1)为 ( x 1 , f ( x 1 ) ) (x_1,f(x_1)) (x1,f(x1))点与 ( x 2 , f ( x 2 ) ) (x_2,f(x_2)) (x2,f(x2))连线的斜率, f ( x 0 ) x 0 \frac{f(x_0)}{x_0} x0f(x0)为 ( 0 , 0 ) (0,0) (0,0)点与 ( x 0 , f ( x 0 ) ) (x_0,f(x_0)) (x0,f(x0))的斜率,从直观上看,后者大于前者,于是有 m ( x 0 ) > 0 m(x_0)>0 m(x0)>0,如图3所示;
下面证明这个判断,令 g ( x ) = f ( x ) x g(x)=\frac{f(x)}{x} g(x)=xf(x),分析其单调性,
g ′ ( x ) = x f ′ ( x ) − f ( x ) x 2 g^{'}(x)=\frac{xf^{'}(x)-f(x)}{x^2} g′(x)=x2xf′(x)−f(x)
要判定其单调性,只需判定其符号,而分母显然为正数,从而只需要分析分子,令
h ( x ) = x f ′ ( x ) − f ( x ) h(x)=xf^{'}(x)-f(x) h(x)=xf′(x)−f(x)
那么
h ′ ( x ) = f ′ ( x ) + x f ′ ′ ( x ) − f ′ ( x ) = x f ′ ′ ( x ) h^{'}(x)=f^{'}(x)+xf^{''}(x)-f^{'}(x)=xf^{''}(x) h′(x)=f′(x)+xf′′(x)−f′(x)=xf′′(x)
由于 x > 0 , f ′ ′ ( x ) < 0 x>0,f^{''}(x)<0 x>0,f′′(x)<0,于是 h ′ ( x ) < 0 h^{'}(x)<0 h′(x)<0,从而 h ( x ) h(x) h(x)为单调减函数,又有 h ( 0 ) = 0 − 0 = 0 h(0)=0-0=0 h(0)=0−0=0,所以 h ( x ) ≤ 0 h(x)\le 0 h(x)≤0,从而对于 x ∈ ( 0 , ∞ ) , g ′ ( x ) ≤ 0 x\in (0,\infty),g^{'}(x)\le 0 x∈(0,∞),g′(x)≤0,从而可知, g ( x ) = f ( x ) x g(x)=\frac{f(x)}{x} g(x)=xf(x)为减函数。
回到 m ( x ) = f ( x ) x − f ( x 2 ) − f ( x 1 ) x 2 − x 1 m(x)=\frac{f(x)}{x}-\frac{f(x_2)-f(x_1)}{x_2-x_1} m(x)=xf(x)−x2−x1f(x2)−f(x1),对于 x ∈ ( x 1 , x 2 ) x\in (x_1,x_2) x∈(x1,x2)其最小值为
m m i n = m ( x 2 ) = f ( x 2 ) x 2 − f ( x 2 ) − f ( x 1 ) x 2 − x 1 = x 2 f ( x 1 ) − x 1 f ( x 2 ) x 2 ( x 2 − x 2 ) m_{min}=m(x_2)=\frac{f(x_2)}{x_2}-\frac{f(x_2)-f(x_1)}{x_2-x_1}=\frac{x_2f(x_1)-x_1f(x_2)}{x_2(x_2-x_2)} mmin=m(x2)=x2f(x2)−x2−x1f(x2)−f(x1)=x2(x2−x2)x2f(x1)−x1f(x2)
其分母为正数,因而只需要考虑其分子符号;对于分子 x 2 f ( x 1 ) − x 1 f ( x 2 ) x_2f(x_1)-x_1f(x_2) x2f(x1)−x1f(x2),将其除以 x 1 x 2 x_1x_2 x1x2,不改变其符号,于是有
x 2 f ( x 1 ) − x 1 f ( x 2 ) x 1 x 2 = f ( x 1 ) x 1 − f ( x 2 ) x 2 \frac{x_2f(x_1)-x_1f(x_2)}{x_1x_2}=\frac{f(x_1)}{x_1}-\frac{f(x_2)}{x_2} x1x2x2f(x1)−x1f(x2)=x1f(x1)−x2f(x2)
由于前面已经分析过, g ( x ) = f ( x ) x g(x)=\frac{f(x)}{x} g(x)=xf(x)为减函数,以及 x 1 < x 2 x_1
下面将问题放到更一般的情况,降噪将 x 1 x_1 x1变为 x 3 x_3 x3,将 x 2 x_2 x2变为 x 4 x_4 x4,大小关系为 x 1 < x 3 < x 4 < x 2 x_1
从而 k 1 = f ( x 1 ) x 1 , k 2 = f ( x 2 ) x 2 , k 3 = f ( x 3 ) x 3 , k 4 = f ( x 4 ) x 4 k_1=\frac{f(x_1)}{x_1},k_2=\frac{f(x_2)}{x_2},k_3=\frac{f(x_3)}{x_3},k_4=\frac{f(x_4)}{x_4} k1=x1f(x1),k2=x2f(x2),k3=x3f(x3),k4=x4f(x4),于是有
Δ 0 = f ( x 2 ) x 2 x 2 − f ( x 1 ) x 1 x 1 \Delta_0=\frac{f(x_2)}{x_2}x_2-\frac{f(x_1)}{x_1}x_1 Δ0=x2f(x2)x2−x1f(x1)x1
Δ 1 = f ( x 4 ) x 4 x 2 − f ( x 3 ) x 3 x 1 \Delta_1=\frac{f(x_4)}{x_4}x_2-\frac{f(x_3)}{x_3}x_1 Δ1=x4f(x4)x2−x3f(x3)x1
Δ 1 − Δ 0 = f ( x 4 ) x 4 x 2 − f ( x 3 ) x 3 x 1 − [ f ( x 2 ) x 2 x 2 − f ( x 1 ) x 1 x 1 ] = x 2 [ f ( x 4 ) x 4 − f ( x 2 ) x 2 ] + x 1 [ f ( x 1 ) x 1 − f ( x 3 ) x 3 ] \Delta_1-\Delta_0=\frac{f(x_4)}{x_4}x_2-\frac{f(x_3)}{x_3}x_1-[\frac{f(x_2)}{x_2}x_2-\frac{f(x_1)}{x_1}x_1]=x_2[\frac{f(x_4)}{x_4}-\frac{f(x_2)}{x_2}]+x_1[\frac{f(x_1)}{x_1}-\frac{f(x_3)}{x_3}] Δ1−Δ0=x4f(x4)x2−x3f(x3)x1−[x2f(x2)x2−x1f(x1)x1]=x2[x4f(x4)−x2f(x2)]+x1[x1f(x1)−x3f(x3)]
由于 0 < x 1 < x 3 < x 4 < x 2 0
综上,对于映射曲线满足 f ( x ) f(x) f(x)为单调增函数, f ( x ) f(x) f(x)的斜率在不断减小, f ( 0 ) = 0 f(0)=0 f(0)=0时,对luma平面降噪会放大图像中的噪声,增强边缘,增加对比度,而通常的tone mapping曲线 f ( x ) f(x) f(x)或者整条曲线满足上述条件,或者整条曲线的一部分满足上述条件,满足上述条件的部分都会对图像进行不同程度的增强和噪声放大。