<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Function histogram
Synopse
Image histogram.
h = histogram(f)
f
Step1:  Function Code for brute force implementation
Step2:  Function code for bidimensional matrix implementation
Step3:  Examples
Step4:  Numerical examples
Step5:  Example 1
Step6:  Speed performance
Step7:  Equation
$$    h(i) = card{p | f(p)=i} \
    \text{or} \
    h(i) = \sum_p \left{ 
      \begin{array}{l l}
        1 & \quad \text{if} \ f(p) = i\
        0 & \quad \text{otherwise}\
      \end{array} \right.
$$
<ASSISTANT_TASK:>
Python Code:
import numpy as np
def histogram(f):
    return np.bincount(f.ravel())
Explanation: Function histogram
Synopse
Image histogram.
h = histogram(f)
f: Input image. Pixel data type must be integer.
h: Output, integer vector.
Description
This function computes the number of occurrence of each pixel value. 
The function histogram_eq is implemented to show an implementation based
on the equation of the histogram.
Function Code
End of explanation
def histogram_eq(f):
    from numpy import amax, zeros, arange, sum
    n = amax(f) + 1
    h = zeros((n,),int)
    for i in arange(n):
        h[i] = sum(i == f)
    return h
Explanation: Function Code for brute force implementation
End of explanation
def histogram_eq1(f):
    import numpy as np
    n = f.size
    m = f.max() + 1
    haux = np.zeros((m,n),int)
    fi = f.ravel()
    i = np.arange(n)
    haux[fi,i] = 1
    h = np.add.reduce(haux,axis=1)
    return h
Explanation: Function code for bidimensional matrix implementation
End of explanation
testing = (__name__ == "__main__")
if testing:
    ! jupyter nbconvert --to python histogram.ipynb
    import numpy as np
    import sys,os
    import matplotlib.image as mpimg
    ia898path = os.path.abspath('../../')
    if ia898path not in sys.path:
        sys.path.append(ia898path)
    import ia898.src as ia
Explanation: Examples
End of explanation
if testing:
    f = np.array([[0,1,2,3,4],
                  [4,3,2,1,1]], 'uint8')
    h = ia.histogram(f)
    print(h.dtype)
    print(h)
if testing:
    h1 = ia.histogram_eq(f)
    print(h1.dtype)
    print(h1)
if testing: 
    h1 = ia.histogram_eq1(f)
    print(h1.dtype)
    print(h1)
Explanation: Numerical examples
End of explanation
if testing:
    %matplotlib inline
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    f = mpimg.imread('../data/woodlog.tif')
    plt.imshow(f,cmap='gray')
if testing:
    h = ia.histogram(f)
    plt.plot(h)
Explanation: Example 1
End of explanation
if testing:
    import numpy as np
    from numpy.random import rand, seed
   
    seed([10])
    f = (255 * rand(1000,1000)).astype('uint8')
    %timeit h = ia.histogram(f)
    %timeit h1 = ia.histogram_eq(f)
    %timeit h2 = ia.histogram_eq1(f)
Explanation: Speed performance
End of explanation
if testing: 
    print(ia.histogram(np.array([3,7,0,0,3,0,10,7,0,7])) == \
          np.array([4, 0, 0, 2, 0, 0, 0, 3, 0, 0, 1]))
Explanation: Equation
$$    h(i) = card{p | f(p)=i} \
    \text{or} \
    h(i) = \sum_p \left{ 
      \begin{array}{l l}
        1 & \quad \text{if} \ f(p) = i\
        0 & \quad \text{otherwise}\
      \end{array} \right.
$$
End of explanation
<END_TASK>