LABORATORIO 08 - Descripción y Reconocimiento
LABORATORIO 08 - Descripción y Reconocimiento
LABORATORIO 08 - Descripción y Reconocimiento
LABORATORIO 08
Descripcion y reconocimiento
1. Objetivos:
El estudiante conoce diversos descriptores de regiones.
El estudiante aplica diversos descriptores para clasificar figuras.
El estudiante obtiene momentos invariantes de una imagen.
2. Instrucciones
Repase el material teorico y el material extra facilitado por el docente, luego implemente los siguientes
enunciados en Python, ASEGURESE QUE LAS GRAFICAS SEAN LO SUFICIENTEMENTE GRANDES
PARA QUE SE VISUALICEN ADECUADAMENTE, solicite ayuda al docente cuando sea necesario.
In [1]:
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage import measure
In [3]:
#EJEMPLO
# Contruyendo una imagen
x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j]
r = np.sin(np.exp((np.sin(x)**3 + np.cos(y)**2))) #imagen construida r
# Mostrando imagen
fig, ax = plt.subplots()
ax.imshow(r, cmap='gray')
ax.axis('image')
ax.set_xticks([])
ax.set_yticks([])
plt.show()
In [4]:
print(contours)
[array([[5.35004742, 0. ],
[5.15558015, 1. ],
[5. , 1.26856114],
[4.39810785, 2. ],
[4. , 2.29444112],
[3. , 2.75184936],
[2. , 2.9875167 ],
[1.85757398, 3. ],
[1. , 3.05764552],
[0. , 3.06729478]]), array([[ 0. , 46.4569752 ],
[ 1. , 46.46777372],
[ 2. , 46.54303405],
[ 3. , 46.74625351],
[ 3.64796562, 47. ],
[ 4. , 47.19859561],
[ 4.87645073, 48. ],
[ 5. , 48.22555109],
[ 5.30157125, 49. ],
[ 5.30157125, 50. ],
[ 5. , 50.77444891],
[ 4.87645073, 51. ],
[ 4. , 51.80140439],
[ 3.64796562, 52. ],
[ 3. , 52.25374649],
[ 2. , 52.45696595],
[ 1. , 52.53222628],
[ 0. , 52.5430248 ]]), array([[ 0. , 95.93270522],
[ 1. , 95.94235448],
[ 1.85757398, 96. ],
[ 2. , 96.0124833 ],
[ 3. , 96.24815064],
[ 4. , 96.70555888],
[ 4.39810785, 97. ],
[ 5. , 97.73143886],
[ 5.15558015, 98. ],
[ 5.35004742, 99. ]]), array([[33. , 25.37068293],
[32.94439414, 26. ],
[32.74077445, 27. ],
[32.42867855, 28. ],
[32.01777945, 29. ],
[32. , 29.03489813],
[31.46361135, 30. ],
[31. , 30.72247986],
[30.80066278, 31. ],
[30. , 31.99333977],
[29.9937921 , 32. ],
[29. , 32.96860332],
[28.96099307, 33. ],
[28. , 33.7124201 ],
[27.49417655, 34. ],
[27. , 34.26154226],
[26. , 34.60795154],
[25. , 34.7597504 ],
[24. , 34.70892296],
[23. , 34.45817635],
[22. , 34.02052378],
[21.96678115, 34. ],
[21. , 33.36086533],
[20.56294581, 33. ],
[20. , 32.49708587],
[19.52792025, 32. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 4/29
19/7/2019 8- Descripción y reconocimiento- Guia
[19. , 31.38981685],
[18.70258937, 31. ],
[18.02200197, 30. ],
[18. , 29.96211924],
[17.49532718, 29. ],
[17.06216828, 28. ],
[17. , 27.80883824],
[16.75819078, 27. ],
[16.56385092, 26. ],
[16.47942099, 25. ],
[16.50764158, 24. ],
[16.6475913 , 23. ],
[16.8947804 , 22. ],
[17. , 21.70020147],
[17.26653769, 21. ],
[17.74686033, 20. ],
[18. , 19.55788366],
[18.35277167, 19. ],
[19. , 18.09945839],
[19.08123105, 18. ],
[19.9885725 , 17. ],
[20. , 16.98844063],
[21. , 16.13330784],
[21.19499887, 16. ],
[22. , 15.49029252],
[23. , 15.03255231],
[23.12520201, 15. ],
[24. , 14.78907376],
[25. , 14.74027903],
[26. , 14.88602501],
[26.33931457, 15. ],
[27. , 15.23827103],
[28. , 15.78548377],
[28.29800604, 16. ],
[29. , 16.54355857],
[29.48748326, 17. ],
[30. , 17.52269058],
[30.40548901, 18. ],
[31. , 18.77522886],
[31.15434896, 19. ],
[31.75278436, 20. ],
[32. , 20.49036113],
[32.2348803 , 21. ],
[32.59774279, 22. ],
[32.85663913, 23. ],
[33. , 23.97758087],
[33.00303761, 24. ],
[33.03017251, 25. ],
[33. , 25.37068293]]), array([[33. , 75.02241913],
[32.85663913, 76. ],
[32.59774279, 77. ],
[32.2348803 , 78. ],
[32. , 78.50963887],
[31.75278436, 79. ],
[31.15434896, 80. ],
[31. , 80.22477114],
[30.40548901, 81. ],
[30. , 81.47730942],
[29.48748326, 82. ],
[29. , 82.45644143],
[28.29800604, 83. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 5/29
19/7/2019 8- Descripción y reconocimiento- Guia
[28. , 83.21451623],
[27. , 83.76172897],
[26.33931457, 84. ],
[26. , 84.11397499],
[25. , 84.25972097],
[24. , 84.21092624],
[23.12520201, 84. ],
[23. , 83.96744769],
[22. , 83.50970748],
[21.19499887, 83. ],
[21. , 82.86669216],
[20. , 82.01155937],
[19.9885725 , 82. ],
[19.08123105, 81. ],
[19. , 80.90054161],
[18.35277167, 80. ],
[18. , 79.44211634],
[17.74686033, 79. ],
[17.26653769, 78. ],
[17. , 77.29979853],
[16.8947804 , 77. ],
[16.6475913 , 76. ],
[16.50764158, 75. ],
[16.47942099, 74. ],
[16.56385092, 73. ],
[16.75819078, 72. ],
[17. , 71.19116176],
[17.06216828, 71. ],
[17.49532718, 70. ],
[18. , 69.03788076],
[18.02200197, 69. ],
[18.70258937, 68. ],
[19. , 67.61018315],
[19.52792025, 67. ],
[20. , 66.50291413],
[20.56294581, 66. ],
[21. , 65.63913467],
[21.96678115, 65. ],
[22. , 64.97947622],
[23. , 64.54182365],
[24. , 64.29107704],
[25. , 64.2402496 ],
[26. , 64.39204846],
[27. , 64.73845774],
[27.49417655, 65. ],
[28. , 65.2875799 ],
[28.96099307, 66. ],
[29. , 66.03139668],
[29.9937921 , 67. ],
[30. , 67.00666023],
[30.80066278, 68. ],
[31. , 68.27752014],
[31.46361135, 69. ],
[32. , 69.96510187],
[32.01777945, 70. ],
[32.42867855, 71. ],
[32.74077445, 72. ],
[32.94439414, 73. ],
[33. , 73.62931707],
[33.03017251, 74. ],
[33.00303761, 75. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 6/29
19/7/2019 8- Descripción y reconocimiento- Guia
[68.4620915 , 68. ],
[68. , 67.42085348],
[67.68439252, 67. ],
[67. , 66.13862449],
[66.89268597, 66. ],
[66.08046987, 65. ],
[66. , 64.90524293],
[65.23949753, 64. ],
[65. , 63.71723347],
[64.38345475, 63. ],
[64. , 62.55051886],
[63.51276204, 62. ],
[63. , 61.40857206],
[62.62534379, 61. ],
[62. , 60.29614915],
[61.7167344 , 60. ],
[61. , 59.21892828],
[60.7799277 , 59. ],
[60. , 58.18316032],
[59.80483183, 58. ],
[59. , 57.1955469 ],
[58.7769109 , 57. ],
[58. , 56.26369326],
[57.67413286, 56. ],
[57. , 55.39768525],
[56.4603439 , 55. ],
[56. , 54.61392805],
[55.07053671, 54. ],
[55. , 53.94452671],
[54. , 53.37937216],
[53.02128336, 53. ],
[53. , 52.98961616],
[52. , 52.70910906],
[51. , 52.57932765],
[50. , 52.54437617],
[49. , 52.54167332],
[48. , 52.50664397],
[47. , 52.37529585],
[46. , 52.08434155],
[45.83220448, 52. ],
[45. , 51.39363273],
[44.64391475, 51. ],
[44.19060417, 50. ],
[44.19060417, 49. ],
[44.64391475, 48. ],
[45. , 47.60636727],
[45.83220448, 47. ],
[46. , 46.91565845],
[47. , 46.62470415],
[48. , 46.49335603],
[49. , 46.45832668],
[50. , 46.45562383],
[51. , 46.42067235],
[52. , 46.29089094],
[53. , 46.01038384],
[53.02128336, 46. ],
[54. , 45.62062784],
[55. , 45.05547329],
[55.07053671, 45. ],
[56. , 44.38607195],
[56.4603439 , 44. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 8/29
19/7/2019 8- Descripción y reconocimiento- Guia
[57. , 43.60231475],
[57.67413286, 43. ],
[58. , 42.73630674],
[58.7769109 , 42. ],
[59. , 41.8044531 ],
[59.80483183, 41. ],
[60. , 40.81683968],
[60.7799277 , 40. ],
[61. , 39.78107172],
[61.7167344 , 39. ],
[62. , 38.70385085],
[62.62534379, 38. ],
[63. , 37.59142794],
[63.51276204, 37. ],
[64. , 36.44948114],
[64.38345475, 36. ],
[65. , 35.28276653],
[65.23949753, 35. ],
[66. , 34.09475707],
[66.08046987, 34. ],
[66.89268597, 33. ],
[67. , 32.86137551],
[67.68439252, 32. ],
[68. , 31.57914652],
[68.4620915 , 31. ],
[69. , 30.26226997],
[69.21303319, 30. ],
[69.91736196, 29. ],
[70. , 28.85785541],
[70.57885881, 28. ],
[71. , 27.19892178],
[71.1330425 , 27. ],
[71.56403005, 26. ],
[71.75469808, 25. ],
[71.69072437, 24. ],
[71.3770176 , 23. ],
[71. , 22.31213273],
[70.86404757, 22. ],
[70.25962122, 21. ],
[70. , 20.65851249],
[69.57330658, 20. ],
[69. , 19.23513085],
[68.84019924, 19. ],
[68.08156811, 18. ],
[68. , 17.90329923],
[67.29003658, 17. ],
[67. , 16.65042427],
[66.47852003, 16. ],
[66. , 15.42097238],
[65.65370454, 15. ],
[65. , 14.2142444 ],
[64.81818982, 14. ],
[64. , 13.03230601],
[63.97156232, 13. ],
[63.08914418, 12. ],
[63. , 11.89673896],
[62.1821186 , 11. ],
[62. , 10.79226368],
[61.25172184, 10. ],
[61. , 9.71931817],
[60.29147896, 9. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 9/29
19/7/2019 8- Descripción y reconocimiento- Guia
[60. , 8.68437988],
[59.29152057, 8. ],
[59. , 7.69522259],
[58.23708253, 7. ],
[58. , 6.76178812],
[57.10539588, 6. ],
[57. , 5.89850459],
[56. , 5.12009387],
[55.80387753, 5. ],
[55. , 4.43419082],
[54.17372084, 4. ],
[54. , 3.8888517 ],
[53. , 3.4659367 ],
[52. , 3.21564317],
[51. , 3.09973054],
[50. , 3.0685023 ],
[49. , 3.06608716],
[48. , 3.03478398],
[47.70207797, 3. ],
[47. , 2.89278414],
[46. , 2.55553603],
[45.06729787, 2. ],
[45. , 1.9346028 ],
[44.35982162, 1. ],
[44.13439904, 0. ]]), array([[70.54699662, 0. ],
[70.64017241, 1. ],
[70.91405574, 2. ],
[71. , 2.18795199],
[71.51101978, 3. ],
[72. , 3.57828859],
[72.54644778, 4. ],
[73. , 4.27094536],
[74. , 4.5304272 ],
[75. , 4.44306077],
[76. , 4.01779504],
[76.02317075, 4. ],
[77. , 3.04892399],
[77.03542531, 3. ],
[77.55320252, 2. ],
[77.88210129, 1. ],
[77.99644381, 0. ]]), array([[77.31678423, 52. ],
[77.74275478, 51. ],
[77.96759651, 50. ],
[77.96759651, 49. ],
[77.74275478, 48. ],
[77.31678423, 47. ],
[77. , 46.48995481],
[76.56236013, 46. ],
[76. , 45.51924927],
[75. , 45.0235228 ],
[74.77142266, 45. ],
[74. , 44.94049421],
[73.74443661, 45. ],
[73. , 45.22607216],
[72. , 45.89597677],
[71.89996028, 46. ],
[71.16794153, 47. ],
[71. , 47.32792191],
[70.7551692 , 48. ],
[70.57040118, 49. ],
[70.57040118, 50. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 10/29
19/7/2019 8- Descripción y reconocimiento- Guia
[70.7551692 , 51. ],
[71. , 51.67207809],
[71.16794153, 52. ],
[71.89996028, 53. ],
[72. , 53.10402323],
[73. , 53.77392784],
[73.74443661, 54. ],
[74. , 54.05950579],
[74.77142266, 54. ],
[75. , 53.9764772 ],
[76. , 53.48075073],
[76.56236013, 53. ],
[77. , 52.51004519],
[77.31678423, 52. ]]), array([[77.99644381, 99. ],
[77.88210129, 98. ],
[77.55320252, 97. ],
[77.03542531, 96. ],
[77. , 95.95107601],
[76.02317075, 95. ],
[76. , 94.98220496],
[75. , 94.55693923],
[74. , 94.4695728 ],
[73. , 94.72905464],
[72.54644778, 95. ],
[72. , 95.42171141],
[71.51101978, 96. ],
[71. , 96.81204801],
[70.91405574, 97. ],
[70.64017241, 98. ],
[70.54699662, 99. ]]), array([[99. , 3.06729478],
[98. , 3.07693742],
[97. , 3.14378904],
[96. , 3.32127365],
[95. , 3.65400572],
[94.34093569, 4. ],
[94. , 4.14828419],
[93. , 4.76181241],
[92.70664554, 5. ],
[92. , 5.49406352],
[91.41576223, 6. ],
[91. , 6.32165061],
[90.26330812, 7. ],
[90. , 7.22210756],
[89.20137761, 8. ],
[89. , 8.18289136],
[88.20205419, 9. ],
[88. , 9.19545586],
[87.24759631, 10. ],
[87. , 10.25275796],
[86.32593747, 11. ],
[86. , 11.34833231],
[85.42863374, 12. ],
[85. , 12.47617836],
[84.54998666, 13. ],
[84. , 13.63103108],
[83.68672793, 14. ],
[83. , 14.80873492],
[82.83799971, 15. ],
[82.00635077, 16. ],
[82. , 16.00806302],
[81.21020407, 17. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 11/29
19/7/2019 8- Descripción y reconocimiento- Guia
[81. , 17.27601067],
[80.42441542, 18. ],
[80. , 18.57421655],
[79.65789822, 19. ],
[79. , 19.91380858],
[78.92888607, 20. ],
[78.24395555, 21. ],
[78. , 21.43927541],
[77.62352232, 22. ],
[77.13933562, 23. ],
[77. , 23.5009915 ],
[76.81522916, 24. ],
[76.7407218 , 25. ],
[76.96288358, 26. ],
[77. , 26.07152126],
[77.35802398, 27. ],
[77.93151192, 28. ],
[78. , 28.08881117],
[78.57510275, 29. ],
[79. , 29.56398352],
[79.28950525, 30. ],
[80. , 30.94964004],
[80.03501078, 31. ],
[80.81106609, 32. ],
[81. , 32.22624033],
[81.61375735, 33. ],
[82. , 33.4671123 ],
[82.43246635, 34. ],
[83. , 34.68530459],
[83.26275336, 35. ],
[84. , 35.88004224],
[84.10360533, 36. ],
[84.96483022, 37. ],
[85. , 37.04093253],
[85.86174188, 38. ],
[86. , 38.15907705],
[86.77982237, 39. ],
[87. , 39.24852937],
[87.72414388, 40. ],
[88. , 40.3033516 ],
[88.70275349, 41. ],
[89. , 41.31647472],
[89.72770619, 42. ],
[90. , 42.27921371],
[90.81722756, 43. ],
[91. , 43.17981726],
[92. , 43.99982625],
[92.00026548, 44. ],
[93. , 44.73666014],
[93.46257111, 45. ],
[94. , 45.36078902],
[95. , 45.83589261],
[95.54306133, 46. ],
[96. , 46.17255425],
[97. , 46.37135141],
[98. , 46.44618356],
[99. , 46.4569752 ]]), array([[99. , 52.5430248 ],
[98. , 52.55381644],
[97. , 52.62864859],
[96. , 52.82744575],
[95.54306133, 53. ],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 12/29
19/7/2019 8- Descripción y reconocimiento- Guia
[95. , 53.16410739],
[94. , 53.63921098],
[93.46257111, 54. ],
[93. , 54.26333986],
[92.00026548, 55. ],
[92. , 55.00017375],
[91. , 55.82018274],
[90.81722756, 56. ],
[90. , 56.72078629],
[89.72770619, 57. ],
[89. , 57.68352528],
[88.70275349, 58. ],
[88. , 58.6966484 ],
[87.72414388, 59. ],
[87. , 59.75147063],
[86.77982237, 60. ],
[86. , 60.84092295],
[85.86174188, 61. ],
[85. , 61.95906747],
[84.96483022, 62. ],
[84.10360533, 63. ],
[84. , 63.11995776],
[83.26275336, 64. ],
[83. , 64.31469541],
[82.43246635, 65. ],
[82. , 65.5328877 ],
[81.61375735, 66. ],
[81. , 66.77375967],
[80.81106609, 67. ],
[80.03501078, 68. ],
[80. , 68.05035996],
[79.28950525, 69. ],
[79. , 69.43601648],
[78.57510275, 70. ],
[78. , 70.91118883],
[77.93151192, 71. ],
[77.35802398, 72. ],
[77. , 72.92847874],
[76.96288358, 73. ],
[76.7407218 , 74. ],
[76.81522916, 75. ],
[77. , 75.4990085 ],
[77.13933562, 76. ],
[77.62352232, 77. ],
[78. , 77.56072459],
[78.24395555, 78. ],
[78.92888607, 79. ],
[79. , 79.08619142],
[79.65789822, 80. ],
[80. , 80.42578345],
[80.42441542, 81. ],
[81. , 81.72398933],
[81.21020407, 82. ],
[82. , 82.99193698],
[82.00635077, 83. ],
[82.83799971, 84. ],
[83. , 84.19126508],
[83.68672793, 85. ],
[84. , 85.36896892],
[84.54998666, 86. ],
[85. , 86.52382164],
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 13/29
19/7/2019 8- Descripción y reconocimiento- Guia
[85.42863374, 87. ],
[86. , 87.65166769],
[86.32593747, 88. ],
[87. , 88.74724204],
[87.24759631, 89. ],
[88. , 89.80454414],
[88.20205419, 90. ],
[89. , 90.81710864],
[89.20137761, 91. ],
[90. , 91.77789244],
[90.26330812, 92. ],
[91. , 92.67834939],
[91.41576223, 93. ],
[92. , 93.50593648],
[92.70664554, 94. ],
[93. , 94.23818759],
[94. , 94.85171581],
[94.34093569, 95. ],
[95. , 95.34599428],
[96. , 95.67872635],
[97. , 95.85621096],
[98. , 95.92306258],
[99. , 95.93270522]])]
In [194]:
a=io.imread("flecha.png",as_gray=True)
contornos=measure.find_contours(a,0.3)
print(len(contornos))
fig, ax = plt.subplots()
ax.imshow(a, cmap='gray')
plt.show()
In [6]:
new_hand = hand.copy()
for _ in range(5):
new_hand = subdivide_polygon(new_hand, degree=2, preserve_ends=True) #suavizar la c
urva usando B-splines
# Crear 2 elipses
img = np.zeros((800, 800), 'int32') # lienzo para las imagenes
rr, cc = ellipse(250, 250, 180, 230, img.shape)# 250,250 es el centro de la imagen
#180,230 Semiejes menores y mayores
img[rr, cc] = 1
rr, cc = ellipse(600, 600, 150, 90, img.shape)
img[rr, cc] = 1
ax2.imshow(img,cmap="gray")
for contour in find_contours(img, 0.5): #Encuentra los contornos en la imagen
localhost:8888/nbconvert/html/Desktop/PROCESAMIENTO DE IMAGENES DIGITALES/CLASE 08_DESCRIPCION Y RECONOCIMIENTO/8- … 16/29
19/7/2019 8- Descripción y reconocimiento- Guia
plt.show()
In [8]:
cont=find_contours(card,0.5)
coords=approximate_polygon(cont[0],tolerance=15)
#print(coords)#Verificar el tamaño de la lista
fig, ax = plt.subplots()
ax.imshow(card, cmap='gray')
ax.plot(cont[0][:,1],cont[0][:,0], '-r', linewidth=2)
ax.plot(coords[:,1],coords[:,0], '-b', linewidth=2)
plt.show()
[array([[255.5, 147. ],
[255.5, 146. ],
[255.5, 145. ],
...,
[254.5, 148. ],
[255. , 147.5],
[255.5, 147. ]])]
In [220]:
fig, ax = plt.subplots()
ax.imshow(image, cmap="gray")# mostrando elipse
ax.plot((x0, x1), (y0, y1), '-r', linewidth=2.5) # dibujo del semieje mayor
ax.plot((x0, x2), (y0, y2), '-r', linewidth=2.5) # dibujo del semieje menor
ax.plot(x0, y0, '.g', markersize=15) #dibujo del centroide
minr, minc, maxr, maxc = props.bbox # minr y minc son la esquina superior, y maxr
y maxc son la esquina inferior
bx = (minc, maxc, maxc, minc, minc) # ordenando cordenadas filas
by = (minr, minr, maxr, maxr, minr) # ordenando cordenadas columnas filas
ax.plot(bx, by, '-b', linewidth=2.5) # dibujando el rectangulo
In [195]:
pent=io.imread("estrella.png",as_gray=True)
lab=measure.label(pent)
propiedades=measure.regionprops(lab)
fig,ax=plt.subplots(1,4,figsize=(16,4))
ax[0].imshow(lab,cmap='gray')
minr, minc, maxr, maxc = props.bbox # minr y minc son la esquina superior, y maxr
y maxc son la esquina inferior
bx = (minc, maxc, maxc, minc, minc) # ordenando cordenadas filas
by = (minr, minr, maxr, maxr, minr) # ordenando cordenadas columnas filas
ax[0].plot(bx, by, '-b', linewidth=2.5) # dibujando el rectangulo
ax[1].imshow(props.convex_image,cmap='gray')#convex hull
co=props.coords #coordenadas de los puntos
print("las coordenadas de los pontos son:\n ",co)
excent=props.eccentricity
print("la excenticidad es: ", excent)
print("El diametro del circulo con area equivalente a la region es:",props.equivale
nt_diameter)
print("El numero de euler de la region es: ",props.euler_number)
print("Area de la region/area del bounding box: ", props.extent)
print("El area sin huecos es: ", props.filled_area)
ax[2].imshow(props.filled_image,cmap='gray')#imagen sin huecos
ax[3].imshow(props.image,cmap='gray')
print("tensor de inercia\n ", props.inertia_tensor)
print("valores propios del tensor de inercia: ",props.inertia_tensor_eigvals)
print("Numero de etiqueta: ",props.label)
print("centroide local, respecto al bbox: ",props.local_centroid)
print("Eje mayor de la elipse que tiene el mismo momento central que la region: ",p
rops.major_axis_length)
print("Eje menor de la elipse que tiene el mismo momento central que la region: ",p
rops.minor_axis_length)
print("Los momentos hasta el 3° orden son:\n",props.moments) #Informacion https://e
n.wikipedia.org/wiki/Image_moment
print("Los momentos centrales hasta el 3° orden son:\n",props.moments_central)
print("Los momentos hu:\n",props.moments_hu) # Momentos invariantes a la rotacion,
traslacion y escalamiento
print("Los momentos normalizados:\n",props.moments_normalized)
print("Orientacion de la elipse que tiene el mismo momento central que la region: "
,props.orientation)
print("El perimetro es: ",props.perimeter)
print("Area region/area Convex Hull: ",props.solidity)# solidez de la region
plt.show()
In [195]:
lab=measure.label(img>0.2)
props=measure.regionprops(lab,intensity_image=img,)
plt.subplot(1,2,1)
plt.imshow(img,cmap='gray')
plt.subplot(1,2,2)
plt.imshow(props[0].intensity_image,cmap='gray')
In [10]:
ax[0].imshow(img,cmap='nipy_spectral')
ax[1].imshow(img_bin,cmap='gray')
ax[2].imshow(img_lab==6,cmap='gray')
plt.show()
In [11]:
%matplotlib inline
props=measure.regionprops(img_lab)
fig,ax=plt.subplots(1,2,figsize=(12,5))
ax[0].imshow(img_lab)
ax[0].set_title('Numero de cada figura')
ax[1].imshow(img_lab)
ax[1].set_title('Perimetro de cada figura etiquetada')
for n,ppd in enumerate(props):
txt=str(round(ppd.perimeter))
x,y=ppd.centroid
ax[1].text(y-20,x,txt,bbox=dict(facecolor='white', alpha=0.8))
In [15]:
fig,ax =plt.subplots(figsize=(18,5))
lienzo=np.zeros(img.shape)
if (ppd.perimeter**2)/ppd.area<15:
lienzo=lienzo+(img_lab==(n+1))
ax.imshow(lienzo,cmap='gray')
plt.show()
In [ ]:
In [287]:
img=io.imread("cañoCristales.jpg",as_gray="True")
img2=transform.rotate(img,30,resize=True)
img3=transform.rescale(img, 0.3)
img4=np.pad(img, ((0,100), (100, 0)), 'constant',constant_values=0)
fig,ax=plt.subplots(2,2,figsize=(14,7))
ax[0,0].imshow(img,cmap='gray')
ax[0,1].imshow(img2,cmap='gray')
ax[1,0].imshow(img3,cmap='gray')
ax[1,1].imshow(img4,cmap='gray')
muij1=measure.moments_central(img)
muij2=measure.moments_central(img2)
muij3=measure.moments_central(img3)
muij4=measure.moments_central(img4)
nuij1=measure.moments_normalized(muij1)
nuij2=measure.moments_normalized(muij2)
nuij3=measure.moments_normalized(muij3)
nuij4=measure.moments_normalized(muij4)
3. Homework
Complete la guía
El nombre del archivo tiene el siguiente formato: (1°apellido)-(1° o 1° Nombre) por ejemplo
Asto-Emerson
El formato tiene que estar importado a PDF
No enviar codigos u otro archivo
La fecha de presentacion cuenta en su calificacion
Los trabajos iguales comparten nota (si hay 2 trabajos iguales y la nota del trabajo es 16, ambos
estudiantes reciben calificacion 8)
In [ ]: