At the moment, I do have the rectangular polar transform almost ready after I solved some quirks, but one issue do remain - After I move the point from which the transform use as a reference for output, the result goes out of bound.
To explain what is Rectangular Polar Image
Your output is generated from reading pixels going from the direction of these line. The greater the Y-Axis, the farther away from the center it’s going to be. When Y is 1, then the output would show that pixel to be located at the bottom of the image.Treat the X line as pixel scanning, and it is what determines the angle from the center when Y is greater than 0.
Transform Input/Output
To show how the result would look like when the transform affects a image when the centerpoint is located at 0,0 - let’s use a sample image:
Target Image
Transformed Image
The current G’MIC implementation
rep_polar_rectangular_transform:
skip ${1=.5},${2=.5}
f "
begin(
point_x=$1*w;
point_y=$2*h;
inv_point_x=w-point_x;
inv_point_y=h-point_y;
cut_ang_s0=atan2(point_y,inv_point_x)*180/pi;
cut_ang_s1=180-atan2(point_y,point_x)*180/pi;
cut_ang_s2=180+abs(atan2(inv_point_y,point_x)*180/pi);
cut_ang_s3=360-abs(atan2(inv_point_y,inv_point_x)*180/pi);
distanceaway(value)=(
if(value==0,w-point_x?w-point_x:1,
if(value==1,h-point_y?h-point_y:1,
if(value==2,point_x?point_x:1,
if(value==3,point_y?point_y:1
);
);
);
);
);
);
surface_angle=(x/w)*360;
sur_180=surface_angle-180*floor(surface_angle/180+(10^-8));
sur_90=sur_180>90?180-sur_180:sur_180;
if(surface_angle>cut_ang_s0&&surface_angle<=cut_ang_s1,side=1, #Top#
if(surface_angle>cut_ang_s1&&surface_angle<=cut_ang_s2,side=2, #Right#
if(surface_angle>cut_ang_s2&&surface_angle<=cut_ang_s3,side=3, #Bottom#
side=0; #Left#
);
);
);
orientation=side%2;
mdist=orientation?90-sur_90:sur_90;
mdist=1/cos((mdist/180)*pi);
dix=(point_x+cos((surface_angle/180)*pi)*distanceaway(side)*mdist*y/h)*((w-1)/w);
diy=(point_y+sin((surface_angle/180)*pi)*distanceaway(side)*mdist*y/h)*((h-1)/h);
i(dix,diy,z,c,1);
"
That being said, what exactly I’m doing wrong when using point location change. Why it goes out of bound?
EDIT: I fixed it for $1. Not for $2. That means result will be correct with $2=.5. If not, then result will be incorrect.
EDIT: I finally determine the cause of my issue has to do with the mdist line. I would need to figure how to create a gradient based on angle found. After that, this command would work.