Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Math 如何在没有瑕疵的情况下扭曲基于像素的径向渐变?_Math_Image Processing_Distortion_Skew_Radial Gradients - Fatal编程技术网

Math 如何在没有瑕疵的情况下扭曲基于像素的径向渐变?

Math 如何在没有瑕疵的情况下扭曲基于像素的径向渐变?,math,image-processing,distortion,skew,radial-gradients,Math,Image Processing,Distortion,Skew,Radial Gradients,现在,我很难倾斜基于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

现在,我很难倾斜基于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#
目标图像

使用此代码生成的结果


如果有什么不清楚的地方,请告诉我。

我终于找到了解决问题的方法。我所做的是使函数旋转x坐标、y坐标、边界框大小,并使用x坐标和y坐标影响倾斜因子

以下是当前的G'MIC-QT代码供参考。但是很难解释我做了什么

r2dx 200%,3
f "begin(
    sd=max(w,h)/min(w,h);
    sx=w>h?sd:1;
    sy=w>h?1:sd;
    ang=pi*(0/180);
    slx=10;
    sly=10;
    skew_x=.5;
    skew_y=.5;
    nw=abs(w*sin(ang))+abs(h*cos(ang));
    nh=abs(w*cos(ang))+abs(h*sin(ang));
    rot_x(a,b)=a*cos(ang)-b*sin(ang);
    rot_y(a,b)=a*sin(ang)+b*cos(ang);
);
xx=(x/w-.5)*sx;
yy=(y/h-.5)*sy;
mx=((rot_x(xx,yy)/sx)+.5)*w;
my=((rot_y(xx,yy)/sy)+.5)*h;
nx=mx-abs(skew_x)*rot_x(xx,yy)*(skew_x>0?nw-mx:mx);
ny=my-abs(skew_y)*rot_y(xx,yy)*(skew_y>0?nh-my:my);
xx=(nx/w-.5)*2*slx;
yy=(ny/h-.5)*2*sly;
radial=sqrt(xx^2+yy^2);
if(1,sur_atan=1-(atan2(xx,yy)+pi)/(2*pi);,sur_atan=(atan2(xx,yy)+pi)/(2*pi););
es=(sur_atan+radial*1)*1;
es=es-floor(es);
if(0,es=(es>.5?1-es:es)*2;);
i((es^1)*w,radial*h,z,c,2,3);
"
r2dx 50%,3
结果如下: