两个系统的python版本: 3.10.5
我试图在我的图像上使用一个二进制掩码,并制作一个新的二值图像。让我好奇的是,当我用同样的代码在我的另一个系统上练习同样的东西时,输出是生成的,但是在另一个系统上,它抛出了这个错误,而二进制映像没有生成。(然后,我想在主图像上加一个40值以下的像素掩码)。五行线的代码是-
在这里,我试图取值在40以下的像素。
im = imread('image')
mask = im<40
plt.figure()
imshow(mask)
plt.show()错误
4 plt.figure()
----> 5 imshow(mask)
6 plt.show()
7
TypeError: numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead.
<Figure size 432x288 with 0 Axes>(如果需要,相应地编辑查询。)
发布于 2022-10-13 16:21:27
您需要使用numpy ma masked_where方法:
import matplotlib.pyplot as plt
import numpy as np
im = plt.imread('image')
mask = np.ma.masked_where(im < 40, im)
plt.figure()
plt.imshow(mask)
plt.show()https://stackoverflow.com/questions/74057916
复制相似问题