本文實(shí)例講述了Python實(shí)現(xiàn)PS濾鏡特效之扇形變換效果。分享給大家供大家參考,具體如下:
尼河口ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!這里用 Python 實(shí)現(xiàn) PS 濾鏡中的一種幾何變換特效,稱為扇形變換,將圖像扭曲成一個(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) # control the radius of the inner circle radius = 150 # control the distance between the inner circle and outer circle high = 200 angle = 0 spreadAngle = math.pi # set the center of the circle, proportion of the image size centerX = 0.5 centerY = 1.0 row, col, channel = img.shape icenterX = col * centerX icenterY = row * centerY img_out = img * 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 - icenterX yy_dif = y_mask - icenterY theta = np.arctan2(-yy_dif, -xx_dif+0.0001) r = np.sqrt(xx_dif*xx_dif + yy_dif * yy_dif) theta = np.mod(theta, 2 * math.pi) x1_mask = col * theta/(spreadAngle+0.00001) y1_mask = row * (1-(r-radius)/(high+0.00001)) ''' mask = x1_mask < 0 x1_mask = x1_mask * (1 - mask) mask = x1_mask > (col - 1) x1_mask = x1_mask * (1 - mask) + (x1_mask * 0 + col -2) * mask mask = y1_mask < 0 y1_mask = y1_mask * (1 - mask) mask = y1_mask > (row -1) y1_mask = y1_mask * (1 - mask) + (y1_mask * 0 + row -2) * mask ''' int_x = np.floor (x1_mask) int_x = int_x.astype(int) int_y = np.floor (y1_mask) 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 x1_mask [ii, jj] < 0 or x1_mask [ii, jj] > col -1 : continue if y1_mask [ii, jj] < 0 or y1_mask [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()
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。