Core Optical, Inc.
HistogramProcessor GetAdaptivelyEqualizedHistogramImage Method Industrial Strength, Scientific Grade
Applies the Contrast-Limited Adaptive 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: 2.0.0.0 (2.0.0.0)
Syntax

public BitmapSource GetAdaptivelyEqualizedHistogramImage(
	SourceData sourceData,
	int channel,
	int windowSize,
	float clipping,
	Int32Rect regionOfInterest = null,
	BinaryMask binaryMask = null,
	bool zeroOutMaskArea = true,
	GammaEncoding gammaEncoding = GammaEncoding.None
)

Parameters

sourceData
Type: PrecisionImage SourceData
A SourceData type containing the image data.
channel
Type: OnlineSystem Int32
An OnlineInt32 type indicating the data channel to process.
windowSize
Type: OnlineSystem Int32
An OnlineInt32 type specifying the dimension (square) of the neighborhood window. If an even number is specified then this value is automatically shifted to the next higher odd number in order to properly center the local analysis window. Avoid a dimension smaller than the root of the histogram resolution (in this case 16). A good starting value is 55.
clipping
Type: OnlineSystem Single
A OnlineSingle type indicating the normalized (0.0 - 1.0) clipping value. Smaller values cause greater noise suppression, larger values cause greater contrast enhancement.
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 data points are not altered and do not contribute to the local histogram statistics. 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 regions of the data appear black. If True, the masked area of the region is inserted unchanged in the resulting image array. This parameter is optional and defaults to True.
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 CLAHE-processed 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.
Exceptions

ExceptionCondition
OnlineSystem ArgumentNullException Thrown when sourceData is null.
OnlineSystem ArgumentOutOfRangeException Thrown when channel is negative or out of range.
OnlineSystem ArgumentOutOfRangeException Thrown when windowSize is less than or equal to zero.
OnlineSystem ArgumentOutOfRangeException Thrown when the number of rows and/or columns in binaryMask do not match those of sourceData.
OnlineSystem ArgumentOutOfRangeException Thrown when clipping is negative or greater than 1.0.
OnlineSystem ArgumentOutOfRangeException Thrown when regionOfInterest specifies a rectangular region not completely contained within the dimensions of the source data.
Remarks

This method applies the Contrast-Limited Adaptive Histogram Equalization (CLAHE) algorithm to the data contained within the specified channel of sourceData. The algorithm is a derivative of the traditional Histogram Equalization algorithm, the difference being that instead of using the entire image as the source of the histogram-equalized mapping function, a smaller neighborhood of pixels is used to generate/apply the mapping function at multiple locations. A second difference is the incorporation of a contrast-limiting clipping level that prevents over-amplification of noise in uniform areas of the image. The implementation in PrecisionImage.NET is a complete sampling implementation i.e. a local window is centered at every data point in the image (or region of interest) and the contrast-limited equalization mapping function is computed and applied to the central data point.

This function can be used with or without a BinaryMask. If a BinaryMask is used, the data underlying any masked region will contribute to the local histogram, but only data points that aren't masked are altered (i.e. masked data points are bypassed but their values still contribute to local histograms). A boolean parmeter is used to specify whether or not the masked data is included in the final image result. If not, regions in the resulting image that correspond to masked areas are portrayed as black.

The CLAHE algorithm is not a well-behaved algorithm in the sense that the clipping strategy does not deal well with sparse histograms. For this reason the implementation in PrecisionImage.NET is fixed at an internal histogram resolution of 8-bits (256 bins).

Examples

The following illustrates the use of this function and compares it to the results generated with the non-adaptive histogram equalization:

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, equalize histogram (non-adaptive) using default settings and display 
// in Image component: 
HistogramProcessor histProcessor = new HistogramProcessor();
image1.Source = histProcessor.GetEqualizedHistogramImage(imageData, 0, HistogramResolution.SixteenBit);

// Generate the adaptively-equalized histogram image using a local window size of 35x35 pixels and clipping of 0.005 
// and display result in Image component:
image2.Source = histProcessor.GetAdaptivelyEqualizedHistogramImage(imageData, 0, 35, 0.005f);

// Triple the clipping level (for more contrast enhancement) and display result in Image component:
image3.Source = histProcessor.GetAdaptivelyEqualizedHistogramImage(imageData, 0, 35, 0.015f);

The above example generates the following 4 images:

As a second example, a CT scan slice is contrast enhanced with a binary mask to filter out the majority of null signal space:

using PrecisionImage;
using PrecisionImage.HistogramProcessing;
using PrecisionImage.BinarizationAndMorphology;

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

// Display CT slice:
image0.Source = SourceImage;

// Generate a binary mask thresholding values less than 7:
Mask = new BinaryMask(SourceImage, 7, true);

// Adaptively equalize the data and display the result: 
HistogramProcessor histProcessor = new HistogramProcessor();
image1.Source = histProcessor.GetAdaptivelyEqualizedHistogramImage(ctData, 0, 30, 0.025f, binaryMask: Mask);

The above code generates the following image pair:

See Also