Help with Trim

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
Pash91
Posts: 15
Joined: 2015-07-09T07:58:48-07:00
Authentication code: 1151

Help with Trim

Post by Pash91 »

Hello, I'm having an issue with trim. I have a set of scanned documents I'm trying to automatically process, but trim doesn't seem to be removing whitespaces from them. I've tried with the borders and with fuzz, but no luck. Any help would be much appreciated. Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with Trim

Post by snibgo »

I'm not sure what you are trying to do.

"-trim" crops by trimming away pixels around the edges that are the same (or similar) colour. Your sample has white edges with a few isolated black pixels. You might de-noise to remove these. Or you might flood-fill with black, then trim away all the black.
snibgo's IM pages: im.snibgo.com
Pash91
Posts: 15
Joined: 2015-07-09T07:58:48-07:00
Authentication code: 1151

Re: Help with Trim

Post by Pash91 »

Thank you, I'll take a look at doing that. Isn't that what fuzz is for though?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with Trim

Post by snibgo »

Black is as far from white as it can be, so you would need "-fuzz 100%", which would remove your image entirely.
snibgo's IM pages: im.snibgo.com
Pash91
Posts: 15
Joined: 2015-07-09T07:58:48-07:00
Authentication code: 1151

Re: Help with Trim

Post by Pash91 »

So, would it be something like this: convert c:\20.png -fuzz 99% -fill white -draw "color 0,0 flood
fill" -trim +repage c:\20.out.png?
Pash91
Posts: 15
Joined: 2015-07-09T07:58:48-07:00
Authentication code: 1151

Re: Help with Trim

Post by Pash91 »

I found this to work well:
convert -density 1200 -deskew 40 20.pdf[0] -deskew 40 -resize 25% +repage t.png;
convert t.png -crop \
`convert t.png -virtual-pixel edge -blur 0x15 -fuzz 20% \
-trim -format '%wx%h%O' info:` +repage 20.png

Is there a way to properly work the deskew into here? Most of my images (without the deskew) are fine, but I can't seem to get some of them that are skewed to deskew correctly.
Pash91
Posts: 15
Joined: 2015-07-09T07:58:48-07:00
Authentication code: 1151

Re: Help with Trim

Post by Pash91 »

I forgot the % for the deskew, that fixed it.
Post Reply