Python 實(shí)現(xiàn)PS濾鏡的旋渦特效
更新時(shí)間:2020年12月03日 11:07:08 作者:未雨愁眸
這篇文章主要介紹了Python 實(shí)現(xiàn) PS 濾鏡的旋渦特效,幫助大家更好的利用python處理圖片,感興趣的朋友可以了解下
實(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濾鏡漩渦特效的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
python matplotlib模塊基本圖形繪制方法小結(jié)【直線,曲線,直方圖,餅圖等】
這篇文章主要介紹了python matplotlib模塊基本圖形繪制方法,結(jié)合實(shí)例形式總結(jié)分析了Python使用matplotlib模塊繪制直線,曲線,直方圖,餅圖等圖形的相關(guān)操作技巧,需要的朋友可以參考下2020-04-04Python中三元運(yùn)算符的簡(jiǎn)潔性及多用途實(shí)例探究
這篇文章主要為大家介紹了Python中三元運(yùn)算符的簡(jiǎn)潔性及多用途實(shí)例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01詳解pycharm自動(dòng)import所需的庫(kù)的操作方法
這篇文章主要介紹了pycharm自動(dòng)import所需的庫(kù)的操作方法,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11python中shapefile庫(kù)讀取shapefile文件信息
本文主要介紹了python中shapefile庫(kù)讀取shapefile文件信息,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06python如何通過正則匹配指定字符開頭與結(jié)束提取中間內(nèi)容
這篇文章主要介紹了python通過正則匹配指定字符開頭與結(jié)束提取中間內(nèi)容的操作方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-02-02