5 "execution_count": null,
9 "from scipy import misc\n",
10 "from PIL import Image\n",
11 "import numpy as np\n",
12 "import matplotlib.pyplot as plt\n",
14 "from mpl_toolkits.mplot3d import Axes3D\n",
21 "execution_count": null,
25 "im = np.loadtxt('paws.numpy')\n",
26 "print(\"pre shape:\", im.shape)\n",
28 "im = np.array(Image.fromarray(im).resize((h*2, w*2)))\n",
29 "print(\"post shape:\", im.shape)\n",
30 "im = im * (255 / np.max(im))"
35 "execution_count": null,
39 "g0 = imagepers.persistence(im)\n",
45 "execution_count": null,
49 "fig = plt.figure()\n",
50 "plt.imshow(im, interpolation=\"nearest\")\n",
52 "xx, yy = np.mgrid[0:im.shape[0], 0:im.shape[1]]\n",
54 "#fig = plt.figure()\n",
55 "#plt.contourf(xx, yy, im, np.arange(0, 255, 20))"
60 "execution_count": null,
64 "fig = plt.figure()\n",
65 "ax = fig.add_subplot(111)\n",
66 "ax.set_title(\"Peristence diagram\")\n",
67 "ax.plot([0,255], [0,255], '-', c='grey')\n",
68 "for i, homclass in enumerate(g0):\n",
69 " p_birth, bl, pers, p_death = homclass\n",
73 " x, y = bl, bl-pers\n",
74 " ax.plot([x], [y], '.', c='b')\n",
75 " ax.text(x, y+2, str(i+1), color='b')\n",
76 "ax.set_xlabel(\"Birth level\")\n",
77 "ax.set_ylabel(\"Death level\")\n",
78 "ax.set_xlim((-5,260))\n",
79 "ax.set_ylim((-5,260))"
84 "execution_count": null,
88 "fig = plt.figure()\n",
89 "ax = fig.add_subplot(111)\n",
90 "ax.set_title(\"Loci of births\")\n",
91 "for i, homclass in enumerate(g0):\n",
92 " p_birth, bl, pers, p_death = homclass\n",
93 " if pers <= 20.0:\n",
96 " ax.plot([x], [y], '.', c='b')\n",
97 " ax.text(x, y+0.25, str(i+1), color='b')\n",
99 "ax.set_xlim((0,im.shape[1]))\n",
100 "ax.set_ylim((0,im.shape[0]))\n",
101 "plt.gca().invert_yaxis()"
106 "execution_count": null,
110 "fig = plt.figure(figsize=(6, 6))\n",
111 "ax = fig.add_subplot(111, projection='3d')\n",
112 "ax.set_zlim(0, 800)\n",
113 "ax.plot_surface(xx, yy, im ,rstride=1, cstride=1, cmap=plt.cm.jet,\n",
120 "execution_count": null,
127 "execution_count": null,
135 "display_name": "Python 3 (ipykernel)",
136 "language": "python",
144 "file_extension": ".py",
145 "mimetype": "text/x-python",
147 "nbconvert_exporter": "python",
148 "pygments_lexer": "ipython3",