Bug #4237
closedpillow uses frombytes not fromstring to read from buffer
Added by Anchi Cheng over 8 years ago. Updated over 8 years ago.
0%
Description
fromstring and tostring are deprecated in newer version. However CentOS 6 default version is 1.1.6 that still uses the old attributes
Updated by Gabriel Lander over 8 years ago
added Anchi's code to check for availability of fromstring
r19854
Updated by Anchi Cheng over 8 years ago
Image.tobytes does not exists if frombytes does not exist, though. You will need to check and handle that, too.
Updated by Gabriel Lander over 8 years ago
Thanks for noticing that. added a check for tostring as well.
r19855
Updated by Gabriel Lander over 8 years ago
turns out Image doesn't contain tobytes, had to switch this back.
r19860
Updated by Anchi Cheng over 8 years ago
Gabe,
Actually, normarray and rgbarray are numpy array and should use tostring. However, the tostring case in setBitmap is inside the case "isinstance(self.imagedata, Image.Image)", I would think that does need to be changed to tobytes for your version of PIL or PILLOW.
You probably will get an error If you run
python leginon/gui/wx/TargetPanel.py some.jpg,
Updated by Gabriel Lander over 8 years ago
Hi Anchi, you're absolutely right, this doesn't work. What a mess.
Should I just use a try/except? How many places does this need to be changed?
elif im.mode == 'RGB':
try:
s = im.tostring()
except:
s = im.tobytes()
a = numpy.fromstring(s, numpy.uint8)
shape = shape + (3,)
Updated by Anchi Cheng over 8 years ago
- Related to Bug #4252: manualmasker.py got an recursion depth exceeded error from numpil.fromstring while saving mask to png format added
Updated by Anchi Cheng over 8 years ago
- Status changed from Assigned to In Code Review
Gabe,
I think I have covered all the ones you have not changed and made them compatible to our version of PIL. Please check and make sure they work for you.
Updated by Alex Noble over 8 years ago
Hi everyone,
I updated my myami before the weekend and now the videos in Appion-Protomo all fail to be created. scipy.misc.imsave and scipy.misc.toimage both fail, the latter spews out a bunch of numpil.py errors. From my research (google), both functions use PIL to alter/generate images from arrays. The traceback is about a thousand lines of numpil errors followed by a max recursion error:
File "/panfs/storage.local/imb/home/ajn10d/myami3/pyami/numpil.py", line 143, in fromstring
return getattr(Image, getPilFromStringFuncName())(data,decoder_name, *args)
File "/panfs/storage.local/imb/home/ajn10d/myami3/pyami/numpil.py", line 143, in fromstring
return getattr(Image, getPilFromStringFuncName())(data,decoder_name, *args)
.
.
.
File "/panfs/storage.local/imb/home/ajn10d/myami3/pyami/numpil.py", line 143, in fromstring
return getattr(Image, getPilFromStringFuncName())(data,decoder_name, *args)
File "/panfs/storage.local/imb/home/ajn10d/myami3/pyami/numpil.py", line 143, in fromstring
return getattr(Image, getPilFromStringFuncName())(data,decoder_name, *args)
File "/panfs/storage.local/imb/home/ajn10d/myami3/pyami/numpil.py", line 131, in getPilFromStringFuncName
im = Image.new('1', (1,1))
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 1801, in new
return Image()._new(core.fill(mode, size, color))
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 462, in _new
new = Image()
RuntimeError: maximum recursion depth exceeded
I haven't found another way yet to save a 2D float32 numpy array to png, and the scipy.misc.toimage cmin and cmax options are critical to my reconstruction videos.
Does anybody have any suggestions? This Scipy functionality is critical for Appion-Protomo; I have 2 in-house users who were trying to run alignments over the weekend and today but they're not able to view results because the videos can't be made. So this is currently making it so that my colleagues cannot do the work that they need to do.
Updated by Alex Noble over 8 years ago
Added watchers. I updated the issue before adding watchers. Please read Update #9.
Updated by Anchi Cheng over 8 years ago
See Issue #4252. I can not test this because it works at NYSBC.
Updated by Carl Negro over 8 years ago
Reported by Yong Zi using manual picker at NYSBC, which is on the myami-beta branch. Is this because we need to merge some changes between myami-trunk and myami-beta?
Beginning Main Loop
!!! DEBUG: _startLoop imagecount=405, count=0
... Pixel size: 1.54
... reading filtered image from mrc file
Traceback (most recent call last):
File "/opt/myamisnap/bin/manualpicker.py", line 733, in <module>
imgLoop.run()
File "/opt/myamisnap/lib/appionlib/appionLoop2.py", line 88, in run
results = self.loopProcessImage(imgdata)
File "/opt/myamisnap/lib/appionlib/particleLoop2.py", line 101, in loopProcessImage
self.peaktree = filterLoop.FilterLoop.loopProcessImage(self, imgdata)
File "/opt/myamisnap/lib/appionlib/filterLoop.py", line 84, in loopProcessImage
peaktree = self.processImage(imgdata, self.filtarray)
File "/opt/myamisnap/bin/manualpicker.py", line 484, in processImage
peaktree = self.runManualPicker(imgdata)
File "/opt/myamisnap/bin/manualpicker.py", line 651, in runManualPicker
self.app.panel.openImageFile(imgpath)
File "/opt/myamisnap/bin/manualpicker.py", line 63, in openImageFile
self.setImage(image.astype(numpy.float32))
File "/opt/myamisnap/lib/leginon/gui/wx/ImagePanel.py", line 322, in setImage
self.setNumericImage(imagedata)
File "/opt/myamisnap/lib/leginon/gui/wx/ImagePanel.py", line 410, in setNumericImage
self.setBitmap()
File "/opt/myamisnap/lib/leginon/gui/wx/ImagePanel.py", line 191, in setBitmap
wximage = self.numpyToWxImage(self.imagedata)
File "/opt/myamisnap/lib/leginon/gui/wx/ImagePanel.py", line 226, in numpyToWxImage
imagedata = Image.fromstring("L", (w, h), normarray.tostring())
File "/usr/lib64/python2.6/site-packages/PIL/Image.py", line 2080, in fromstring
"Please call frombytes() instead.")
NotImplementedError: fromstring() has been removed. Please call frombytes() instead.
Updated by Anchi Cheng over 8 years ago
Will be a good one to ask Scot and Gabe together if it was resolved between the two.
Updated by Gabriel Lander over 8 years ago
we're still getting these errors, it would be great if we could solve this once and for all now that we're all together.
Updated by Gabriel Lander over 8 years ago
- Status changed from In Code Review to Closed