La detección de elipses se encuentra en mi entrada anterior.
Código:
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 det_centro(image): | |
ellipses = list() | |
pic = image.load() | |
for x in range(image.size[0]): | |
for y in range(image.size[1]): | |
if pic[x,y] == 255: | |
ellipses.append((x,y)) | |
ellipses = cluster_edges(ellipses) | |
centers = list() | |
print len(ellipses) | |
for i in ellipses: | |
x, y = (0, 0) | |
for j in i: | |
x += j[0] | |
y += j[1] | |
x = int(float(x)/len(i)) | |
y = int(float(y)/len(i)) | |
centers.append((x, y)) | |
return centers | |
def det_elipse(image_name, output="output.png", size=(128, 128)): | |
image = Image.open(image_name) | |
original_image = image.copy() | |
image.thumbnail(size, Image.ANTIALIAS) | |
border_points, gradient_values = border_detection(image, output="output.png", umbral=60) | |
imageEllipse = find_centers(image, border_points, gradient_values, output) | |
imageEllipse.save('grayscale_'+output) | |
filtro_umbral(imageEllipse, umbral = 130) | |
centers = det_centro(imageEllipse) | |
pic = image.load() | |
dimensiones = list() | |
for c in centers: | |
actual = list(c[:]) | |
horizontal = 0 | |
while pic[tuple(actual)] != (255, 255, 255): | |
actual[0] += 1 | |
horizontal += 1 | |
if horizontal > size[0]: | |
break | |
actual = list(c[:]) | |
vertical = 0 | |
while pic[tuple(actual)] != (255, 255, 255): | |
actual[1] += 1 | |
vertical += 1 | |
if vertical > size[1]: | |
break | |
dimensiones.append((horizontal, vertical)) | |
razon = list(image.size) | |
image = original_image | |
razon[0] = float(image.size[0]) / razon[0] | |
razon[1] = float(image.size[1]) / razon[1] | |
draw = ImageDraw.Draw(image) |
Etiquetas e identificación en elipses.
Porcentaje:
1 comentario:
Se supone que iban a _rellenar_ los elipses. La entrada no hace claro cómo determinas si una figura es o no es un elipse. 6 pts.
Publicar un comentario