Page 1 of 1

Getting info:- out of -trim and deskew

Posted: 2014-06-04T08:42:04-07:00
by aporthog
I want to get the final geometry of an image that has been trimmed and deskewed for use in another program but I can't figure out how to do it. I read this but don't understand the output I am seeing:

http://www.imagemagick.org/Usage/crop/#trim

This documentation tells how to get information out of -trim but doesn't interpret it.

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -trim info:-

out2.tif TIFF 1668x2715 1776x2969+1+113 8-bit sRGB 0.047u 0:00.017
1668x2715 is the final dimensions of the image. What exactly is 1776x2969+1+113? The documentation says it refers to the part that has been trimmed but I have no idea how to interpret that.

What I want to do is get the final geometry of an image after a series of operations. This will happen inside a program so doesn't have to be in a single IM command, but that's always nice if it's possible.

This is the initial image:

Image

After the series of operations I want to get a [w]x[h]+dx+dy coordinates and a rotation with respect to the original.

The first operation is a known initial crop value:

Code: Select all

convert input.tif -crop 1774x2967+336+1491 output.tif
Image

The second operation I tack on is a deskew:

Code: Select all

convert input.tif -crop 1774x2967+336+1491 -background black -deskew 60% output.tif
Image

The last operation is the -trim:

Code: Select all

convert input.tif -crop 1774x2967+336+1491 -background black -deskew 60% -bordercolor black -border 1x1 -fuzz 88% -trim output.tif
Image

So what I want to end up with is the deskew angle to slightly rotate the inital image and the [w]x[h]+dx+dy coordinates of the final image within the original image. I know how to get the deskew angle by putting -print %[deskew:angle] null: at the end of my command, but I'm not sure how to combine that with the other information I need.

Any ideas? The original tiff image is here: http://ucblibrary4.berkeley.edu/~apollo ... /input.tif

Re: Getting info:- out of -trim and deskew

Posted: 2014-06-04T09:58:29-07:00
by fmw42
Add +repage, unless you want to know where the result would be offset from the padded image.

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -trim +repage info:

Also see

http://www.imagemagick.org/script/escape.php

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -trim +repage -format "%O  %P" info:
or

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -format "%@" info:
If those fail, then redirect std err to std out by adding at the end 2>&1