Python 2.7 使用matplotlib Python打开.tif图像

Python 2.7 使用matplotlib Python打开.tif图像,python-2.7,image-processing,matplotlib,Python 2.7,Image Processing,Matplotlib,我对python非常陌生,我正在尝试将一个.tif图像加载到下面的代码中,以便稍后在不同的x和y坐标处用点标记它 import matplotlib.pyplot as plt import matplotlib.image as mpimg image = mpimg.imread("mothTest.tif") plt.imshow(image) plt.show() 我使用了下图: 它会产生以下错误: File "<ipython-input-1-69a4ce2424d3>

我对python非常陌生,我正在尝试将一个.tif图像加载到下面的代码中,以便稍后在不同的x和y坐标处用点标记它

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image = mpimg.imread("mothTest.tif")
plt.imshow(image)
plt.show()
我使用了下图:

它会产生以下错误:

  File "<ipython-input-1-69a4ce2424d3>", line 1, in <module>
    runfile('Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python App/Centroid_LUT.py', wdir='Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python App')

  File "C:\Users\Michaela\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)

  File "C:\Users\Michaela\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python App/Centroid_LUT.py", line 29, in <module>
    image = mpimg.imread("mothTest.tif")

  File "C:\Users\Michaela\Anaconda2\lib\site-packages\matplotlib\image.py", line 1278, in imread
    im = pilread(fname)

  File "C:\Users\Michaela\Anaconda2\lib\site-packages\matplotlib\image.py", line 1256, in pilread
    with Image.open(fname) as image:

  File "C:\Users\Michaela\Anaconda2\lib\site-packages\PIL\Image.py", line 512, in __getattr__
    raise AttributeError(name)

AttributeError: __exit__
文件“”,第1行,在
runfile('Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python APP/Centroid_LUT.py',wdir='Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python APP')
文件“C:\Users\Michaela\Anaconda2\lib\site packages\spyder\utils\site\sitecustomize.py”,第866行,在runfile中
execfile(文件名、命名空间)
文件“C:\Users\Michaela\Anaconda2\lib\site packages\spyder\utils\site\sitecustomize.py”,第87行,在execfile中
exec(编译(脚本文本,文件名,'exec'),glob,loc)
文件“Z:/04项目内部/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python APP/Centroid_LUT.py”,第29行,在
image=mpimg.imread(“mothTest.tif”)
文件“C:\Users\Michaela\Anaconda2\lib\site packages\matplotlib\image.py”,第1278行,在imread中
im=pilread(fname)
文件“C:\Users\Michaela\Anaconda2\lib\site packages\matplotlib\image.py”,第1256行,在pilread中
使用Image.open(fname)作为图像:
文件“C:\Users\Michaela\Anaconda2\lib\site packages\PIL\Image.py”,第512行,在\uu getattr中__
提升属性错误(名称)
AttributeError:\uuu退出__

有人知道如何解决这个问题吗?任何帮助都将不胜感激

根据枕头的文档,PIL和枕头不能在同一环境中共存。我以前安装过PIL,所以在我从卸载了PIL并从安装了Pillow 3.0之后,所有的工作都顺利进行,上面的代码都发布了

使用Python2.7、matplotlib 2.0.2、PIL 1.1.7和Pillow 3.0,上述代码可以毫无问题地运行并加载tif图像。我在安装Pillow软件包时遇到了一些困难。当我通过.exe安装它时,Pillow-3.0.0-py2.7.egg-info会被安装到我的网站包中,而不是安装到包本身。我也试着直接从git下载到我的站点软件包中,但是当我去检查它是否被正确导入(通过import Pillow)时,我得到一个错误,指出该软件包不在站点软件包文件夹中。推荐的安装Pillow的方法是。使用anaconda您也可以直接使用其软件包管理器,尽管我认为anaconda默认安装了枕头。谢谢!我意识到我有问题,因为我安装了PIL而不是枕头。一切都好了!然后,您可以回答自己的问题,并在2天内接受该答案,这样这个问题就不会永远无法解决。