machinevisiontoolbox.Image.hist

Image.hist(nbins=256, opt=None)

Image histogram

Parameters:
  • nbins (int, optional) – number of histogram bins, defaults to 256

  • opt (str) – histogram option

Returns:

histogram of image

Return type:

Histogram

Returns an object that summarizes the distribution of pixel values in each color plane.

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('street.png')
>>> type(hist)
>>> hist = img.hist()
>>> hist
>>> hist.plot()

(Source code, png, hires.png, pdf)

../_images/machinevisiontoolbox-Image-hist-1.png

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('flowers1.png')
>>> hist = img.hist()
>>> hist
>>> hist.plot(style='stack')

(Source code, png, hires.png, pdf)

../_images/machinevisiontoolbox-Image-hist-2.png
Note:
  • For an integer image the bins spans the greylevel range 0-255.

  • For a floating point image the histogram spans the greylevel range 0.0 to 1.0 with 256 bins.

  • For floating point images all NaN and Inf values are first removed.

  • Computed using OpenCV CalcHist. Only works on floats up to 32 bit, float64 images are automatically converted to float32.

References:
  • Robotics, Vision & Control for Python, Section 14.4.3, P. Corke, Springer 2023.

Seealso:

Histogram opencv.calcHist