I read an image with ndimage, which results in a binary image like this:
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)