Adaptive histogram equalization in constant time
Journal of Real-Time Image Processing (2024) 21:93
https://doi.org/10.1007/s11554-024-01465-1
RESEARCH
Adaptive histogram equalization in constant time
Philipp Härtinger1 · Carsten Steger1
Received: 11 March 2024 / Accepted: 17 April 2024 / Published online: 16 May 2024
© The Author(s) 2024
Abstract
Adaptive Histogram Equalization (AHE) and its contrast-limited variant CLAHE are well-known and effective methods for
improving the local contrast in an image. However, the fastest available implementations scale linearly with the filter mask
size, which results in high execution times. This presents an obstacle in real-world applications, where large filter mask sizes
are desired while maintaining low execution times. In this work, we propose an efficient algorithm for AHE that reduces
the per-pixel computational complexity to O(1). To the best of our knowledge, this is the first time that a constant-time
algorithm is proposed for AHE and CLAHE. In contrast to commonly used fast implementations, our method computes the
exact result for each pixel without interpolation artifacts. We benchmark and compare our method to existing algorithms.
Our experiments show that our method exhibits superior execution times independent of the filter mask size, which makes
AHE and CLAHE fast enough to be usable in real-world applications.
Keywords Histogram equalization · Contrast enhancement · Image processing · Computational efficiency
1 Introduction
Histogram Equalization (HE) is a classical method for
improving the global contrast of an image. It linearizes the
gray value histogram, such that the result image uses the
full range of the possible gray values. A drawback of this
method is, however, that local variations are not taken into
account. Adaptive Histogram Equalization (AHE) [4, 5, 11]
solves this issue by considering only the gray values within
a rectangular filter window around each pixel to compute
an individual HE transfer function for the respective pixel.
Because AHE can lead to over-amplification of noise, Pizer
et al. [12] proposed Contrast-Limited Adaptive Histogram
Equalization (CLAHE), which allows to limit the maximum
desired contrast in homogeneous regions. Due to its efficacy,
CLAHE is still a popular image preprocessing method [9,
14] and has successfully been used to improve the performance of Deep Learning models [2, 13]. The computational
complexity of AHE and CLAHE is very high, because they
* Philipp Härtinger
require computing the histogram of each filter window.
Using a naive implementation in which the histogram is recomputed explicitly for each window, the runtime can easily
become multiple seconds, minutes, or even hours, depending
on the size of the filter window. To circumvent this problem, most publicly available implementations of AHE and
CLAHE are based on an approximative algorithm that is
fast, but can lead to visible artifacts in the resulting image.
This severely impacts the applicability of AHE in many realworld scenarios, where runtimes of just a few milliseconds
are required and visual artifacts are not acceptable. Because
of this restriction, we only consider methods that implement
an exact variant of AHE and CLAHE and thus do not lead
to such artifacts.
In this work, we propose a fast constant-time algorithm
for AHE and CLAHE that is free of visual artifacts and
thus suitable for practical applications. Section 2 discusses
related work. In Sect. 3, we describe the O(1) algorithm for
sliding-window histograms as well as efficient implementations of the AHE and CLAHE transfer functions. In Sect. 4,
we benchmark our method against previous algorithms and
discuss the results. Finally, Sect. 5 presents our conclusions.
Carsten Steger
1
MVTec Software GmbH, Arnulfstr. 205, 80634 Munich,
Germany
Vol.:(0123456789)
93 Page 2 of 9
Journal of Real-Time Image Processing (2024) 21:93
(a) Input
(b) IAHE
(c) CLAHE
Fig. 1 Interpolation artifacts of IAHE. (a) shows the original input
image with a linear gray value ramp. (b) shows the result of IAHE,
with banding artifacts due to the interpolation. (c) shows the smooth
result of exact CLAHE. The artifacts on the left and right are due to
border treatment and thus inevitable
2 Related work
In the past, many improvements for AHE and CLAHE have
been proposed. Pizer et al. [12] suggest an approximative
approach in which the HE transfer function is computed
only for a subset of all pixels and interpolated between
these points. This method is also referred to as Interpolated
Adaptive Histogram Equalization (IAHE). It is a popular
choice in many computer vision libraries due to its low
execution time. However, the interpolation can lead to
artifacts, as shown in Fig. 1. In practice, filtering an image
translated by several pixels can lead to a significantly
different result than filtering the original image, meaning
that the interpolation-based approach is not shift-equivariant.
This poses a problem, e.g., in industrial inspection, where the
artifacts might be interpreted as defects, leading to falsely
rejected parts. Our work differs fundamentally from IAHE in
that we compute the exact transfer function for each pixel and
thus avoid the interpolation artifacts shown in Fig. 1b. Kim
et al. [7] propose Block-Overlapped Histogram Equalization
(BOHE), which applies Huang’s O(n) sliding-window
histogram method [3] to AHE. The core idea in [3] is that
when the window slides one pixel to the right, one can simply
update the histogram computed for the previous pixel instead
of fully recomputing it. Sund et al. [15, 16] propose SlidingWindow Adaptive Histogram Equalization (SWAHE), which
applies the O(n) algorithm from [3] to CLAHE. Wang and
Tao [17] also apply [3] to AHE and propose several small
improvements to speed up the computation of the HE transfer
function. Kong and Ibrahim [8] propose Multiple Layers
Block-Overlapped Histogram Equalization (MLBOHE),
which also applies Huang’s O(n) algorithm [3] to AHE.
Furthermore, they employ an optimized zig-zag sliding
order to avoid recomputation of the window histogram at
the beginning of each row. Kim et al. [6] propose Partially
Overlapped Sub-Block Histogram Equalization (POSHE),
where HE is applied to overlapping sub-blocks of the image
and the results are accumulated. Due to the large stride of
half the window size, the result must be filtered to reduce
blocking artifacts. Fu et al. [1] propose POSHE-based
Optimum Clip-Limit Contrast Enhancement (POSHEOC),
which combines POSHE [6] with CLAHE.
Our work mainly follows [7] and [15–17] in that we
improve the computational complexity of the AHE and
CLAHE algorithms. In contrast to the existing linear-time
methods, our proposed method has a constant per-pixel
runtime that is independent of the filter window size. Contrary to [1, 6, 12], we do not use approximative algorithms.
This means that our method reproduces the exact same
results as the original algorithms for AHE and CLAHE
and does not introduce visu (...truncated)