Trimming background and isolated pixels
Posted: 2019-10-08T07:52:25-07:00
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:
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:
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?
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
Code: Select all
mogrify -define connected-components:area-threshold=25 \
-define connected-components:mean-color=true \
-connected-components 4 -threshold 50%%\
*.tiff
Are there any other solutions?