Liga al proyecto
Recordando un poco lo que se hizo para obtener los histogramas
1. Pasamos la imagen a escala de grises ya que con un umbral diferente se pueden tener diferentes contrastes en la imagen.
2. Se ralizo lo que es una sumatoria de filas y columnas para crear los dos histograma.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def histo_agujero(): | |
image = argv[1] | |
im = Image.open(image) | |
imagen=im.load() | |
ancho, alto = im.size | |
#ima, nueva = pixeleg() | |
histoh = [] | |
histov = [] | |
#pixel_horizontal | |
for b in range(alto): | |
sumart = 0 | |
for a in range(ancho): | |
sumart += imagen[a,b][1] | |
histoh.append(sumart) | |
#pixel_vertical | |
for a in range(ancho): | |
sumart = 0 | |
for b in range(alto): | |
sumart += imagen[a,b][1] | |
histov.append(sumart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def minimos_pix(vechisto): | |
minimo = list() | |
media = sum(vechisto)/len(vechisto) | |
print media | |
for a in range(1, len(vechisto)-1): | |
if vechisto[a-1] > vechisto[a] and vechisto[a+1] > vechisto[a]: | |
if(vechisto[a] < media): | |
minimo.append(vechisto[a]) | |
return minimo |
La imagen a utilizar es la siguiente
Escala de grises

Gráficamos los Histogramas:
Código Relevante Grafica:Tome como base el código realizado por la doctora y se implemento dentro del codigo ya presentado anteriormente para mostrar los histogramas de pixeles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def graficar_histo(histoh,histov,image): | |
plt.clf() | |
fig1=plt.subplot(111) | |
nivel_x=max(histoh) | |
nivel_y=max(histov) | |
ancho,alto=image.size | |
if ancho>alto: | |
n=ancho | |
else: | |
n=alto | |
if nivel_x > nivel_y: | |
nivelt=nivel_x | |
else: | |
nivelt=nivel_y | |
print 'horixontal',histoh | |
print 'vertical',histov | |
plt.ylim(-0.1 * nivel,nivel * 1.1) | |
plt.xlim(-0.1*n,1.1*n) | |
plt.title('Histograma') | |
x=range(1,ancho+1) | |
y=range(1,alto+1) | |
plt.plot(x,histoh,'r-',linewidth=2,label='horizontal') | |
plt.plot(y,histov,'b-',linewidth=2,label='vertical') | |
cua = fig.get_position() | |
fig.set_position([cua.x0, cua.y0 + cua.height * 0.1,cua.width, cua.height * 0.9]) | |
fig.legend(loc = 'upper center', bbox_to_anchor=(0.5, -0.05), | |
fancybox = True, shadow = True, ncol = 1) | |
plt.show() | |
return |
Referencia:
http://elisa.dyndns-web.com/~elisa/teaching/comp/vision/agujeros.pdf
idealmente sería una regla horizontal y una vertical por cada agujero; hay un chorro de ruido en tu detección. 9 pts. Cuida la ortografía.
ResponderEliminar