python---图片格式转换问题,NotImplementedError: tostring() has been removed.
2018-01-06 23:33
615 查看
python—图片格式转换问题
学习用python简单处理图片:打开\显示\保存图像:https://www.cnblogs.com/denny402/p/5096001.html
出现如下问题:
1、python—图片格式转换问题
参考:http://bbs.csdn.net/topics/320035857
2、报错信息:NotImplementedError: tostring() has been removed. Please call tobytes() instead.
参考:http://blog.csdn.net/hjxu2016/article/details/71055658
3、裁剪图片出现“SystemError: tile cannot extend outside image“错误信息。后两个数字必须比前两个大。
https://zhidao.baidu.com/question/1689969007353725628.html
参考:http://www.cnblogs.com/denny402/p/5096330.html
中”二、裁剪图片“
学习用python简单处理图片:打开\显示\保存图像:https://www.cnblogs.com/denny402/p/5096001.html
出现如下问题:
1、python—图片格式转换问题
root@kali:~/python/laowangpy/function/binzcmsyzm# python Python 2.7.3 (default, Nov 24 2017, 16:26:37) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from PIL import Image >>> import matplotlib.pyplot as plt >>> im = Image.open("11.jpg") >>> plt.figure("11") <matplotlib.figure.Figure object at 0x978746c> >>> plt.imshow(im) <matplotlib.image.AxesImage object at 0x9a1a7cc> >>> plt.show() >>> print im.size (126, 41) >>> print im.mode RGB >>> print im.format JPEG >>> im.save("33.png") >>> im = Image.open("20180106223129.png") >>> plt.figure("999") <matplotlib.figure.Figure object at 0x966516c> >>> plt.imshow(im) <matplotlib.image.AxesImage object at 0x9c5f9ec> >>> plt.show() >>> print im.size (50, 20) >>> print im.mode P >>> print im.format PNG >>> im.save("20180106223129.jpg") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/Pillow-4.4.0.dev0-py2.7-linux-i686.egg/PIL/Image.py", line 1931, in save save_handler(self, fp, filename) File "/usr/local/lib/python2.7/dist-packages/Pillow-4.4.0.dev0-py2.7-linux-i686.egg/PIL/JpegImagePlugin.py", line 607, in _save raise IOError("cannot write mode %s as JPEG" % im.mode) IOError: cannot write mode P as JPEG >>> im = im.convert("RGB") >>> im.save("20180106223129.jpg") >>>
参考:http://bbs.csdn.net/topics/320035857
2、报错信息:NotImplementedError: tostring() has been removed. Please call tobytes() instead.
>>> from PIL import Image >>> im = Image.open("timg.jpg") >>> im.show() >>> >>> import matplotlib.pyplot as plt >>> im = Image.open("timg.jpg") >>> plt.figure("timg") <matplotlib.figure.Figure object at 0x9de830c> >>> plt.imshow(im) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2377, in imshow ret = ax.imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 6796, in imshow im.set_data(X) File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 402, in set_data self._A = pil_to_array(A) File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 1260, in pil_to_array x = toarray(im) File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 1245, in toarray x_str = im.tostring('raw',im.mode,0,-1) File "/usr/local/lib/python2.7/dist-packages/Pillow-4.4.0.dev0-py2.7-linux-i686.egg/PIL/Image.py", line 738, in tostring raise NotImplementedError("tostring() has been removed. " NotImplementedError: tostring() has been removed. Please call tobytes() instead. >>>
参考:http://blog.csdn.net/hjxu2016/article/details/71055658
3、裁剪图片出现“SystemError: tile cannot extend outside image“错误信息。后两个数字必须比前两个大。
https://zhidao.baidu.com/question/1689969007353725628.html
>>> from PIL import Image >>> import matplotlib.pyplot as plt >>> img = Image.open("nv.jpg") >>> gray = img.convert("L") >>> plt.figure("beauty") <matplotlib.figure.Figure object at 0x9c6baac> >>> plt.subplot(1,2,1),plt.title("origin") (<matplotlib.axes.AxesSubplot object at 0x9c6b9cc>, <matplotlib.text.Text object at 0x993fcac>) >>> plt.imshow(img),plt.axis("off") (<matplotlib.image.AxesImage object at 0x9e9be0c>, (-0.5, 1023.5, 694.5, -0.5)) >>> box=(300,200,260,300) >>> roi=img.crop(box) >>> plt.subplot(1,2,2),plt.title("roi") (<matplotlib.axes.AxesSubplot object at 0x9a1ad4c>, <matplotlib.text.Text object at 0xa1c67ec>) >>> plt.imshow(roi),plt.axis("off") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2377, in imshow ret = ax.imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 6796, in imshow im.set_data(X) File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 402, in set_data self._A = pil_to_array(A) File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 1260, in pil_to_array x = toarray(im) File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 1245, in toarray x_str = im.tostring('raw',im.mode,0,-1) File "/usr/local/lib/python2.7/dist-packages/Pillow-4.4.0.dev0-py2.7-linux-i686.egg/PIL/Image.py", line 742, in tostring return self.tobytes() File "/usr/local/lib/python2.7/dist-packages/Pillow-4.4.0.dev0-py2.7-linux-i686.egg/PIL/Image.py", line 722, in tobytes e.setimage(self.im) SystemError: tile cannot extend outside image >>> box=(100,200,260,300) >>> roi=img.crop(box) >>> plt.subplot(1,2,2),plt.title("roi") (<matplotlib.axes.AxesSubplot object at 0x9a1ad4c>, <matplotlib.text.Text object at 0xa1c67ec>) >>> plt.imshow(roi),plt.axis("off") (<matplotlib.image.AxesImage object at 0x9c6bf8c>, (-0.5, 159.5, 99.5, -0.5)) >>> plt.show() >>>
参考:http://www.cnblogs.com/denny402/p/5096330.html
中”二、裁剪图片“
相关文章推荐
- 更新PIL库后遇到NotImplementedError: tostring() has been removed. Please call tobytes() instead
- NotImplementedError: tostring() has been removed. Please call tobytes() instead的解决办法
- 解决 NotImplementedError: fromstring() has been removed. Please call frombytes() instead.
- error: ‘std::memset’ has not been declared问题的解放办法
- python读取.mat文件时出现’NotImplementedError: Please use HDF reader for matlab v7.3 files‘问题的解决方案
- python读取.mat文件时出现’NotImplementedError: Please use HDF reader for matlab v7.3 files‘问题的解决方案
- 解决:org.apache.tomcat.jni.Error: 70023: This function has not been implemented on this platform
- 解决maven打包编译出现File encoding has not been set问题
- python图像处理问题AttributeError: 'NoneType' object has no attribute 'shape'
- SSH error:a public key file has not been specified by this session
- Application MyTest has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- ActivityManager: Warning: Activity not started, its current task has been brought to the front 的的问题
- error:The global default build tree(WINCEROOT) has not been set
- QT,error: '::ioctl' has not been declared,调用ioctl
- 编译opencv2.4.11时出现错误:error: ‘NppiGraphcutState’ has not been declared
- “Location of the Android SDK has not been set up in the preferences”问题的解决
- 解决maven打包编译出现File encoding has not been set问题
- Python 出现错误 SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform.