How to find a mapping $f:\mathbb{R}^2\to \mathbb{R}^2$ which maps the rectangular region with corners $(x_1,y_1),(x_1,y_2),(x_2,y_1),(x_2,y_2)$ to another rectangular region where $f(x_1,y_1)=(x_1,\frac{y_1+y_2}{2}),f(x_1,y_2)=(\frac{x_1+x_2}{2},y_2),f(x_2,y_2)=(x_2,\frac{y_1+y_2}{2}),$ $f(x_2,y_1)=(\frac{x_1+x_2}{2},y_1)$ ?
Edit:
An illustration of the mapping I am trying to get. The function $f$ should map the gray region in the first image to the gray region in the second. By mapping, I mean a continuous function( guess this will be a contraction)


Here's a simpler approach. As this transformation can be done with a line-preserving mapping, then it has to be a linear mapping. You may therefore write: $$ f(x,y)=(ax+by+c,\ dx+ey+f), $$ where $a$, $b$, $c$, $d$, $e$, $f$ are six constant coefficients to be determined. To find them, you can use the first three given constraints: $$ f(x_1,y_1)=\Big(x_1,\frac{y_1+y_2}{2}\Big), \quad f(x_1,y_2)=\Big(\frac{x_1+x_2}{2},y_2\Big), \quad f(x_2,y_2)=\Big(x_2,\frac{y_1+y_2}{2}\Big). $$ These amount to six linear equations, which can be easily solved to get: $$ a= \frac{1}{2},\ b= \frac{ x_1- x_2}{2( y_1- y_2)},\ c= \frac{x_2 y_1 -x_1 y_2}{2 ( y_1- y_2)},\ d= \frac{ y_2- y_1}{2( x_1- x_2)},\ e= \frac{1}{2},\ f= \frac{x_1 y_1 -x_2 y_2}{2 ( x_1- x_2)}. $$ You can check that the fourth constraint is also satisfied.