Python实现PS滤镜Fish lens图像扭曲效果示例
作者:Matrix_11 时间:2022-02-01 05:25:02
本文实例讲述了Python实现PS滤镜Fish lens图像扭曲效果。分享给大家供大家参考,具体如下:
这里实现 PS 滤镜中的一种几何变换– Fish lens, 对图像做扭曲,感觉就像通过一个凸镜或者凹镜在观察图像一样。
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:/Visual Effects/PS Algorithm/4.jpg'
img=io.imread(file_name2)
img = img_as_float(img)
row, col, channel = img.shape
img_out = img * 1.0
R=(min(row, col)/2)
# gamma > 1 zoom in gamma < 1 zoom out
gamma = 1.5
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
r_new = R*np.power(r/R, gamma)
x_new = r_new * np.cos(theta) + center_x
y_new = center_y - r_new * 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.title('www.jb51.net')
plt.imshow (img)
plt.axis('off')
plt.figure (2)
plt.title('www.jb51.net')
plt.imshow (img_out)
plt.axis('off')
plt.show()
运行效果:
希望本文所述对大家Python程序设计有所帮助。
来源:http://blog.csdn.net/matrix_space/article/details/72301893
标签:Python,PS滤镜
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MYSQL数据库表设计与优化(二)
2010-10-25 20:12:00
python turtle绘图命令及案例
2022-04-29 10:26:58
![](https://img.aspxhome.com/file/2023/7/65907_0s.png)
Pycharm常用快捷键总结及配置方法
2023-09-24 11:15:44
![](https://img.aspxhome.com/file/2023/5/76135_0s.png)
PyTorch如何创建自己的数据集
2022-10-17 05:22:17
![](https://img.aspxhome.com/file/2023/1/90281_0s.png)
python3的pip路径在哪
2023-01-27 14:15:39
SQL Server技巧之快速得到表的记录总数
2011-01-04 14:36:00
![](https://img.aspxhome.com/file/UploadPic/20111/20111420216938s.jpg)
django实现后台显示媒体文件
2023-07-26 15:03:23
整理Python中常用的conda命令操作
2022-07-17 16:53:33
![](https://img.aspxhome.com/file/2023/6/84986_0s.png)
Python爬虫获取op.gg英雄联盟英雄对位胜率的源码
2024-01-02 13:03:52
![](https://img.aspxhome.com/file/2023/3/83933_0s.png)
无法远程登入MySQL数据库的几种解决办法
2012-04-13 11:57:41
python 使用第三方库requests-toolbelt 上传文件流的示例
2021-05-13 05:48:31
![](https://img.aspxhome.com/file/2023/2/94002_0s.png)
通过python下载FTP上的文件夹的实现代码
2022-03-16 11:19:12
ASP3.0中的流控制能力
2008-10-19 17:41:00
用JAVASCRIPT格式化数字成货币(逗号隔开)
2008-01-30 12:34:00
SQL Server数据库触发器安全隐患解析
2009-03-25 12:56:00
登录与注册两者的距离
2009-01-02 16:48:00
![](https://img.aspxhome.com/file/UploadPic/20091/2/xanyou1-36s.png)
Python算法输出1-9数组形成的结果为100的所有运算式
2022-05-02 22:45:48
Python在Matplotlib图中显示中文字体的操作方法
2023-03-30 00:29:54
Python单例模式实例分析
2023-11-26 03:22:52
python3实现网页版raspberry pi(树莓派)小车控制
2021-05-05 05:35:18
![](https://img.aspxhome.com/file/2023/3/101283_0s.jpg)