gpt4 book ai didi

python-2.7 - imshow 一个灰度图像和一个二进制图像 python

转载 作者:行者123 更新时间:2023-12-03 23:37:44 25 4
gpt4 key购买 nike

我有一个灰度图像和一个二值图像,我想使用 hstack 并排绘制它们。看起来已经进行了某种调整以使二进制变暗。有人遇到过这个问题吗?

enter image description here

这是我的代码

O = (self.img >= t) * 1
I = img
both = np.hstack((I, O))
imshow(both, cmap='gray')
show()

最佳答案

这是为了证明与您的案例有些不同,我不知道其数据。我怀疑数组 'O' 中的所有值都为零,因此,该图以黑色 Pane 的形式出现。

import numpy as np
import matplotlib.pyplot as plt

fig=plt.figure(figsize=(8, 4))

# make up some data for demo purposes
raw = np.random.randint(10, size=(6,6))
# apply some logic operatioin to the data
O = (raw >= 5) * 1 # get either 0 or 1 in the array
I = np.random.randint(10, size=(6,6)) # get 0-9 in the array

# plot each image ...
# ... side by side
fig.add_subplot(1, 2, 1) # subplot one
plt.imshow(I, cmap=plt.cm.gray)

fig.add_subplot(1, 2, 2) # subplot two
# my data is OK to use gray colormap (0:black, 1:white)
plt.imshow(O, cmap=plt.cm.gray) # use appropriate colormap here
plt.show()

结果图像:

enter image description here

关于python-2.7 - imshow 一个灰度图像和一个二进制图像 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46615864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com