Page 1 of 1

Help with Trim

Posted: 2015-07-09T08:06:01-07:00
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

Re: Help with Trim

Posted: 2015-07-09T08:17:35-07:00
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.

Re: Help with Trim

Posted: 2015-07-09T08:21:28-07:00
by Pash91
Thank you, I'll take a look at doing that. Isn't that what fuzz is for though?

Re: Help with Trim

Posted: 2015-07-09T08:31:22-07:00
by snibgo
Black is as far from white as it can be, so you would need "-fuzz 100%", which would remove your image entirely.

Re: Help with Trim

Posted: 2015-07-09T08:32:16-07:00
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?

Re: Help with Trim

Posted: 2015-07-09T10:11:12-07:00
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.

Re: Help with Trim

Posted: 2015-07-09T10:12:52-07:00
by Pash91
I forgot the % for the deskew, that fixed it.