数据分析与展示--图像杏彩平台制作的手绘效果(实例)

图像一般是使用RGB模式杏彩平台制作QQ2952777280【话仙源码论坛】hxforum.com【木瓜源码论坛】papayabbs.com ,是一个三色数组

PIL库

from PIL import Image
import numpy as np
im = np.array(Image.open("ZSC.jpg"))
print(im.shape,im.dtype)
print(im)
图像变化(相反)

复制代码
from PIL import Image
import numpy as np
a = np.array(Image.open("timg.jpg"))
print(a.shape,a.dtype)
b = [255,255,255] - a
im = Image.fromarray(b.astype('uint8'))
im.save('untimg.jpg')
复制代码
图像变化(灰度)

复制代码
from PIL import Image
import numpy as np
a = np.array(Image.open("timg.jpg").convert('L'))
print(a.shape,a.dtype)
b = 255 - a
im = Image.fromarray(b.astype('uint8'))
im.save('huitimg.jpg')
复制代码
图像变化(色彩变淡)

复制代码
from PIL import Image
import numpy as np
a = np.array(Image.open("timg.jpg"))
print(a.shape,a.dtype)
b = (100/255)*a +150
im = Image.fromarray(b.astype('uint8'))
im.save('jujitimg.jpg')
复制代码
图像变化(色彩变深)

复制代码
from PIL import Image
import numpy as np
a = np.array(Image.open("timg.jpg"))
print(a.shape,a.dtype)
b = 255*(a/255)**2
im = Image.fromarray(b.astype('uint8'))
im.save('liangtimg.jpg')
复制代码

图像的手绘效果

手绘特点:

1.黑白灰色系

2.边界较重

3.相同相近的色彩趋近白色

4.有光源

复制代码
from PIL import Image
import numpy as np
a = np.asarray(Image.open('shouhui.jpg').convert('L')).astype('float')

depth = 10.
grad = np.gradient(a) #取图像灰度的梯度值
grad_x,grad_y = grad #分别取横纵图像梯度值
grad_x = grad_xdepth/100. #深度值方向梯度值/范围
grad_y = grad_y*depth/100.
A = np.sqrt(grad_x2 + grad_y2 + 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) #此处np.cos(vec_el)单位光源在地平面上的投影长度
dy = np.cos(vec_el)
np.sin(vec_az) #xyz是光源对三个方向的影响程度
dz = np.sin(vec_el)

b = 255(dxuni_x + dyuni_y + dzuni_z) #梯度与光源互相作用
b = b.clip(0,255) #处理超过255的像素

im = Image.fromarray(b.astype('uint8'))
im.save('sou.jpg')

猜你喜欢

转载自blog.51cto.com/13889009/2150553