[mmwatershed] [Up] [mmlabel] Measurements

mmhistogram
Find the histogram of the image f.

Synopsis

h = mmhistogram( f, option = "uint16" )

Implemented in Python.

Input

f Image Gray-scale (uint8 or uint16) or binary image.
option String

Values: "uint16" or "int32".

Default: "uint16"

Output

h Image Gray-scale (uint8 or uint16) image.

Histogram in a uint16 or an int32 vector.

Description

Finds the histogram of the image f and returns the result in the vector h. For binary image the vector size is 2, for gray-scale uint8 and uint16 images, the vector size is the maximum pixel value plus one. h[0] gives the number of pixels with value 0.

Examples

>>> f=uint8([0, 1, 1, 2, 2, 2, 5, 3, 5])

              
>>> h=mmhistogram(f)

              
>>> print h
[1 2 3 1 0 2]
>>> f=mmreadgray('lenina.tif')

              
>>> mmshow(f)

              
>>> h=mmhistogram(f)

              
>>> mmplot([[h]],[['style', 'impulses']])
f [[h]],[['style', 'impulses']]

Equation

Source Code

def mmhistogram(f, option="uint16"):
    from Numeric import searchsorted, sort, ravel, concatenate, product
    n = searchsorted(sort(ravel(f)), range(max(ravel(f))+1))
    n = concatenate([n, [product(f.shape)]])
    h = n[1:]-n[:-1]
    return h
    

See also

mmstats Find global image statistics.
mmblob Blob measurements from a labeled image.
mmgrain Gray-scale statistics for each labeled region.
mmfreedom Control automatic data type conversion.
[mmwatershed] [Up] [mmlabel] Python