200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > Python: PS滤镜--径向模糊

Python: PS滤镜--径向模糊

时间:2019-09-15 21:03:08

相关推荐

Python: PS滤镜--径向模糊

本文用 Python 实现 PS 滤镜中的径向模糊特效,具体的算法原理和效果可以参考之前的博客:

/matrix_space/article/details/39211735

from skimage import img_as_floatimport matplotlib.pyplot as pltfrom skimage import ioimport numpy as npimport numpy.matlibfile_name='D:/Visual Effects/PS Algorithm/4.jpg';img=io.imread(file_name)img = img_as_float(img)img_out = img.copy()row, col, channel = img.shapexx = 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)center_y = (row -1) / 2.0center_x = (col -1) / 2.0R = np.sqrt((x_mask - center_x) **2 + (y_mask - center_y) ** 2)angle = np.arctan2(y_mask - center_y , x_mask - center_x)Num = 20arr = np.arange(Num)for i in range (row):for j in range (col):R_arr = R[i, j] - arr R_arr[R_arr < 0] = 0new_x = R_arr * np.cos(angle[i,j]) + center_xnew_y = R_arr * np.sin(angle[i,j]) + center_yint_x = new_x.astype(int)int_y = new_y.astype(int)int_x[int_x > col-1] = col - 1int_x[int_x < 0] = 0int_y[int_y < 0] = 0int_y[int_y > row -1] = row -1img_out[i,j,0] = img[int_y, int_x, 0].sum()/Numimg_out[i,j,1] = img[int_y, int_x, 1].sum()/Numimg_out[i,j,2] = img[int_y, int_x, 2].sum()/Numplt.figure(1)plt.imshow(img)plt.axis('off')plt.figure(2)plt.imshow(img_out)plt.axis('off')plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。