Imoverlay在python中

tyl*_*ler 4 python matlab image matplotlib python-imaging-library

我正在尝试使用matplotlib imshow()将矩阵覆盖在另一个矩阵上.我希望叠加矩阵是红色的,而"背景矩阵"是骨骼,色彩映射明智.因此,简单地添加图像不起作用,因为您只能有一个色彩图.除了使用imshow()添加矩阵之外,我还没有找到另一种"叠加"的方法.

我试图或多或少地替换这个matlab 模块.

请让我知道我有什么替代品!

Joe*_*ton 6

只需使用蒙面数组.

例如

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

x = np.arange(100).reshape(10,10)
y = np.zeros((10,10))

# Make a region in y that we're interested in...
y[4:6, 1:8] = 1

y = np.ma.masked_where(y == 0, y)

plt.imshow(x, cmap=mpl.cm.bone)
plt.imshow(y, cmap=mpl.cm.jet_r, interpolation='nearest')

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述