Histogram Matching

Source code Author Update time

This demo demonstrates the feature of histogram matching.

Purpose of Histogram matching is to transform the intensities in a source image so that the intensities distribute according to the histogram of a specified target image.

Here, histogram matching is shown for the RGB image. But, it can also be applied on grayscale images too. Histogram matching 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.

using ImageContrastAdjustment
using Images
using Plots
using TestImages

Load example images: one source image and one reference image


You need to use julia >= v"1.3.0" and TestImages >= v"1.3.1" in order to load these two test images.

img_source = testimage("chelsea");
img_reference = testimage("coffee");

Applying histogram matching on source image using the reference image. Here we use adjust_histogram function from ImageContrastAdjustment.jl. It returns a histogram matched image with a granularity of nbins, i.e., number of bins. The first argument img is the image to be matched, and the second argument targetimg is the image with the desired histogram to be matched to.

img_transformed = adjust_histogram(img_source, Matching(targetimg = img_reference))
mosaicview(img_source, img_reference, img_transformed; nrow = 1)