I read an image with ndimage, which results in a binary image like this:
Here's another method using OpenCV
import cv2
image = cv2.imread('2.png')
invert = cv2.bitwise_not(image) # OR
# invert = 255 - image
If your image is represented with non-negative floating point values topping out at 1.0, you can use 1 - close_image
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)
numpy.invert(close_img)
I use invert array. It works for me.
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)