本文实例讲述了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.ddpool.cn')

plt.imshow (img)

plt.axis('off')

plt.figure (2)

plt.title('www.ddpool.cn')

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');

参考来源:http://www.jhlabs.com/index.html

本例Python运行效果:

原图

效果图

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

python绘制立体扇形_Python实现PS滤镜特效之扇形变换效果示例相关推荐

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

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

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

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

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

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

  4. python图片旋转脚本_Python实现PS滤镜的旋转模糊功能示例

    本文实例讲述了Python实现PS滤镜的旋转模糊功能.分享给大家供大家参考,具体如下: 这里用 Python 实现 PS 滤镜中的旋转模糊,具体的算法原理和效果可以参考附录相关介绍.Python代码如 ...

  5. python做万花筒代码_Python实现PS滤镜的万花筒效果示例

    本文实例讲述了Python实现PS滤镜的万花筒效果.分享给大家供大家参考,具体如下: 这里用 Python 实现 PS 的一种滤镜效果,称为万花筒.也是对图像做各种扭曲变换,最后图像呈现的效果就像从万 ...

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

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

  7. python 调整灰度图像对比度_Python实现PS图像调整之对比度调整功能示例

    本文实例讲述了Python实现PS图像调整之对比度调整功能.分享给大家供大家参考,具体如下: 这里用 Python 实现 PS 里的图像调整–对比度调整.具体的算法原理如下: (1).nRGB = R ...

  8. python绘制像素图_Python用61行代码实现图片像素化的示例代码

    起因 看到网上的像素图片,感觉蛮有趣的,就打算用python一些PIL类库写一个. 实现思路 把一张图片分成多个块,每个块的颜色都等于这个色块中颜色最多的颜色,如下图. 这个图取2×2的像素为块的大小 ...

  9. python 视频滤镜_Python实现PS滤镜功能之波浪特效示例

    本文实例讲述了Python实现PS滤镜功能之波浪特效.分享给大家供大家参考,具体如下: 这里用 Python 实现 PS 滤镜的波浪特效,具体效果可以参考附录说明 import numpy as np ...

最新文章

  1. kingadmin页面开发
  2. ubuntu16.04安装新版本golang
  3. 关于git fetch 和git pull 的区别
  4. python 怎么验证是否安装成功 scrapy
  5. android apk如何入门
  6. 如何编写数据库可视化界面_编写用于数据可视化的替代文本
  7. Java中的XSL转换:一种简单的方法
  8. hdu 4322 最大费用流
  9. Java进阶 创建和销毁对象
  10. xbanner 动画特效设置android,Axure教程:如何实现爱彼迎App首页Banner的切换效果
  11. 怎么保存php格式,把php代码保存到php文件实现方法
  12. Windows核心编程_PE文件格式解析
  13. JavaScrip节点属性-访问子节点
  14. RGB图像转到HSI图像
  15. bzoj 3123 可持久化线段树启发式合并
  16. php+mysql+记账系统_做了个php+mysql简单记账系统
  17. win10用计算机分区,win10怎么分区,详细教您win10怎么对磁盘进行分区
  18. 改wifi密码显示服务器拒绝访问权限,wifi密码对但是拒绝接入? | 192路由网
  19. 五分钟入门 Dingo API 1
  20. 优必选大型仿人服务机器人Walker X的核心技术突破

热门文章

  1. 给windows 98 客户虚拟机安装VMWare tools
  2. 有用的Chrome扩展介绍 - Octotree - GitHub code tree
  3. JSP的文件上传处理
  4. get event by http request via CL_HTMLB_MANAGER
  5. SAP CRM的订单模型移植到S4HANA后,在订单保存功能上作出的改进
  6. App in Scala
  7. Control currency conversion in gateway
  8. 使用noConclict后仍然能够在函数体内继续使用$的方法
  9. how I can force redetermination everytime
  10. 使用命令行工具mc连接SAP云平台Leonardo机器学习服务的AWS存储