Page 1 of 1

Trimming background and isolated pixels

Posted: 2019-10-08T07:52:25-07:00
by Lodu
Hi!

I'm using IM 7 on a Mac OS 10.12. I'm trying to trim several black and white scanned pages of a book so that I can get rid off the black background. Here are a couple of these images :
- https://drive.google.com/file/d/1k5bQqs ... sp=sharing
- https://drive.google.com/file/d/1J7yYqP ... sp=sharing

I thought I could easily do that with something like that:

Code: Select all

convert image.tif -trim image_cropped.tif
Unfortunately there are a very few isolated white pixels (groups of 1or 2 generally) in the background that are preventing a complete trimming of the pictures... I'm trying to remove these. I tried to adapt some code I found online using connected-components:

Code: Select all

mogrify -define connected-components:area-threshold=25 \
-define connected-components:mean-color=true \
-connected-components 4 -threshold 50%%\
*.tiff
It works fine on text pages but it produces very large files (60 Mo vs 3.9 Mo for the normal files) and it does not work on the plates of the book I scanned because objects are drawn with lots of small dots...

Are there any other solutions?

Re: Trimming background and isolated pixels

Posted: 2019-10-08T08:46:21-07:00
by snibgo
There are many way to denoise an image. When the noise is small dark marks on a light background, we can blur then threshold. This finds the trimmed parameters from a denoised image, and uses those parameters on the input image.

Code: Select all

magick \
  VII-3-Prussing-1982-072.tif \
  \( +clone -blur 0x2 -threshold 50% -set option:MYCROP %@ +delete \) \
  -crop %[MYCROP] \
  out.png

Re: Trimming background and isolated pixels

Posted: 2019-10-09T04:04:05-07:00
by Lodu
Thanks a lot for your answer!

Unfortunately, as these are monochromatic images with only black and white pixels, the blur did not have much effect on the white pixels on the black borders I want to remove... I would like to remove these so that I could just use make an automatic crop with -trim.

Re: Trimming background and isolated pixels

Posted: 2019-10-09T04:21:58-07:00
by snibgo
Did you try the command I showed? It works for me. Resized down for the web:
Image