class Histogram – Histogram Object

The histogram object is returned by Image.get_histogram(). The underlying class name is histogram.

For grayscale images the histogram has a single channel of bins. For RGB565 images the histogram has three channels covering the CIE-LAB L, A, and B axes. In both cases each channel is normalized so that its bins sum to 1.0.

Per-channel bin lists are exposed as both bound methods (hist.bins()) and through subscript notation (hist[0]). The high-level reductions get_percentile(), get_threshold(), and get_statistics() return the corresponding Percentile, Threshold, and Statistics attrtuples.

class image.histogram

Please call Image.get_histogram() to create this object. It has no public constructor.

bins() list[float]

Return the bin list for a grayscale histogram. Each entry is in the range 0.0 to 1.0 and the entries sum to 1.0.

Equivalent to histogram[0].

l_bins() list[float]

Return the bin list for the LAB L channel of an RGB565 histogram. Each entry is in the range 0.0 to 1.0 and the entries sum to 1.0.

Equivalent to histogram[0].

a_bins() list[float]

Return the bin list for the LAB A channel of an RGB565 histogram. Each entry is in the range 0.0 to 1.0 and the entries sum to 1.0.

Equivalent to histogram[1].

b_bins() list[float]

Return the bin list for the LAB B channel of an RGB565 histogram. Each entry is in the range 0.0 to 1.0 and the entries sum to 1.0.

Equivalent to histogram[2].

get_percentile(percentile: float) image.percentile

Compute the CDF of every histogram channel and return the bin value at the requested percentile (a float in 0.01.0).

Useful for finding the min/max of a color distribution while ignoring outliers (get_percentile(0.05) and get_percentile(0.95) give a robust min/max).

Returns a Percentile attrtuple.

get_threshold() image.threshold

Use Otsu’s Method on every channel to find the threshold value that best splits each channel’s distribution into a “background” and “foreground” half. The returned thresholds are well-suited to feed directly into Image.binary() or any other method that takes LAB L/A/B color thresholds.

Returns a Threshold attrtuple.

get_statistics() image.statistics

Compute the mean, median, mode, standard deviation, min, max, lower quartile, and upper quartile of every histogram channel.

Returns a Statistics attrtuple.

get_stats() image.statistics

Alias for get_statistics().

statistics() image.statistics

Alias for get_statistics().