ipynb: Update
[persistence.git] / 2Dpers.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": null,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "from scipy import misc\n",
10 "import numpy as np\n",
11 "import matplotlib.pyplot as plt\n",
12 "\n",
13 "from mpl_toolkits.mplot3d import Axes3D\n",
14 "\n",
15 "import imagepers"
16 ]
17 },
18 {
19 "cell_type": "code",
20 "execution_count": null,
21 "metadata": {},
22 "outputs": [],
23 "source": [
24 "im = np.loadtxt('paws.numpy')\n",
25 "im = misc.imresize(im, 2.0)\n",
26 "im = im * (255 / np.max(im))"
27 ]
28 },
29 {
30 "cell_type": "code",
31 "execution_count": null,
32 "metadata": {},
33 "outputs": [],
34 "source": [
35 "g0 = imagepers.persistence(im)\n",
36 "g0"
37 ]
38 },
39 {
40 "cell_type": "code",
41 "execution_count": null,
42 "metadata": {},
43 "outputs": [],
44 "source": [
45 "fig = plt.figure()\n",
46 "plt.imshow(im, interpolation=\"nearest\")\n",
47 "plt.colorbar()\n",
48 "xx, yy = np.mgrid[0:im.shape[0], 0:im.shape[1]]\n",
49 "\n",
50 "#fig = plt.figure()\n",
51 "#plt.contourf(xx, yy, im, np.arange(0, 255, 20))"
52 ]
53 },
54 {
55 "cell_type": "code",
56 "execution_count": null,
57 "metadata": {},
58 "outputs": [],
59 "source": [
60 "fig = plt.figure()\n",
61 "ax = fig.add_subplot(111)\n",
62 "ax.set_title(\"Peristence diagram\")\n",
63 "ax.plot([0,255], [0,255], '-', c='grey')\n",
64 "for i, homclass in enumerate(g0):\n",
65 " p_birth, bl, pers, p_death = homclass\n",
66 " if pers <= 1.0:\n",
67 " continue\n",
68 " \n",
69 " x, y = bl, bl-pers\n",
70 " ax.plot([x], [y], '.', c='b')\n",
71 " ax.text(x, y+2, str(i+1), color='b')\n",
72 "ax.set_xlabel(\"Birth level\")\n",
73 "ax.set_ylabel(\"Death level\")\n",
74 "ax.set_xlim((-5,260))\n",
75 "ax.set_ylim((-5,260))"
76 ]
77 },
78 {
79 "cell_type": "code",
80 "execution_count": null,
81 "metadata": {},
82 "outputs": [],
83 "source": [
84 "fig = plt.figure()\n",
85 "ax = fig.add_subplot(111)\n",
86 "ax.set_title(\"Loci of births\")\n",
87 "for i, homclass in enumerate(g0):\n",
88 " p_birth, bl, pers, p_death = homclass\n",
89 " if pers <= 20.0:\n",
90 " continue\n",
91 " y, x = p_birth\n",
92 " ax.plot([x], [y], '.', c='b')\n",
93 " ax.text(x, y+0.25, str(i+1), color='b')\n",
94 " \n",
95 "ax.set_xlim((0,im.shape[1]))\n",
96 "ax.set_ylim((0,im.shape[0]))\n",
97 "plt.gca().invert_yaxis()"
98 ]
99 },
100 {
101 "cell_type": "code",
102 "execution_count": null,
103 "metadata": {},
104 "outputs": [],
105 "source": [
106 "fig = plt.figure()\n",
107 "ax = fig.gca(projection='3d')\n",
108 "ax.plot_surface(xx, yy, im ,rstride=1, cstride=1, cmap=plt.cm.jet,\n",
109 " linewidth=0)"
110 ]
111 },
112 {
113 "cell_type": "code",
114 "execution_count": null,
115 "metadata": {},
116 "outputs": [],
117 "source": [
118 "plt.show()"
119 ]
120 },
121 {
122 "cell_type": "code",
123 "execution_count": null,
124 "metadata": {
125 "collapsed": true
126 },
127 "outputs": [],
128 "source": []
129 }
130 ],
131 "metadata": {
132 "kernelspec": {
133 "display_name": "Python 3",
134 "language": "python3.5",
135 "name": "python3"
136 },
137 "language_info": {
138 "codemirror_mode": {
139 "name": "ipython",
140 "version": 3
141 },
142 "file_extension": ".py",
143 "mimetype": "text/x-python",
144 "name": "python",
145 "nbconvert_exporter": "python",
146 "pygments_lexer": "ipython3",
147 "version": "3.5.5"
148 }
149 },
150 "nbformat": 4,
151 "nbformat_minor": 1
152 }