自动色彩均衡算法(ACE)原理及实现

来源:互联网 发布:宋本广韵 知乎 编辑:程序博客网 时间:2024/06/05 14:23

前注:ACE在图像处理方面可以有两种表示,一种是本篇要说的:Automatic Color Equalization,即自动彩色均衡;还有一种是:Adaptive Contrast Enhancement,即自适应对比度增强 。不要搞混了~_~

高动态范围图像处理:

高动态范围图像是指在一幅图像中,既有明亮的区域又有阴影区域,为了使细节清晰,需要满足以下几点:

(1)对动态范围具有一定的压缩能力;

(2)对亮暗区域的细节有一定的显示能力;

(3)满足上面条件基础上不破坏图像的清晰度。

对于高动态范围处理,基于人眼视觉系统(HSV)在颜色连续和亮度连续方面得到较好的满足。

自动色彩均衡算法原理:

Rizzi等依据Retinex理论提出了自动颜色均衡算法,该算法考虑了图像中颜色和亮度的空间位置关系,进行局部特性的自适应滤波,实现具有局部和非线性特征的图像亮度与色彩调整和对比度调整,同时满足灰色世界理论假设和白色斑点假设。

ACE算法包括两个步骤:


第一步:对图像进行色彩/空域调整,完成图像的色差校正,得到空域重构图像;

(1)

式中,Rc 是中间结果,Ic(p)-Ic(j)为两个不同点的亮度差,d(p,j)表示距离度量函数,r(*)为亮度表现函数,需是奇函数;这一步可以适应局部图像对比度,r(*)能够放大较小的差异,并丰富大的差异,根据局部内容扩展或者压缩动态范围。一般得,r(*)为:

     

第二步:对校正后的图像进行动态扩展。ACE算法是对单一色道进行的,对于彩色图片需要对每一个色道分别处理。

其中,一种简单的线性扩展可以表示为:


还可以将其映射到[0,255]的空间中:

          (5)

通过上面的操作,ACE可看成是人类视觉系统的简化模型,其增强过程是与人的感知是一致的。

自动彩色均衡算法改进:

式(1)算法复杂度较高,对于一副像素数为N的图像,需要执行O(N2)级次非线性映射计算,图像尺寸越大,耗时越多,所以针对式(1)产生了许多加速改进算法。例如:LLLUT加速策略【4】,参考【3】将ACE转换为对规范直方图均衡化的一种平滑和局部修正的方法,并给出了求解最优模型:


其中,

对于改进方法,可以考虑的因素:
1)其他的坡度函数Sa(t),多项式函数逼近;


2)除了1/||x-y||外的权重函数的选择;
3)在求和的过程中,y可以限制在一个小窗口中;
4)L(x)的一些其他的方法;

程序下载地址:http://www.ipol.im/pub/art/2012/g-ace/

另外,可以参照参考[8]的python程序,这里po一下:

import cv2  import numpy as np  import math  def stretchImage(data, s=0.005, bins = 2000):    #线性拉伸,去掉最大最小0.5%的像素值,然后线性拉伸至[0,1]      ht = np.histogram(data, bins);      d = np.cumsum(ht[0])/float(data.size)      lmin = 0; lmax=bins-1      while lmin<bins:          if d[lmin]>=s:              break          lmin+=1      while lmax>=0:          if d[lmax]<=1-s:              break          lmax-=1      return np.clip((data-ht[1][lmin])/(ht[1][lmax]-ht[1][lmin]), 0,1)  g_para = {}  def getPara(radius = 5):                      #根据半径计算权重参数矩阵      global g_para      m = g_para.get(radius, None)      if m is not None:          return m      size = radius*2+1      m = np.zeros((size, size))      for h in range(-radius, radius+1):          for w in range(-radius, radius+1):              if h==0 and w==0:                  continue              m[radius+h, radius+w] = 1.0/math.sqrt(h**2+w**2)      m /= m.sum()      g_para[radius] = m      return m  def zmIce(I, ratio=4, radius=300):                     #常规的ACE实现      para = getPara(radius)      height,width = I.shape      zh,zw = [0]*radius + range(height) + [height-1]*radius, [0]*radius + range(width)  + [width -1]*radius      Z = I[np.ix_(zh, zw)]      res = np.zeros(I.shape)      for h in range(radius*2+1):          for w in range(radius*2+1):              if para[h][w] == 0:                  continue              res += (para[h][w] * np.clip((I-Z[h:h+height, w:w+width])*ratio, -1, 1))      return res  def zmIceFast(I, ratio, radius):                #单通道ACE快速增强实现      height, width = I.shape[:2]      if min(height, width) <=2:          return np.zeros(I.shape)+0.5      Rs = cv2.resize(I, ((width+1)/2, (height+1)/2))      Rf = zmIceFast(Rs, ratio, radius)             #递归调用      Rf = cv2.resize(Rf, (width, height))      Rs = cv2.resize(Rs, (width, height))      return Rf+zmIce(I,ratio, radius)-zmIce(Rs,ratio,radius)      def zmIceColor(I, ratio=4, radius=3):               #rgb三通道分别增强,ratio是对比度增强因子,radius是卷积模板半径      res = np.zeros(I.shape)      for k in range(3):          res[:,:,k] = stretchImage(zmIceFast(I[:,:,k], ratio, radius))      return res  if __name__ == '__main__':      m = zmIceColor(cv2.imread('3.jpg')/255.0)*255      cv2.imwrite('zmIce.jpg', m)  

参考:

  1. http://www.ipol.im/pub/art/2012/g-ace/
  2. 《ACE: An automatic color equalization algorithm》
  3. 《Automatic Color Enhancement (ACE) and its FastImplementation》[J].IPOL
  4. 《A local linear lut method for increasing the speed of generic image fiLLLUTering algorithm》[R].Technical Report
  5. 《Perceptual Color Correction Through Varia-tional Techniques》[J].IEEE
  6. 《自动色彩均衡算法的快速优化》[J].武汉大学学报
  7. http://blog.csdn.net/u013626386/article/details/47808761
  8. http://blog.csdn.net/zmshy2128/article/details/53470357   --python
阅读全文
0 0