待解决: from scipy.misc import imread 报错ImportError: cannot import name 'imread' 及 词云图片模糊问题

词云制作时,报错
from scipy.misc import imread ImportError: cannot import name ‘imread’

解决
网上查资料得知
scipy已经将imread等命令删除,官方文档中有说明“Functions from scipy.interpolate (spleval, spline, splmake, and spltopp) and functions from scipy.misc (bytescale, fromimage, imfilter, imread, imresize, imrotate, imsave, imshow, toimage) have been removed. The former set has been deprecated since v0.19.0 and the latter has been deprecated since v1.0.0. ”
scipy库中的imread要被弃用。将from scipy.misc import imread改成from imageio import imread后,报错消失。
(参考: https://blog.csdn.net/qq_44981134/article/details/90210406)
(另有解决方法待验证: https://blog.csdn.net/GFChong/article/details/91520270)
(另收藏:【超分辨率】各种python图像库的图片读取方法总结 -
https://blog.csdn.net/TeFuirnever/article/details/90896239)

代码段

#WordCloud.py

import jieba
import wordcloud
from imageio import imread

mk=imread("chinamap.jpg")
f=open("新时代中国特色社会主义.txt","r",encoding="utf-8")
t=f.read()
f.close()
ls=jieba.lcut(t)
txt=" ".join(ls)
w=wordcloud.WordCloud(font_path="msyh.ttc",mask=mk,\
                      width=1000,height=700,background_color='white'\
                      )
w.generate(txt)
w.to_file("wordcloud.jpg")

待解决:
使用图片:
待解决: from scipy.misc import imread 报错ImportError: cannot import name 'imread' 及 词云图片模糊问题_第1张图片
生成词云图片时,未得到目标地图形状效果且模糊不清:
待解决: from scipy.misc import imread 报错ImportError: cannot import name 'imread' 及 词云图片模糊问题_第2张图片
可能是选取图片的问题???
图片应为背景透明,内部形状不透明(仅猜想)

更换图片为:
待解决: from scipy.misc import imread 报错ImportError: cannot import name 'imread' 及 词云图片模糊问题_第3张图片
生成词云图片成功:
待解决: from scipy.misc import imread 报错ImportError: cannot import name 'imread' 及 词云图片模糊问题_第4张图片

更换图片为:
待解决: from scipy.misc import imread 报错ImportError: cannot import name 'imread' 及 词云图片模糊问题_第5张图片
生成词云图片成功:
待解决: from scipy.misc import imread 报错ImportError: cannot import name 'imread' 及 词云图片模糊问题_第6张图片
图片很模糊,需进一步优化,如何优化???

你可能感兴趣的:(Python,报错)