python素描照片

#!/usr/bin/python
# -*- coding: utf-8 -*-
from PIL import Image
import numpy as np
 
a = np.asarray(Image.open("/root/1.jpg").convert('L')).astype('float')
 
depth = 10.                      # (0-100)
grad = np.gradient(a)             #取图像灰度的梯度值
grad_x, grad_y =grad               #分别取横纵图像梯度值
grad_x = grad_x*depth/100.
grad_y = grad_y*depth/100.
A = np.sqrt(grad_x**2 + grad_y**2 + 1.)
uni_x = grad_x/A
uni_y = grad_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)   #光源对x 轴的影响
dy = np.cos(vec_el)*np.sin(vec_az)   #光源对y 轴的影响
dz = np.sin(vec_el)              #光源对z 轴的影响
 
b = 255*(dx*uni_x + dy*uni_y + dz*uni_z)     #光源归一化
b = b.clip(0,255)
 
im = Image.fromarray(b.astype('uint8'))  #重构图像
im.save("/root/123.jpg")
print("保存成功查看")
报错1:-bash: pip: command not found
         wget https://bootstrap.pypa.io/get-pip.py
         python get-pip.py
报错2:from PIL import Image, ImageFilter,ImageOps
         pip install pillow
         ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
         pip install -i https://pypi.douban.com/simple pillow
报错3:ImportError: No module named numpy
           ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy
        pip install -i https://pypi.douban.com/simple numpy

  

windows安装插件:
        下载安装pip:https://pypi.org/project/pip/#modal-close
         win+r--->cmd
         python setup.py install
         pip install pillow/pip install -i https://pypi.douban.com/simple pillow(报超时执行后面这条)

     pip install numpy(安装numpy和安装pillow一样)
from PIL import Image
import numpy as np
 
a = np.asarray(Image.open("E:/picture/1.png").convert('L')).astype('float')
 
depth = 10.                      # (0-100)
grad = np.gradient(a)             #取图像灰度的梯度值
grad_x, grad_y =grad               #分别取横纵图像梯度值
grad_x = grad_x*depth/100.
grad_y = grad_y*depth/100.
A = np.sqrt(grad_x**2 + grad_y**2 + 1.)
uni_x = grad_x/A
uni_y = grad_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)   #光源对x 轴的影响
dy = np.cos(vec_el)*np.sin(vec_az)   #光源对y 轴的影响
dz = np.sin(vec_el)              #光源对z 轴的影响
 
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:/123.jpg")
print("保存成功查看")

  

  

  

posted @ 2020-04-21 13:26  MlxgzZ  阅读(211)  评论(0编辑  收藏  举报