Page 1 of 1

Trimming borders. Nothing seems to work.

Posted: 2008-12-09T20:55:05-07:00
by jmage
I have a pdf full of scanned images. I have taken out one image and put it here:

http://i38.tinypic.com/2mhiom9.jpg

I am trying to get rid of the black border around the scanned page (or as much of it as I can).
I know there is a thin white border around the black one.

I try:
convert file.jpg -fuzz 50% -trim +repage out.jpg

And it doesn't even get rid of the white border. I try all different fuzz numbers. I've been trying everything I can but nothing works.

I try
convert file.jpg -bordercolor whilte -border 1x1 -fuzz 80% -trim +repage out.jpg

And it still does nothing.

Can someone tell me what magic I need to use to get rid of both the thin white and thick black borders?

I have read the http://www.imagemagick.org/Usage/crop/#trim and all that works great on the simple images, but nothing works on my images for some reason. I've tried converting them to gif, jpg, tif, etc. They are greyscale tif originally in the PDF.

Help!

Re: Trimming borders. Nothing seems to work.

Posted: 2008-12-09T21:41:19-07:00
by fmw42
convert 2mhiom9.jpg -fuzz 50% -trim -trim tmp.png

You need to trim the white with the first -trim and the black with the second -trim. I am not sure how low you can set the fuzz or you might set the fuzz at two different values before each trim. But at least the above works.

Re: Trimming borders. Nothing seems to work.

Posted: 2008-12-09T22:03:12-07:00
by jmage
I've tried:

convert 2mhiom9.jpg -fuzz 50% -trim -trim -trim -trim -trim tmp.png

And I still have large black borders all around.

I would ideally like all the black around the edge gone (but not on the scanned text document in the middle) since it is a toner killer when printing.

An option that could "convert all areas of black that are of atleast WxH size (or some radius)o f consistent blackness and all adjacent blackness (with fuzziness factor) to white", like a flood fill with fuzziness, but first automatically finding the areas to flood.

convert "file.pdf" -bordercolor black -border 1x1 -fill white -fuzz 5% -floodfill +0+0 black -shave 1x1
Sort of works, but the resulting pdf is in much lower quality (and is much larger). I need to retain original quality somehow.

Re: Trimming borders. Nothing seems to work.

Posted: 2008-12-09T23:11:20-07:00
by fmw42
try

convert 2mhiom9.jpg -fuzz 50% -trim -trim -trim -trim -trim -fill white -opaque black tmp.png

Re: Trimming borders. Nothing seems to work.

Posted: 2008-12-09T23:17:49-07:00
by jmage
That's a bit too aggressive since the original scanned text in the middle has black spots that become white.

I edited my previous post with the floodfill option. Retaining original pdf image quality and small filesize is my next hurdle. Thanks for the pointers.

Re: Trimming borders. Nothing seems to work.

Posted: 2008-12-09T23:52:23-07:00
by fmw42
After trimming, you can unrotate the image. See my unrotate script at http://www.fmwconcepts.com/imagemagick/index.html

or try IM -deskew

That could help get rid of some of the black border. My magicwand script may also be of some use changing colors only around the border. You may have to add a small border to ensure the black is all around the image after removing the white border.