Professional Documents
Culture Documents
1. Método Otsu
1.1 Introducción
El método de segmentación más simple es la umbralización, donde por medio de la generación
de una imagen binaria se busca separar entre objetos y fondo.
1.2 Umbralización
En la umbralización se transforma una imagen en escala de grises a binaria, según el valor de
cada "pixel" es mayor o menor que el valor de un determinado umbral ("threshold").
<grrodri@gmail.com> 1
© 2010 Jorge Rodríguez Araújo
k
k =∑ i⋅p i [media acumulada]
i =0
k
c= [media de la clase (B o F)]
k
Donde p i es la probabilidad de aparición de un determinado nivel i .
if __name__ == '__main__':
import Image
from pylab import *
im = Image.open('rice.tif')
width, height = im.size
# Histograma normalizado
hist = array(im.histogram(), float) / (width * height)
img = array(im.getdata())
thr = otsu_threshold(hist)
img_thr = threshold(img, thr, width, height)
figure()
gray()
subplot(121)
imshow(img.reshape(height, width))
<grrodri@gmail.com> 2
© 2010 Jorge Rodríguez Araújo
subplot(122)
imshow(img_thr.reshape(height, width))
savefig('threshold.png')
print thr
125
<grrodri@gmail.com> 3