Python with scikit image to invert colors back and white

I read the image with ndimage and the image result as follows: enter image description here

I want to SHOW THIS PICTURE

Black → White and White → Black

Thus, iteration with a watershed can destroy this black object.

Please help me. Thanks you

+8
source share
5 answers
numpy.invert(close_img)

I use an inverted array. His work is for me. Thanks you

+15
source

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

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

, 1.0, 1 - close_image

+2

I like Pamungkas Jayuda anwer, but it only works if your data is integers. In my case, I just used a simple inverse with a small value in the denominator to avoid dividing by zero:

1 / (2e5 + img)
+1
source

Here is another method using OpenCV

import cv2

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

0
source

All Articles