De-warp a curve on a grid (scanned architectural plan)

Here’s an example from a while ago: