Displacement map

I am trying to make displacement map for perspective correction, but so far my math goes wrong. [COLOR=#22229c]Here’s[/COLOR] what I’ve got; as you see, some lines are not preserved. Correct math, anybody?