ImageHistogram Class

An immutable histogram of one channel of the pixels of an image or a frame (ImageProcessingExtensions.ComputeHistogram): the number of pixels at each sample level.

public sealed class ImageHistogram

Remarks

There is one bin per sample level, at the storage precision: 256 bins for 8-bit pixel formats, 65,536 for 16-bit ones. Every pixel is counted, fully transparent ones included.

Properties

NameDescription
BinCountGets the number of bins: 256 for 8-bit pixel formats, 65,536 for 16-bit ones.
ChannelGets the channel that is counted.
CountsGets the number of pixels of every level, indexed by the level.
TotalCountGets the number of pixels counted, the sum of the bins.

Gets the number of bins: 256 for 8-bit pixel formats, 65,536 for 16-bit ones.

public int BinCount { get; }

Property value

int

Gets the channel that is counted.

public HistogramChannel Channel { get; }

Property value

HistogramChannel

Gets the number of pixels of every level, indexed by the level.

public ReadOnlySpan<long> Counts { get; }

Property value

ReadOnlySpan<long>

Gets the number of pixels counted, the sum of the bins.

public long TotalCount { get; }

Property value

long

Indexers

NameDescription
this[int]Gets the number of pixels whose sample is a level.

Gets the number of pixels whose sample is a level.

public long this[int level] { get; }

Parameters

level int
The level, from 0 to BinCount - 1.

Property value

long

Exceptions

ArgumentOutOfRangeException
level is out of range.

Methods

NameDescription
GetOtsuThreshold()Gets the threshold that Otsu's method chooses: the level t that maximizes the variance between the class of the levels up to t and the class of the levels above it, w1 * w2 * (m1 - m2)², where w1 and w2 are the numbers of pixels of the classes and m1 and m2 their mean levels.

GetOtsuThreshold()

ImageHistogram.cs

Gets the threshold that Otsu's method chooses: the level t that maximizes the variance between the class of the levels up to t and the class of the levels above it, w1 * w2 * (m1 - m2)², where w1 and w2 are the numbers of pixels of the classes and m1 and m2 their mean levels.

public int GetOtsuThreshold()

Returns

int The threshold: the pixels above it form the upper class.

Remarks

The candidates are the levels from the lowest one present to the one below the highest one present, and the first maximum wins. The variances are computed as scikit-image's threshold_otsu computes them, from exact integer sums, so the threshold is the one it returns for the same integer samples. When a single level is present, it is the threshold. ImageProcessingExtensions.Threshold with ThresholdMethod.Otsu uses the threshold of the HistogramChannel.Luminance histogram.