视觉图像:对比度受限直方图均衡化CLAHE

2025-10-19 13:47:56

1、CLAHE算法原理:

CLAHE与AHE不同的地方是对比度限幅,为了克服AHE的过度放大噪声的问题;

①设自适应直方图均衡化方法的滑动窗口大小为M*M,则局部映射函数为:

为滑动窗口局部直方图的累积分布函数(cumulative distribution function);

②的导数为直方图,从而局部映射函数的斜率S为:

故,限制直方图高度就等效于限制局部映射函数的斜率,进而限制对比度强度;

③设限定最大斜率为Smax,则允许的直方图高度最大为:

④对高度大于Hmax的直方图应截去多余的部分;

实际处理中,设截取阈值T(而非Hmax)对直方图进行截断,将截去的部分均匀的分布在整个灰阶范围上,以保证总的直方图面积不变,从而使整个直方图上升高度L,则有:

⑤最后改进的直方图为:

综上所述,改变最大的映射函数斜率Smax及相应的最大直方图高度Hmax,可获得不同增强效果的图像;

CLAHE通过限制局部直方图的高度来限制局部对比度的增强幅度,从而限制噪声的放大和局部对比度的过增强。

视觉图像:对比度受限直方图均衡化CLAHE

视觉图像:对比度受限直方图均衡化CLAHE

2、插值加速方法:

AHE方法,不管是否带有对比度限制,都需要对图像中的每个像素计算其领域及变换函数,算法耗时严重;

对其进行插值加速,使算法效率有极大提升,且质量没有下降;

①将图像均匀分成等份矩阵大小,常见8行8列64块;

②计算每个块的直方图,CDF,变换函数;

对于块的中心像素(黑色小方块)是完全符合定义的;

③对其他的像素通过其邻近的四个黑色小方块的变换函数插值来获取;

位于中间的像素(蓝色阴影)采用双线性插值;

位于边缘的部分(绿色阴影)采用线性插值;

位于角点处的部分(红色阴影)采用块所在的变换函数;

视觉图像:对比度受限直方图均衡化CLAHE

3、OpenCV中,CLAHE函数实现:

#include<opencv2\core\core.hpp>

#include <opencv2\opencv.hpp>

#include<vector>

using namespace cv; 

using namespace std; 

int main(int argc, char** argv)

{

       // 读取RBG图片,转成Lab模式

       Mat bgr_image = imread("src.jpg");

       if (!bgr_image.rows){

              cout << "imread failed!"<< endl;

              return 0;

       }

       Mat lab_image;

       cvtColor(bgr_image, lab_image, CV_BGR2Lab);

       // 提取L通道

       vector<Mat> lab_planes(3);

       split(lab_image, lab_planes);

       // CLAHE 算法

       Ptr<CLAHE> clahe = createCLAHE();

       clahe->setClipLimit(4);

       Mat dst;

       clahe->apply(lab_planes[0], dst);

       dst.copyTo(lab_planes[0]);

       merge(lab_planes, lab_image);

       //恢复RGB图像

       Mat image_clahe;

       cvtColor(lab_image, image_clahe, CV_Lab2BGR);

       //打印结果

       imshow("原始图片", bgr_image);

       imshow("CLAHE处理", image_clahe);

       waitKey();

       return 0;

}

视觉图像:对比度受限直方图均衡化CLAHE

视觉图像:对比度受限直方图均衡化CLAHE

视觉图像:对比度受限直方图均衡化CLAHE

4、CLAHE源码解析:

ContrastLimitAHE .h:

#ifndef _CONTRAST_LIMIT_AHE_H_

#define _CONTRAST_LIMIT_AHE_H_

#include "stdafx.h"

#include <iostream>

using namespace std;

class ContrastLimitAHE 

public: 

       ContrastLimitAHE(); 

       ~ContrastLimitAHE();

       int m_nGridX;                /* CLAHE 宽网格的个数 */ 

       int m_nGridY;                /* CLAHE 高网格的个数 */ 

       unsigned char m_aLUT[256];   /* CLAHE lookup table used for scaling of input image 输入图像缩放的查找表*/        

       int Initial(int nMaxPixel, int nMinPixel, int uiNrBins, int nX, int nY, int nWidth, int nHeight,float fCliplimit); 

      

       int m_nWidth;                /* CLAHE 宽 */

       int m_nHeight;               /* CLAHE 高 */

       int m_nCliplimit; 

       int m_nHistBins; 

       int m_nGridSize_X; 

       int m_nGridSize_Y; 

       int *m_pMapArray; 

       int m_nGridSize;            /* Actual size of contextual regions实际周边区域大小 */ 

       int ProcessCLAHE(unsigned char* pImage); 

       void MakeHistogram(unsigned char* pImage,int* pulHistogram); 

       void ClipHistogram(int* pulHistogram); 

       void MapHistogram(int* pulHistogram); 

       void Interpolate (unsigned char * pImage); 

       int m_nMaxPixel; 

       int m_nMinPixel; 

       void ShiftInterpolate(unsigned char* pImage, int nSizeX, int nSizeY, int* pulMapLU, int* pulMapRU, int *pulMapLB, int *pulMapRB); 

       int LineInterpolate(unsigned char* pImage, int nSizeX, int nSizeY, int* pLU, int* pRU, int* pLB, int* pRB); 

}; 

#endif

5、参考资料:

[1] D. J. Ketcham, R. W. Lowe & J. W. Weber: Image enhancement techniques for cockpit displays. Tech. rep., Hughes Aircraft. 1974.

[2] R. A. Hummel: Image Enhancement by Histogram Transformation. Computer Graphics and Image Processing 6 (1977) 184195.

[3] S. M. Pizer, E. P. Amburn, J. D. Austin, et al.: Adaptive Histogram Equalization and Its Variations. Computer Vision, Graphics, and Image Processing 39 (1987) 355-368.

[4] K. Zuiderveld: Contrast Limited Adaptive Histogram Equalization. In: P. Heckbert: Graphics Gems IV, Academic Press 1994, ISBN 0-12-336155-9

[5] T. Sund & A. Møystad: Sliding window adaptive histogram equalization of intra-oral radiographs: effect on diagnostic quality. Dentomaxillofac Radiol. 2006 May;35(3):133-8.

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