简体   繁体   English

使用 python 中的 .tiff 图像进行深度学习

[英]Working with .tiff images in python for deep learning

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.我目前正在使用 python 中的成像流式细胞术图像进行项目。图像是.tiff,示例文件名为 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.我曾尝试使用 matplotlib 和 PIL 以及 tifffile 库,但无论我尝试什么,似乎都不起作用。 It always tells me FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/zacha/Desktop/cell_images/27_Ch1.ome.tiff'.它总是告诉我 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.我尝试将一些图像转换为 .png 图像,代码可以正常工作并加载图像,这并不理想,因为我有一个包含几十万张图像的数据集。 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.我想知道 StackOverflow 宇宙中是否有人知道如何处理这样的问题或过去处理过 python 中的 .tiff 图像。 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.非常感谢阅读或回答此问题的人。

Try rasterio and matplotlib尝试栅格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))

You can try this code to open any tiff file:您可以尝试使用此代码打开任何 tiff 文件:

import rasterio
from rasterio.plot import show
tiff_img = rasterio.open('filename.tif')
show(tiff_img)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM