Histogram matching is an image processing task where an image is altered in such a way that its histogram matches the histogram of another reference (template) image's histogram. The algorithm is described as follows:
- Compute the cumulative histogram for each image.
- For any given pixel value, xi, in the input image, find the corresponding pixel value, xj, in the output image by matching the input image's histogram with the template image's histogram (G(xi)=H(xj), as shown in the following diagram.
- Replace pixel xi in the input with xj as shown in the following diagram:
In this recipe, we will implement histogram matching for colored images on our own.