I have devised fairly simple methods for:
Straightening horizons – distorting an image so an arbitrary line becomes straight and horizontal.
Straightening two lines – distorting an image so two arbitrary lines becomes straight and horizontal and parallel to each other.
The “arbitrary lines” can be drawn by hand over a copy of the image with Gimp, or created automatically for example from edges of a photographed page.
The methods can be combined. For example, we can make two opposite sides of a photographed page straight and parallel, and repeat for the other two sides.
The methods use Imagemagick, in Windows BAT scripts. The scripts could be converted to bash or other languages. An enterprising person could convert them to G’MIC commands.
Read more here: Source link