原链接:https://jingyan.baidu.com/article/15622f24d5c6bdfdfcbea5e2.html
图像变形,可以归结为像素的坐标变换。
那么,本文使用的是anaconda(python3.6)以及matplotlib模块。
工具/原料
电脑
anaconda(python3.6)
matplotlib模块
方法/步骤
def f(i,j):
return i**2-j**2
def g(i,j):
return 2*i*j
def f(i,j):
return i-j**2
def g(i,j):
return 2*i*j
def f(i,j):
return i**2-j
def g(i,j):
return 2*i*j
def f(i,j):
return i+0.1*np.sin(3*np.pi*j)
def g(i,j):
return j
def f(i,j):
def f(i,j):return i+0.1*np.sin(2*np.pi*j)
def g(i,j):
return j+0.1*np.sin(3*np.pi*i)
END
注意事项
- 最后的代码
import numpy as np
p=np.array([[0,0.],[0,1],[1,1],[1,0]])
q=np.array([[0.3,0.3],[0,1],[1,1],[1,0]])
import matplotlib.image as py
img=py.imread('C:/Users/Administrator/Pictures/0.png')
u,v=img.shape[:2]
def f(i,j):
return i+0.1*np.sin(2*np.pi*j)
def g(i,j):
return j+0.1*np.sin(3*np.pi*i)
M=[]
N=[]
for i in range(u):
for j in range(v):
i0=i/u
j0=j/v
u0=int(f(i0,j0)*512)
v0=int(g(i0,j0)*512)
M.append(u0)
N.append(v0)
m1,m2=max(M),max(N)
n1,n2=min(M),min(N)
r=np.zeros((m1-n1,m2-n2,4))
for i in range(u):
for j in range(v):
i0=i/u
j0=j/v
u0=int(f(i0,j0)*512)-n1-1
v0=int(g(i0,j0)*512)-n2-1
r[u0,v0]=img[i,j]
py.imsave('C:/Users/Administrator/Pictures/1.png',r)