# Synopse

The iah2stats function computes several statistics given an image histogram.

• g = iah2stats(h)
• Output
• g: unidimensional array. Array containing the statistics from the histogram
• Input
• h: 1-D ndarray: histogram

# Description

The iah2stats function extracts some relevant statistics of the images where the histogram was computed:

• Mean (mean grayscale value)
• Variance (variance of grayscale values)
• Skewness
• Kurtosis
• entropy
• mode (gray scale value with largest occurrence)
• Percentile 1%
• Percentile 10%
• Percentile 50% (This is the median gray scale value)
• Percentile 90%
• Percentile 99%

# Function Code

```01. def iah2stats(h):
02.     import numpy as np
03.     import ia636 as ia
04.
05.     hn = 1.0*h/h.sum() # compute the normalized image histogram
06.     v = np.zeros(11) # number of statistics
07.
08.     # compute statistics
09.     n = len(h) # number of gray values
10.     v[0]  = np.sum((np.arange(n)*hn)) # mean
11.     v[1]  = np.sum(np.power((np.arange(n)-v[0]),2)*hn) # variance
12.     v[2]  = np.sum(np.power((np.arange(n)-v[0]),3)*hn)/(np.power(v[1],1.5))# skewness
13.     v[3]  = np.sum(np.power((np.arange(n)-v[0]),4)*hn)/(np.power(v[1],2))-3# kurtosis
14.     v[4]  = -(hn[hn>0]*np.log(hn[hn>0])).sum() # entropy
15.     v[5]  = np.argmax(h) # mode
16.     v[6:]  = ia.iah2percentile(h,np.array([1,10,50,90,99])) # 1,10,50,90,99% percentile
17.     return v```

# Examples

## Numeric Example

```1. import numpy as np
2. import ia636 as ia
3.
4. f = np.array([1,1,1,0,1,2,2,2,1])
5. h = ia.iahistogram(f)
6. print 'statistics =', ia.iah2stats(h)```
```statistics = [ 1.22222222  0.39506173 -0.20992233 -0.62109375  0.93688831  1.          0.08
0.8         1.          2.          2.        ]
```

## Image Example

```01. from scipy.stats import mode, kurtosis, skew, entropy
02.
05. h = ia.iahistogram(f)
06. v = ia.iah2stats(h)
07. print 'mean =',v[0]
08. print 'variance =',v[1]
09. print 'skewness =',v[2]
10. print 'kurtosis = ',v[3]
11. print 'entropy = ',v[4]
12. print 'mode = ',v[5]
13. print 'percentil 1% = ',v[6]
14. print 'percentil 10% = ',v[7]
15. print 'percentil 50% = ',v[8]
16. print 'percentil 90% = ',v[9]
17. print 'percentil 99% = ',v[10]```
```mean = 137.065933228
variance = 7604.25522007
skewness = -0.554976386125
kurtosis =  -1.4152064701
entropy =  4.99579946489
mode =  14.0
percentil 1% =  2.0
percentil 10% =  8.0
percentil 50% =  180.0
percentil 90% =  222.0
percentil 99% =  251.0
```

# Equation

The follow equations represent the statistics equations, where N denotes the number of intensity levels in the imagem ( usually between 0 and 255) and is the probability density function, i.e. the normalized histogram (h) of the image, and X is a random variable that represents the pixels intensities .

## Mode

The value that appears most often.

## Median

It is the numerical value separating the higher half of a data sample or a probability distribution.

## Percentil

O k-ésimo percentil Pk é o valor xk que corresponde à frequência cumulativa de N k/100, onde N é o tamanho amostral.

Dessa forma:

• O 1º percentil determina o 1 % menor dos dados
• O 98º percentil determina o 98 % menor dos dados
• O 50º percentil determina o 50 % menor dos dados, representa a mediana

A definição para o p-ésimo percentil de N valores ordenados é correspondente ao valor que ocupa a posição k dada abaixo:

# Contributions

• Mariana Bento, August 2013