# Histogram Matching

The Histogram Matching (also called Histogram Specification) algorithm generates an output image based upon a specified histogram.

## Contents

### Background

The process of Histogram Matching takes in an input image and produces an output image that is based upon a specified histogram. The required parameters for this algorithm are the input image and the specified image, from which the specified histogram can be obtained.

The algorithm works as follows:

The histograms for the input image p(f) and the specified image pd(g) are generated. Here, the desired histogram of the specified image is denoted as pd(g). Cumulative histograms - P(f) and Pd(g) are then generated using the following equations:

Equation 1
$P(f) = \sum_{k=0}^fp(k)$

Equation 2
$P_d(g) = \sum_{k=0}^gP_d(k)$

where f and g are the pixel intensity levels.

The transformation function is obtained by choosing g for each f, such that if g > f, then Pd(g) > P(f). The transformation function is then applied to the input image to produce an output image by remapping the pixel intensities. The objective is to find a transformed digital picture of a given picture, such that the sum of absolute errors between the intensity level histogram of the transformed picture and that of a reference picture is minimized. Refer to Figure 1.       