使用matplotlib Python打开.tif图像

时间:2017-07-25 19:08:03

标签: 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()

我使用了以下图片:enter image description here

并产生以下错误:

  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 个答案:

答案 0 :(得分:1)

根据Pillow的文件here,PIL和Pillow不能在同一环境中共存。我以前安装了PIL,所以在我从this link卸载PIL并安装了Pillow 3.0之后,所有内容都与上面发布的代码一起顺利进行。