Search code examples
pythonpython-imaging-libraryscikit-image

scikit-image can not import an image


Environment:

  • Python 3.7.0
  • After creating a virtualenv, scikit-image is via pip installed.
  • scikit-image==0.16.2, Pillow==7.1.1
  • Anaconda on Linux

Source Code:

from skimage.io import imread
file_path = "image_you_like.png"
img = imread(file_path, plugin="pil", as_gray=False)

Expected Result:

img is a numpy array of an image.

Actual Result:

Do not trust the line number, because I inserted a few print functions.

~/Python/experiment/venv/lib/python3.7/site-packages/PIL/PngImagePlugin.py in _seek(self, frame, rewind)
    789 
    790             try:
--> 791                 cid, pos, length = self.png.read()
    792             except (struct.error, SyntaxError):
    793                 break

AttributeError: 'NoneType' object has no attribute 'read'

Question

How can I prevent this error and read an image?

After some analysis I found that imread works if plugin="matplotlib" or plugin="imageio". The problem is that some functions such as skimage.data.camera call imread with plugin="pil" and therefore I can not try any sample image of scikit-image.

[EDIT]

from skimage.io.manage_plugins import plugin_store
print(plugin_store["imread"])

prints the following

[('imageio', <function imread at 0x7efe39112c20>), ('matplotlib', <function imread at 0x7efe37f51290>)]

So "pil" can not be found in the list.


Solution

  • This issue was reported on github.

    As a user the easiest solution is to downgrade the version to 6.2.2.