Python 实现PS滤镜中的径向模糊特效
作者:未雨愁眸 时间:2023-11-04 19:48:49
实现效果
实现代码
from skimage import img_as_float
import matplotlib.pyplot as plt
from skimage import io
import numpy as np
import numpy.matlib
file_name='D:/2020121173119242.png' # 图片路径
img=io.imread(file_name)
img = img_as_float(img)
img_out = img.copy()
row, col, channel = img.shape
xx = np.arange (col)
yy = np.arange (row)
x_mask = numpy.matlib.repmat (xx, row, 1)
y_mask = numpy.matlib.repmat (yy, col, 1)
y_mask = np.transpose(y_mask)
center_y = (row -1) / 2.0
center_x = (col -1) / 2.0
R = np.sqrt((x_mask - center_x) **2 + (y_mask - center_y) ** 2)
angle = np.arctan2(y_mask - center_y , x_mask - center_x)
Num = 20
arr = np.arange(Num)
for i in range (row):
for j in range (col):
R_arr = R[i, j] - arr
R_arr[R_arr < 0] = 0
new_x = R_arr * np.cos(angle[i,j]) + center_x
new_y = R_arr * np.sin(angle[i,j]) + center_y
int_x = new_x.astype(int)
int_y = new_y.astype(int)
int_x[int_x > col-1] = col - 1
int_x[int_x < 0] = 0
int_y[int_y < 0] = 0
int_y[int_y > row -1] = row -1
img_out[i,j,0] = img[int_y, int_x, 0].sum()/Num
img_out[i,j,1] = img[int_y, int_x, 1].sum()/Num
img_out[i,j,2] = img[int_y, int_x, 2].sum()/Num
plt.figure(1)
plt.imshow(img)
plt.axis('off')
plt.figure(2)
plt.imshow(img_out)
plt.axis('off')
plt.show()
来源:https://www.cnblogs.com/mtcnn/p/9412386.html
标签:python,ps滤镜,径向模糊


猜你喜欢
讲述SQL Server数据转换服务小妙招
2010-07-26 14:43:00
Python argparse模块使用方法解析
2022-10-12 10:58:57
Flask和Django框架中自定义模型类的表名、父类相关问题分析
2022-04-04 00:23:17
用Python展示动态规则法用以解决重叠子问题的示例
2023-02-09 02:20:36

Vue中的基础过渡动画及实现原理解析
2024-06-05 15:28:24

5个有效改进网页UI设计的技巧
2008-12-19 12:04:00

mysql递归函数with recursive的用法举例
2024-01-16 22:37:22
深入解析Python编程中JSON模块的使用
2022-11-30 00:21:27
兼容firefox的给每一个onClick再附加一个事件
2023-08-24 18:29:47
MySQL优化之数据表的处理
2008-12-22 14:45:00
python导入坐标点的具体操作
2023-02-24 19:59:46

MYSQL5.6.33数据库主从(Master/Slave)同步安装与配置详解(Master-Linux Slave-windows7)
2024-01-17 00:23:34

js constructor的实际作用分析
2024-02-25 01:41:31
Python深度学习pytorch实现图像分类数据集
2023-07-05 01:50:58

使用ASP常见问题解答
2007-10-11 14:07:00
《色彩解答》系列之一 色彩层次
2008-02-17 14:26:00

破解空间实现域名绑定到子目录方法
2010-03-14 11:29:00
sql2005 远程连接问题解决方法
2024-01-19 13:37:42
又为ajax上传工具重新写了一个服务器端上传程序
2009-12-21 14:30:00
Python判断字符串是否为合法标示符操作
2023-09-28 18:49:01