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


Posted in Python onJanuary 24, 2018

本文实例讲述了Python实现PS滤镜碎片特效功能。分享给大家供大家参考,具体如下:

这里用 Python 实现 PS 滤镜中的碎片特效,这个特效简单来说就是将图像在 上,下,左,右 四个方向做平移,然后将四个方向的平移的图像叠加起来做平均。具体的效果图与说明可参考附录说明

from skimage import img_as_float
import matplotlib.pyplot as plt
from skimage import io
file_name='D:/Visual Effects/PS Algorithm/4.jpg';
img=io.imread(file_name)
img = img_as_float(img)
img_1 = img.copy()
img_2 = img.copy()
img_3 = img.copy()
img_4 = img.copy()
img_out = img.copy()
Offset = 7
row, col, channel = img.shape
img_1[:, 0 : col-1-Offset, :] = img[:, Offset:col-1, :]
img_2[:, Offset:col-1, :] = img[:, 0 : col-1-Offset, :] 
img_3[0:row-1-Offset, :, :] = img[Offset:row-1, :, :]
img_4[Offset:row-1, :, :] = img[0:row-1-Offset, :, :]
img_out = (img_1 + img_2 + img_3 + img_4) / 4.0
plt.figure(1)
plt.imshow(img)
plt.axis('off');
plt.figure(2)
plt.imshow(img_out)
plt.axis('off');

附:PS 滤镜算法原理——碎片效果

%%% Fragment
%%% 对原图做四个方向的平移,然后对平移的结果取平均
%%% 碎片效果
clc;
clear all;
Image=imread('4.jpg');
Image=double(Image)/255;
[row,col,k]=size(Image);
Image1=Image;
Image2=Image;
Image3=Image;
Image4=Image;
Offset=5;
%%% 左移
Image1(:,1:col-Offset,:)=Image(:,1+Offset:col,:);
%%% 右移
Image2(:,1+Offset:col,:)=Image(:,1:col-Offset,:);
%%%% 上移
Image3(1+Offset:row,:,:)=Image(1:row-Offset,:,:);
%%% 下移
Image4(1:row-Offset,:,:)=Image(1+Offset:row,:,:);
Image=(Image1+Image2+Image3+Image4)/4;
figure, imshow(Image);

原图:

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

效果图:

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

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

Python 相关文章推荐
在Python中使用Mako模版库的简单教程
Apr 08 Python
Python记录详细调用堆栈日志的方法
May 05 Python
python线程池(threadpool)模块使用笔记详解
Nov 17 Python
django输出html内容的实例
May 27 Python
Django 中使用流响应处理视频的方法
Jul 20 Python
Python 从相对路径下import的方法
Dec 04 Python
python 使用正则表达式按照多个空格分割字符的实例
Dec 20 Python
python实现电子产品商店
Feb 26 Python
python简单鼠标自动点击某区域的实例
Jun 25 Python
wxPython实现带颜色的进度条
Nov 19 Python
Python IDLE或shell中切换路径的操作
Mar 09 Python
Python中22个万用公式的小结
Jul 21 Python
python的re正则表达式实例代码
Jan 24 #Python
python实现生命游戏的示例代码(Game of Life)
Jan 24 #Python
Python 获得命令行参数的方法(推荐)
Jan 24 #Python
Python实现的rsa加密算法详解
Jan 24 #Python
利用Python+Java调用Shell脚本时的死锁陷阱详解
Jan 24 #Python
python做量化投资系列之比特币初始配置
Jan 23 #Python
python在非root权限下的安装方法
Jan 23 #Python
You might like
Codeigniter中禁止A Database Error Occurred错误提示的方法
2014/06/12 PHP
Yii框架实现图片上传的方法详解
2017/05/20 PHP
php+javascript实现的动态显示服务器运行程序进度条功能示例
2017/08/07 PHP
PHP+百度AI OCR文字识别实现了图片的文字识别功能
2019/05/08 PHP
Prototype最新版(1.5 rc2)使用指南(1)
2007/01/10 Javascript
改版了网上的一个js操作userdata
2007/04/27 Javascript
字符串的replace方法应用浅析
2011/12/06 Javascript
2014最热门的JavaScript代码高亮插件推荐
2014/11/25 Javascript
对比分析json及XML
2014/11/28 Javascript
js 左右悬浮对联广告代码示例
2014/12/12 Javascript
jQuery插件Tooltipster实现漂亮的工具提示
2015/04/12 Javascript
js实现的简单图片浮动效果完整实例
2016/05/10 Javascript
JS实现自定义状态栏动画文字效果示例
2017/10/12 Javascript
JS中双击和单击事件冲突的解决方法
2018/04/09 Javascript
Vue波纹按钮组件制作
2018/04/30 Javascript
vue element中axios下载文件(后端Python)
2019/05/10 Javascript
[42:25]EG vs Spirit Supermajor 败者组 BO3 第二场 6.4
2018/06/05 DOTA
pygame学习笔记(3):运动速率、时间、事件、文字
2015/04/15 Python
在DigitalOcean的服务器上部署flaskblog应用
2015/12/19 Python
Python编程中归并排序算法的实现步骤详解
2016/05/04 Python
Python使用requests发送POST请求实例代码
2018/01/25 Python
解决Python pandas plot输出图形中显示中文乱码问题
2018/12/12 Python
python pandas模块基础学习详解
2019/07/03 Python
Django基础知识 URL路由系统详解
2019/07/18 Python
Python编程快速上手——Excel到CSV的转换程序案例分析
2020/02/28 Python
Urban Outfitters美国官网:美国生活方式品牌
2016/08/26 全球购物
WoolOvers澳洲官方网站:英国针织服装公司
2018/05/13 全球购物
介绍一下Linux中的链接
2016/06/05 面试题
应届大学生的推荐信
2013/11/20 职场文书
校园主题婚礼活动策划方案
2014/09/15 职场文书
员工试用期自我鉴定范文
2014/09/15 职场文书
机关领导干部作风整顿整改措施
2014/09/19 职场文书
北京英文导游词
2015/02/12 职场文书
2019年鼓励无偿献血倡议书
2019/09/17 职场文书
IDEA使用SpringAssistant插件创建SpringCloud项目
2021/06/23 Java/Android
Spring中的使用@Async异步调用方法
2021/11/01 Java/Android