备注
前往结尾 下载完整示例代码。或者通过 Binder 在浏览器中运行此示例。
生成足迹(结构元素)#
这个示例展示了如何使用 skimage.morphology
中的函数来生成用于形态学操作的足迹(结构元素)。每个图的标题表示函数的调用。
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from skimage.morphology import (
square,
rectangle,
diamond,
disk,
cube,
octahedron,
ball,
octagon,
star,
)
# Generate 2D and 3D structuring elements.
struc_2d = {
"square(15)": square(15),
"rectangle(15, 10)": rectangle(15, 10),
"diamond(7)": diamond(7),
"disk(7)": disk(7),
"octagon(7, 4)": octagon(7, 4),
"star(5)": star(5),
}
struc_3d = {"cube(11)": cube(11), "octahedron(5)": octahedron(5), "ball(5)": ball(5)}
# Visualize the elements.
fig = plt.figure(figsize=(8, 8))
idx = 1
for title, struc in struc_2d.items():
ax = fig.add_subplot(3, 3, idx)
ax.imshow(struc, cmap="Paired", vmin=0, vmax=12)
for i in range(struc.shape[0]):
for j in range(struc.shape[1]):
ax.text(j, i, struc[i, j], ha="center", va="center", color="w")
ax.set_axis_off()
ax.set_title(title)
idx += 1
for title, struc in struc_3d.items():
ax = fig.add_subplot(3, 3, idx, projection=Axes3D.name)
ax.voxels(struc)
ax.set_title(title)
idx += 1
fig.tight_layout()
plt.show()
脚本总运行时间: (0 分钟 1.130 秒)