【发布时间】:2019-11-21 22:12:53
【问题描述】:
现在,我无法倾斜基于 sqrt(x^2+y^2) 的径向渐变。我想要的是与 Illustrator 具有相同方式的平滑倾斜,但用于与失真相关的像素图像处理。
我尝试应用倾斜的径向渐变来进行失真如下所示:
Description of filter - Use Spiral gradient for finding the x-location of image, and radial gradient for finding y-location.
Then use the values that are found in order to distort the image.
Scripting Language - G'MIC-QT
x is x-location of pixel within for loop
y is y-location of pixel within for loop
w is width
h is height
foo:
r2dx 200%,3#Resize Image using linear interpolation. Used for subpixel processing#
f "begin(
sd=max(w,h)/min(w,h); #Divide the biggest side by the smallest size.#
sx=w>h?sd:1; #Find x-scale to scale x-coordinate#
sy=w>h?1:sd; #Find y-scale to scale y-coordinate#
ang=pi*(0/180); #Convert angle to radian. 0 next to /180 is the function angle.#
slx=2; #Scale of x-coordinate#
sly=2; #Scale of y-coordinate#
skew_x=.15; #Offset x-skewing#
skew_y=.15; #Offset y-skewing#
skew_ang=atan2(skew_y,skew_x)+pi/2; #Find skew angle#
skew_fact=sqrt(skew_x^2+skew_y^2); #Find multiplier for skewing#
srot_x(a,b)=a*cos(skew_ang)-b*sin(skew_ang); #Function for rotating the skewing function#
srot_y(a,b)=a*sin(skew_ang)+b*cos(skew_ang); #Function for rotating the skewing function#
rot_x(a,b)=a*cos(ang)-b*sin(ang); #Distortion Angle Function#
rot_y(a,b)=a*sin(ang)+b*cos(ang); #Distortion Angle Function#
);
XX=(x/w-.5)*2*sx*slx; #Convert x into -1,1 range if image is a square#
YY=(y/h-.5)*2*sy*sly; #Convert y into -1,1 range if image is a square#
SXX=(x/w-.5)*2*sx*slx; #Convert x into -1,1 range if image is a square. Used for skewing!#
SYY=(y/h-.5)*2*sy*sly; #Convert y into -1,1 range if image is a square. Used for skewing!#
xx=rot_x(XX,YY); #Rotation of function#
yy=rot_y(XX,YY); #Rotation of function#
sxx=srot_x(SXX,SYY)*sx*slx; #Rotation of skewing function#
syy=srot_y(SXX,SYY)*sy*sly; #Rotation of skewing function#
skew_atan=atan2(abs(sxx),syy)*skew_fact*sqrt(sxx^2+syy^2);#Generate Skewing Function#
radial=sqrt(xx^2+yy^2)*1+skew_atan; #Combine radial gradient with skewing Function#
if(1,sur_atan=1-(atan2(xx,yy)+pi)/(2*pi);,sur_atan=(atan2(xx,yy)+pi)/(2*pi););#Determine direction of spiral#
es=(sur_atan+radial*1)*1; #Part 1 of Spiral Gradient#
es=es-floor(es); #Part 2 of Spiral#
if(0,es=(es>.5?1-es:es)*2;); #If true, then spiral is continuous, else spiral is non-continuous#
i((es^1)*w,radial*h,z,c,2,3);#i(x-location,y-location,z-location,channel_numbers,interpolation,boundary); The i means image.#
"
r2dx 50%,3 #Resize Image using linear interpolation. Used for subpixel processing#
目标图片
使用此代码的结果
如果有任何不清楚的地方,请告诉我。
【问题讨论】:
标签: math image-processing distortion skew radial-gradients