Page 1 of 1

Cut black edges off a book page scan

Posted: 2018-08-08T22:47:54-07:00
by GrazingScientist
Hi everybody,

I am using ImageMagick 7.0.7-38 Q16 x86_64 on a MacOS 10.13.6.

I got thousands of book page scans like this, this and this. You will realize that all these book scans have a black border on 3 edges which varies in size.

I simply want to get rid of (most) of these edges and only get the page. Is this possible with IM?

I already tried things like:

Code: Select all

convert input.jpg -fuzz 10% -trim +repage out.jpg
or

Code: Select all

convert input.jpg -border 1x1 -bordercolor black -fuzz 10% -trim +repage out.jpg
(not perfectly sure on the commands here, but I think you get the idea. Also, the "10%" is only an example. I tried various numbers there.)
And also the MagicWand script from Fred, which is awesome but for a noob like me still a little too far away.

Do you see how I can remove the edges in the given images?

Thanks in advance!

Re: Cut black edges off a book page scan

Posted: 2018-08-09T08:47:42-07:00
by fmw42
Try my multicrop2 script. Use the smallest -f value and the largest -d value that will not remove all regions.


http://www.fmwconcepts.com/misc_tests/m ... 04019.jpeg

Code: Select all

multicrop2 -b "gray(60)" -f 75 -d 1000000  3704019.jpeg 3704019_result.jpg
http://www.fmwconcepts.com/misc_tests/m ... lt-000.jpg

There is going to be some remaining border. But you can use -shave afterwards to remove it.

Re: Cut black edges off a book page scan

Posted: 2018-08-10T00:18:57-07:00
by GrazingScientist
Your result looks amazing! o.O

I tried to reproduce this on my Mac but failed.
I downloaded the script, made it executeable, and applied it as you mentioned above (only with './multicrop2').
I can see that the script is working, because the terminal is busy doing stuff but outputs only three empty lines. When it's done, no result was produced in the same folder. I also tried giving aboslute paths of both input and output file but still nothing is happening. Do I need further scripts from your HP?

Re: Cut black edges off a book page scan

Posted: 2018-08-10T09:39:28-07:00
by fmw42
I don't know what happened, but when I tried it again today, it did not work just as you described. I don't know why, but I must have tried -f 75 and thought it worked, but it is too large a value. The same command seems to work today using -f 50. Try that and let me know.

Re: Cut black edges off a book page scan

Posted: 2018-08-10T11:18:48-07:00
by GrazingScientist
The -f 50 did the trick! SIR! YOU! ARE! AMAZING! Thanks sooooo much!

Re: Cut black edges off a book page scan

Posted: 2018-08-10T12:20:39-07:00
by fmw42
If you want to remove more of the black, since you have a large margin, you can follow up with the Imagemagick command -shave. See https://www.imagemagick.org/Usage/crop/#shave