Python: PS 滤镜--扇形变换
本文用 Python 实现 PS 滤镜中的一种几何变换特效,称为扇形变换,将图像扭曲成一个扇形,具体的算法原理和效果图可以参考以前的博客:
http://blog.csdn.net/matrix_space/article/details/46789467
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)
# control the radius of the inner circle
radius = 150
# control the distance between the inner circle and outer circle
high = 200
angle = 0
spreadAngle = math.pi
# set the center of the circle, proportion of the image size
centerX = 0.5
centerY = 1.0
row, col, channel = img.shape
icenterX = col * centerX
icenterY = row * centerY
img_out = img * 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 - icenterX
yy_dif = y_mask - icenterY
theta = np.arctan2(-yy_dif, -xx_dif+0.0001)
r = np.sqrt(xx_dif*xx_dif + yy_dif * yy_dif)
theta = np.mod(theta, 2 * math.pi)
x1_mask = col * theta/(spreadAngle+0.00001)
y1_mask = row * (1-(r-radius)/(high+0.00001))
'''
mask = x1_mask < 0
x1_mask = x1_mask * (1 - mask)
mask = x1_mask > (col - 1)
x1_mask = x1_mask * (1 - mask) + (x1_mask * 0 + col -2) * mask
mask = y1_mask < 0
y1_mask = y1_mask * (1 - mask)
mask = y1_mask > (row -1)
y1_mask = y1_mask * (1 - mask) + (y1_mask * 0 + row -2) * mask
'''
int_x = np.floor (x1_mask)
int_x = int_x.astype(int)
int_y = np.floor (y1_mask)
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 x1_mask [ii, jj] < 0 or x1_mask [ii, jj] > col -1 :
continue
if y1_mask [ii, jj] < 0 or y1_mask [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()
Python: PS 滤镜--扇形变换的更多相关文章
- Python: PS 滤镜-- 极坐标变换到平面坐标
本文用 Python 实现 PS 中的一种滤镜 极坐标变换到平面坐标,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/de ...
- Python: PS 滤镜--水波特效
本文用 Python 实现 PS 滤镜中的 水波特效 import numpy as np from skimage import img_as_float import matplotlib.pyp ...
- Python: PS 滤镜--旋涡特效
本文用Python 实现 PS 滤镜的旋涡特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/42215 ...
- Python: PS 滤镜--USM 锐化
本文用 Python 实现 PS 滤镜中的 USM 锐化效果,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...
- Python: PS 滤镜--素描
本文用 Python 实现 PS 滤镜中的素描特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/386 ...
- Python: PS 滤镜--表面模糊
本文用 Python 实现 PS 滤镜中的表面模糊,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/528 ...
- Python: PS 滤镜--旋转模糊
本文用 Python 实现 PS 滤镜中的旋转模糊,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/392 ...
- Python: PS滤镜--径向模糊
本文用 Python 实现 PS 滤镜中的径向模糊特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/3 ...
- Python: PS 滤镜--马赛克
本文利用 Python 实现PS 滤镜中的马赛克效果,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/30 ...
随机推荐
- <Sicily>Inversion Number(线段树求逆序数)
一.题目描述 There is a permutation P with n integers from 1 to n. You have to calculate its inversion num ...
- vue 中使用querySelect 封装的万能选择器
function query (el) { if (typeof el === 'string') { var selector = el; el = document.querySelector(e ...
- 编译php并与nginx整合
告诉 Nginx 如何处理 php 文件: nginx>vim conf/nginx.conf location ~ \.php${ ...
- 认识Vue组件
前言 Vue.js是一套构建用户界面的渐进式框架(官方说明).通俗点来说,Vue.js是一个轻量级的,易上手易使用的,便捷,灵活性强的前端MVVM框架.简洁的API,良好健全的中文文档,使开发者能够较 ...
- PatentTips - Virtualizing performance counters
BACKGROUND Generally, the concept of virtualization in information processing systems allows multipl ...
- 洛谷 P2440 木材加工
P2440 木材加工 题目背景 要保护环境 题目描述 题目描述: 木材厂有一些原木,现在想把这些木头切割成一些长度相同的小段木头(木头有可能有 剩余),需要得到的小段的数目是给定的.当然,我们希望得到 ...
- hbase源码系列(十二)Get、Scan在服务端是如何处理
hbase源码系列(十二)Get.Scan在服务端是如何处理? 继上一篇讲了Put和Delete之后,这一篇我们讲Get和Scan, 因为我发现这两个操作几乎是一样的过程,就像之前的Put和Del ...
- easyui combobox 设置值 顺序放在最后
easyui combobox 设置值 顺序放在最后 如果设置函数.又设置选中的值,注意顺序, 设置值需要放到最后,否则会设置了之后又没有了: $('#spanId'+i).combobox(res) ...
- abap选择屏幕上的button
1.背景:近期在看sap的一些abapDemo,看了一个比較好用的功能.分享一下.希望对用到的兄弟有帮助,主要功能是:在选择屏幕上弹出一个小窗体.放一些button在上面,触发不同button,会处理 ...
- java调用com组件将office文件转换成pdf
在非常多企业级应用中都涉及到将office图片转换成pdf进行保存或者公布的场景,由于pdf格式的文档方便进行加密和权限控制(类似于百度文库).总结起来眼下将office文件转换 成pdf的方法主要有 ...