Python 实现PS滤镜的旋涡特效

作者:未雨愁眸 时间:2022-03-03 02:53:52 

实现效果:

Python 实现PS滤镜的旋涡特效

实现代码


import numpy as np
from skimage import img_as_float
import matplotlib.pyplot as plt
from skimage import io
import math
import numpy.matlib

file_name2='D:/2020121173119242.png'    # 图片路径
img=io.imread(file_name2)

img = img_as_float(img)

row, col, channel = img.shape
img_out = img * 1.0
degree = 70

center_x = (col-1)/2.0
center_y = (row-1)/2.0

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)

xx_dif = x_mask - center_x
yy_dif = center_y - y_mask

r = np.sqrt(xx_dif * xx_dif + yy_dif * yy_dif)

theta = np.arctan(yy_dif / xx_dif)

mask_1 = xx_dif < 0
theta = theta * (1 - mask_1) + (theta + math.pi) * mask_1

theta = theta + r/degree

x_new = r * np.cos(theta) + center_x
y_new = center_y - r * np.sin(theta)

int_x = np.floor (x_new)
int_x = int_x.astype(int)
int_y = np.floor (y_new)
int_y = int_y.astype(int)

for ii in range(row):
 for jj in range (col):
   new_xx = int_x [ii, jj]
   new_yy = int_y [ii, jj]

if x_new [ii, jj] < 0 or x_new [ii, jj] > col -1 :
     continue
   if y_new [ii, jj] < 0 or y_new [ii, jj] > row -1 :
     continue

img_out[ii, jj, :] = img[new_yy, new_xx, :]

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/9412156.html

标签:python,ps滤镜,漩涡
0
投稿

猜你喜欢

  • 基于OpenCV的PHP图像人脸识别技术

    2023-11-23 22:02:54
  • 索引的原理及索引建立的注意事项

    2012-08-21 10:27:47
  • 简单form标准化实例——整体布局

    2007-05-11 17:04:00
  • SQL Server 交叉表查询 case

    2012-01-05 19:31:38
  • PHPStudy hosts文件可能不存在或被阻止打开及同步hosts失败问题

    2023-06-08 10:29:10
  • python matplotlib 画dataframe的时间序列图实例

    2023-05-17 00:12:34
  • PHP基于非递归算法实现先序、中序及后序遍历二叉树操作示例

    2023-08-16 04:46:47
  • 电商网站的购买按钮

    2011-07-04 12:18:59
  • Response.Flush的用法

    2010-04-08 12:54:00
  • 数据库基础:MySQL 添加用户的两种方法

    2009-05-07 14:26:00
  • 如何在js中使用FileSystemObject(fso)

    2007-09-23 09:10:00
  • 回顾Javascript React基础

    2023-07-13 00:57:00
  • 简单实用的图片播放器1.0(Javascript + css )

    2008-07-16 10:39:00
  • php中$_GET与$_POST过滤sql注入的方法

    2023-07-13 14:38:12
  • 简述php环境搭建与配置

    2023-11-15 09:08:28
  • 讲解SQL Server2005数据项的分拆与合并

    2009-01-04 14:40:00
  • 一空间多域名绑定不同目录方法

    2009-03-09 18:32:00
  • asp如何设定程序的执行次数?

    2010-05-18 18:31:00
  • Python 自由定制表格的实现示例

    2023-11-11 16:54:41
  • 让IE6更快的走向灭亡

    2010-02-03 15:05:00
  • asp之家 网络编程 m.aspxhome.com