If I am understanding you correctly you want to undistort an image that is not taken straight on. If this is the case then GIMP has great tools for this. The handle transform tool may be best. Also make sure lens correction is applied to remove pincushion or barrel distortion. 4.11. Handle Transform
If working with RAW files or even JPGs then Darktable has good lens correction tool, and perspective control tool to straighten images of paintings. But GIMP should meet your needs.