No BSD License  

Highlights from
Contrast Limited Adaptive Histogram Equalization (CLAHE)

4.0

4.0 | 6 ratings Rate this file 73 Downloads (last 30 days) File Size: 3.8 KB File ID: #22182

Contrast Limited Adaptive Histogram Equalization (CLAHE)

by

 

Best to read the reference in "Graphics Gems IV", Academic Press, 1994 pages 474-485

| Watch this File

File Information
Description

This is an image contrast enhancement algorithm that overcomes limitations in standard histogram equalization (HE). The two primary features is adaptive HE (AHE), which divides the images into regions and performs local HE, and the contrast limited AHE (CLAHE), which reduces noise by partially reducing the local HE. Bilinear interpolation is used to avoid visibility of region boundaries.

  "Contrast Limited Adaptive Histogram Equalization"
  by Karel Zuiderveld, karel@cv.ruu.nl
  in "Graphics Gems IV", Academic Press, 1994

Ported by Leslie Smith

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (24)
17 Dec 2014 EiGeN  
30 Nov 2014 muhammad  
07 Oct 2014 Portgas Ace

can't seem to make it work. Can you give me a sample on how to use this?

20 Aug 2014 Seyoung

If error occured "runCLAHE.m" at 53,
Replace "Bin= 1 + LUT(round(Image));" for:
"Bin=1+LUT(round(Image+1));"

and check the function arguements one more time.

12 Jan 2014 Tuhin Sheikh

How to modify the following codes for Gaussian specification ?

case 'rayleigh', % suitable for underwater imagery
% pdf = (t./alpha^2).*exp(-t.^2/(2*alpha^2))*U(t)
% cdf = 1-exp(-t.^2./(2*alpha^2))
hconst = 2*alpha^2;
vmax = 1 - exp(-1/hconst);
val = vmax*(histSum/numPixInTile);
val(val>=1) = 1-eps; % avoid log(0)
temp = sqrt(-hconst*log(1-val));
mapping = min(selectedRange(1)+temp*valSpread,...
selectedRange(2));

28 Nov 2012 Assed Highs

OK, my last comment haha, I don't know what I was thinking about using "adapthisteq" function. SOLUTION:

- Add the following code to runCLAHE.m:

LUT=makeLUT(Min,Max,NrBins);
avgBin = NrPixels/NrBins;

LUT2=zeros(graylevels,1);
[x]=size(LUT);
LUT2(1:x(1),1)=LUT;

Bin=1+LUT2(round(Image));

graylevels is the color depth of used image. If it's 8 bit, just replace "graylevels" for 255.

- If you still having the error, change "Bin=1+LUT2(round(Image));" for "Bin=1+LUT2(round(Image+1))" to avoid pixels with 0 value.

28 Nov 2012 Assed Highs

One last comment, just to clariry. To avoid "index out of bounds":

- Add the following code to runCLAHE.m:

LUT=makeLUT(Min,Max,NrBins);
avgBin = NrPixels/NrBins;

LUT2=zeros(graylevels,1);
[x]=size(LUT);
LUT2(1:x(1),1)=LUT;

Bin=1+LUT2(round(Image));

graylevels is the color depth of used image. If it's 8 bit, just replace "graylevels" for 255.

- Right before calling runCLAHE.m, add:
"image=adapthisteq(image);"

