1

I want to scan a collection of rectangular photos, both color and black-and-white. I am generally quite happy with the scanning, but I run into some practical problems, due to the fact that photos are placed by hand and may not be well aligned with the scanning canvas (or the edges of the scanner)

I assume that my photo has been scanned into a white background rectangle containing the rectangular picture I want, possibly not aligned with the edge of the white rectangle.

Is there an application (preferably running on Linux) that can rotate automatically the scan so that the picture edges are horizontal/vertical? If it also crop out the surrounding white background, it is even better (though proper Unix design would separate this issue).

I know how to do that by hand with Gimp, checking the rotation with my eyes. But I would like to have it done automatically.

To make things clearer with actual images: given the first image below with the irregular white border, I would like to automatically extract the second one, without any surrounding white.

enter image description here               enter image description here

Note: I had to add the dashed-line to show the edges of the first image. If you want to test a proposed solution for the automatic extraction, you should rather use this image.

  • Downvoting is fine, if only you would tell why, which might help solving my problem, or suggest how to explain it better. I am aware of imagemagick (see my tags), but I do not know how to use it for my purpose. – babou Jul 9 '18 at 11:52
  • gimpchat.com/viewtopic.php?f=4&t=14972 ??? – user8779 Jul 9 '18 at 12:29
1

Sounds like you're looking for ImageMagick. This is typically installed by default with a lot of the more popular distros. If not you can use your distros package manager to install it.

Normal image rotation

$ sudo yum install ImageMagick

-or-

$ sudo apt-get install ImageMagick

ImageMagick includes many CLI tools, one of which is convert. Using convert you can rotate images like so:

$ convert -rotate "90" in.jpg out.jpg

There are many more examples on using convert here. The rest of the tools included with ImageMagick can do image editing, scaling, and annotating.

Deskewing

The other method for rotating images that are typically off a bit vertically or horizontally is called deskewing.

From the ImageMagick online command line options help:

-deskew threshold{%}
straighten an image. A threshold of 40% works for most images.

Use -set option:deskew:auto-crop true | false to auto crop the image.

To use this option, you'd use the convert CLI tool that's another of ImageMagicks CLI tools:

 $ convert skewed.jpeg -deskew 40% not_skewed.jpg

References

  • Thanks. I am aware of imagemagick (see my tags), but I do not see how it can help me. My problem is more complex than what you seem to have understood. I added a concrete example to make things clearer. – babou Jul 9 '18 at 12:00
  • 1
    Ah. You want to deskew the image see here stackoverflow.com/q/41546181/33204 – slm Jul 9 '18 at 12:03
  • Thanks again. That seems to be it. I did not know the technical word. Still, I am a bit surprised since skewing normally denotes some kind of distortion, while in this case there is no distortion, only a rotation. Can I be sure it will only rotate my image, witout distorting it? Another point is that this option is not listed on the imagemagick page imagemagick.org/script/convert.php , though it is available on my Linux. Actually, I have some difficulty finding on the web a description or definition of deskew and what it does precisely. I am still looking ... nay suggestion? – babou Jul 9 '18 at 13:16
  • @babou - I believe it's lossless, it looks like it's setting the deskew attribute in the image header itself - imagemagick.org/discourse-server/viewtopic.php?t=29229. – slm Jul 9 '18 at 17:05
  • Is there really a standard deskew attribute, that would contain both the angle of rotation and the center of rotation? But this corresponds to an image that is not aligned with the canvas, i.e. with edges that are not horizontal or vertical. This is odd. Strange also that I cannot find an official definition of deskew in imagemagick, but only forum discussions. – babou Jul 9 '18 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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