Extract Multiple Smaller Images from a Large Image.

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
arpeggio
Posts: 7
Joined: 2013-01-07T06:13:17-07:00
Authentication code: 6789

Extract Multiple Smaller Images from a Large Image.

Post by arpeggio »

Hi Guys,

I have a many large images like the attached.
http://postimg.org/image/yv52hpk0r/

Each Large Image has multiple (1~5) smaller images (sometimes of different size) pasted. All I need to do is extract those smaller images into separate image files, without any white borders is preferred. Can this be done with ImageMagick? & if so how?

I have been playing with fuzz & trim but doesnt seem to have much effect.
Example:
convert Lge_Image.jpg -fuzz 70% -trim +repage +adjoin Sml_Image_%d.jpg

Thank you in advance,
Arpeggio
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract Multiple Smaller Images from a Large Image.

Post by snibgo »

Fred may have a script for this if you use bash.

Trim it, scale to one column, and find the groups of near-white pixels. This gives you the y-coordinates of the positions to crop. After cropping, trim each image.

The file is JPG, so the white areas may not be exctly white.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract Multiple Smaller Images from a Large Image.

Post by snibgo »

Another method, that can be used when the white borders don't cross the entire input image so we can't make simple guillotine cuts:

Turn everything non-white into black, so each subimage is a black rectangle, on a general white background. Use "-connected components" to find them. This directly gives us the crop parameters for the individual pictures.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract Multiple Smaller Images from a Large Image.

Post by fmw42 »

I do not understand the problem given that link. I have a script for unix systems (Linux, Mac OSX and Windows with Cygwin) called multicrop. See my link below.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract Multiple Smaller Images from a Large Image.

Post by snibgo »

I suppose he wants to chop the single linked image into three images. Using a "-connected-components" technique, we get these three:
Image
Image
Image
snibgo's IM pages: im.snibgo.com
Post Reply