Python实现PS滤镜碎片特效功能示例
作者:Matrix_11 时间:2021-04-25 01:35:31
本文实例讲述了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程序设计有所帮助。
来源:http://blog.csdn.net/matrix_space/article/details/72303014
标签:Python,PS,滤镜
0
投稿
猜你喜欢
PHP实现判断二叉树是否对称的方法
2023-06-28 13:24:10
javascript根据像素点取位置示例
2023-09-03 22:58:54
python写入文件自动换行问题的方法
2022-06-13 11:28:18
python解析xml文件操作实例
2022-01-02 10:39:13
python算法表示概念扫盲教程
2022-06-22 00:43:34
透彻掌握ASP分页技术
2009-03-09 18:26:00
PyQt5实现简易计算器
2022-12-14 02:12:38
Python对称的二叉树多种思路实现方法
2022-09-12 17:27:10
Python selenium爬取微博数据代码实例
2023-07-01 02:46:49
Python基于Serializer实现字段验证及序列化
2023-07-19 21:50:36
简单了解python字符串前面加r,u的含义
2021-12-26 19:08:39
Oracle时间日期操作方法小结第1/2页
2010-11-29 19:40:00
python 实现rolling和apply函数的向下取值操作
2022-03-15 07:10:08
python字典和json.dumps()的遇到的坑分析
2023-07-27 22:03:29
简析Python的闭包和装饰器
2021-06-25 03:25:40
Python将图片转换为字符画的方法
2022-06-15 07:52:27
置信椭圆原理以及椭圆图形绘制方式
2021-04-24 04:25:04
tensorboard 可视化之localhost:6006不显示的解决方案
2021-01-20 15:39:41
Pytorch实现常用乘法算子TensorRT的示例代码
2021-08-17 17:49:47
python和php哪个更适合写爬虫
2023-10-28 00:51:14