Python實現(xiàn)PS濾鏡碎片特效功能示例
本文實例講述了Python實現(xiàn)PS濾鏡碎片特效功能。分享給大家供大家參考,具體如下:
這里用 Python 實現(xiàn) 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
%%% 對原圖做四個方向的平移,然后對平移的結(jié)果取平均
%%% 碎片效果
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);
原圖:

效果圖:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
將Python的Django框架與認(rèn)證系統(tǒng)整合的方法
這篇文章主要介紹了將Python的Django框架與認(rèn)證系統(tǒng)整合的方法,包括指定認(rèn)證后臺和編寫認(rèn)證后臺等內(nèi)容,需要的朋友可以參考下2015-07-07
python深度學(xué)習(xí)tensorflow實例數(shù)據(jù)下載與讀取
這篇文章主要為大家介紹了python深度學(xué)習(xí)tensorflow實例數(shù)據(jù)下載與讀取示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Python cookbook(字符串與文本)針對任意多的分隔符拆分字符串操作示例
這篇文章主要介紹了Python cookbook(字符串與文本)針對任意多的分隔符拆分字符串操作,結(jié)合實例形式分析了Python使用split()及正則表達(dá)式進(jìn)行字符串拆分操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2018-04-04

