Why not make an horizontal or/and vertical rotation of your image to "change" the origin when calculating your points ? For the margin, choose a number easy to substract or add (10, 20, 30, ...), it won't be too hard...
And, with photoshop, you can "extend your canvas/working zone" (it's a "word by word" translation from my french edition

) to "simulate" your margin size...