本文实例讲述了Python实现PS滤镜特效之扇形变换效果。分享给大家供大家参考,具体如下:

这里用 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:/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.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()

附录:PS 滤镜— —扇形warp

clc;

clear all;

close all;

addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');

I=imread('4.jpg');

I=double(I);

Image=I/255;

[height, width, depth]=size(Image);

% set the parameters

radius = 150; % control the radius of the inner circle

high = 200; % control the distance between the inner circle and outer circle

angle = 0;

spreadAngle=pi;

centerX = 0.5; % set the center of the circle, proportion of the image size

centerY = 1.0;

icenterX=width*centerX;

icenterY=height*centerY;

Image_new=Image*0;

for i=1:height

for j=1:width

dx=j-icenterX;

dy=i-icenterY;

theta=atan2(-dy, -dx)+angle;

r=sqrt(dy*dy+dx*dx);

theta=mod(theta, 2*pi);

x=width * theta/(spreadAngle+0.00001);

y=height * (1-(r-radius)/(high+0.00001));

% % if (x<=1) x=1; end

% % if (x>=width) x=width-1; end;

% % if (y>=height) y=height-1; end;

% % if (y<1) y=1; end;

% %

if (x<=1) continue; end

if (x>=width) continue; end;

if (y>=height) continue; end;

if (y<1) continue; end;

x1=floor(x);

y1=floor(y);

p=x-x1;

q=y-y1;

Image_new(i,j,:)=(1-p)*(1-q)*Image(y1,x1,:)+p*(1-q)*Image(y1,x1+1,:)...

+q*(1-p)*Image(y1+1,x1,:)+p*q*Image(y1+1,x1+1,:);

end

end

imshow(Image_new)

imwrite(Image_new, 'out.jpg');

本例Python运行效果:

原图

效果图

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

您可能感兴趣的文章:

Python实现PS滤镜中马赛克效果示例

Python实现PS滤镜的旋转模糊功能示例

Python实现PS滤镜碎片特效功能示例

Python实现PS滤镜功能之波浪特效示例

Python实现PS滤镜的万花筒效果示例

Python实现PS图像调整黑白效果示例

Python实现PS图像调整颜色梯度效果示例

Python实现PS图像明亮度调整效果示例

Python实现PS图像抽象画风效果的方法

Python tkinter实现的图片移动碰撞动画效果【附源码下载】

Python利用matplotlib生成图片背景及图例透明的效果

python通过pil将图片转换成黑白效果的方法

时间: 2018-01-24

