Split images by white space

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?".
hm2k

Split images by white space

Post by hm2k »

I've an image file with various image objects within which are separated by white space.

It's quite simple as they are rectangle images, stacked with white space between them.

I was interested to know if ImageMagick has a solution to separate or split these image objects into separate image files.

If not, is it possible and what would the best direction be to automate such an action?

Thanks.

User avatar
fmw42
Posts: 25915
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split images by white space

Post by fmw42 »

Post an example. Also see my unix script, multicrop, at the link below.

hm2k

Re: Split images by white space

Post by hm2k »

Here's three objects in an image file separated by white space:

Image

Mission: automatically separate each object into a separate image file, with whitespace trimmed.

Is multicrop able to do this?

Cheers.


User avatar
fmw42
Posts: 25915
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split images by white space

Post by fmw42 »

Yes, my multicrop script should be able to do that quite easily as long as the objects do not have too much white on their edges and into their interior. See the examples that are even rotated on my page as referenced above.

Note it is a unix bash script and does not work directly on windows without Cygwin.

hm2k

Re: Split images by white space

Post by hm2k »

Thanks for your reply.

As you can see there is sufficient whitespace around each object.

I'll be running this on my linux based dev machine.

Can you tell me what arguments I need to pass to tell it to separate the objects into separate files? I can't seem to see the option to do that.

Thanks.

hm2k

Re: Split images by white space

Post by hm2k »

multicrop does not appear to split into multiple files.

I did however come across segment_image

See: http://www.imagemagick.org/Usage/scripts/segment_image

The results here seemed ideal:

viewtopic.php?f=1&t=11705#p37863

However, this resulted in an error:

Code: Select all

[user@blade artwork]# ./segment_image img-1.jpg img-1.gif
convert: Improper image header `-'.
convert: unrecognized option `-reverse'.
Perhaps anthony could help me further... *if* this is the right approach.

Cheers.

User avatar
fmw42
Posts: 25915
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split images by white space

Post by fmw42 »

multicrop p29cE.jpg p29cE_out.jpg

Processing Image 0
Size: 398x136
Page Geometry: 443x540+17+44
Processing Image 1
Size: 404x145
Page Geometry: 443x540+17+222
Processing Image 2
Size: 404x127
Page Geometry: 443x540+20+393


Produces:
p29cE_out-0.jpg, p29cE_out-1.jpg, p29cE_out-2.jpg

Image

Image

Image

hm2k

Re: Split images by white space

Post by hm2k »

Ah, my mistake, I didn't realise it worked quite like that; the man page didn't explain that it would output to multiple files.

However, I've been unable to get it to work so far, I'm getting the following error:

Code: Select all

[user@blade artwork]# ./multicrop p29cE.jpg p29cE_out.jpg
convert: unrecognized option `-quiet'.

--- FILE DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---

...
The file does exist; is an image; is readable and not zero bytes.

snibgo
Posts: 12553
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Split images by white space

Post by snibgo »

Looking at the script, the complaint about the file arose simply because the convert failed. It failed because it didn't recognise "-quiet". What version IM are you running? I suggest you update it.
snibgo's IM pages: im.snibgo.com

hm2k

Re: Split images by white space

Post by hm2k »

Code: Select all

[user@blade artwork]# convert -version
Version: ImageMagick 6.0.7 07/25/08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2004 ImageMagick Studio LLC
What version is required?

snibgo
Posts: 12553
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Split images by white space

Post by snibgo »

I don't know. But your version is six (!) years old. "-quiet" may have been introduced since then, along with other features the script uses.
snibgo's IM pages: im.snibgo.com

hm2k

Re: Split images by white space

Post by hm2k »

No, this is CentOS which uses backporting: http://tinyurl.com/r77l2

Can you recommend a more up to date RPM release for CentOS 4 or RHEL 4 that can be used instead?

Thanks.

snibgo
Posts: 12553
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Split images by white space

Post by snibgo »

Sorry, I wouldn't know.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25915
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split images by white space

Post by fmw42 »

you can remove the -quiet and -regard-warnings from that command line in the script and it should work for that. But since you have such an old version of IM (over 500 versions old), it would really be best to upgrade as there may be other issues of currency in my scripts. I started developing them with IM 6.3.5. So anything earlier than than may have trouble due to upgrades with IM that I counted on in my scripts.

Post Reply