2022年c语言CLAHE算法 .pdf
《2022年c语言CLAHE算法 .pdf》由会员分享,可在线阅读,更多相关《2022年c语言CLAHE算法 .pdf(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、CLAHE 算法*Contrast Limited Adaptive Histogram Equalization*by Karel Zuiderveld,karelcv.ruu.nl*in Graphics Gems IV,Academic Press,1994*These functions implement Contrast Limited Adaptive Histogram Equalization.*The main routine(CLAHE)expects an input image that is stored contiguously in*memory;the CLA
2、HE output image overwrites the original input image and has the*same minimum and maximum values(which must be provided by the user).*This implementation assumes that the X-and Y image resolutions are an integer*multiple of the X-and Y sizes of the contextual regions.A check on various other*error co
3、nditions is performed.*#define the symbol BYTE_IMAGE to make this implementation suitable for*8-bit images.The maximum number of contextual regions can be redefined*by changing uiMAX_REG_X and/or uiMAX_REG_Y;the use of more than 256*contextual regions is not recommended.*The code is ANSI-C and is al
4、so C+compliant.*Author:Karel Zuiderveld,Computer Vision Research Group,*Utrecht,The Netherlands(karelcv.ruu.nl)*/#ifdef BYTE_IMAGE typedef unsigned char kz_pixel_t;/*for 8 bit-per-pixel images*/#define uiNR_OF_GREY(256)#else typedef unsigned short kz_pixel_t;/*for 12 bit-per-pixel images(default)*/#
5、define uiNR_OF_GREY(4096)#endif/*Prototype of CLAHE function.Put this in a separate include file.*/int CLAHE(kz_pixel_t*pImage,unsigned int uiXRes,unsigned int uiYRes,kz_pixel_t Min,kz_pixel_t Max,unsigned int uiNrX,unsigned int uiNrY,unsigned int uiNrBins,float fCliplimit);/*Local prototypes*/stati
6、c void ClipHistogram(unsigned long*,unsigned int,unsigned long);static void MakeHistogram(kz_pixel_t*,unsigned int,unsigned int,unsigned int,unsigned long*,unsigned int,kz_pixel_t*);static void MapHistogram(unsigned long*,kz_pixel_t,kz_pixel_t,unsigned int,unsigned long);名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页
7、,共 7 页 -static void MakeLut(kz_pixel_t*,kz_pixel_t,kz_pixel_t,unsigned int);static void Interpolate(kz_pixel_t*,int,unsigned long*,unsigned long*,unsigned long*,unsigned long*,unsigned int,unsigned int,kz_pixel_t*);/*Start of actual code*/#include /*To get prototypes of malloc()and free()*/const uns
8、igned int uiMAX_REG_X=16;/*max.#contextual regions in x-direction*/const unsigned int uiMAX_REG_Y=16;/*max.#contextual regions in y-direction*/*main function CLAHE*/int CLAHE(kz_pixel_t*pImage,unsigned int uiXRes,unsigned int uiYRes,kz_pixel_t Min,kz_pixel_t Max,unsigned int uiNrX,unsigned int uiNrY
9、,unsigned int uiNrBins,float fCliplimit)/*pImage-Pointer to the input/output image*uiXRes-Image resolution in the X direction*uiYRes-Image resolution in the Y direction*Min-Minimum greyvalue of input image(also becomes minimum of output image)*Max-Maximum greyvalue of input image(also becomes maximu
10、m of output image)*uiNrX-Number of contextial regions in the X direction(min 2,max uiMAX_REG_X)*uiNrY-Number of contextial regions in the Y direction(min 2,max uiMAX_REG_Y)*uiNrBins-Number of greybins for histogram(dynamic range)*float fCliplimit-Normalized cliplimit(higher values give more contrast
11、)*The number of effective greylevels in the output image is set by uiNrBins;selecting*a small value(eg.128)speeds up processing and still produce an output image of*good quality.The output image will have the same minimum and maximum value as the input*image.A clip limit smaller than 1 results in st
12、andard(non-contrast limited)AHE.*/unsigned int uiX,uiY;/*counters*/unsigned int uiXSize,uiYSize,uiSubX,uiSubY;/*size of context.reg.and subimages*/unsigned int uiXL,uiXR,uiYU,uiYB;/*auxiliary variables interpolation routine*/unsigned long ulClipLimit,ulNrPixels;/*clip limit and region pixel count*/k
13、z_pixel_t*pImPointer;/*pointer to image*/kz_pixel_t aLUTuiNR_OF_GREY;/*lookup table used for scaling of input image*/unsigned long*pulHist,*pulMapArray;/*pointer to histogram and mappings*/unsigned long*pulLU,*pulLB,*pulRU,*pulRB;/*auxiliary pointers interpolation*/if(uiNrX uiMAX_REG_X)return-1;/*#o
14、f regions x-direction too large*/if(uiNrY uiMAX_REG_Y)return-2;/*#of regions y-direction too large*/if(uiXRes%uiNrX)return-3;/*x-resolution no multiple of uiNrX*/名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 7 页 -if(uiYRes&uiNrY)return-4;/*y-resolution no multiple of uiNrY*/if(Max=uiNR_OF_GREY)return-5;/*maximum t
15、oo large*/if(Min=Max)return-6;/*minimum equal or larger than maximum*/if(uiNrX 2|uiNrY 0.0)/*Calculate actual cliplimit*/ulClipLimit=(unsigned long)(fCliplimit*(uiXSize*uiYSize)/uiNrBins);ulClipLimit=(ulClipLimit 1UL)?1UL:ulClipLimit;else ulClipLimit=1UL14;/*Large value,do not clip(AHE)*/MakeLut(aLU
16、T,Min,Max,uiNrBins);/*Make lookup table for mapping of greyvalues*/*Calculate greylevel mappings for each contextual region*/for(uiY=0,pImPointer=pImage;uiY uiNrY;uiY+)for(uiX=0;uiX uiNrX;uiX+,pImPointer+=uiXSize)pulHist=&pulMapArrayuiNrBins*(uiY*uiNrX+uiX);MakeHistogram(pImPointer,uiXRes,uiXSize,ui
17、YSize,pulHist,uiNrBins,aLUT);ClipHistogram(pulHist,uiNrBins,ulClipLimit);MapHistogram(pulHist,Min,Max,uiNrBins,ulNrPixels);pImPointer+=(uiYSize-1)*uiXRes;/*skip lines,set pointer*/*Interpolate greylevel mappings to get CLAHE image*/for(pImPointer=pImage,uiY=0;uiY 1;uiYU=0;uiYB=0;else if(uiY=uiNrY)/*
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年c语言CLAHE算法 2022 语言 CLAHE 算法
限制150内