python转图片为手绘图像

正确代码:

>>> from PIL import Image
>>> import numpy as np
>>> a = np.asarray(Image.open('D:\pictures\me.jpg').convert('L')).astype('float')
>>> depth = 10.
>>> grad = np.gradient(a)
>>> gray_x,gray_y = grad
>>> gray_x = gray_x*depth/100.
>>> gray_y = gray_y*depth/100.
>>> A = np.sqrt(gray_x**2 + gray_y**2+ 1.)
>>> uni_x = gray_x/A
>>> uni_y = gray_y/A
>>> uni_z = 1./A
>>> vec_el = np.pi/2.2
>>> vec_az = np.pi/4.
>>> dx = np.cos(vec_el)*np.cos(vec_az)
>>> dy = np.cos(vec_el)*np.sin(vec_az)
>>> dz = np.sin(vec_el)
>>> b=255*(dx*uni_x + dy*uni_y + dz*uni_z)
>>> b = b.clip(0,255)
>>> im=Image.fromarray(b.astype('uint8'))
>>> im.save('D:\pictures\meHD.jpg')

错误提示:
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 11-12: truncated
更改:
这是路径错误,在路径前加一个小写的r即可

错误提示:
Traceback (most recent call last):
File “<pyshell#1>”, line 1, in
import numpy as np
ModuleNotFoundError: No module named ‘numpy’
原因:没有安装numpy的环境

PS:运行程序前需要安装PIL和numpy环境

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值