2
\$\begingroup\$

I have a photograph of a printed document that I made for lack of easy access to a flatbed scanner at the time and place I had easy access to the document (in case you ask, the document was sent to me and this is all legit but I needed the image quickly and I didnt have a scanner at hand).

Now of course the camera lens has some geometry error, line straightness aberration or whatever would be the correct term to retrieve the answer I am looking for, that I would like corrected in an easy fashion (definitely not looking for a coding solution here).

(There is also some lighting problem particularly in the corners of the picture but this is about the geometry thing as well and first of all.)

I recall that in an answer in "that" QA - which IIRC largely focused around a manual process with GIMP involving averaging and masking or something to do adaptive thresholding (IIRC without calling it so) -

someone recommended using some one-stop-shop type linux software that was named something about easy and scanning or something because it could also do lighting correction in photos as well as flatbed scans.

(I may be wrong in that it was really the same QA but I think it was. Also, I did download and use that software back then but that was a number of computers ago and it seems the downloaded package is gone because I didn't have a constant need for it and life happened and now I just can't find it, or any usable trace of it, for that matter.)

The workings of that software was you just load the picture you got and go through IIRC five steps without needing much skill but receive impressive results impressively easily just by going through the steps, like in a wizard type software.

Basically you just put in something camera-wise fairly botched image that you wish it were a clean PDF and you get just that.

All other info I remember is it was definitely on a Linux system and I think it was free and libre software or at the very least very close to that.

BTW there is some impressive commandline software solution (which is not that) for adaptive thresholding mentioned in stackoverflow 1811800 using ImageMagick -lat but that's a completely different beast and not doing geometry correction.

Also, the software in question maybe could be started from the commandline (duh) but in itself it was all GUI.

Any help appreciated finding that QA or that software.

\$\endgroup\$
2
  • \$\begingroup\$ I remember something baked in microsoft office for android. If you go into that app and on the bottom there is an actions button. Then either scan to pdf or pictures to pdf. I think it did it somewhat automatic. I only used the feature once, but thought it was neat. \$\endgroup\$
    – gns100
    Commented Jun 28, 2022 at 14:31
  • \$\begingroup\$ There is a Software Recommendations site, and for popular graphic software like GIMP or Adobe Photoshop, those questions could probably be asked on Graphic Design. Also, the site list is text searchable for me. \$\endgroup\$
    – jaskij
    Commented Jun 28, 2022 at 16:40

4 Answers 4

9
\$\begingroup\$

Look like Gimp, which was born on Linux but also has versions for Windows and OSX these days.

If your problem is to fix something like this:

enter image description here

Then you just start the Perspective tool, set it to Corrective mode, and align its 4 handles with the 4 corners of the document:

enter image description here

Then run the tool:

enter image description here

You will note that the tool doesn't respect the aspect ratio of the original document (because AFAIK there is no way to tell from just the picture), but if it's a standard document (Legal, Letter, A4) you already know its size, so you can use Image > Scale Image to fix this (very often you need to scale your photo anyway, it is usually too big to be usable in a document or a web site). The input fields will do the math for you (here, I know that the input document is A4, so its aspect ratio is 1.414):

enter image description here

Which gives:

enter image description here

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Worth noting: the lensfun plugin might also be useful in your example. The inwardly curved borders suggest a bit of lens distortion that has not been corrected. (Do that first!) \$\endgroup\$
    – Matthew
    Commented Jun 28, 2022 at 14:52
  • \$\begingroup\$ A bit of practical experimentation hints that the added complexity isn't really worth it, with this kind of "casual" shooting the distortions coming from a document not completely flat are somewhat more visible than those from the lens. I also had to redo my shots since lensfun had no data for my first lens (Canon EFS-35mm Macro). \$\endgroup\$
    – xenoid
    Commented Jun 28, 2022 at 20:12
  • \$\begingroup\$ Ah, that's a good point. And the OP probably doesn't have a convenient sheet of glass or other way to force the subject material to be flat. \$\endgroup\$
    – Matthew
    Commented Jun 28, 2022 at 20:25
  • \$\begingroup\$ @Matthew the borders do look curved, but I think it came from the image manipulation. Holding a straight edge against the original image seems to show the edge of the paper and the printed border are both straight. \$\endgroup\$
    – FreeMan
    Commented Jun 30, 2022 at 17:52
0
\$\begingroup\$

While it sounds like you are looking for a PC solution, I thought perhaps I'd share how I'd do that on my iPhone/iPad when I'm away from my computer and can't use Photoshop.

On my iPhone I use this app... Scanner Pro-OCR Scanning & Fax 4+ by Readdle Technologies Limited

Once you import images from your photo stream into a new document you can edit the skew.

I use it frequently for scanning documents. When photographed against a contrasting background (example: white paper on a black desk) it automatically finds the corners.

\$\endgroup\$
0
\$\begingroup\$

Lightroom Classic can do this. In the Develop module select the Transform panel. There is an auto mode but for photographing quilts I use Guided. You then click two points along each side of the document and it makes it rectangular. I don't think it gives control over the aspect ratio. I would go into Photoshop if I wanted that to be exact. Once you have it rectangular, which I find much easier in Lightroom, Edit->Transform will let you match it to guide lines that are at the correct positions.

\$\endgroup\$
0
\$\begingroup\$

You can do this with darktable.

This is the image I am using as an example.

After importing and double-clicking the image, the darkroom view will look like this:

darkroom view of a freshly imported image in darktable

Now on the right, find the module "rotate and perspective":

"rotate and perspective" module

Beside "structure" you have three options: the leftmost allows you to draw guide lines, the middle one allows you to draw a rectangle, the rightmost is the one you should try first: it automatically tries to detect straight lines. If this doesn't yield blue and green lines on the edges of your document, then use the middle option to draw a rectangle along them instead; the following steps will be the same.

result of clicking the button to automatically analyze the line structure

Then beside "fit" you have three options, for the problem asked about in this question you want the rightmost which corrects both horizontally and vertically.

perspective-corrected image

Now all you need to do is crop the image, which you can do using the "crop" module: after opening it, drag the edges of your image to where you want them, then close the "crop" module by clicking on it.

cropped image

On the left hand side, you can now export the image with whatever configuration you want.

darktable export dialog

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.