这里是通过使用numpy.array数组来对图像进行处理。 这里是代码: from PIL import Image import numpy as np a = np.array(Image.open(“F:/a.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_e1 = np.pi / 2.2 #光源的俯视角度,弧度值 vec_az = np.pi / 4 #光源的方位角度,弧度值 dx = np.cos(vec_e1) * np.cos(vec_az) #光源对x轴的影响 dy = np.cos(vec_e1) * np.sin(vec_az) #光源对y轴的影响 dz = np.sin(vec_e1) #光源对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(‘F:/b.jpg’) 原图: 下面是效果图:
Python将彩色图像修改为手绘图像
Hobby lead creation, technology change world.
- Post link: 460.html
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.