Python實(shí)現(xiàn)PS濾鏡功能之波浪特效示例
本文實(shí)例講述了Python實(shí)現(xiàn)PS濾鏡功能之波浪特效。分享給大家供大家參考,具體如下:
這里用 Python 實(shí)現(xiàn) PS 濾鏡的波浪特效,具體效果可以參考附錄說明
import numpy as np
from skimage import img_as_float
import matplotlib.pyplot as plt
from skimage import io
import numpy.matlib
import math
file_name2='D:/Visual Effects/PS Algorithm/4.jpg'
img=io.imread(file_name2)
img = img_as_float(img)
row, col, channel = img.shape
img_out = img * 1.0
alpha = 70.0
beta = 30.0
degree = 20.0
center_x = (col-1)/2.0
center_y = (row-1)/2.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 - center_x
yy_dif = center_y - y_mask
x = degree * np.sin(2 * math.pi * yy_dif / alpha) + xx_dif
y = degree * np.cos(2 * math.pi * xx_dif / beta) + yy_dif
x_new = x + center_x
y_new = center_y - y
int_x = np.floor (x_new)
int_x = int_x.astype(int)
int_y = np.floor (y_new)
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 x_new [ii, jj] < 0 or x_new [ii, jj] > col -1 :
continue
if y_new [ii, jj] < 0 or y_new [ii, jj] > row -1 :
continue
img_out[ii, jj, :] = img[new_yy, new_xx, :]
plt.figure (1)
plt.title('chabaoo.cn')
plt.imshow (img)
plt.axis('off')
plt.figure (2)
plt.title('chabaoo.cn')
plt.imshow (img_out)
plt.axis('off')
plt.show()
附錄:PS 濾鏡——波浪 wave
%%% Wave
%%% 波浪效果
clc;
clear all;
close all;
addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');
I=imread('4.jpg');
Image=double(I);
% Image=0.2989 * I(:,:,1) + 0.5870 * I(:,:,2) + 0.1140 * I(:,:,3);
[row, col,channel]=size(Image);
R=floor(max(row, col)/2);
Image_new=Image;
Degree=30; % 控制扭曲的程度
Center_X=(col+1)/2;
Center_Y=(row+1)/2;
for i=1:row
for j=1:col
x0=j-Center_X;
y0=Center_Y-i;
x=Degree*sin(2*pi*y0/128)+x0;
y=Degree*cos(2*pi*x0/128)+y0;
x=x+col/2;
y=row/2-y;
if(x>1 && x<col && y<row && y>1)
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
end
figure, imshow(Image_new/255);
本例Python運(yùn)行效果:
原圖

效果圖

更多關(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è)計有所幫助。
- Python 實(shí)現(xiàn)PS濾鏡的旋渦特效
- Python 實(shí)現(xiàn)PS濾鏡中的徑向模糊特效
- Python實(shí)現(xiàn)PS濾鏡特效Marble Filter玻璃條紋扭曲效果示例
- Python實(shí)現(xiàn)PS濾鏡Fish lens圖像扭曲效果示例
- Python實(shí)現(xiàn)PS濾鏡特效之扇形變換效果示例
- Python實(shí)現(xiàn)PS濾鏡碎片特效功能示例
- Python實(shí)現(xiàn)PS濾鏡的萬花筒效果示例
- Python實(shí)現(xiàn)PS濾鏡的旋轉(zhuǎn)模糊功能示例
- Python實(shí)現(xiàn)PS濾鏡中馬賽克效果示例
- Python實(shí)現(xiàn)PS濾鏡中的USM銳化效果
相關(guān)文章
如何利用Python快速統(tǒng)計文本的行數(shù)
這篇文章主要介紹了如何利用Python快速統(tǒng)計文本的行數(shù),要快速統(tǒng)計一個文本文件中的行數(shù),其實(shí)就是要統(tǒng)計這個文本文件中換行符的個數(shù),下面我們就一起進(jìn)入文章看看具體的操作過程吧2021-12-12
Python實(shí)現(xiàn)從log日志中提取ip的方法【正則提取】
這篇文章主要介紹了Python實(shí)現(xiàn)從log日志中提取ip的方法,涉及Python文件讀取、數(shù)據(jù)遍歷、正則匹配等相關(guān)操作技巧,需要的朋友可以參考下2018-03-03
用python實(shí)現(xiàn)爬取奧特曼圖片實(shí)例
大家好,本篇文章主要講的是用python實(shí)現(xiàn)爬取奧特曼圖片實(shí)例,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下2022-02-02
keras和tensorflow使用fit_generator 批次訓(xùn)練操作
這篇文章主要介紹了keras和tensorflow使用fit_generator 批次訓(xùn)練操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
Django實(shí)現(xiàn)WebSocket在線聊天室功能(channels庫)
本文基于channels庫Django實(shí)現(xiàn)WebSocket在線聊天室功能,包括安裝及創(chuàng)建django項(xiàng)目的全過程,通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-09-09
keras使用Sequence類調(diào)用大規(guī)模數(shù)據(jù)集進(jìn)行訓(xùn)練的實(shí)現(xiàn)
這篇文章主要介紹了keras使用Sequence類調(diào)用大規(guī)模數(shù)據(jù)集進(jìn)行訓(xùn)練的實(shí)現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06
Python實(shí)現(xiàn)迭代時使用索引的方法示例
這篇文章主要介紹了Python實(shí)現(xiàn)迭代時使用索引的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Python使用enumerate()函數(shù)以及zip()函數(shù)獲取元素索引的相關(guān)操作技巧,需要的朋友可以參考下2018-06-06

