Reputation: 2310
I seem to have encountered a bug in scipy.misc.imread, and I'm looking for a workaround. Here's a clip of the error report:
from scipy.misc import imread
im = imread('380.bmp')
...
C:\Anaconda3\lib\site-packages\PIL\BmpImagePlugin.py in _bitmap(self, header, offset)
145 raw_mode = MASK_MODES[(file_info['bits'], file_info['rgb_mask'])]
146 else:
--> 147 raise IOError("Unsupported BMP bitfields layout")
148 else:
149 raise IOError("Unsupported BMP bitfields layout")
OSError: Unsupported BMP bitfields layout
I can open the image without problems in an image viewer, so I'm sure it's not corrupted.
The main question is: What's the best alternative to imread, so I can get around this issue? Alternatively, if you know a way to fix imread, that would also be good.
By the way, I'm using Python 3.5.1 in Anaconda 2.4.1 (64 bit)
Upvotes: 3
Views: 2417
Reputation: 11
I also got this same error while using PIL.Image.
This error message is a bit generic and there are a lot of possibilities of what went wrong, but in my case it was a bitmap that was in fact valid and therefore should have been supported. I filed an issue on PIL's Github and they agreed it was a bug and gave me a fix. See https://github.com/python-pillow/Pillow/issues/6435 .
Hopefully the fix will be released in a future version of PIL (>= 9.3.0).
Upvotes: 1
Reputation: 195
I had been facing the same error while using PIL.Image. I bypassed the issue using cv2. My code is something like this:
import cv2 #pip install opencv-python
from PIL import Image #pip install pillow
temp_img = cv2.imread(filename.bmp)
color_corrected = cv2.cvtColor(temp_img, cv2.COLOR_BGR2RGB)
img = Image.fromarray(color_corrected)
Best of luck.
Upvotes: 1