亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python實現(xiàn)PS濾鏡特效Marble Filter玻璃條紋扭曲效果示例

 更新時間:2018年01月29日 11:13:47   作者:Matrix_11  
這篇文章主要介紹了Python實現(xiàn)PS濾鏡特效Marble Filter玻璃條紋扭曲效果,涉及Python基于skimage庫實現(xiàn)圖形條紋扭曲效果的相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Python實現(xiàn)PS濾鏡特效Marble Filter玻璃條紋扭曲效果。分享給大家供大家參考,具體如下:

這里用 Python 實現(xiàn) PS 濾鏡特效,Marble Filter, 這種濾鏡使圖像產(chǎn)生不規(guī)則的扭曲,看起來像某種玻璃條紋, 具體的代碼如下:

import numpy as np
import math
import numpy.matlib
from skimage import io
import random
from skimage import img_as_float
import matplotlib.pyplot as plt
def Init_arr():
  B = 256
  P = np.zeros((B+B+2, 1))
  g1 = np.zeros((B+B+2, 1))
  g2 = np.zeros((B+B+2, 2))
  g3 = np.zeros((B+B+2, 3))
  N_max = 1e6
  for i in range(B+1):
    P[i] = i
    g1[i] = (((math.floor(random.random()*N_max)) % (2*B))-B)*1.0/B
    g2[i, :] = (np.mod((np.floor(np.random.rand(1, 2)*N_max)), (2*B))-B)*1.0/B
    g2[i, :] = g2[i, :] / np.sum(g2[i, :] **2)
    g3[i, :] = (np.mod((np.floor(np.random.rand(1, 3)*N_max)), (2*B))-B)*1.0/B
    g3[i, :] = g3[i, :] / np.sum(g3[i, :] **2)
  for i in range(B, -1, -1):
    k = P[i]
    j = math.floor(random.random()*N_max) % B
    P [i] = P [j]
    P [j] = k
  P[B+1:2*B+2]=P[0:B+1];
  g1[B+1:2*B+2]=g1[0:B+1];
  g2[B+1:2*B+2, :]=g2[0:B+1, :]
  g3[B+1:2*B+2, :]=g3[0:B+1, :]
  P = P.astype(int)
  return P, g1, g2, g3
def Noise_2(x_val, y_val, P, g2):
  BM=255
  N=4096
  t = x_val + N
  bx0 = ((np.floor(t).astype(int)) & BM) + 1
  bx1 = ((bx0 + 1).astype(int) & BM) + 1
  rx0 = t - np.floor(t)
  rx1 = rx0 - 1.0
  t = y_val + N
  by0 = ((np.floor(t).astype(int)) & BM) + 1
  by1 = ((bx0 + 1).astype(int) & BM) + 1
  ry0 = t - np.floor(t)
  ry1 = rx0 - 1.0
  sx = rx0 * rx0 * (3 - 2.0 * rx0)
  sy = ry0 * ry0 * (3 - 2.0 * ry0)
  row, col = x_val.shape
  q1 = np.zeros((row, col ,2))
  q2 = q1.copy()
  q3 = q1.copy()
  q4 = q1.copy()
  for i in range(row):
    for j in range(col):
      ind_i = P[bx0[i, j]]
      ind_j = P[bx1[i, j]]
      b00 = P[ind_i + by0[i, j]]
      b01 = P[ind_i + by1[i, j]]
      b10 = P[ind_j + by0[i, j]]
      b11 = P[ind_j + by1[i, j]]
      q1[i, j, :] = g2[b00, :]
      q2[i, j, :] = g2[b10, :]
      q3[i, j, :] = g2[b01, :]
      q4[i, j, :] = g2[b11, :]
  u1 = rx0 * q1[:, :, 0] + ry0 * q1[:, :, 1]
  v1 = rx1 * q2[:, :, 0] + ry1 * q2[:, :, 1]
  a = u1 + sx * (v1 - u1)
  u2 = rx0 * q3[:, :, 0] + ry0 * q3[:, :, 1]
  v2 = rx1 * q4[:, :, 0] + ry1 * q4[:, :, 1]
  b = u2 + sx * (v2 - u2)
  out = (a + sy * (b - a)) * 1.5
  return out
file_name='D:/Visual Effects/PS Algorithm/4.jpg';
img=io.imread(file_name)
img = img_as_float(img)
row, col, channel = img.shape
xScale = 25.0
yScale = 25.0
turbulence =0.25
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)
x_val = x_mask / xScale
y_val = y_mask / yScale
Index = np.arange(256)
sin_T=-yScale*np.sin(2*math.pi*(Index)/255*turbulence);
cos_T=xScale*np.cos(2*math.pi*(Index)/255*turbulence)
P, g1, g2, g3 = Init_arr()
Noise_out = Noise_2(x_val, y_val, P, g2)
Noise_out = 127 * (Noise_out + 1)
Dis = np.floor(Noise_out)
Dis[Dis>255] = 255
Dis[Dis<0] = 0
Dis = Dis.astype(int)
img_out = img.copy()
for ii in range(row):
  for jj in range(col):
    new_x = jj + sin_T[Dis[ii, jj]]
    new_y = ii + cos_T[Dis[ii, jj]]
    if (new_x > 0 and new_x < col-1 and new_y > 0 and new_y < row-1):
      int_x = int(new_x)
      int_y = int(new_y)
      img_out[ii, jj, :] = img[int_y, int_x, :]
