int vert_steps = 287;
int horz_steps = 388;
double p1_x = 53.5;
double p1_y = 48;
double p2_x = 1203.5;
double p2_y = 52.5;
double p3_x = 52;
double p3_y = 1602.5;
image source;
source.open("tc4 scan.png");
image target;
target.open("tc4 result.png");
target.new(vert_steps+1, horz_steps+1);
double vert_dx = (p2_x - p1_x)/vert_steps;
double vert_dy = (p2_y - p1_y)/vert_steps;
double horz_dx = (p3_x - p1_x)/horz_steps;
double horz_dy = (p3_y - p1_y)/horz_steps;
int loaded_width = source.width;
int loaded_height = source.height;
for x from 0 to vert_steps+1
for y from 0 to horz_steps+1
{
double p_x = p1_x + x * vert_dx + y * horz_dx;
double p_y = p1_y + x * vert_dy + y * horz_dy;
int i_x = floor(p_x + 0.5);
int i_y = floor(p_y + 0.5);
if ( 0 <= i_x && i_x <= loaded_width
&& 0 <= i_y && i_y <= loaded_height)
{
doublecolor col = source.getInterpolatedColour(i_x, i_y);
target.setColour(x, y, col);
}
}
|