How to invert black and white with scikit-image?

六月ゝ 毕业季﹏ 提交于 2019-12-05 18:09:13

问题


I read an image with ndimage, which results in a binary image like this:

I would like to invert the image such that white turns into black, and vice versa.

Help is appreciated.


回答1:


numpy.invert(close_img)

I use invert array. Its work for me. Thanks you




回答2:


With the devel version of scikit-image (upcomming v0.13), you can use invert(). Example:

from skimage import util 
img = data.camera() 
inverted_img = util.invert(img)



回答3:


If your image is represented with non-negative floating point values topping out at 1.0, you can use 1 - close_image




回答4:


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:

1 / (2e5 + img)



回答5:


Here's another method using OpenCV

import cv2

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



来源:https://stackoverflow.com/questions/28084908/how-to-invert-black-and-white-with-scikit-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!