图像的手绘效果(Python)

PIL库,Python Image Library

PIL库是一个具有强大图像处理能力的第三方库

在命令行下的安装方法:pip install pillow

from PIL import Image

image是PIL库中代表一个图像的类(对象)

from PIL import Image

import numpy as np

im = np.array(Image.open("D:/web/testsite0/images/2.jpg"))

print(im.shape,im.dtype)
(300, 597) uint8

 

from PIL import Image

import numpy as np

a = np.array(Image.open("D:/PYECourse/txshxg/fcity.jpg").convert('L'))

b = 255 -a

im = Image.fromarray(b.astype('uint8'))

im.save("D:/PYECourse/txshxg/fcity3.jpg")

from PIL import Image

import numpy as np

a = np.array(Image.open("D:/PYECourse/txshxg/fcity.jpg").convert('L'))

c = (100/255)*a + 150

im = Image.fromarray(c.astype('uint8'))

im.save("D:/PYECourse/txshxg/fcity4.jpg")

 

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
from PIL import Image
import numpy as np
a = np.asarray(Image.open("D:/PYECourse/txshxg/beijing.jpg").convert('L')).astype('float')

depth = 10.
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)
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:/PYECourse/txshxg/beijingHD.jpg")




    

原图:

转载于:https://www.cnblogs.com/kmxojer/p/11258230.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值