Image.hist#

Image.hist(nbins: int = 256, sorted: bool | str = False, span: Literal['dtype'] | tuple[float, float] | None = 'dtype', clip: bool = False, opt: str | None = None) Histogram[source]#

Image histogram

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

  • sorted (bool) – sort bins by count rather than value, defaults to False

  • span (str, tuple(float, float), None) – histogram span definition, defaults to 'dtype'; 'dtype' means full span of image dtype if integer or [0,1] for float, None means finite data min/max, (a,b) means explicit range

  • clip (bool, optional) – clip out-of-span values to span endpoints before binning, defaults to False. If False, out-of-span values are ignored.

  • opt (str, optional) – deprecated histogram option string, use sorted instead; supported legacy value is 'sorted'

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

Example:

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

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

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

Note

  • Histogram horizontal range is controlled by span.

  • span='dtype' uses full datatype span (for example uint8: 0-255,

    float: 0.0-1.0).

  • span=None uses the finite min/max of image data.

  • Values outside span are ignored unless clip=True,

    in which case they are clipped to the span endpoints.

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

    computing the histogram.

  • Histogram is computed using numpy.histogram independently for each plane.

References:
Seealso:

stats Histogram numpy.histogram