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環境

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章