Trimming borders. Nothing seems to work.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jmage

Trimming borders. Nothing seems to work.

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trimming borders. Nothing seems to work.

Post 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.
jmage

Re: Trimming borders. Nothing seems to work.

Post 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.
Last edited by jmage on 2008-12-09T23:11:28-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trimming borders. Nothing seems to work.

Post by fmw42 »

try

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

Re: Trimming borders. Nothing seems to work.

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trimming borders. Nothing seems to work.

Post 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.
Post Reply