Page 1 of 1

Splicing image with variable height objects on it

Posted: 2017-02-13T09:40:28-07:00
by ibelcomputing
Suppose we have a picture (several thousand, in fact) with several HTTP DIVs (User forms), all with the same blue header and with one dark gray border around them, stacked one over another over a white background. However, each object is of a different height, so the imagemagick -crop option can't be used with constant values. The width is fixed.

How can one splice each picture in several, each one containing one object?

Re: Splicing image with variable height objects on it

Posted: 2017-02-13T11:27:49-07:00
by fmw42
Can you post an example image? You can upload to some free hosting service such as dropbox.com and put the URL here.

If you are using Imagemagick, please provide your IM version and platform/OS?

Re: Splicing image with variable height objects on it

Posted: 2017-02-13T17:10:35-07:00
by ibelcomputing
Example image:

https://drive.google.com/open?id=0B277G ... WdjaUItMDQ

The contents of each box are arbitrary, so is the number of boxes in the picture.

Using Mac OS Sierra, ImageMagick Version: ImageMagick 6.9.6-5 Q16 x86_64 2016-11-15. Can change or update versions, or use other OSes if necessary.

Re: Splicing image with variable height objects on it

Posted: 2017-02-13T18:19:59-07:00
by fmw42
Scale the image down to 1 column and threshold to b/w. Then save as txt format and search for the start of each black section to the next black section and subtract one (or end of successive white section). Get those coordinates and use them to crop the original image. Or save as png and do successive trims (or -format %@ to get the trim coordinates) and get the trim offsets to use to crop the original image.

Code: Select all

convert fullpage.png -alpha off -colorspace gray -auto-level -scale 1x! -negate -threshold 0 tmp.png
or

Code: Select all

convert fullpage.png -alpha off -colorspace gray -auto-level -scale 1x! -negate -threshold 0 txt:
See %@ at http://www.imagemagick.org/script/escape.php

See txt: at http://www.imagemagick.org/Usage/files/#txt

Note that this only works in this simple way because you have no text in any of the sections.