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中的Matplotlib模块入门教程
Apr 15 Python
详解Django框架中用context来解析模板的方法
Jul 20 Python
Python简单检测文本类型的2种方法【基于文件头及cchardet库】
Sep 18 Python
浅谈pandas中shift和diff函数关系
Apr 08 Python
Django管理员账号和密码忘记的完美解决方法
Dec 06 Python
python将list转为matrix的方法
Dec 12 Python
python爬取微信公众号文章的方法
Feb 26 Python
对Tensorflow中Device实例的生成和管理详解
Feb 04 Python
Python异常继承关系和自定义异常实现代码实例
Feb 20 Python
使用python把xmind转换成excel测试用例的实现代码
Oct 12 Python
python实现简易名片管理系统
Apr 11 Python
Python实现Excel文件的合并(以新冠疫情数据为例)
Mar 20 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
护卫神php套件 php版本升级方法(php5.5.24)
2015/05/10 PHP
php微信开发之图片回复功能
2018/06/14 PHP
推荐:极酷右键菜单
2006/11/29 Javascript
js判断IE6/IE7/FF的代码[XMLHttpRequest]
2011/02/16 Javascript
ajax提交表单实现网页无刷新注册示例
2014/05/08 Javascript
javascript记录文本框内文字个数检测文字个数变化
2014/10/14 Javascript
XML文件转化成NSData对象的方法
2015/08/12 Javascript
jQuery中bind(),live(),delegate(),on()绑定事件方法实例详解
2016/01/19 Javascript
理解javascript模块化
2016/03/28 Javascript
微信公众号支付H5调用支付解析
2016/11/04 Javascript
详解javascript获取url信息的常见方法
2016/12/19 Javascript
Easyui使用Dialog行内按钮布局的实例
2017/07/27 Javascript
js禁止Backspace键使浏览器后退的实现方法
2017/09/01 Javascript
JS图片延迟加载插件LazyImgv1.0用法分析【附demo源码下载】
2017/09/04 Javascript
Vue中组件之间数据的传递的示例代码
2017/09/08 Javascript
Vue 组件参数校验与非props特性的方法
2019/02/12 Javascript
Vue中错误图片的处理的实现代码
2019/11/07 Javascript
[55:42]VG vs VGJ.T 2018国际邀请赛淘汰赛BO1 8.21
2018/08/22 DOTA
使用grappelli为django admin后台添加模板
2014/11/18 Python
Python使用pygame模块编写俄罗斯方块游戏的代码实例
2015/12/08 Python
详解python的数字类型变量与其方法
2016/11/20 Python
tensorflow 使用flags定义命令行参数的方法
2018/04/23 Python
详解Python做一个名片管理系统
2019/03/14 Python
浅谈Python3 numpy.ptp()最大值与最小值的差
2019/08/24 Python
django formset实现数据表的批量操作的示例代码
2019/12/06 Python
python 读取更新中的log 或其它文本方式
2019/12/24 Python
在django admin详情表单显示中添加自定义控件的实现
2020/03/11 Python
Python代码注释规范代码实例解析
2020/08/14 Python
NFL加拿大官方网上商店:NHLShop.ca
2019/03/12 全球购物
RealTek面试题
2016/06/28 面试题
软件配置管理有什么好处
2015/04/15 面试题
2014全国两会学习心得体会2000字
2014/03/10 职场文书
教师考核评语
2014/04/28 职场文书
学风建设主题班会
2015/08/17 职场文书
给校长的建议书作文300字
2015/09/14 职场文书
标准演讲稿格式结尾应该怎么书写?
2019/07/17 职场文书