从2D图像轮廓

时间:2013-09-09 19:54:25

标签: python matplotlib

我想知道是否可以在Python中从2D图像绘制轮廓(水平曲线)图形。更具体地说,我想知道如何读取图像数据(例如,灰度像素的集合),并将其用于z输入 我正在阅读一些关于matplotlib的文章,但我找不到输入是图像的例子。

1 个答案:

答案 0 :(得分:4)

您可以使用contour from matplotlib功能。

import numpy as np
import pylab as plt

# Sample data
row = np.linspace(-2,2,20)
X,Y = np.meshgrid(row,row)
Z    = np.exp(-((X-1.5)**2+(Y+1)**2))
Z   += np.exp(-((X)**2+(Y)**2))

plt.subplot(121)
plt.imshow(Z,interpolation='none',origin='lower')
plt.subplot(122)
plt.contour(X,Y,Z)
plt.show()
print X,Y

enter image description here

您也可以使用contourf填写

enter image description here

相关问题