Split images by white space
Split images by white space
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Split images by white space
Post an example. Also see my unix script, multicrop, at the link below.
Re: Split images by white space
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.

Mission: automatically separate each object into a separate image file, with whitespace trimmed.
Is multicrop able to do this?
Cheers.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Split images by white space
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.
Note it is a unix bash script and does not work directly on windows without Cygwin.
Re: Split images by white space
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.
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
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:
Perhaps anthony could help me further... *if* this is the right approach.
Cheers.
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'.
Cheers.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Split images by white space
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



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
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:
The file does exist; is an image; is readable and not zero bytes.
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 ---
...
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Split images by white space
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
Re: Split images by white space
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Split images by white space
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
Re: Split images by white space
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.
Can you recommend a more up to date RPM release for CentOS 4 or RHEL 4 that can be used instead?
Thanks.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Split images by white space
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.