Python 如何使用 scikit-image 反转黑白?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28084908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to invert black and white with scikit-image?
提问by Pamungkas Jayuda
采纳答案by Pamungkas Jayuda
numpy.invert(close_img)
I use invert array. It works for me.
我使用反转数组。这个对我有用。
回答by eadsjr
If your image is represented with non-negative floating point values topping out at 1.0, you can use 1 - close_image
如果您的图像以 1.0 的非负浮点值表示,您可以使用 1 - close_image
回答by Fran?ois Boulogne
With the devel version of scikit-image (upcomming v0.13), you can use invert(). Example:
使用 scikit-image 的开发版本(即将发布的 v0.13),您可以使用invert()。例子:
from skimage import util
img = data.camera()
inverted_img = util.invert(img)
回答by ambodi
I like Pamungkas Jayuda's anwer, but it works only on the assumption that your data is an integer. In my case, I just used simple inversion with a small value on the denominator to avoid division by zero:
我喜欢Pamungkas Jayuda的回答,但它仅适用于您的数据是整数的假设。就我而言,我只是使用了分母上一个小值的简单反演来避免被零除:
1 / (2e5 + img)
回答by nathancy
Here's another method using OpenCV
这是使用 OpenCV 的另一种方法
import cv2
image = cv2.imread('2.png')
invert = cv2.bitwise_not(image) # OR
# invert = 255 - image