Splicing image with variable height objects on it

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
ibelcomputing
Posts: 2
Joined: 2017-02-13T09:27:44-07:00
Authentication code: 1151

Splicing image with variable height objects on it

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

Re: Splicing image with variable height objects on it

Post 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?
ibelcomputing
Posts: 2
Joined: 2017-02-13T09:27:44-07:00
Authentication code: 1151

Re: Splicing image with variable height objects on it

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

Re: Splicing image with variable height objects on it

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