Hubbry Logo
Histogram matchingHistogram matchingMain
Open search
Histogram matching
Community hub
Histogram matching
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Histogram matching
Histogram matching
from Wikipedia
An example of histogram matching

In image processing, histogram matching or histogram specification is the transformation of an image so that its histogram matches a specified histogram.[1] The well-known histogram equalization method is a special case in which the specified histogram is uniformly distributed.[2]

It is possible to use histogram matching to balance detector responses as a relative detector calibration technique. It can be used to normalize two images, when the images were acquired at the same local illumination (such as shadows) over the same location, but by different sensors, atmospheric conditions or global illumination.

Implementation

[edit]

Consider a grayscale input image X. It has a probability density function pr(r), where r is a grayscale value, and pr(r) is the probability of that value. This probability can easily be computed from the histogram of the image by

Where nj is the frequency of the grayscale value rj, and n is the total number of pixels in the image.

Now consider a desired output probability density function pz(z). A transformation of pr(r) is needed to convert it to pz(z).

Input image CDF matched to desired output CDF

Each pdf (probability density function) can easily be mapped to its cumulative distribution function by

Where L is the total number of gray level (256 for a standard image).

The idea is to map each r value in X to the z value that has the same probability in the desired pdf. I.e. S(rj) = G(zi) or z = G−1(S(r)).[3]

Example

[edit]

The following input grayscale image is to be changed to match the reference histogram.

The input image has the following histogram

Histogram of input image

It will be matched to this reference histogram to emphasize the lower gray levels.

Desired reference histogram

After matching, the output image has the following histogram

Histogram of output image after matching

And looks like this

Output image after histogram matching

Algorithm

[edit]

Given two images, the reference and the target images, we compute their histograms. Following, we calculate the cumulative distribution functions of the two images' histograms – for the reference image and for the target image. Then for each gray level , we find the gray level for which , and this is the result of histogram matching function: . Finally, we apply the function on each pixel of the reference image.

Exact histogram matching

[edit]

In typical real-world applications, with 8-bit pixel values (discrete values in range [0, 255]), histogram matching can only approximate the specified histogram. All pixels of a particular value in the original image must be transformed to just one value in the output image.

Exact histogram matching is the problem of finding a transformation for a discrete image so that its histogram exactly matches the specified histogram.[4] Several techniques have been proposed for this. One simplistic approach converts the discrete-valued image into a continuous-valued image and adds small random values to each pixel so their values can be ranked without ties. However, this introduces noise to the output image.

Because of this there may be holes or open spots in the output matched histogram.

Multiple histogram matching

[edit]

The histogram matching algorithm can be extended to find a monotonic mapping between two sets of histograms. Given two sets of histograms and , the optimal monotonic color mapping is calculated to minimize the distance between the two sets simultaneously, namely where is a distance metric between two histograms. The optimal solution is calculated using dynamic programming.[5]

See also

[edit]

References

