Last active
July 3, 2019 04:01
-
-
Save rescurib/fe9561a5d45c6a2ba660a06c08ea3d2a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Tue Jul 2 22:15:13 2019 | |
@author: Rodolfo E. Escobar U. | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from skimage import draw, measure | |
# Generación de una imagen binaria con dos objetos separados | |
Bim = np.zeros([300,300]) | |
C1i,C1j = draw.circle(80,100,70) | |
Bim[C1i,C1j] = 1 | |
C2i,C2j = draw.circle(220,220,50) | |
Bim[C2i,C2j] = 1 | |
#Etiquetado | |
E = measure.label(Bim) | |
#Propiedades de regiones | |
PR = measure.regionprops(E) | |
#PR[i].area => área del objeto i | |
#PR[i].perimeter => Perímetro del objeto i | |
#PR[i].centroid => centroide del objeto i | |
plt.imshow(Bim,cmap='gray') | |
plt.show() | |
print(u"Región 1:") | |
print("Area (pixeles): " + str(PR[0].area)) | |
print("Perimetro (pixeles): " + str(PR[0].perimeter)) | |
print("Centroide: " + str(PR[0].centroid)) | |
print('\n') | |
print(u"Región 2:") | |
print("Area (pixeles): " + str(PR[1].area)) | |
print("Perimetro (pixeles): " + str(PR[1].perimeter)) | |
print("Centroide: " + str(PR[1].centroid)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment