imgcv.histogram.matching

Functions

check_image(image)

Check if the input is a numpy array

matchHistogram(image, reference)

Matches the histogram of the image to the reference image. Works for both grayscale and color images. Matching is done for each channel seperately.

_match_cumulative_cdf(source, template)

This function matches the cumulative distribution function of the source and template images. This is used for histogram matching.

_find_nearest_above(tmpl_rounded, target)

Finds the nearest value in the tmpl_rounded array which is greater than the target value. This is used for histogram matching.

Module Contents

imgcv.histogram.matching.check_image(image)

Check if the input is a numpy array

Parameters:

image (np.ndarray) – Input image to be transformed

Raises:
  • TypeError – If the input is not a numpy array

  • ValueError – If the input is not a grayscale or color image

imgcv.histogram.matching.matchHistogram(image, reference)

Matches the histogram of the image to the reference image. Works for both grayscale and color images. Matching is done for each channel seperately.

Parameters:
  • image (np.ndarray) – The input image

  • reference (np.ndarray) – The reference image

Raises:

ValueError – Thrown when the number of channels in the image and reference are not same

Returns:

The matched image tuple: The source cumulative distribution function and the source histogram tuple: The reference cumulative distribution function and the reference histogram

Return type:

ndarray

imgcv.histogram.matching._match_cumulative_cdf(source, template)

This function matches the cumulative distribution function of the source and template images. This is used for histogram matching.

Parameters:
  • source (ndarray) – The source image

  • template (ndarray) – The reference or template image

Returns:

The matched image with the same shape as the source image for single channel tuple: The source unique intensity values, their counts and the normalized quantiles tuple: The template unique intensity values, their counts and the normalized quantiles

Return type:

ndarray

imgcv.histogram.matching._find_nearest_above(tmpl_rounded, target)

Finds the nearest value in the tmpl_rounded array which is greater than the target value. This is used for histogram matching.

Parameters:
  • tmpl_rounded (ndarray) – The rounded values of the cumulative distribution function of the template image

  • target (int) – The target pixel value from the source image

Returns:

The index of the nearest value of the pixel value in the tmpl_rounded array

Return type:

int