0

I am currently working on a project using imaging flow cytometry images in python. the images are .tiff an example file name is image27_Ch1.ome.tiff . I am having a little trouble with opening these images. I have tried to use matplotlib and PIL and the tifffile library but whatever I try does not seem to work. It always tells me FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/zacha/Desktop/cell_images/27_Ch1.ome.tiff' . Although I double and triple-checked that the directory to the image is correct, even when I copy and paste the path to the image from the image properties itself it still gives me this error. I tried converting a few images into .png images and the code works and will load the images, this is not ideal because I have a data set of a few hundred thousand images. I was wondering if anyone out there in the StackOverflow universe knows how to deal with a problem like this or has dealt with .tiff images in python in the past. Below is some of the code that I have tried to open these images.

import matplotlib.pyplot as plt
path = 'C:/Users/zacha/Desktop/cell_images/27_Ch1.ome.tiff'
I = plt.imread(path)


from PIL import Image
path = 'C:/Users/zacha/Desktop/cell_images/27_Ch1.ome.tiff'
image = Image.open(path)

Thank you very much to whoever reads or answers this question.

  • https://stackoverflow.com/questions/11727598/pil-image-open-working-for-some-images-but-not-others – pippo1980 Jun 17 '21 at 16:46
  • To avoid (or solve) problems with paths, copy your TIFF to the directory where your script is running and open it using just its filename (without the directory) rather than its full path. Also use `os.system('DIR')` to see what image files are in the directory where you are running. – Mark Setchell Jun 17 '21 at 20:01
  • And the file name is not `27_Ch1.ome.tif` instead of `27_Ch1.ome.tiff`? Since the code works for PNG images, and the error message is pretty clear, I can't think of any other issue than improper naming and/or extensions. – HansHirse Jun 18 '21 at 06:20
  • @HansHirse have tried both 27_Ch1.ome.tif and 27_Ch1.ome.tiff with no luck Within the same directory I opened the tif image in paint and saved it as a png image so the file now looks like 27_Ch1.ome.png. So in this directory, I now have two images 27_Ch1.ome.tiff and 27_Ch1.ome.png. The png image opens and displays without an issue but the tif image is still giving me the same error. I cant change all my images manually to pngs because I have a few hundred thousand of them. – Zachary Anstey Jun 18 '21 at 11:44
  • It looks like you're on windows, but you're using unix foward slash directory separators. ...while most libs seem to manage the conversion to windows backslashes correctly, maybe quickly try using backslashes instead of foward. – Richard Jun 23 '21 at 16:12
  • The other option is use a pathlib object instead of a string to represent the path, if PIL supports being passed pathlib's. Even if it doesn't support path's as pathlib's, you could first simply use pathlib to check for the existence of the file before passing it's string representation to PIL to open. – Richard Jun 23 '21 at 16:14

2 Answers2

0

Try rasterio and matplotlib

import rasterio
import matplotlib.pyplot as plt
src_path = "Your_sat_img.tif"
img = rasterio.open(src_path)
plt.figure(figsize=(22, 22))
plt.imshow(img.read([1,2,3]).transpose(1, 2, 0))
0

You can try this code to open any tiff file:

import rasterio
from rasterio.plot import show
tiff_img = rasterio.open('filename.tif')
show(tiff_img)
ChillGod
  • 43
  • 1
  • 7