Python實(shí)現(xiàn)PS濾鏡Fish lens圖像扭曲效果示例
本文實(shí)例講述了Python實(shí)現(xiàn)PS濾鏡Fish lens圖像扭曲效果。分享給大家供大家參考,具體如下:
這里實(shí)現(xiàn) PS 濾鏡中的一種幾何變換– Fish lens, 對(duì)圖像做扭曲,感覺就像通過一個(gè)凸鏡或者凹鏡在觀察圖像一樣。
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:/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
R=(min(row, col)/2)
# gamma > 1 zoom in gamma < 1 zoom out
gamma = 1.5
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
r_new = R*np.power(r/R, gamma)
x_new = r_new * np.cos(theta) + center_x
y_new = center_y - r_new * 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.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()
運(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濾鏡特效之扇形變換效果示例
- 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)文章
對(duì)python 樹狀嵌套結(jié)構(gòu)的實(shí)現(xiàn)思路詳解
今天小編就為大家分享一篇對(duì)python 樹狀嵌套結(jié)構(gòu)的實(shí)現(xiàn)思路詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-08-08
Python將多個(gè)excel文件合并為一個(gè)文件
這篇文章主要為大家詳細(xì)介紹了Python將多個(gè)excel文件合并為一個(gè)文件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
Python如何做點(diǎn)擊率數(shù)據(jù)預(yù)測(cè)
這篇文章主要介紹了Python做點(diǎn)擊率數(shù)據(jù)預(yù)測(cè),在這個(gè)場(chǎng)景中,我們通常需要根據(jù)用戶的歷史行為、物品的特征、上下文信息等因素來預(yù)測(cè)用戶點(diǎn)擊某個(gè)特定物品(如廣告、推薦商品)的概率,需要的朋友可以參考下2024-06-06
Django實(shí)戰(zhàn)之用戶認(rèn)證(初始配置)
這篇文章主要介紹了Django實(shí)戰(zhàn)之用戶認(rèn)證(初始配置),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07
Python中用psycopg2模塊操作PostgreSQL方法
python可以操作多種數(shù)據(jù)庫,本篇文章給大家介紹了用psycopg2模塊操作PostgreSQL方法,一起來學(xué)習(xí)下。2017-11-11
使用ChatGPT進(jìn)行Abaqus二次開發(fā)詳解
這篇文章主要為大家介紹了使用ChatGPT進(jìn)行Abaqus二次開發(fā)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03

