python matplotlib图像-默认反转白色和黑色

标签 python opencv matplotlib

我开始使用 openCV,并且正在阅读《使用 Python 编程计算机视觉》一书。似乎我有一个默认设置,它被设置为书中使用的内容的反转(或反转?),因为图像在我的计算机上是黑色的,而书中的图像是白色的。

有什么方法可以设置默认黑白翻转而不用每次都做计算吗?

这是书中的一些示例代码。在书里,背景是白色的,但在我的电脑上,它是黑色的:

from PIL import Image
from numpy import *
from scipy.ndimage import filters

im = array(Image.open('empire.jpg').convert('L'))

sigma = 5
imx = zeros(im.shape)
filters.gaussian_filter(im,(sigma,sigma),(0,1),imx)  
imy = zeros(im.shape)
filters.gaussian_filter(im,(sigma,sigma),(1,0),imy)  
magnitude = sqrt(imx**2+imy**2)  

figure()  
subplot(1,4,1)
imshow(im)
subplot(1,4,2)
imshow(imx)
subplot(1,4,3)
imshow(imy)
subplot(1,4,4)
imshow(magnitude)

我正在使用 mac book pro 并使用 python 2.7。这可能在某个地方得到了回答,但我找不到答案 - 可能没有使用正确的标签/关键字......提前谢谢。

最佳答案

这不是默认值,但您可以通过从 1 中减去数组来反转颜色:

plt.imshow(1 - 数组)

关于python matplotlib图像-默认反转白色和黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26497681/

相关文章:

python - 创建 virtualenv 时出现错误。该错误说明了有关 python3 的内容

python - 在 python 中迭代所有先前的值

c++ - 检测丢失的对象

c++ - 在没有固定角度的图像上绘制旋转边界框

android - 如何在 C++ OpenCV 中显示带有 putText 的计时器结果?

python - Seaborn tsplot 不能很好地在 x 轴上显示日期时间

python - 在 Matplotlib 中绘制特定轴

python - 模块无法加载,仅标题发生变化(pygame)

python - 如何在同一绘图上对多个字典进行箱线图

python - Ruby 相当于 Python 的 "dir"?