最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實現(xiàn)PS濾鏡Fish lens圖像扭曲效果示例

 更新時間:2018年01月29日 10:54:51   作者:Matrix_11  
這篇文章主要介紹了Python實現(xiàn)PS濾鏡Fish lens圖像扭曲效果,結(jié)合實例形式分析了Python實現(xiàn)PS濾鏡的圖像扭曲效果相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Python實現(xiàn)PS濾鏡Fish lens圖像扭曲效果。分享給大家供大家參考,具體如下:

這里實現(xiàn) PS 濾鏡中的一種幾何變換– Fish lens, 對圖像做扭曲,感覺就像通過一個凸鏡或者凹鏡在觀察圖像一樣。

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('www.fzitv.net')
plt.imshow (img)
plt.axis('off')
plt.figure (2)
plt.title('www.fzitv.net')
plt.imshow (img_out)
plt.axis('off')
plt.show()

運行效果:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設(shè)計有所幫助。

相關(guān)文章

最新評論

怀来县| 凌源市| 佳木斯市| 明溪县| 克山县| 大田县| 林西县| 井研县| 延吉市| 五寨县| 广西| 米林县| 万荣县| 黔南| 边坝县| 内乡县| 泽州县| 含山县| 青龙| 梧州市| 潍坊市| 方山县| 崇左市| 镇江市| 霍邱县| 莒南县| 红桥区| 昌邑市| 和平县| 平定县| 昌黎县| 时尚| 松桃| 兰考县| 罗平县| 定结县| 商都县| 盘山县| 科技| 尤溪县| 二连浩特市|