Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用scikit图像反转黑白?_Python_Image_Image Processing_Scipy_Scikit Image - Fatal编程技术网

Python 如何使用scikit图像反转黑白?

Python 如何使用scikit图像反转黑白?,python,image,image-processing,scipy,scikit-image,Python,Image,Image Processing,Scipy,Scikit Image,我用读取图像,结果得到如下二值图像: 我想反转图像,使白色变成黑色,反之亦然 谢谢你的帮助 numpy.invert(close_img) 我使用反转数组。它对我很有用。如果你的图像是用1.0的非负浮点值表示的,你可以使用1-close\u image和scikit图像的开发版本(升级到v0.13),你可以使用invert()。例如: from skimage import util img = data.camera() inverted_img = util.invert(img)

我用读取图像,结果得到如下二值图像:

我想反转图像,使白色变成黑色,反之亦然

谢谢你的帮助

numpy.invert(close_img)

我使用反转数组。它对我很有用。

如果你的图像是用1.0的非负浮点值表示的,你可以使用
1-close\u image

和scikit图像的开发版本(升级到v0.13),你可以使用invert()。例如:

from skimage import util 
img = data.camera() 
inverted_img = util.invert(img)
我喜欢的是anwer,但它只在假设数据是整数的情况下起作用。在我的例子中,我只是使用分母上的一个小值的简单反转来避免被零除:

1 / (2e5 + img)

下面是使用OpenCV的另一种方法

import cv2

image = cv2.imread('2.png')
invert = cv2.bitwise_not(image) # OR
# invert = 255 - image

如果您的图像是dtype bool,那么您只需执行
~close\u img
。如果您的图像是dtype unsigned integer,您还可以使用
~close\u img
。它可以用于最大值为255的图像。只需使用
255-关闭图像
很好,非常有用。它比cv2.bitwise\u工作得更好。谢谢