python 画三角形matli_Python实现PS滤镜特效之扇形变换效果示例相关推荐

  1. python绘制立体扇形_Python实现PS滤镜特效之扇形变换效果示例

    本文实例讲述了Python实现PS滤镜特效之扇形变换效果.分享给大家供大家参考,具体如下: 这里用 Python 实现 PS 滤镜中的一种几何变换特效,称为扇形变换,将图像扭曲成一个扇形,具体的算法原 ...

  2. python 画三角形matli_Python实现PS滤镜特效Marble Filter玻璃条纹扭曲效果示例

    本文实例讲述了Python实现PS滤镜特效Marble Filter玻璃条纹扭曲效果.分享给大家供大家参考,具体如下: 这里用 Python 实现 PS 滤镜特效,Marble Filter, 这种滤 ...

  3. python 画三角形matli_python 实现波浪滤镜特效

    本文用 Python 实现 PS 滤镜的波浪特效 import numpy as np from skimage import img_as_float import matplotlib.pyplo ...

  4. Python实现PS滤镜Fish lens图像扭曲效果示例

    Python实现PS滤镜Fish lens图像扭曲效果 这篇文章主要介绍了Python实现PS滤镜Fish lens图像扭曲效果,结合实例形式分析了Python实现PS滤镜的图像扭曲效果相关操作技巧 ...

  5. python 艺术照片滤镜_Python实现PS滤镜Fish lens图像扭曲效果示例

    本文实例讲述了Python实现PS滤镜Fish lens图像扭曲效果.分享给大家供大家参考,具体如下: 这里实现 PS 滤镜中的一种几何变换– Fish lens, 对图像做扭曲,感觉就像通过一个凸镜 ...

  6. python 艺术照片滤镜_[宜配屋]听图阁 - Python实现PS滤镜Fish lens图像扭曲效果示例...

    本文实例讲述了Python实现PS滤镜Fish lens图像扭曲效果.分享给大家供大家参考,具体如下: 这里实现 PS 滤镜中的一种几何变换– Fish lens, 对图像做扭曲,感觉就像通过一个凸镜 ...

  7. Python: PS 滤镜特效 -- Marble Filter

    本文用 Python 实现 PS 滤镜特效,Marble Filter, 这种滤镜使图像产生不规则的扭曲,看起来像某种玻璃条纹, 具体的代码如下: import numpy as np import ...

  8. python怎么画波浪_python 实现波浪滤镜特效

    本文用 Python 实现 PS 滤镜的波浪特效 import numpy as np from skimage import img_as_float import matplotlib.pyplo ...

  9. python图片马赛克_Python实现PS滤镜中马赛克效果示例

    本文实例讲述了Python实现PS滤镜中马赛克效果.分享给大家供大家参考,具体如下: 这里利用 Python 实现PS 滤镜中的马赛克效果,具体的算法原理和效果可以参考附录说明,Python示例代码如 ...

  10. python画三角形并涂色_如何用python画叠加三角形?

    python中可以使用下面的程序实现画叠加三角形:import turtle def drawTriangle(num,len,flag):#flag用来调整画三角形的方向 flag*=-1 len/ ...

最新文章

  1. 网页鼠标滚动实现图片缩放
  2. 《数据库SQL实战》查找薪水涨幅超过15次的员工号emp_no以及其对应的涨幅次数t
  3. java语言基础与go语言基础,数据类型区别
  4. 第一个正式的python版本_LeetCode | 0278. First Bad Version第一个错误的版本【Python】...
  5. 【LeetCode】【HOT】21. 合并两个有序链表(递归)
  6. mac 下php,Mac 下 PHP
  7. Git 将本地的一个分支上的代码合并到本地的另一个分支
  8. 蓝桥杯---等差数列(C语言)
  9. Spring Cloud微服务下的权限架构调研
  10. mysql 61错误解决方法
  11. 【vue】--路由解耦 传值的方式
  12. ASP.NET-第八天-加强课程
  13. kmo检验和bartlett球形检验_互助问答59期:多期DID平行趋势检验以及因子分析累计方差贡献率...
  14. Ubuntu20.04 安装在U盘上
  15. SolidWorks的发展历史(1994~2007)
  16. 计算机网络管理员操作技能考试试卷操作,计算机网络管理员高级工操作技能考核试卷(第一套)...
  17. OSChina 周六乱弹 —— 飞机上飞离太阳那么近晒黑了不是很正常吗
  18. 高光谱图像算法实习工程师面经
  19. PS证件照排版计算器
  20. 计算机电源MOD,电源全模组和非模组究竟有什么区别?

热门文章

  1. 华为系统升级提示服务器不可用怎么办,更新服务器不可用
  2. latex全文设置段间距_latex 标题、段落及行距
  3. Atitit 档案学 档案管理 attilax学习总结
  4. 什么是PLC软元件和软继电器
  5. nginx 配置https 负载均衡
  6. 【实验】基于朴素贝叶斯的新闻分类
  7. 大一期末计算机考试评分标准,大学生平时成绩考核评价标准
  8. 假设你毕业后有两个选择:一个是在某处找工作,另一个是自己创业。你要做决定。写一篇文章解释你的决定的理由
  9. 架构系列---QR二维码和扫描二维码登陆原理
  10. 使用FFmpeg命令合并音视频