Contrast-limited adaptive histogram equalization (CLAHE)
Apply Contrast-Limited Adaptive Histogram Equalization (CLAHE)
Apply CLAHE to an image and display the results.
I = imread('tire.tif'); J = adapthisteq(I,'clipLimit',0.02,'Distribution','rayleigh'); imshowpair(I,J,'montage'); title('Original Image (left) and Contrast Enhanced Image (right)')
Apply CLAHE to Indexed Color Image
Read the indexed color image into the workspace.
[X, MAP] = imread('shadow.tif');
Convert the indexed image into a truecolor (RGB) image, then convert the RGB image into the L*a*b* color space.
RGB = ind2rgb(X,MAP); LAB = rgb2lab(RGB);
Scale values to the range expected by the
adapthisteq function, [0 1].
L = LAB(:,:,1)/100;
Perform CLAHE on the L channel. Scale the result to get back to the range used by the L*a*b* color space.
L = adapthisteq(L,'NumTiles',[8 8],'ClipLimit',0.005); LAB(:,:,1) = L*100;
Convert the resulting image back into the RGB color space.
J = lab2rgb(LAB);
Display the original image and the processed image.
figure imshowpair(RGB,J,'montage') title('Original (left) and Contrast Enhanced (right) Image')
Shadows in the enhanced image look darker and highlights look brighter. The overall contrast is improved.
I — Grayscale image
2-D numeric matrix
Grayscale image, specified as a 2-D numeric matrix.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
"NumTiles",[8 16] divides the image into 8 rows and 16
columns of tiles.
NumTiles — Number of tiles
[8,8] (default) | 2-element vector of positive integers
Number of rectangular contextual regions (tiles) into which
adapthisteq divides the image, specified as a
2-element vector of positive integers. With the original image divided
M rows and
N columns of
tiles, the value of
must be at least
2. The total number of tiles is
M*N. The optimal number of tiles depends on
the type of the input image, and it is best determined through
ClipLimit — Contrast enhancement limit
0.01 (default) | number in the range [0, 1]
Contrast enhancement limit, specified as a number in the range [0, 1]. Higher limits result in more contrast.
ClipLimit is a contrast factor that prevents
oversaturation of the image specifically in homogeneous areas. These
areas are characterized by a high peak in the histogram of the
particular image tile due to many pixels falling inside the same gray
level range. Without the clip limit, the adaptive histogram equalization
technique could produce results that, in some cases, are worse than the
NBins — Number of histogram bins used to build a contrast enhancing transformation
256 (default) | positive integer
Number of histogram bins used to build a contrast enhancing transformation, specified as a positive integer. Higher values result in greater dynamic range at the cost of slower processing speed.
Range — Range of output data
"full" (default) |
Range of the output image data, specified as one of these values.
|Use the full range of the output class (such as [0
255] for |
|Limit the range to |
Distribution — Desired histogram shape
"uniform" (default) |
Desired histogram shape, specified as one of the following values:
|Create a flat histogram.|
|Create a bell-shaped histogram.|
|Create a curved histogram.|
Distribution specifies the distribution that
adapthisteq uses as the basis for creating the
contrast transform function. The distribution you select should depend
on the type of the input image. For example, underwater imagery appears
to look more natural when the Rayleigh distribution is used.
Alpha — Distribution parameter
0.4 (default) | nonnegative number
Distribution parameter, specified as a nonnegative number.
Alpha is only used when
Distribution is set to
J — Contrast enhanced image
Contrast enhanced image, returned as a 2-D matrix of the same data type as
the input image
CLAHE operates on small regions in the image, called tiles,
rather than the entire image.
adapthisteq calculates the contrast
transform function for each tile individually. Each tile's contrast is enhanced, so that
the histogram of the output region approximately matches the histogram specified by the
Distribution value. The neighboring tiles are then combined
using bilinear interpolation to eliminate artificially induced boundaries. The contrast,
especially in homogeneous areas, can be limited to avoid amplifying any noise that might
be present in the image.
 Zuiderveld, Karel. "Contrast Limited Adaptive Histograph Equalization." Graphic Gems IV. San Diego: Academic Press Professional, 1994. 474–485.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
adapthisteq supports the generation of C
code (requires MATLAB®
Coder™). For more information, see Code Generation for Image Processing.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version HistoryIntroduced before R2006a
R2022b: Support for thread-based environments
adapthisteq now supports thread-based
R2022a: Generate CUDA code using GPU Coder
adapthisteq now supports the generation of
optimized CUDA® code (requires GPU Coder™).
R2021a: Generate C code using MATLAB Coder
adapthisteq now supports the generation of
C code (requires MATLAB