国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現PS濾鏡Fish lens圖像扭曲效果示例

2020-02-22 23:01:45
字體:
來源:轉載
供稿:網友

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

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

import numpy as npfrom skimage import img_as_floatimport matplotlib.pyplot as pltfrom skimage import ioimport mathimport numpy.matlibfile_name2='D:/Visual Effects/PS Algorithm/4.jpg'img=io.imread(file_name2)img = img_as_float(img)row, col, channel = img.shapeimg_out = img * 1.0R=(min(row, col)/2)# gamma > 1 zoom in gamma < 1 zoom outgamma = 1.5center_x = (col-1)/2.0center_y = (row-1)/2.0xx = 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_xyy_dif = center_y - y_maskr = np.sqrt(xx_dif * xx_dif + yy_dif * yy_dif)theta = np.arctan(yy_dif / xx_dif)mask_1 = xx_dif < 0theta = theta * (1 - mask_1) + (theta + math.pi) * mask_1r_new = R*np.power(r/R, gamma)x_new = r_new * np.cos(theta) + center_xy_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.jb51.net')plt.imshow (img)plt.axis('off')plt.figure (2)plt.title('www.jb51.net')plt.imshow (img_out)plt.axis('off')plt.show()

運行效果:

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金平| 喀喇| 双峰县| 青阳县| 新化县| 瓮安县| 清远市| 连南| 龙江县| 保山市| 雅安市| 长武县| 贵州省| 石门县| 永丰县| 西乌珠穆沁旗| 讷河市| 高尔夫| 广汉市| 武安市| 湘乡市| 萨迦县| 珲春市| 峨眉山市| 康平县| 武川县| 湖州市| 福州市| 棋牌| 新竹市| 承德县| 遵化市| 平利县| 隆子县| 福贡县| 固阳县| 华池县| 龙胜| 柳州市| 丹巴县| 隆子县|