plt.figure(1)
plt.title('chabaoo.cn')
plt.imshow(img)
plt.axis('off');
plt.figure(2)
plt.title('chabaoo.cn')
plt.imshow(img_out)
plt.axis('off');
plt.show();

運行效果:

附:PS 濾鏡 Marble 效果原理

  clc;
  clear all;
  close all;
  addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');
  I=imread('4.jpg');
  I=double(I);
  Image=I/255;
  xScale = 20;
  yScale = 20;
  amount = 1;
  turbulence =0.25;
  Image_new=Image;
  [height, width, depth]=size(Image);
  Index=1:256;
  sin_T=-yScale*sin(2*pi*(Index-1)/256*turbulence);
  cos_T=xScale*cos(2*pi*(Index-1)/256*turbulence);
  [ind, g1, g2, g3]=init_arr();
  for ii=1:height
  % %   [ind, g1, g2, g3]=init_arr();
    for jj=1:width
      dis=min(max( floor(127*(1+Noise2(jj/xScale, ii/yScale, ind, g2))), 1), 256);
      x=jj+sin_T(dis);
      y=ii+cos_T(dis);
  % %     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(ii,jj,:)=(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

更多關(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文件與目錄操作技巧匯總

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

相關(guān)文章

  • 如何使用Python實現(xiàn)名片管理系統(tǒng)

    如何使用Python實現(xiàn)名片管理系統(tǒng)

    這篇文章主要介紹了如何使用Python實現(xiàn)名片管理系統(tǒng),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)又是幫助
    2022-08-08
  • 使用Python測試Ping主機IP和某端口是否開放的實例

    使用Python測試Ping主機IP和某端口是否開放的實例

    今天小編就為大家分享一篇使用Python測試Ping主機IP和某端口是否開放的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • 純python實現(xiàn)機器學(xué)習(xí)之kNN算法示例

    純python實現(xiàn)機器學(xué)習(xí)之kNN算法示例

    本篇文章主要介紹了純python實現(xiàn)機器學(xué)習(xí)之kNN算法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • 通過python獲取甲流分布數(shù)據(jù)

    通過python獲取甲流分布數(shù)據(jù)

    近期,多地學(xué)校出現(xiàn)因甲流導(dǎo)致的班級停課,兒科甲流患者就診量呈數(shù)倍增長,今天我們同樣的操作來獲取下現(xiàn)在甲流感染的數(shù)據(jù),需要的朋友可以參考下
    2023-03-03
  • 淺析python多線程中的鎖

    淺析python多線程中的鎖

    這篇文章主要介紹了淺析python多線程中的鎖,鎖由Python的threading模塊提供,并且它最多被一個線程所持有,當(dāng)一個線程試圖獲取一個已經(jīng)鎖在資源上的鎖時,該線程通常會暫停運行,直到這個鎖被釋放,需要的朋友可以參考下
    2023-07-07
  • 解決Pyinstaller 打包exe文件 取消dos窗口(黑框框)的問題

    解決Pyinstaller 打包exe文件 取消dos窗口(黑框框)的問題

    今天小編就為大家分享一篇解決Pyinstaller 打包exe文件 取消dos窗口(黑框框)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • python 計算概率密度、累計分布、逆函數(shù)的例子

    python 計算概率密度、累計分布、逆函數(shù)的例子

    這篇文章主要介紹了python 計算概率密度、累計分布、逆函數(shù)的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • 簡單講解Python中的字符串與字符串的輸入輸出

    簡單講解Python中的字符串與字符串的輸入輸出

    這篇文章主要介紹了Python中的字符串與字符串的輸入輸出,Python3.x版本中默認(rèn)以Unicode為編碼,省去了不少麻煩,需要的朋友可以參考下
    2016-03-03
  • Python基于jieba, wordcloud庫生成中文詞云

    Python基于jieba, wordcloud庫生成中文詞云

    這篇文章主要介紹了Python基于jieba, wordcloud庫生成中文詞云,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-05-05
  • 深入討論Python函數(shù)的參數(shù)的默認(rèn)值所引發(fā)的問題的原因

    深入討論Python函數(shù)的參數(shù)的默認(rèn)值所引發(fā)的問題的原因

    這篇文章主要介紹了深入討論Python函數(shù)的參數(shù)的默認(rèn)值所引發(fā)的問題的原因,利用了Python解釋器在內(nèi)存地址分配中的過程解釋了參數(shù)默認(rèn)值帶來陷阱的原因,需要的朋友可以參考下
    2015-03-03

最新評論