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

首頁 > 編程 > Python > 正文

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

2020-01-04 16:08:22
字體:
來源:轉載
供稿:網(wǎng)友

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

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

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)# control the radius of the inner circleradius = 150# control the distance between the inner circle and outer circlehigh = 200angle = 0spreadAngle = math.pi# set the center of the circle, proportion of the image sizecenterX = 0.5centerY = 1.0row, col, channel = img.shapeicenterX = col * centerXicenterY = row * centerYimg_out = img * 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 - icenterXyy_dif = y_mask - icenterYtheta = 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 < 0x1_mask = x1_mask * (1 - mask)mask = x1_mask > (col - 1)x1_mask = x1_mask * (1 - mask) + (x1_mask * 0 + col -2) * maskmask = y1_mask < 0y1_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('m.survivalescaperooms.com')plt.imshow (img)plt.axis('off')plt.figure (2)plt.title('m.survivalescaperooms.com')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運行效果:

原圖

Python,PS濾鏡,扇形變換

效果圖

Python,PS濾鏡,扇形變換

 

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


注:相關教程知識閱讀請移步到python教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 抚远县| 金门县| 武陟县| 章丘市| 鹿邑县| 合川市| 唐海县| 青岛市| 化州市| 荃湾区| 昌黎县| 六盘水市| 文安县| 仙桃市| 沾益县| 华亭县| 资源县| 平阴县| 敖汉旗| 正镶白旗| 江华| 台中市| 当涂县| 大方县| 响水县| 宜丰县| 阿拉善盟| 万安县| 太仓市| 同仁县| 上思县| 烟台市| 河曲县| 浙江省| 鄂温| 永宁县| 莎车县| 苍山县| 富蕴县| 潜山县| 交城县|