- If you still having the error, change "Bin=1+LUT2(round(Image));" for "Bin=1+LUT2(round(Image+1))" to avoid pixels with 0 value (if there's still one after applying adapthisteq function).

That should work.

28 Nov 2012 Assed Highs

Fixed, it was my fault.

Just make sure that "Max" and "Min" are double because if some of those are integers, maphistogram.m will make and empty map.

Works perfect, thanks for sharing!

28 Nov 2012 Assed Highs

Ok, forget what I said in my last comment. Add this to the code:

LUT=makeLUT(Min,Max,NrBins);
avgBin = NrPixels/NrBins;

LUT2=zeros(graylevels,1);
[x]=size(LUT);
LUT2(1:x(1),1)=LUT;

Bin=1+LUT2(round(Image));

graylevels is the color depth of used image. If it's 8 bit, just replace "graylevels" for 255.

Anyway, the function always returns an empty matrix. I would try to fix it.

Thanks,

28 Nov 2012 Assed Highs

Thanks!

The error is related to the value of the pixel. Whenever you got a pixel with 0 value you will get that error because Matlab does not consider it as an index value.

Replace "Bin= 1 + LUT(round(Image));" for:

"Bin=1+LUT(round(Image+1));"

It will fix the error.

On the other hand, whenever I try this algorithm, the output is a matrix with the same size of the original image but with zeros. Someone knows what the problem is?

01 Oct 2012 Hector

I am reviewing the article of Zuiderveld, but I don't what do you want with the line:
Bin= 1 + LUT(round(Image));"

maybe resizing the LUT array?

27 Sep 2012 Leslie Smith

I think the error might be related to the image size - when I wrote it I only tested it on even sized images.

Let me again recommend using adapthisteq in the Image Processing Toolbox. It is more robust and doesn't have these limitations.

27 Sep 2012 Pratik Oak

hey guys.. I also got error like this
"subscript should be real positive index"

"Error in ==> runCLAHE at 55
Bin= 1 + LUT(round(Image));"

27 Oct 2011 LIAO xj

quite useful! thanks a lot!

17 Jun 2011 Leslie Smith

The full argument list is
runCLAHE(Image,XRes,YRes,Min,Max,NrX,NrY,NrBins,Cliplimit,modHist)
The comments in the beginning of the function describe the arguments.
Once again I will suggest you use adapthisteq in the Image processing toolbox because Matlab's routine is more robust.

17 Jun 2011 Rado

Excuse me, this may be a stupid question, but can you tell me how to use this function?

I tried to define the variable "Image" to be the path of the image I want to process. Then I removed the comment symbols in front of:
% [XRes,YRes]=size(Image);
% CEimage = Image;
in "runCLAHE.m".

I typed the command:
J=runCLAHE(Image);

The error I got was:
?? Input argument "Cliplimit" is undefined.

Error in ==> runCLAHE at 34
if Cliplimit == 1

Can you help me with that?

Again, sorry for the stupid question and thanks in advance!

12 May 2011 Leslie Smith

The "Subscript indices must either be real positive integers or logicals" is basically that the index is out of bounds.

Obviously you are taking a class where the assignment is to create the CLAHE code. IMO, that is what you should do because the goal of a class is the learning, not the grade.

12 May 2011 Freyssineta

When i execute runCLAHE.m the error is "Subscript indices must either be real positive integers or logicals"

yup i know about adapthistheq function in matlab. But i did'nt allowed to use that function with my lecturer so i must make clahe code manually.
What should i do?

11 May 2011 Leslie Smith

I suggest you use adapthisteq in the Image processing toolbox because Matlab's routine is more robust.
Although you don't say what the error is, my guess is that it is "index out of bounds" for the look up table LUT. If I remember correctly, runCLAHE needs for the dimensions of the image to be even to work properly. Again, you are likely better off to use adapthisteq.

11 May 2011 Freyssineta

hey guys.. I got error like this
"Error in ==> runCLAHE at 55
Bin= 1 + LUT(round(Image));"

Do you know the solution?
please help me. I need it

26 Apr 2010 Alireza Saberi

Thank you much, I really was in need to this codes

15 Apr 2009 Idillus  
20 Nov 2008 Leslie Smith

Thanks for the reference. I had looked for and did not find the Matlab CLAHE and was surprised when I thought it did not exist.
Leslie

20 Nov 2008 Steve Eddins

You might want to take a look at adapthisteq, which is in the Image Processing Toolbox. This function also implements CLAHE. See:

http://www.mathworks.com/access/helpdesk/help/toolbox/images/adapthisteq.html

Contact us