# Synopse

Image histogram.

• h = iahistogram(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 iahistogram_eq is implemented to show an implementation based on the equation of the histogram.

# Function Code

```1. import numpy as np
2.
3. def iahistogram(f):
4.
5.     return np.bincount(f.ravel())```

# Function Code for brute force implementation

```1. def iahistogram_eq(f):
2.
3.     import numpy as np
4.
5.     n = f.max() + 1
6.     h = np.zeros((n,),np.int)
7.     for i in np.arange(n):
8.       h[i] = (i == f).sum()
9.     return h```

# Function code for bidimensional matrix implementation

```01. def iahistogram_eq1(f):
02.
03.     import numpy as np
04.     n = f.size
05.     m = f.max() + 1
06.     haux = np.zeros((m,n),int)
07.     fi = f.ravel()
08.     i = xrange(n)
09.     haux[fi,i] = 1
10.     h = haux.sum(axis=1)
11.     return h```

# Examples

## Numerical examples

```1. import ia636 as ia
2.
3. f = uint8(
4.    [[0,1,2,3,4],
5.     [4,3,2,1,1]])
6.
7. h = ia.iahistogram(f)
8. print h.dtype
9. print h```
```int64
[1 3 2 2 2]
```
```1. h1 = ia.iahistogram_eq(f)
2. print h1.dtype
3. print h1```
```int64
[1 3 2 2 2]
```

## Example 1

```1. f = adreadgray('woodlog.pgm')
3. h = ia.iahistogram(f)

## Speed performance

```01. import numpy as np
02. from numpy.random import rand, seed
03. import time
04.
05. seed([10])
06. f = (256 * rand(1000,1000)).astype(uint8)
07. t1 = time.time();    h = ia.iahistogram(f); tf1 = time.time()
08. t2 = time.time();    h = ia.iahistogram_eq(f); tf2 = time.time()
09. t3 = time.time();    h = ia.iahistogram_eq1(f); tf3 = time.time()
10. print 'iahistogram = ', tf1-t1
11. print 'iahistogram_eq = ', tf2-t2
12. print 'iahistogram_eq1 = ', tf3-t3```
```iahistogram =  0.0210158824921
iahistogram_eq =  1.56812691689
iahistogram_eq1 =  3.13373994827
```