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('www.dhdzp.com')
plt.imshow (img)
plt.axis('off')
plt.figure (2)
plt.title('www.dhdzp.com')
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文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
- 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實(shí)現(xiàn)批量發(fā)送個(gè)性化郵件
在現(xiàn)代工作環(huán)境中,我們經(jīng)常需要向多個(gè)收件人發(fā)送個(gè)性化的郵件,因此本文小編為大家整理了Python實(shí)現(xiàn)批量發(fā)送個(gè)性化郵件的示例代碼,希望對(duì)大家有所幫助2023-11-11
pandas數(shù)據(jù)清洗實(shí)現(xiàn)刪除的項(xiàng)目實(shí)踐
本文主要介紹了pandas數(shù)據(jù)清洗實(shí)現(xiàn)刪除的項(xiàng)目實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
Python實(shí)現(xiàn)將一段文字復(fù)制到所選的文件當(dāng)中
這篇文章主要為大家詳細(xì)介紹了Python如何將一段文字復(fù)制到所選的文件當(dāng)中,文中的示例代碼講解詳細(xì), 感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-02-02
Python中應(yīng)該使用%還是format來格式化字符串
這篇文章主要介紹了Python中應(yīng)該使用%還是format來格式化字符串的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-09-09
python環(huán)境路徑配置以及命令行運(yùn)行腳本
這篇文章主要為大家詳細(xì)介紹了python環(huán)境路徑配置以及命令行運(yùn)行腳本,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04
Python提高運(yùn)行速度工具之Pandarallel的使用教程
為了提高運(yùn)行速度,我們一般會(huì)采用多進(jìn)程的方式。而常見的方案對(duì)于普通python玩家來說都不是特別友好,怎樣才能算作一個(gè)友好的并行處理方案?本文就來和大家講講pandarallel的使用2022-09-09

