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

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

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

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

這里實(shí)現(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('m.fzitv.net')
plt.imshow (img)
plt.axis('off')
plt.figure (2)
plt.title('m.fzitv.net')
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文件與目錄操作技巧匯總

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

相關(guān)文章

最新評論

沧州市| 扶绥县| 松滋市| 将乐县| 涿州市| 京山县| 滨州市| 淮北市| 平武县| 肇源县| 色达县| 福清市| 台东县| 武冈市| 专栏| 莱芜市| 武定县| 汕尾市| 德安县| 临颍县| 漳浦县| 辽中县| 新巴尔虎右旗| 永泰县| 阳高县| 聂荣县| 雷波县| 万源市| 新泰市| 永嘉县| 霍城县| 东阿县| 方山县| 西畴县| 武强县| 海淀区| 赤壁市| 彭水| 九龙县| 南皮县| 旌德县|