绪:直方图均衡简单、高效;但是,图像中不同的区域灰度分布相差甚远,对它们使用同一种变换常常产生不理想的效果;实际应用中,常常需要增强图像的某些局部区域的细节。为了解决这类问题,Pizer等提出了局部直方图均衡化的方法(AHE);AHE方法仅仅考虑了局部区域的像素,忽略了图像其他区域的像素,且对于图像中相似区域具有过度放大噪声的缺点;K. Zuiderveld等人提出了对比度受限CLAHE的图像增强方法;通过限制局部直方图的高度来限制局部对比度的增强幅度,从而限制噪声的放大及局部对比度的过增强;也可以被用来对图像去雾操作;CLAHE和AHE的区别在于前者对区域对比度进行了限制,且采用插值来加快计算;
工具/原料
方法/步骤
2插值加速方法:AHE方法,不管是否带有对比度限制,都需要对图像中的每个像素计算其领域及变换函数,算法耗时严重;对其进行插值加速,使算法效率有极大提升,且质量没有下降;①将图像均匀分成等份矩阵大小,常见8行8列64块;②计算每个块的直方图,CDF,变换函数;对于块的中心像素(黑色小方块)是完全符合定义的;③对其他的像素通过其邻近的四个黑色小方块的变换函数插值来获取;位于中间的像素(蓝色阴影)采用双线性插值;位于边缘的部分(绿色阴影)采用线性插值;位于角点处的部分(红色阴影)采用块所在的变换函数;
3OpenCV中,CLAHE函数实现:#include#include #include 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 lab_planes(3); split(lab_image, lab_planes); // CLAHE 算法 Ptr 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;}
4CLAHE源码解析:ContrastLimitAHE .h: #ifndef _CONTRAST_LIMIT_AHE_H_#define _CONTRAST_LIMIT_AHE_H_ #include "stdafx.h"#include 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.
注意事项