在skimage中,如何从一个生成的图像中获取cmap,并在另一个图像中使用它?

In skimage, how to get cmap from one generated image, and use it in another image?

如果我用 cmap="gray" 绘制两个图像:

那么如何在 Im2 上获得相同的浅灰色?

import matplotlib.pyplot as plt
import numpy as np

Im1 = np.array([[0.1,0.2],[0.02,0.002]])
plt.subplot(1, 2, 1)
plt.imshow(Im1, cmap="gray")

Im2 = np.array([[0.1,0.1],[0.1,0.1]])
plt.subplot(1, 2, 2)
plt.imshow(Im2, cmap="gray")

plt.show()

谢谢

您可能想在两个子图中使用相同的 Normalize 对象,如下所示:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import Normalize

Im1 = np.array([[0.1,0.2],[0.02,0.002]])
Im2 = np.array([[0.1,0.1],[0.1,0.1]])

_min = min(t.min() for t in [Im1, Im2])
_max = max(t.max() for t in [Im1, Im2])
norm = Normalize(vmin=_min, vmax=_max)

plt.subplot(1, 2, 1)
plt.imshow(Im1, cmap="gray", norm=norm)

plt.subplot(1, 2, 2)
plt.imshow(Im2, cmap="gray", norm=norm)

plt.show()