First of all – I am not going to discuss CLAHE (Contrast Limited Adaptive Histogram Equalization) here. This is because there is a lot of standard material available on the internet as well as in books for studying the algorithm in detail. This,  this, and this should be more than enough to fill you up on CLAHE.

In this post, I am going to write about my personal experience with a CLAHE code that I found online – free of course (no legal issues here). Why I am writing about this is that I was able to find and solve a problem with that code. On request, the code’s author (Toby Breckon) mailed me saying that the code worked perfectly on Windows 32- and 64-bit systems. He was not sure about 64-bit Linux systems (I am using Ubuntu 11.04 64-bit).

The code has a very ‘involved’ pointer handling which though quite efficient – was not very readable to me (I am not a computer major but I am working on Image Processing – sorry!) and what’s more? It resulted in a ‘Segmentation fault‘ when compiled with the standard g++ compiler for C++. I assumed that the fault lay in my code – after all, I am the noob. But, after a marathon debugging session using feedback prints on to the console printf (“Now I am on line number ***”) ) and in the Eclipse IDE, I was able to find the culprit – the definition of the MakeHistogram function. And soon enough, after drawing a flowchart (on-paper) of the code and tracking each pointer’s position between iterations, I was able to pin-point the problematic part of the code and corrected it. Soon enough, I had the CLAHE-ed images popping on my screen.

Following is the revised code of the culprit – the MakeHistogram function in the clahe.cc file. Please note – if you have not downloaded the tar.gz file from the link I shared above, you will not find the following code useful (or sensible for that matter).


void MakeHistogram (kz_pixel_t* pImage, unsigned int uiXRes,
 unsigned int uiSizeX, unsigned int uiSizeY,
 unsigned long* pulHistogram,
 unsigned int uiNrGreylevels, kz_pixel_t* pLookupTable)
/* This function classifies the greylevels present in the array image into
 * a greylevel histogram. The pLookupTable specifies the relationship
 * between the greyvalue of the pixel (typically between 0 and 4095) and
 * the corresponding bin in the histogram (usually containing only 128 bins).
 */
{
 unsigned int i,j=0;

for (i = 0; i < uiNrGreylevels; i++) pulHistogram[i] = 0L; /* clear histogram */

for (i = 0; i < uiSizeY; i++) {
 j = 0;
 while (j < uiSizeX) { pulHistogram[pLookupTable[pImage[j]]]++; ++j; }
 pImage = &pImage[uiXRes];
 }
}

Updated – The author of the original code mentioned above thanked me for pointing out the Linux 64-bit bug. YAY!

Advertisements