Page 1 of 2
Split images by white space
Posted: 2010-04-19T15:12:22-07:00
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.
Re: Split images by white space
Posted: 2010-04-19T15:26:44-07:00
by fmw42
Post an example. Also see my unix script, multicrop, at the link below.
Re: Split images by white space
Posted: 2010-04-20T01:55:29-07:00
by hm2k
Here's three objects in an image file separated by white space:
Mission: automatically separate each object into a separate image file, with whitespace trimmed.
Is multicrop able to do this?
Cheers.
Re: Split images by white space
Posted: 2010-04-20T02:28:34-07:00
by Bonzo
Re: Split images by white space
Posted: 2010-04-20T09:10:03-07:00
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.
Re: Split images by white space
Posted: 2010-04-21T01:44:24-07:00
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.
Re: Split images by white space
Posted: 2010-04-21T09:15:19-07:00
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.
Re: Split images by white space
Posted: 2010-04-21T09:21:43-07:00
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

Re: Split images by white space
Posted: 2010-04-21T09:44:48-07:00
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.
Re: Split images by white space
Posted: 2010-04-21T10:23:46-07:00
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.
Re: Split images by white space
Posted: 2010-04-21T10:26:49-07:00
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?
Re: Split images by white space
Posted: 2010-04-21T10:31:03-07:00
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.
Re: Split images by white space
Posted: 2010-04-21T10:50:58-07:00
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.
Re: Split images by white space
Posted: 2010-04-21T10:57:32-07:00
by snibgo
Sorry, I wouldn't know.
Re: Split images by white space
Posted: 2010-04-21T11:21:12-07:00
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.