求助.python使用matplotlib出错

ChaoticNg 2017-11-15 09:29:30
from PIL import Image
import matplotlib.pyplot as plt


pil_im = Image.open('d:/1.jpg').convert('L')

plt.figure("gray")

plt.imshow(pil_im)

plt.show()


提示一堆最后: AttributeError: 'numpy.ndarray' object has no attribute 'mask'
...全文
679 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_42097515 2019-08-22
  • 打赏
  • 举报
回复
楼主,我遇到和您一样的问题,我用这种办法,没有解决,还有别的方法?谢谢楼主的回答,如果可能的话,可不可以把解决思路和办法发到2782762830@qq.com,谢谢楼主。
以下是程序:
def load_image(depth_name):
y = []
for filename in os.listdir(r"./" + depth_name):
depthM = cv2.imread(depth_name + "/" + filename)
# depthM1=np.array(depthM)
# depthM1 = depthM.shape
depthM = Image.open(depth_name + "/" + filename)
depthM = depthM.convert('1')
depthM = np.array(depthM.getdata(), dtype=np.uint8)
# depthM = np.array(depthM.getdata(),dtype='float')
y.append(depthM)
y = np.vstack(y)
print(y.shape)
# print(y.shape)
return y

for m in range(4):

#测试集输出
outimage=self.ae.predict([x_test,y_test])
#查看outimage数据格式
outimage=np.array(outimage)
print("outimage:",outimage.shape)
outimage = outimage[0,:,:]
print("outimage1:",outimage.shape)
outimage = outimage[m,:]
print("输出图形的大小:",outimage.shape)
# outimage = outimage.reshape((100,150))
# print("输出重新转化后的图形:",outimage.shape)
#输出图像
outimage_min=outimage.min(0)
outimage_max=outimage.max(0)
print("最小值:",outimage_min)
print("最大值:",outimage_max)
ranges=outimage_max-outimage_min
norm_image=np.zeros(np.shape(outimage))
print("norm_image:",norm_image.shape)
n=outimage.shape[0]
norm_image=outimage-np.tile(outimage_min,(1,n))
norm_image=norm_image/np.tile(ranges,(1,n))
#print("修改后的norm_image:",norm_image.shape)
#norm_image.shape=(1,15000)
norm_image=norm_image.astype("uint8")
norm_image=norm_image.reshape(100,150)
print("修改后的norm_image:",norm_image.shape)
show_image=Image.fromarray(norm_image)
plt.subplot(2,2,m+1)
plt.imshow(show_image)
plt.show()
plt.close()
# plt.imshow(show_image)
ChaoticNg 2017-11-15
  • 打赏
  • 举报
回复
from PIL import Image import matplotlib.pyplot as plt img=Image.open('d:/1.jpg').convert("1") plt.figure("dog") plt.imshow(img) plt.show() 已解决, 灰度模式改成二值图像"1" 就可以了
手无护鸡之力 2017-11-15
  • 打赏
  • 举报
回复
你装numpy了没

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