batch - Auto-crop black margins dynamically of scanned images?

23
2014-04
  • naxa

    I have a notebook photocopied and the photocopy scanned, about 200 pages. For various reasons I need to print this material. There are large amounts of black areas at the sides of the page (after the page itself ends), "black margins".

    The image looks like this:

    img

    I would like to remove the black places, but keeping all text. * The even and odd pages have the black part at different places. * Notably, there is a white edge outside the black one, too! * Most notably, the black areas has no fixed width (I've tried to overlay all the images for even and odd pages separately). It's width varies. The batch algorythm should be able to detect it.

    Is there a way to remove these black-white margins automatically, keeping the text?

    I can use Windows XP or Linux.

  • Answers
  • Karan

    XnView has a batch processing mode with an auto crop feature:

    1

    As you can see, the colour and the tolerance level can be modified as required, so that may help.

    IrfanView has a similar feature, although it's a bit more hidden. Under Options > Properties/Settings > Browsing/Editing you can set the tolerance value for auto crop borders:

    2

    You can batch auto crop via File > Batch conversion:

    3

    If none of these help then you might have to break out the big guns and use something like Photoshop, perhaps with appropriate auto crop plugins.

  • peanut_butter

    I would recommend using a free utility called Scan Tailor, which removes borders, straightens and does other fixes to scanned images. Below is the result I got with minimal input to your sample file. While it is hard to say how it will work for an entire batch, but the preliminary results seem promising.

    If you are looking for a true scripting solution to the problem you might try your hand at ImageMagick, a very powerful command line utility to work images. Specifically I would look at the sections on removing border and trimming. However I didn't have much luck getting it to work on your test image. You might want to look in the forums, where others seem to have similar issues.

    Sample image post processed by Scan Tailor


  • Related Question

    size - Lilypond: Is there a way to auto-crop the paper
  • Boldewyn

    In Lilypond the paper size can be set to A4, A5, Letter and so forth. However I have only a short song, and I want to embed it lateron. Therefore the output from Lilypond must be cropped somehow.

    Is there a possibility to let Lilypond itself do this? Some setting to the \paper{} block, perhaps?


  • Related Answers
  • thSoft
    • If you want only the first system, you can use the -dpreview command-line option.
    • If you want multiple systems:

      \include "lilypond-book-preamble.ly"

      \paper { oddFooterMarkup = ##f }

    • Have ImageMagick convert autocrop it with the -trim option, e.g. via a shell script.

  • harrymc

    From the Lilypond manual:

    Extra sizes may be added by editing the definition for paper-alist in the initialization file scm/paper.scm.

    You can therefore add your own page sizes to the default ones.

  • Flor

    I managed this with running:

    lilypond -dbackend=eps -dresolution=600 --png FILE.ly
    

    And a paper section within the FILE.ly like this:

    \paper {
      indent = 0\mm
      line-width = 110\mm
      oddHeaderMarkup = ""
      evenHeaderMarkup = ""
      oddFooterMarkup = ""
      evenFooterMarkup = ""
    }