Skip to content

Commit 960aefb

Browse files
authored
Added "mesh_img.py" and "plot_mesh.py". (#71)
* Added two functions "mesh_img.py" and "plot_mesh.py". The file "mesh_img.py" provides a way to generate any kind of object inside the pyEIT unit circle mesh. With "plot_mesh.py" it is possible to plot a pyEITmesh.
1 parent 731ad2a commit 960aefb

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

pyeit/mesh/mesh_img.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import numpy as np
2+
from wrapper import create
3+
4+
5+
def groundtruth_IMG_based(IMG, n_el=16, perm_empty_gnd=1, perm_obj=10, h0=0.1):
6+
"""
7+
Wraps a image to the PyEITMesh unit circle area.
8+
9+
input: - 200x200 image
10+
- n_el: number of electrodes
11+
- perm_empty_gnd: perm of the empty ground
12+
- perm_obj: perm ob the object area
13+
- h0: refinement of the mesh
14+
15+
return: mesh_obj (PyEITMesh)
16+
"""
17+
18+
mesh_obj = create(n_el=n_el, h0=h0)
19+
X_Y = np.array(np.where(IMG == 1))
20+
X = X_Y[1, :] - 100
21+
Y = (X_Y[0, :] - 100) * -1
22+
pts = mesh_obj.element
23+
tri = mesh_obj.node
24+
tri_centers = np.mean(tri[pts], axis=1)
25+
mesh_x = np.round(tri_centers[:, 0] * 100)
26+
mesh_y = np.round(tri_centers[:, 1] * 100)
27+
Perm = np.ones(tri_centers.shape[0]) * perm_empty_gnd
28+
for i in range(len(X)):
29+
for j in range(len(mesh_x)):
30+
if X[i] == mesh_x[j] and Y[i] == mesh_y[j]:
31+
Perm[j] = perm_obj
32+
mesh_obj.perm = Perm
33+
return mesh_obj

pyeit/mesh/plot_mesh.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
def plot_mesh(mesh_obj):
6+
"""Plot PyEITMesh"""
7+
plt.style.use("default")
8+
pts = mesh_obj.node
9+
tri = mesh_obj.element
10+
x, y = pts[:, 0], pts[:, 1]
11+
fig = plt.figure()
12+
ax = fig.add_subplot(111)
13+
ax.tripcolor(
14+
x,
15+
y,
16+
tri,
17+
np.real(mesh_obj.perm),
18+
edgecolors="k",
19+
shading="flat",
20+
alpha=0.5,
21+
cmap=plt.cm.viridis,
22+
)
23+
# draw electrodes
24+
ax.plot(x[mesh_obj.el_pos], y[mesh_obj.el_pos], "ro")
25+
for i, e in enumerate(mesh_obj.el_pos):
26+
ax.text(x[e], y[e], str(i + 1), size=12)
27+
ax.set_title(r"mesh")
28+
ax.set_aspect("equal")
29+
ax.set_ylim([-1.2, 1.2])
30+
ax.set_xlim([-1.2, 1.2])
31+
fig.set_size_inches(6, 6)

0 commit comments

Comments
 (0)