Python 實(shí)現(xiàn)PS濾鏡的旋渦特效
實(shí)現(xiàn)效果:

實(shí)現(xiàn)代碼
import numpy as np
from skimage import img_as_float
import matplotlib.pyplot as plt
from skimage import io
import math
import numpy.matlib
file_name2='D:/2020121173119242.png' # 圖片路徑
img=io.imread(file_name2)
img = img_as_float(img)
row, col, channel = img.shape
img_out = img * 1.0
degree = 70
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
r = np.sqrt(xx_dif * xx_dif + yy_dif * yy_dif)
theta = np.arctan(yy_dif / xx_dif)
mask_1 = xx_dif < 0
theta = theta * (1 - mask_1) + (theta + math.pi) * mask_1
theta = theta + r/degree
x_new = r * np.cos(theta) + center_x
y_new = center_y - r * np.sin(theta)
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.imshow (img)
plt.axis('off')
plt.figure (2)
plt.imshow (img_out)
plt.axis('off')
plt.show()
以上就是Python 實(shí)現(xiàn) PS 濾鏡的旋渦特效的詳細(xì)內(nèi)容,更多關(guān)于python ps濾鏡漩渦特效的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
基于Python和C++實(shí)現(xiàn)刪除鏈表的節(jié)點(diǎn)
這篇文章主要介紹了基于Python和C++實(shí)現(xiàn)刪除鏈表的節(jié)點(diǎn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07
Windows系統(tǒng)下使用flup搭建Nginx和Python環(huán)境的方法
這篇文章主要介紹了Windows系統(tǒng)下使用flup搭建Nginx和Python環(huán)境的方法,文中使用到了flup這個Python的FastCGI工具,需要的朋友可以參考下2015-12-12
使用Jest?在?Visual?Studio?Code?中進(jìn)行單元測試的流程分析
Jest是一個流行的JavaScript測試框架,它提供了簡潔、靈活和強(qiáng)大的工具來編寫和運(yùn)行單元測試,今天通過本文給大家介紹使用Jest在Visual Studio Code中進(jìn)行單元測試的流程分析,感興趣的朋友跟隨小編一起看看吧2023-07-07
python實(shí)現(xiàn)簡單的超市商品銷售管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)超市商品銷售管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-11-11
利用Python找出序列中出現(xiàn)最多的元素示例代碼
這篇文章主要給大家介紹了關(guān)于利用Python找出序列中出現(xiàn)最多的元素的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
Python實(shí)現(xiàn)的簡單計(jì)算器功能詳解
這篇文章主要介紹了Python實(shí)現(xiàn)的簡單計(jì)算器功能,結(jié)合實(shí)例形式詳細(xì)分析了Python實(shí)現(xiàn)計(jì)算器功能的具體步驟、相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-08-08
使用python實(shí)現(xiàn)微信小程序自動簽到功能
這篇文章主要介紹了使用python實(shí)現(xiàn)微信小程序自動簽到功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
Python個人博客程序開發(fā)實(shí)例用戶驗(yàn)證功能
這篇文章主要介紹了怎樣用Python來實(shí)現(xiàn)一個完整的個人博客系統(tǒng),我們通過實(shí)操上手的方式可以高效的鞏固所學(xué)的基礎(chǔ)知識,感興趣的朋友一起來看看吧2022-12-12

