I need a python method to open and import TIFF images into numpy arrays so I can analyze and modify the pixel data and then save them as TIFFs again. (They are basically light intensity maps in greyscale, representing the respective values per pixel)
I couldn’t find any documentation on PIL methods concerning TIFF. I tried to figure it out, but only got “bad mode” or “file type not supported” errors.
What do I need to use here?
First, I downloaded a test TIFF image from this page called
a_image.tif. Then I opened with PIL like this:This showed the rainbow image. To convert to a numpy array, it’s as simple as:
We can see that the size of the image and the shape of the array match up:
And the array contains
uint8values:Once you’re done modifying the array, you can turn it back into a PIL image like this: