Python實(shí)現(xiàn)PS濾鏡的旋轉(zhuǎn)模糊功能示例
本文實(shí)例講述了Python實(shí)現(xiàn)PS濾鏡的旋轉(zhuǎn)模糊功能。分享給大家供大家參考,具體如下:
這里用 Python 實(shí)現(xiàn) PS 濾鏡中的旋轉(zhuǎn)模糊,具體的算法原理和效果可以參考附錄相關(guān)介紹。Python代碼如下:
from skimage import img_as_float import matplotlib.pyplot as plt from skimage import io import numpy as np import numpy.matlib file_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.shape 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) center_y = (row -1) / 2.0 center_x = (col -1) / 2.0 R = np.sqrt((x_mask - center_x) **2 + (y_mask - center_y) ** 2) angle = np.arctan2(y_mask - center_y , x_mask - center_x) Num = 20 arr = ( np.arange(Num) + 1 ) / 100.0 for i in range (row): for j in range (col): T_angle = angle[i, j] + arr new_x = R[i, j] * np.cos(T_angle) + center_x new_y = R[i, j] * np.sin(T_angle) + center_y int_x = new_x.astype(int) int_y = new_y.astype(int) int_x[int_x > col-1] = col - 1 int_x[int_x < 0] = 0 int_y[int_y < 0] = 0 int_y[int_y > row -1] = row -1 img_out[i,j,0] = img[int_y, int_x, 0].sum()/Num img_out[i,j,1] = img[int_y, int_x, 1].sum()/Num img_out[i,j,2] = img[int_y, int_x, 2].sum()/Num plt.figure(1) plt.imshow(img) plt.axis('off') plt.figure(2) plt.imshow(img_out) plt.axis('off') plt.show()
附:PS 濾鏡——旋轉(zhuǎn)模糊
這里給出灰度圖像的模糊算法,彩色圖像只要分別對(duì)三個(gè)通道做模糊即可。
%% spin blur % 旋轉(zhuǎn)模糊 clc; clear all; close all; I=imread('4.jpg'); I=double(I); % % % I_new=I; % % % for kk=1:3 % % % I_new(:,:,kk)=Spin_blur_Fun(I(:,:,kk), 30, 30); % % % end % % % imshow(I_new/255) Image=I; Image=0.2989 * I(:,:,1) + 0.5870 * I(:,:,2) + 0.1140 * I(:,:,3); [row, col]=size(Image); Image_new=Image; Center_X=(col+1)/2; Center_Y=(row+1)/2; validPoint=1; angle=5; radian=angle*pi/180; radian2=radian*radian; Num=30; Num2=Num*Num; for i=1:row for j=1:col validPoint=1; x0=j-Center_X; y0=Center_Y-i; x1=x0; y1=y0; Sum_Pixel=Image(i,j); for k=1:Num x0=x1; y0=y1; %%% 逆時(shí)針 % x1=x0-radian*y0/Num-radian2*x0/Num2; % y1=y0+radian*x0/Num-radian2*y0/Num2; %%% 順時(shí)針 x1=x0+radian*y0/Num-radian2*x0/Num2; y1=y0-radian*x0/Num-radian2*y0/Num2; x=floor(x1+Center_X); y=floor(Center_Y-y1); if(x>1 && x<col && y>1 && y<row) validPoint=validPoint+1; Sum_Pixel=Sum_Pixel+Image(y,x); end end Image_new(i,j)=Sum_Pixel/validPoint; end end imshow(Image_new/255);
原圖
效果圖
效果圖
更多關(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文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
- Python 實(shí)現(xiàn)PS濾鏡的旋渦特效
- Python 實(shí)現(xiàn)PS濾鏡中的徑向模糊特效
- Python實(shí)現(xiàn)PS濾鏡特效Marble Filter玻璃條紋扭曲效果示例
- Python實(shí)現(xiàn)PS濾鏡Fish lens圖像扭曲效果示例
- Python實(shí)現(xiàn)PS濾鏡特效之扇形變換效果示例
- Python實(shí)現(xiàn)PS濾鏡功能之波浪特效示例
- Python實(shí)現(xiàn)PS濾鏡碎片特效功能示例
- Python實(shí)現(xiàn)PS濾鏡的萬花筒效果示例
- Python實(shí)現(xiàn)PS濾鏡中馬賽克效果示例
- Python實(shí)現(xiàn)PS濾鏡中的USM銳化效果
相關(guān)文章
使用urllib庫的urlretrieve()方法下載網(wǎng)絡(luò)文件到本地的方法
今天小編就為大家分享一篇使用urllib庫的urlretrieve()方法下載網(wǎng)絡(luò)文件到本地的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-12-12django admin管理工具自定義時(shí)間區(qū)間篩選器DateRangeFilter介紹
這篇文章主要介紹了django admin管理工具自定義時(shí)間區(qū)間篩選器DateRangeFilter介紹,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-05-05PyCharm安裝庫numpy失敗問題的詳細(xì)解決方法
今天使用pycharm編譯python程序時(shí),由于要調(diào)用numpy包,但又未曾安裝numpy,于是就根據(jù)pycharm的提示進(jìn)行安裝,最后竟然提示出錯(cuò),下面這篇文章主要給大家介紹了關(guān)于PyCharm安裝庫numpy失敗問題的詳細(xì)解決方法,需要的朋友可以參考下2022-06-06Python進(jìn)程崩潰AttributeError異常問題解決
這篇文章主要介紹了Python進(jìn)程崩潰(AttributeError異常)問題解決,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下方法2023-06-06Python datetime 格式化 明天,昨天實(shí)例
這篇文章主要介紹了Python datetime 格式化 明天,昨天實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03在Python程序中操作文件之isatty()方法的使用教程
這篇文章主要介紹了在Python程序中操作文件之isatty()方法的使用教程,是Python入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-05-05舉例講解Python中的list列表數(shù)據(jù)結(jié)構(gòu)用法
這篇文章主要介紹了Python中的list列表數(shù)據(jù)結(jié)構(gòu)用法,列表是Python內(nèi)置的六種集合類數(shù)據(jù)類型中最常見的之一,需要的朋友可以參考下2016-03-03