class

CrImage::Util::Histogram

Inherits Reference / Object

Represents a histogram of pixel intensity values.

A histogram shows the distribution of pixel brightness levels (0-255) in an image. Useful for analyzing image characteristics and applying contrast enhancements.

The histogram contains 256 bins, one for each possible intensity value, and tracks the total number of pixels analyzed.

Constructors

new(bins : Array(Int32), total_pixels : Int32)
Source

Instance methods

bins
Source
mean

Calculates the mean (average) intensity value across all pixels.

Returns: Average brightness value (0.0-255.0)

Source
median

Calculates the median intensity value (50th percentile).

Returns: The intensity value at which half the pixels are darker

Source
percentile(p : Float64) : Int32

Returns the intensity value at the specified percentile (0-100).

For example, percentile(95) returns the brightness level below which 95% of pixels fall.

Parameters:

  • p : Percentile value (0.0-100.0)

Returns: Intensity value at that percentile

Raises: ArgumentError if percentile is outside 0-100 range

Source
std_dev

Calculates the standard deviation of intensity values.

Measures the spread of brightness values. Higher values indicate more contrast, lower values indicate more uniform brightness.

Returns: Standard deviation of pixel intensities

Source
total_pixels
Source