Reputation: 926
scikit-image==0.16.2
, Pillow==7.1.1
from skimage.io import imread
file_path = "image_you_like.png"
img = imread(file_path, plugin="pil", as_gray=False)
img
is a numpy array of an image.
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'
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.
Upvotes: 3
Views: 1312
Reputation: 926
This issue was reported on github.
As a user the easiest solution is to downgrade the version to 6.2.2.
Upvotes: 2