欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實現(xiàn)PS濾鏡特效之扇形變換效果示例

 更新時間:2018年01月26日 09:50:17   作者:Matrix_11  
這篇文章主要介紹了Python實現(xiàn)PS濾鏡特效之扇形變換效果,結(jié)合實例形式分析了Python實現(xiàn)PS濾鏡扇形變換效果的原理與相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Python實現(xiàn)PS濾鏡特效之扇形變換效果。分享給大家供大家參考,具體如下:

這里用 Python 實現(xiàn) PS 濾鏡中的一種幾何變換特效,稱為扇形變換,將圖像扭曲成一個扇形,具體的算法原理和效果圖可以參考附錄說明

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.dbjr.com.cn')
plt.imshow (img)
plt.axis('off')
plt.figure (2)
plt.title('www.dbjr.com.cn')
plt.imshow (img_out)
plt.axis('off')
plt.show()

附錄:PS 濾鏡— —扇形warp

  clc;
  clear all;
  close all;
  addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');
  I=imread('4.jpg');
  I=double(I);
  Image=I/255;
  [height, width, depth]=size(Image);
  % set the parameters
  radius = 150; % control the radius of the inner circle
  high = 200;  % control the distance between the inner circle and outer circle
  angle = 0;       
  spreadAngle=pi;  
  centerX = 0.5; % set the center of the circle, proportion of the image size
  centerY = 1.0;
  icenterX=width*centerX;
  icenterY=height*centerY;
  Image_new=Image*0;
  for i=1:height
    for j=1:width
      dx=j-icenterX;
      dy=i-icenterY;
      theta=atan2(-dy, -dx)+angle;
      r=sqrt(dy*dy+dx*dx);
      theta=mod(theta, 2*pi);
      x=width * theta/(spreadAngle+0.00001);
      y=height * (1-(r-radius)/(high+0.00001));
  % %     if (x<=1)   x=1; end
  % %     if (x>=width)  x=width-1; end;
  % %     if (y>=height) y=height-1; end;
  % %     if (y<1) y=1;   end;
  % %     
      if (x<=1)   continue; end
      if (x>=width)  continue; end;
      if (y>=height) continue; end;
      if (y<1) continue;   end;
      x1=floor(x);
      y1=floor(y);
      p=x-x1;
      q=y-y1;
      Image_new(i,j,:)=(1-p)*(1-q)*Image(y1,x1,:)+p*(1-q)*Image(y1,x1+1,:)...
        +q*(1-p)*Image(y1+1,x1,:)+p*q*Image(y1+1,x1+1,:);
    end
  end
  imshow(Image_new)
  imwrite(Image_new, 'out.jpg');

參考來源:http://www.jhlabs.com/index.html

本例Python運行效果:

原圖

效果圖

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

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

相關(guān)文章

  • Python學(xué)習(xí)之字符串常用方法總結(jié)

    Python學(xué)習(xí)之字符串常用方法總結(jié)

    這篇文章主要為大家介紹了Python中字符串的幾個常用方法總結(jié),文中的示例代碼講解詳細,對我們學(xué)習(xí)Python字符串有一定幫助,需要的可以參考一下
    2022-03-03
  • 如何在Python中將字符串轉(zhuǎn)換為數(shù)組詳解

    如何在Python中將字符串轉(zhuǎn)換為數(shù)組詳解

    最近在用Python,做一個小腳本,有個操作就是要把內(nèi)容換成數(shù)組對象再進行相關(guān)操作,下面這篇文章主要給大家介紹了關(guān)于如何在Python中將字符串轉(zhuǎn)換為數(shù)組的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • Pycharm連接遠程mysql報錯的實現(xiàn)

    Pycharm連接遠程mysql報錯的實現(xiàn)

    本文主要介紹了Pycharm連接遠程mysql報錯的實現(xiàn),文中通過圖文介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-08-08
  • python畫環(huán)形圖的方法

    python畫環(huán)形圖的方法

    這篇文章主要為大家詳細介紹了python畫環(huán)形圖的相關(guān)代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • win10 64bit下python NLTK安裝教程

    win10 64bit下python NLTK安裝教程

    這篇文章主要為大家詳細介紹了win10 64bit下python NLTK安裝教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • 基于Python編寫簡易的成語接龍游戲

    基于Python編寫簡易的成語接龍游戲

    成語接龍是中華民族傳統(tǒng)的文字游戲。它歷史悠久,是傳統(tǒng)文字、文化、文明的一個縮影,也是老少皆宜的民間文化娛樂活動。本文將用Python制作一個簡單的成語接龍游戲,需要的可以參考一下
    2022-03-03
  • Python兩個字典鍵同值相加的幾種方法

    Python兩個字典鍵同值相加的幾種方法

    今天小編就為大家分享一篇關(guān)于Python兩個字典鍵同值相加的幾種方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • python內(nèi)置進制轉(zhuǎn)換函數(shù)的操作

    python內(nèi)置進制轉(zhuǎn)換函數(shù)的操作

    這篇文章主要介紹了python內(nèi)置進制轉(zhuǎn)換函數(shù)的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • python實現(xiàn)單鏈表中刪除倒數(shù)第K個節(jié)點的方法

    python實現(xiàn)單鏈表中刪除倒數(shù)第K個節(jié)點的方法

    這篇文章主要為大家詳細介紹了python實現(xiàn)單鏈表中刪除倒數(shù)第K個節(jié)點的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • PyCharm 2020.2.2 x64 下載并安裝的詳細教程

    PyCharm 2020.2.2 x64 下載并安裝的詳細教程

    這篇文章主要介紹了PyCharm 2020.2.2 x64 下載并安裝的詳細教程,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10

最新評論