[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
Histogram matching, also known as histogram specification, is a technique in that transforms the intensity of a source image to closely resemble that of a specified target histogram, often derived from a reference image, in order to adjust contrast, brightness, and overall tonal distribution. This method enables the transfer of visual characteristics, such as lighting and , from the reference image to the source without altering the underlying scene content. The algorithm operates by first computing the histograms of both the source and target images, which represent the frequency distributions of pixel intensities. It then derives the cumulative distribution functions (CDFs) for each: the source CDF s=T(r)=0rpr(w)dws = T(r) = \int_0^r p_r(w) \, dw, where pr(r)p_r(r) is the source probability density, and the target CDF G(z)=0zpz(w)dwG(z) = \int_0^z p_z(w) \, dw. The transformation maps each source intensity rr to a target intensity zz via z=G1(T(r))z = G^{-1}(T(r)), ensuring the output image's histogram approximates the target. This mapping minimizes the difference between the transformed and target histograms, typically measured by the sum of absolute errors. Unlike histogram equalization, which spreads intensities toward a uniform distribution for general enhancement, histogram matching allows precise control by specifying any desired distribution. Histogram matching finds applications in image enhancement to improve visibility in low-contrast scenes, such as microscopic or , and in standardizing images captured under varying illumination for comparison or analysis. It is also used in color transfer techniques to apply the aesthetic style of one image to another, and in preprocessing for tasks like or segmentation by normalizing intensity variations. The method supports grayscale, color, 2D, and 3D images, making it versatile across domains including , , and multimedia processing.

Fundamentals

Definition and Purpose

Histogram matching is a technique in that adjusts the intensity values of a source so that its aligns with that of a target or a desired distribution, thereby modifying the image's contrast and brightness while maintaining its underlying spatial structure. This non-linear transformation maps each pixel intensity in the source to a corresponding value in the target based on their cumulative distributions, effectively transferring the statistical properties of the target's intensity profile to the source without altering the relative positions of pixels. The primary purpose of histogram matching is to achieve consistent visual appearance and enhanced interpretability across images captured under varying conditions, such as different lighting or sensors. It finds widespread application in for to mimic desired stylistic effects, normalization of or color images in to standardize scans for diagnosis and analysis, style transfer in artistic rendering, and preprocessing in pipelines to improve feature extraction and performance. A key benefit is its model-free approach, which relies solely on empirical histograms—representations of pixel intensity probability distributions—avoiding the assumptions of parametric techniques like gamma correction that apply a fixed power-law transformation. This flexibility enables precise adaptation to arbitrary target distributions, promoting uniformity in datasets without over- or under-enhancing specific intensity ranges.

Histograms and Cumulative Distributions

In digital image processing, a histogram is a discrete function h(rk)h(r_k) that quantifies the frequency distribution of pixel intensities rkr_k in an image, serving as a fundamental tool for analyzing and enhancing image characteristics such as contrast and brightness. When normalized, it represents a probability density function (PDF) that captures the likelihood of each intensity level occurring in the image. The construction of a histogram for a of size M×NM \times N with LL possible gray levels begins by counting the occurrences nkn_k of each intensity rkr_k, where 0rk<L0 \leq r_k < L. The normalized histogram is then computed as h(rk)=nkMNh(r_k) = \frac{n_k}{M N}, transforming the frequency counts into probabilities that sum to 1 across all levels. This normalization is essential for statistical interpretations and subsequent transformations. The cumulative distribution function (CDF) is derived from the histogram as the running sum of its values: F(r)=i=0rh(ri)F(r) = \sum_{i=0}^{r} h(r_i) This function accumulates the probabilities up to intensity level rr, providing a cumulative perspective on the intensity distribution. It is particularly useful for mapping operations that redistribute intensities based on percentile rankings. Key properties of the CDF include its monotonic increasing nature, starting at F(0)=h(0)F(0) = h(0) and reaching F(L1)=1F(L-1) = 1, which ensures a smooth progression from the lowest to the highest intensity. In discrete implementations, this enables precise, percentile-based adjustments to intensity values without gaps or overlaps in the transformed distribution. These attributes make the CDF a cornerstone for probabilistic intensity transformations. For histogram matching, which aims to align the intensity distribution of a source image to that of a target, the histograms of both images must first be computed and normalized to obtain their respective CDFs as the foundational step for deriving the mapping function.

Core Algorithm

Standard Matching Procedure

The standard histogram matching procedure transforms the intensity distribution of a source image to closely resemble that of a target image by mapping pixel values based on their cumulative distributions. This global technique operates on the entire image and assumes grayscale or single-channel intensities for simplicity, though it can extend to color channels independently. The process begins by computing the histograms of both the source image, denoted as HsH_s, and the target image, denoted as HtH_t, which represent the frequency distributions of pixel intensities in each. These histograms are then normalized to form the cumulative distribution functions (CDFs), FsF_s for the source and FtF_t for the target, by accumulating the probabilities from the lowest to highest intensity levels. Next, for each unique intensity value ss in the source image, the procedure determines the corresponding matched intensity by finding the value tt in the target such that the CDF value at ss in the source equals the CDF value at tt in the target, effectively applying the inverse mapping from the target's CDF to the source's CDF output. This mapping is precomputed into a lookup table for efficiency, allowing every pixel in the source image to be replaced with its matched intensity value. In cases of discrete intensities, such as 8-bit grayscale images with 256 possible levels, the inverse CDF may not yield exact matches due to the finite binning, so linear interpolation between adjacent target levels or nearest-neighbor rounding is commonly applied to approximate the continuous inverse. The resulting matched image thus has an intensity histogram that approximates the target's distribution, though the match is inherently approximate owing to this discretization.

Mathematical Formulation

Histogram matching seeks to transform the intensity values of a source image, with cumulative distribution function (CDF) Fs(s)F_s(s), such that the resulting distribution matches that of a target image, with CDF Ft(t)F_t(t). The core objective is to derive a monotonic transformation function GG such that Ft(G(s))=Fs(s)F_t(G(s)) = F_s(s), ensuring the output image's intensity distribution aligns with the target's histogram while preserving the relative ordering of pixel intensities. In the continuous case, the transformation is explicitly given by G(z)=Ft1(Fs(z))G(z) = F_t^{-1}(F_s(z)), where Ft1F_t^{-1} denotes the inverse CDF of the target distribution. This formulation arises from the probability integral transform, which maps the source CDF to a uniform distribution and then inverts the target CDF to achieve the desired output. For the probability densities ps(z)p_s(z) and pt(w)p_t(w) of the source and target, respectively, the change-of-variables formula yields the output density as pw(w)=ps(G1(w))dG1dwp_w(w) = p_s(G^{-1}(w)) \left| \frac{dG^{-1}}{dw} \right|
Add your contribution
Related Hubs
User Avatar
No comments yet.