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