Core Optical, Inc.
HistogramProcessor GetEqualizedHistogramImage Method Industrial Strength, Scientific Grade
Applies the Histogram Equalization algorithm to the source data and returns an image of the result. The original data is not altered.

Namespace: PrecisionImage.HistogramProcessing
Assembly: PrecisionImage (in PrecisionImage.dll) Version: (

public BitmapSource GetEqualizedHistogramImage(
	SourceData sourceData,
	int channel,
	HistogramResolution histogramResolution = HistogramResolution.EightBit,
	Int32Rect regionOfInterest = null,
	BinaryMask binaryMask = null,
	bool zeroOutMaskArea = false,
	GammaEncoding gammaEncoding = GammaEncoding.None


Type: PrecisionImage SourceData
A SourceData type containing the image data.
Type: OnlineSystem Int32
An OnlineInt32 type indicating the data channel to process.
histogramResolution (Optional)
Type: PrecisionImage.HistogramProcessing HistogramResolution
A HistogramResolution enumeration specifying the resolution of the histogram used internally by the algorithm when characterizing the source data. This parameter is optional and defaults to 8-bit histogram resolution.
regionOfInterest (Optional)
Type: OnlineSystem.Windows Int32Rect
An OnlineInt32Rect type indicating the region of interest. Coordinates are zero-index based. This parameter is optional and defaults to the entire image.
binaryMask (Optional)
Type: PrecisionImage.BinarizationAndMorphology BinaryMask
A BinaryMask type specifying a mask indicating areas of the image to bypass. Masked regions are not altered, nor are they used internally when determining the initial histogram. This parameter is optional.
zeroOutMaskArea (Optional)
Type: OnlineSystem Boolean
A OnlineBoolean indicating whether to the masked areas are zeroed in the output image. If True, the masked region of the data appears black. If False, the masked area of the region is inserted unchanged in the resulting image. This parameter is optional and defaults to False.
gammaEncoding (Optional)
Type: PrecisionImage GammaEncoding
A GammaEncoding enumeration specifying the gamma encoding of the unmasked region. If the unmasked region is to be zeroed out in the resulting image this parameter is ignored. This parameter is optional and defaults to GammaEncoding.None

Return Value

A OnlineBitmapSource object containing the image of the histogram-equalized data. If a region of interest was specified, the returned OnlineBitmapSource object portrays the processed data of the specified region only and has the same dimensions as regionOfInterest. Otherwise, the returned OnlineBitmapSource object has the same dimensions as the source data.

OnlineSystem ArgumentNullException Thrown when sourceData is null.
OnlineSystem ArgumentOutOfRangeException Thrown when sourceData contains less than 1 data channel.
OnlineSystem ArgumentOutOfRangeException Thrown when channel is negative or out of range.
OnlineSystem ArgumentOutOfRangeException Thrown when regionOfInterest specifies a rectangular region not completely contained within the dimensions of the source data.
OnlineSystem ArgumentOutOfRangeException Thrown when the number of rows and/or columns in binaryMask do not match those of sourceData.

This method applies the histogram equalization algorithm to the data contained within the specified channel of sourceData. The data is portrayed such that its probabilty distribution function is as flat as possible, maximizing image entropy.

Histogram equalization is an inherently discrete operation i.e. the data is discretized into a series of histogram bins before and after equalization. To ensure optimum results and minimize discretization error, specify a HistogramResolution that most closely resembles the nature of the original data. For example, if the sourceData is originally sourced from a 16-bit image, specify histogramResolution to be SixteenBit. This parameter also controls the OnlinePixelFormat of the output image. If EightBit is specified, the output image is of type OnlineGray8. Otherwise, the image is of type OnlineGray16.


The following illustrates the use of this method to automatically improve the contrast of a low contrast 16-bit micrograph:

using PrecisionImage;
using PrecisionImage.HistogramProcessing;

// Read the source image from disk and load into a SourceData object: 
Uri imageUri                   = new Uri("Toxicysts.tif", UriKind.Relative);
TiffBitmapDecoder imageDecoder = new TiffBitmapDecoder(imageUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource SourceImage       = imageDecoder.Frames[0];
SourceData imageData           = new SourceData(SourceImage, GammaEncoding.None);

// Display original image in Image component:
image0.Source = SourceImage;

// Instantiate a HistogramProcessor and equalize histogram using default settings: 
HistogramProcessor histProcessor = new HistogramProcessor();
BitmapSource ProcessedImage     = histProcessor.GetEqualizedHistogramImage(imageData, 0, HistogramResolution.SixteenBit);

// Display histogram-equalized result in Image component:
image1.Source = ProcessedData;

The above example produces a pair of images similar to the following (their histograms are shown underneath the original and processed image to illustrate the effect of the algorithm on the image histogram):

See Also