from PIL import Image
import numpy as np
import os
import cv2 as cv
def mulhanpicture(path):
filelist = os.listdir(path)
for item in filelist:
if item.endswith('.png') or item.endswith('.jpg'):
item = path + '/' + item
item_save = item[:-4] + '_hand' + item[-4:]
a = np.asarray(Image.open(item,).convert('L')).astype('float')
depth = 5 #改值可改变程度(0-100)
grad = np.gradient(a)
grad_x,grad_y = grad
grad_x = grad_x*depth/100.0
grad_y = grad_y*depth/100.0
A = np.sqrt(grad_x**2+grad_y**2+1.0)
unix = grad_x/A
uniy = grad_y/A
uniz = 1.0/A
vecaz = np.pi/2.2
vecel = np.pi/4.0
dx = np.cos(vecel)*np.cos(vecaz)
dy = np.cos(vecel)*np.sin(vecaz)
dz = np.sin(vecel)
b = 255*(dx*unix+dy*uniy+dz*uniz)
b = b.clip(0,255)
im = Image.fromarray(b.astype('uint8'))
im.show()
cv.waitKey(30)
im.save(item_save)
mulhanpicture('F:\picture2')
来源:CSDN
作者:why you so
链接:https://blog.csdn.net/qq_38650447/article/details/103651751